Skip to content

Commit da98c20

Browse files
committed
[Discover] Add grid flyout jest test (#89088)
1 parent 0642909 commit da98c20

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* and the Server Side Public License, v 1; you may not use this file except in
5+
* compliance with, at your election, the Elastic License or the Server Side
6+
* Public License, v 1.
7+
*/
8+
9+
import React from 'react';
10+
import { findTestSubject } from '@elastic/eui/lib/test';
11+
import { mountWithIntl } from '@kbn/test/jest';
12+
import { DiscoverGridFlyout } from './discover_grid_flyout';
13+
import { esHits } from '../../../__mocks__/es_hits';
14+
import { createFilterManagerMock } from '../../../../../data/public/query/filter_manager/filter_manager.mock';
15+
import { indexPatternMock } from '../../../__mocks__/index_pattern';
16+
import { DiscoverServices } from '../../../build_services';
17+
import { DocViewsRegistry } from '../../doc_views/doc_views_registry';
18+
import { setDocViewsRegistry } from '../../../kibana_services';
19+
import { indexPatternWithTimefieldMock } from '../../../__mocks__/index_pattern_with_timefield';
20+
21+
describe('Discover flyout', function () {
22+
setDocViewsRegistry(new DocViewsRegistry());
23+
24+
it('should be rendered correctly using an index pattern without timefield', async () => {
25+
const onClose = jest.fn();
26+
const component = mountWithIntl(
27+
<DiscoverGridFlyout
28+
columns={['date']}
29+
indexPattern={indexPatternMock}
30+
hit={esHits[0]}
31+
onAddColumn={jest.fn()}
32+
onClose={onClose}
33+
onFilter={jest.fn()}
34+
onRemoveColumn={jest.fn()}
35+
services={({ filterManager: createFilterManagerMock() } as unknown) as DiscoverServices}
36+
/>
37+
);
38+
39+
const url = findTestSubject(component, 'docTableRowAction').prop('href');
40+
expect(url).toMatchInlineSnapshot(`"#/doc/the-index-pattern-id/i?id=1"`);
41+
findTestSubject(component, 'euiFlyoutCloseButton').simulate('click');
42+
expect(onClose).toHaveBeenCalled();
43+
});
44+
45+
it('should be rendered correctly using an index pattern with timefield', async () => {
46+
const onClose = jest.fn();
47+
const component = mountWithIntl(
48+
<DiscoverGridFlyout
49+
columns={['date']}
50+
indexPattern={indexPatternWithTimefieldMock}
51+
hit={esHits[0]}
52+
onAddColumn={jest.fn()}
53+
onClose={onClose}
54+
onFilter={jest.fn()}
55+
onRemoveColumn={jest.fn()}
56+
services={({ filterManager: createFilterManagerMock() } as unknown) as DiscoverServices}
57+
/>
58+
);
59+
60+
const actions = findTestSubject(component, 'docTableRowAction');
61+
expect(actions.length).toBe(2);
62+
expect(actions.first().prop('href')).toMatchInlineSnapshot(
63+
`"#/doc/index-pattern-with-timefield-id/i?id=1"`
64+
);
65+
expect(actions.last().prop('href')).toMatchInlineSnapshot(
66+
`"#/context/index-pattern-with-timefield-id/1?_g=(filters:!())&_a=(columns:!(date),filters:!())"`
67+
);
68+
findTestSubject(component, 'euiFlyoutCloseButton').simulate('click');
69+
expect(onClose).toHaveBeenCalled();
70+
});
71+
});

0 commit comments

Comments
 (0)