From 5e6986f7985983cf2076c129d4741f9e09a59649 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 25 Jan 2021 09:41:43 +0100 Subject: [PATCH 1/2] Add jest test --- .../discover_grid_flyout.test.tsx | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/plugins/discover/public/application/components/discover_grid/discover_grid_flyout.test.tsx diff --git a/src/plugins/discover/public/application/components/discover_grid/discover_grid_flyout.test.tsx b/src/plugins/discover/public/application/components/discover_grid/discover_grid_flyout.test.tsx new file mode 100644 index 00000000000000..5ba763046668c2 --- /dev/null +++ b/src/plugins/discover/public/application/components/discover_grid/discover_grid_flyout.test.tsx @@ -0,0 +1,39 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * and the Server Side Public License, v 1; you may not use this file except in + * compliance with, at your election, the Elastic License or the Server Side + * Public License, v 1. + */ + +import React from 'react'; +import { findTestSubject } from '@elastic/eui/lib/test'; +import { mountWithIntl } from '@kbn/test/jest'; +import { DiscoverGridFlyout } from './discover_grid_flyout'; +import { esHits } from '../../../__mocks__/es_hits'; +import { createFilterManagerMock } from '../../../../../data/public/query/filter_manager/filter_manager.mock'; +import { indexPatternMock } from '../../../__mocks__/index_pattern'; +import { DiscoverServices } from '../../../build_services'; +import { DocViewsRegistry } from '../../doc_views/doc_views_registry'; +import { setDocViewsRegistry } from '../../../kibana_services'; + +describe('Discover flyout', function () { + it('should be rendered', async () => { + setDocViewsRegistry(new DocViewsRegistry()); + const component = mountWithIntl( + + ); + + const url = findTestSubject(component, 'docTableRowAction').prop('href'); + expect(url).toMatchInlineSnapshot(`"#/doc/the-index-pattern-id/i?id=1"`); + }); +}); From 5a3b95cc45f0ecd47530022849bdab90220e3355 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Tue, 26 Jan 2021 12:11:52 +0100 Subject: [PATCH 2/2] Improve test --- .../discover_grid_flyout.test.tsx | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/plugins/discover/public/application/components/discover_grid/discover_grid_flyout.test.tsx b/src/plugins/discover/public/application/components/discover_grid/discover_grid_flyout.test.tsx index 5ba763046668c2..f9428e30569f7e 100644 --- a/src/plugins/discover/public/application/components/discover_grid/discover_grid_flyout.test.tsx +++ b/src/plugins/discover/public/application/components/discover_grid/discover_grid_flyout.test.tsx @@ -16,17 +16,20 @@ import { indexPatternMock } from '../../../__mocks__/index_pattern'; import { DiscoverServices } from '../../../build_services'; import { DocViewsRegistry } from '../../doc_views/doc_views_registry'; import { setDocViewsRegistry } from '../../../kibana_services'; +import { indexPatternWithTimefieldMock } from '../../../__mocks__/index_pattern_with_timefield'; describe('Discover flyout', function () { - it('should be rendered', async () => { - setDocViewsRegistry(new DocViewsRegistry()); + setDocViewsRegistry(new DocViewsRegistry()); + + it('should be rendered correctly using an index pattern without timefield', async () => { + const onClose = jest.fn(); const component = mountWithIntl( { + const onClose = jest.fn(); + const component = mountWithIntl( + + ); + + const actions = findTestSubject(component, 'docTableRowAction'); + expect(actions.length).toBe(2); + expect(actions.first().prop('href')).toMatchInlineSnapshot( + `"#/doc/index-pattern-with-timefield-id/i?id=1"` + ); + expect(actions.last().prop('href')).toMatchInlineSnapshot( + `"#/context/index-pattern-with-timefield-id/1?_g=(filters:!())&_a=(columns:!(date),filters:!())"` + ); + findTestSubject(component, 'euiFlyoutCloseButton').simulate('click'); + expect(onClose).toHaveBeenCalled(); }); });