-
Notifications
You must be signed in to change notification settings - Fork 8.2k
/
page_template.test.tsx
213 lines (169 loc) · 7.17 KB
/
page_template.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { setMockValues } from '../../__mocks__/kea_logic';
import React from 'react';
import { shallow } from 'enzyme';
import { EuiCallOut } from '@elastic/eui';
import { KibanaPageTemplate } from '../../../../../../../src/plugins/kibana_react/public';
import { FlashMessages } from '../flash_messages';
import { Loading } from '../loading';
import { EnterpriseSearchPageTemplate } from './page_template';
describe('EnterpriseSearchPageTemplate', () => {
beforeEach(() => {
jest.clearAllMocks();
setMockValues({ readOnlyMode: false });
});
it('renders', () => {
const wrapper = shallow(<EnterpriseSearchPageTemplate />);
expect(wrapper.type()).toEqual(KibanaPageTemplate);
});
it('renders children', () => {
const wrapper = shallow(
<EnterpriseSearchPageTemplate>
<div className="hello">world</div>
</EnterpriseSearchPageTemplate>
);
expect(wrapper.find('.hello').text()).toEqual('world');
});
describe('loading state', () => {
it('renders a loading icon in place of children', () => {
const wrapper = shallow(
<EnterpriseSearchPageTemplate isLoading>
<div className="test" />
</EnterpriseSearchPageTemplate>
);
expect(wrapper.find(Loading).exists()).toBe(true);
expect(wrapper.find('.test').exists()).toBe(false);
});
it('renders children & does not render a loading icon when the page is done loading', () => {
const wrapper = shallow(
<EnterpriseSearchPageTemplate isLoading={false}>
<div className="test" />
</EnterpriseSearchPageTemplate>
);
expect(wrapper.find(Loading).exists()).toBe(false);
expect(wrapper.find('.test').exists()).toBe(true);
});
});
describe('empty state', () => {
it('renders a custom empty state in place of children', () => {
const wrapper = shallow(
<EnterpriseSearchPageTemplate
isEmptyState
emptyState={<div className="emptyState">Nothing here yet!</div>}
>
<div className="test" />
</EnterpriseSearchPageTemplate>
);
expect(wrapper.find('.emptyState').exists()).toBe(true);
expect(wrapper.find('.test').exists()).toBe(false);
// @see https://github.com/elastic/kibana/blob/master/dev_docs/tutorials/kibana_page_template.mdx#isemptystate
// if you want to use KibanaPageTemplate's `isEmptyState` without a custom emptyState
});
it('does not render the custom empty state if the page is not empty', () => {
const wrapper = shallow(
<EnterpriseSearchPageTemplate
isEmptyState={false}
emptyState={<div className="emptyState">Nothing here yet!</div>}
>
<div className="test" />
</EnterpriseSearchPageTemplate>
);
expect(wrapper.find('.emptyState').exists()).toBe(false);
expect(wrapper.find('.test').exists()).toBe(true);
});
it('does not render an empty state if the page is still loading', () => {
const wrapper = shallow(
<EnterpriseSearchPageTemplate
isLoading
isEmptyState
emptyState={<div className="emptyState" />}
/>
);
expect(wrapper.find(Loading).exists()).toBe(true);
expect(wrapper.find('.emptyState').exists()).toBe(false);
});
});
describe('read-only mode', () => {
it('renders a callout if in read-only mode', () => {
setMockValues({ readOnlyMode: true });
const wrapper = shallow(<EnterpriseSearchPageTemplate />);
expect(wrapper.find(EuiCallOut).exists()).toBe(true);
});
it('does not render a callout if not in read-only mode', () => {
setMockValues({ readOnlyMode: false });
const wrapper = shallow(<EnterpriseSearchPageTemplate />);
expect(wrapper.find(EuiCallOut).exists()).toBe(false);
});
});
describe('flash messages', () => {
it('renders FlashMessages by default', () => {
const wrapper = shallow(<EnterpriseSearchPageTemplate />);
expect(wrapper.find(FlashMessages).exists()).toBe(true);
});
it('does not render FlashMessages if hidden', () => {
// Example use case: manually showing flash messages in an open flyout or modal
// and not wanting to duplicate flash messages on the overlayed page
const wrapper = shallow(<EnterpriseSearchPageTemplate hideFlashMessages />);
expect(wrapper.find(FlashMessages).exists()).toBe(false);
});
});
describe('page chrome', () => {
const SetPageChrome = () => <div />;
it('renders a product-specific <SetPageChrome />', () => {
const wrapper = shallow(<EnterpriseSearchPageTemplate setPageChrome={<SetPageChrome />} />);
expect(wrapper.find(SetPageChrome).exists()).toBe(true);
});
it('invokes page chrome immediately (without waiting for isLoading to be finished)', () => {
const wrapper = shallow(
<EnterpriseSearchPageTemplate setPageChrome={<SetPageChrome />} isLoading />
);
expect(wrapper.find(SetPageChrome).exists()).toBe(true);
// This behavior is in contrast to page view telemetry, which is invoked after isLoading finishes
// In addition to the pageHeader prop also changing immediately, this makes navigation feel much snappier
});
});
describe('EuiPageTemplate props', () => {
it('overrides the restrictWidth prop', () => {
const wrapper = shallow(<EnterpriseSearchPageTemplate restrictWidth />);
expect(wrapper.find(KibanaPageTemplate).prop('restrictWidth')).toEqual(true);
});
it('passes down any ...pageTemplateProps that EuiPageTemplate accepts', () => {
const wrapper = shallow(
<EnterpriseSearchPageTemplate
template="empty"
paddingSize="s"
pageHeader={{ pageTitle: 'hello world' }}
/>
);
expect(wrapper.find(KibanaPageTemplate).prop('template')).toEqual('empty');
expect(wrapper.find(KibanaPageTemplate).prop('paddingSize')).toEqual('s');
expect(wrapper.find(KibanaPageTemplate).prop('pageHeader')!.pageTitle).toEqual('hello world');
});
it('sets enterpriseSearchPageTemplate classNames while still accepting custom classNames', () => {
const wrapper = shallow(
<EnterpriseSearchPageTemplate className="hello" pageContentProps={{ className: 'world' }} />
);
expect(wrapper.find(KibanaPageTemplate).prop('className')).toEqual(
'enterpriseSearchPageTemplate hello'
);
expect(wrapper.find(KibanaPageTemplate).prop('pageContentProps')!.className).toEqual(
'enterpriseSearchPageTemplate__content world'
);
});
it('automatically sets the Enterprise Search logo onto passed solution navs', () => {
const wrapper = shallow(
<EnterpriseSearchPageTemplate solutionNav={{ name: 'Enterprise Search', items: [] }} />
);
expect(wrapper.find(KibanaPageTemplate).prop('solutionNav')).toEqual({
icon: 'logoEnterpriseSearch',
name: 'Enterprise Search',
items: [],
});
});
});
});