@axinom/mosaic-ui 0.32.0-rc.5 → 0.32.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/components/Actions/Action/Action.d.ts.map +1 -1
  2. package/dist/components/Buttons/Button/Button.d.ts +9 -10
  3. package/dist/components/Buttons/Button/Button.d.ts.map +1 -1
  4. package/dist/components/Buttons/Button/Button.model.d.ts +21 -0
  5. package/dist/components/Buttons/Button/Button.model.d.ts.map +1 -0
  6. package/dist/components/Buttons/Button/index.d.ts +3 -0
  7. package/dist/components/Buttons/Button/index.d.ts.map +1 -0
  8. package/dist/components/Buttons/Button.model.d.ts +69 -7
  9. package/dist/components/Buttons/Button.model.d.ts.map +1 -1
  10. package/dist/components/Buttons/CompositeButton/CompositeButton.d.ts +5 -14
  11. package/dist/components/Buttons/CompositeButton/CompositeButton.d.ts.map +1 -1
  12. package/dist/components/Buttons/CompositeButton/CompositeButton.model.d.ts +20 -0
  13. package/dist/components/Buttons/CompositeButton/CompositeButton.model.d.ts.map +1 -0
  14. package/dist/components/Buttons/CompositeButton/index.d.ts +3 -0
  15. package/dist/components/Buttons/CompositeButton/index.d.ts.map +1 -0
  16. package/dist/components/Buttons/TextButton/TextButton.d.ts +5 -9
  17. package/dist/components/Buttons/TextButton/TextButton.d.ts.map +1 -1
  18. package/dist/components/Buttons/TextButton/TextButton.model.d.ts +18 -0
  19. package/dist/components/Buttons/TextButton/TextButton.model.d.ts.map +1 -0
  20. package/dist/components/Buttons/TextButton/index.d.ts +3 -0
  21. package/dist/components/Buttons/TextButton/index.d.ts.map +1 -0
  22. package/dist/components/Buttons/index.d.ts +3 -3
  23. package/dist/components/Buttons/index.d.ts.map +1 -1
  24. package/dist/components/Explorer/Explorer.d.ts.map +1 -1
  25. package/dist/components/Explorer/NavigationExplorer/NavigationExplorer.d.ts +3 -2
  26. package/dist/components/Explorer/NavigationExplorer/NavigationExplorer.d.ts.map +1 -1
  27. package/dist/components/FormElements/ToggleButton/ToggleButton.d.ts +2 -2
  28. package/dist/components/FormElements/ToggleButton/ToggleButton.d.ts.map +1 -1
  29. package/dist/components/List/ListRow/ListRow.d.ts.map +1 -1
  30. package/dist/components/PageHeader/PageHeaderAction/PageHeaderAction.d.ts.map +1 -1
  31. package/dist/components/models.d.ts +5 -2
  32. package/dist/components/models.d.ts.map +1 -1
  33. package/dist/index.es.js +3 -3
  34. package/dist/index.es.js.map +1 -1
  35. package/dist/index.js +3 -3
  36. package/dist/index.js.map +1 -1
  37. package/package.json +3 -3
  38. package/src/components/Actions/Action/Action.spec.tsx +14 -0
  39. package/src/components/Actions/Action/Action.tsx +5 -2
  40. package/src/components/Buttons/Button/Button.model.ts +30 -0
  41. package/src/components/Buttons/Button/Button.scss +3 -1
  42. package/src/components/Buttons/Button/Button.spec.tsx +254 -83
  43. package/src/components/Buttons/Button/Button.stories.tsx +20 -0
  44. package/src/components/Buttons/Button/Button.tsx +103 -32
  45. package/src/components/Buttons/Button/index.ts +2 -0
  46. package/src/components/Buttons/Button.model.ts +84 -9
  47. package/src/components/Buttons/CompositeButton/CompositeButton.model.ts +32 -0
  48. package/src/components/Buttons/CompositeButton/CompositeButton.scss +6 -1
  49. package/src/components/Buttons/CompositeButton/CompositeButton.spec.tsx +277 -89
  50. package/src/components/Buttons/CompositeButton/CompositeButton.stories.tsx +20 -0
  51. package/src/components/Buttons/CompositeButton/CompositeButton.tsx +94 -30
  52. package/src/components/Buttons/CompositeButton/index.ts +2 -0
  53. package/src/components/Buttons/TextButton/TextButton.model.ts +27 -0
  54. package/src/components/Buttons/TextButton/TextButton.scss +3 -1
  55. package/src/components/Buttons/TextButton/TextButton.spec.tsx +198 -87
  56. package/src/components/Buttons/TextButton/TextButton.stories.tsx +20 -0
  57. package/src/components/Buttons/TextButton/TextButton.tsx +74 -20
  58. package/src/components/Buttons/TextButton/index.ts +2 -0
  59. package/src/components/Buttons/index.ts +3 -6
  60. package/src/components/Explorer/Explorer.tsx +2 -2
  61. package/src/components/Explorer/NavigationExplorer/NavigationExplorer.tsx +4 -3
  62. package/src/components/FormElements/CustomTags/CustomTags.spec.tsx +26 -16
  63. package/src/components/FormElements/ToggleButton/ToggleButton.tsx +2 -2
  64. package/src/components/List/ListRow/ListRow.tsx +18 -13
  65. package/src/components/PageHeader/PageHeaderAction/PageHeaderAction.spec.tsx +513 -388
  66. package/src/components/PageHeader/PageHeaderAction/PageHeaderAction.tsx +11 -7
  67. package/src/components/models.ts +5 -2
@@ -1,14 +1,15 @@
1
1
  import { mount, shallow } from 'enzyme';
2
2
  import React from 'react';
3
3
  import { act } from 'react-dom/test-utils';
4
+ import { Link, BrowserRouter as Router } from 'react-router-dom';
4
5
  import { noop } from '../../../helpers/utils';
5
6
  import { TextButton } from '../../Buttons';
6
7
  import { ConfirmationConfig, ConfirmDialog } from '../../ConfirmDialog';
7
8
  import { IconName } from '../../Icons';
8
9
  import {
10
+ PageHeaderAction,
9
11
  isPageHeaderJsAction,
10
12
  isPageHeaderNavigationAction,
11
- PageHeaderAction,
12
13
  } from './PageHeaderAction';
13
14
  import {
14
15
  PageHeaderActionProps,
@@ -21,515 +22,639 @@ const defaultProps: PageHeaderActionProps = {
21
22
  };
22
23
 
23
24
  describe('PageHeaderAction', () => {
24
- it('renders the component without crashing', () => {
25
- const wrapper = shallow(<PageHeaderAction {...defaultProps} />);
26
-
27
- expect(wrapper).toBeTruthy();
28
- });
29
-
30
- it('renders a label', () => {
31
- const mockLabel = 'test-label';
32
- const wrapper = mount(
33
- <PageHeaderAction {...defaultProps} label={mockLabel} />,
34
- );
35
-
36
- const label = wrapper.find('span');
37
-
38
- expect(label.text()).toBe(mockLabel);
39
- });
40
-
41
- it('renders a Icon, if set', () => {
42
- const mockLabel = 'test-label';
43
- const wrapper = mount(
44
- <PageHeaderAction
45
- {...defaultProps}
46
- label={mockLabel}
47
- icon={IconName.ChevronRight}
48
- />,
49
- );
50
-
51
- const Icon = wrapper.find('.icons');
52
-
53
- expect(Icon.exists()).toBe(true);
54
- });
25
+ describe('PageHeaderJSAction', () => {
26
+ it('renders the component without crashing', () => {
27
+ const wrapper = shallow(<PageHeaderAction {...defaultProps} />);
55
28
 
56
- it('image is used instead of icon if icon prop is a string', () => {
57
- const mockLabel = 'test-label';
58
- const wrapper = mount(
59
- <PageHeaderAction
60
- {...defaultProps}
61
- label={mockLabel}
62
- icon={'test'}
63
- imgAlt={'alt'}
64
- />,
65
- );
66
-
67
- const Icon = wrapper.find('.icons');
68
-
69
- expect(Icon.exists()).toBe(false);
70
- });
29
+ expect(wrapper).toBeTruthy();
30
+ });
71
31
 
72
- it('raises onActionSelected', () => {
73
- const spy = jest.fn();
74
- const wrapper = mount(<PageHeaderAction {...defaultProps} onClick={spy} />);
32
+ it('renders a label', () => {
33
+ const mockLabel = 'test-label';
34
+ const wrapper = mount(
35
+ <PageHeaderAction {...defaultProps} label={mockLabel} />,
36
+ );
75
37
 
76
- const container = wrapper.find('.container');
77
- container.simulate('click');
38
+ const label = wrapper.find('span');
78
39
 
79
- expect(spy).toHaveBeenCalledTimes(1);
80
- });
40
+ expect(label.text()).toBe(mockLabel);
41
+ });
81
42
 
82
- describe('confirmation', () => {
83
- it(`'Simple' mode changes the background color when clicked for the first time`, () => {
84
- const spy = jest.fn();
43
+ it('renders a Icon, if set', () => {
44
+ const mockLabel = 'test-label';
85
45
  const wrapper = mount(
86
46
  <PageHeaderAction
87
47
  {...defaultProps}
88
- label={'test-label'}
89
- confirmationMode="Simple"
90
- onClick={spy}
48
+ label={mockLabel}
49
+ icon={IconName.ChevronRight}
91
50
  />,
92
51
  );
93
- let container = wrapper.find('.container');
94
- expect(container.hasClass('hasConfirm')).toBe(false);
95
-
96
- wrapper.simulate('click');
97
- wrapper.update();
98
52
 
99
- container = wrapper.find('.container');
53
+ const Icon = wrapper.find('.icons');
100
54
 
101
- expect(container.hasClass('hasConfirm')).toBe(true);
55
+ expect(Icon.exists()).toBe(true);
102
56
  });
103
57
 
104
- it(`'Simple' mode renders a confirmation message, raises the 'onClick' event after confirmation, and resets the action label`, () => {
58
+ it('image is used instead of icon if icon prop is a string', () => {
105
59
  const mockLabel = 'test-label';
106
- const confirmationMsg = 'Click again to confirm';
107
- const spy = jest.fn();
108
60
  const wrapper = mount(
109
61
  <PageHeaderAction
110
62
  {...defaultProps}
111
63
  label={mockLabel}
112
- confirmationMode="Simple"
113
- onClick={spy}
64
+ icon={'test'}
65
+ imgAlt={'alt'}
114
66
  />,
115
67
  );
116
68
 
117
- let span = wrapper.find('span');
118
-
119
- expect(span.text()).toBe(mockLabel);
120
-
121
- wrapper.simulate('click');
122
-
123
- span = wrapper.find('span');
124
-
125
- expect(span.text()).toBe(confirmationMsg);
126
-
127
- wrapper.simulate('click');
69
+ const Icon = wrapper.find('.icons');
128
70
 
129
- span = wrapper.find('span');
130
-
131
- expect(spy).toHaveBeenCalledTimes(1);
132
- expect(span.text()).toBe(mockLabel);
71
+ expect(Icon.exists()).toBe(false);
133
72
  });
134
73
 
135
- it(`'Simple' mode renders a confirmation message, and doesn't raise the 'onClick' event on 'mouseleave' when confirmation is required`, async () => {
136
- const mockLabel = 'test-label';
137
- const confirmationMsg = 'Click again to confirm';
74
+ it('raises onActionSelected', () => {
138
75
  const spy = jest.fn();
139
- jest.useFakeTimers();
140
-
141
76
  const wrapper = mount(
142
- <PageHeaderAction
143
- {...defaultProps}
144
- label={mockLabel}
145
- confirmationMode="Simple"
146
- onClick={spy}
147
- />,
77
+ <PageHeaderAction {...defaultProps} onClick={spy} />,
148
78
  );
149
79
 
150
- await act(async () => {
151
- wrapper.simulate('click');
152
- });
153
- wrapper.update();
80
+ const container = wrapper.find('.container');
81
+ container.simulate('click');
154
82
 
155
- let span = wrapper.find('span');
156
- let container = wrapper.find('.container');
83
+ expect(spy).toHaveBeenCalledTimes(1);
84
+ });
157
85
 
158
- expect(container.hasClass('hasConfirm')).toBe(true);
159
- expect(span.text()).toBe(confirmationMsg);
160
- expect(spy).not.toHaveBeenCalled();
86
+ describe('confirmation', () => {
87
+ it(`'Simple' mode changes the background color when clicked for the first time`, () => {
88
+ const spy = jest.fn();
89
+ const wrapper = mount(
90
+ <PageHeaderAction
91
+ {...defaultProps}
92
+ label={'test-label'}
93
+ confirmationMode="Simple"
94
+ onClick={spy}
95
+ />,
96
+ );
97
+ let container = wrapper.find('.container');
98
+ expect(container.hasClass('hasConfirm')).toBe(false);
161
99
 
162
- await act(async () => {
163
- await wrapper.simulate('mouseleave');
164
- });
165
- wrapper.update();
100
+ wrapper.simulate('click');
101
+ wrapper.update();
102
+
103
+ container = wrapper.find('.container');
166
104
 
167
- await act(async () => {
168
- jest.runAllTimers();
105
+ expect(container.hasClass('hasConfirm')).toBe(true);
169
106
  });
170
- wrapper.update();
171
107
 
172
- span = wrapper.find('span');
173
- container = wrapper.find('.container');
108
+ it(`'Simple' mode renders a confirmation message, raises the 'onClick' event after confirmation, and resets the action label`, () => {
109
+ const mockLabel = 'test-label';
110
+ const confirmationMsg = 'Click again to confirm';
111
+ const spy = jest.fn();
112
+ const wrapper = mount(
113
+ <PageHeaderAction
114
+ {...defaultProps}
115
+ label={mockLabel}
116
+ confirmationMode="Simple"
117
+ onClick={spy}
118
+ />,
119
+ );
174
120
 
175
- expect(span.text()).toBe(mockLabel);
176
- expect(spy).not.toHaveBeenCalled();
177
- expect(container.hasClass('hasConfirm')).toBe(false);
178
- });
121
+ let span = wrapper.find('span');
179
122
 
180
- it(`'Advanced' mode changes the background color when clicked for the first time`, async () => {
181
- const spy = jest.fn();
182
- const wrapper = mount(
183
- <PageHeaderAction
184
- {...defaultProps}
185
- label={'test-label'}
186
- confirmationMode="Advanced"
187
- onClick={spy}
188
- />,
189
- );
190
- let container = wrapper.find('.container').first();
191
- expect(container.hasClass('hasConfirm')).toBe(false);
123
+ expect(span.text()).toBe(mockLabel);
192
124
 
193
- await act(async () => {
194
- await wrapper.simulate('click');
195
- });
196
- wrapper.update();
125
+ wrapper.simulate('click');
197
126
 
198
- container = wrapper.find('.container').first();
127
+ span = wrapper.find('span');
199
128
 
200
- expect(container.hasClass('hasConfirm')).toBe(true);
201
- });
129
+ expect(span.text()).toBe(confirmationMsg);
202
130
 
203
- it(`'Advanced' mode confirmation pop up, raises the 'onClick' event after the 'Confirm' button is clicked, and finally dismisses the confirmation pop up`, async () => {
204
- const spy = jest.fn();
205
- const wrapper = mount(
206
- <PageHeaderAction
207
- {...defaultProps}
208
- label={'test-label'}
209
- confirmationMode="Advanced"
210
- onClick={spy}
211
- />,
212
- );
213
- let confirmation = wrapper.find(ConfirmDialog);
131
+ wrapper.simulate('click');
214
132
 
215
- expect(confirmation.exists()).toBe(false);
133
+ span = wrapper.find('span');
216
134
 
217
- await act(async () => {
218
- await wrapper.simulate('click');
135
+ expect(spy).toHaveBeenCalledTimes(1);
136
+ expect(span.text()).toBe(mockLabel);
219
137
  });
220
- wrapper.update();
221
-
222
- confirmation = wrapper.find(ConfirmDialog);
223
138
 
224
- expect(confirmation.exists()).toBe(true);
225
-
226
- const confirmButton = wrapper.find(TextButton).last();
139
+ it(`'Simple' mode renders a confirmation message, and doesn't raise the 'onClick' event on 'mouseleave' when confirmation is required`, async () => {
140
+ const mockLabel = 'test-label';
141
+ const confirmationMsg = 'Click again to confirm';
142
+ const spy = jest.fn();
143
+ jest.useFakeTimers();
144
+
145
+ const wrapper = mount(
146
+ <PageHeaderAction
147
+ {...defaultProps}
148
+ label={mockLabel}
149
+ confirmationMode="Simple"
150
+ onClick={spy}
151
+ />,
152
+ );
153
+
154
+ await act(async () => {
155
+ wrapper.simulate('click');
156
+ });
157
+ wrapper.update();
158
+
159
+ let span = wrapper.find('span');
160
+ let container = wrapper.find('.container');
161
+
162
+ expect(container.hasClass('hasConfirm')).toBe(true);
163
+ expect(span.text()).toBe(confirmationMsg);
164
+ expect(spy).not.toHaveBeenCalled();
165
+
166
+ await act(async () => {
167
+ await wrapper.simulate('mouseleave');
168
+ });
169
+ wrapper.update();
170
+
171
+ await act(async () => {
172
+ jest.runAllTimers();
173
+ });
174
+ wrapper.update();
175
+
176
+ span = wrapper.find('span');
177
+ container = wrapper.find('.container');
178
+
179
+ expect(span.text()).toBe(mockLabel);
180
+ expect(spy).not.toHaveBeenCalled();
181
+ expect(container.hasClass('hasConfirm')).toBe(false);
182
+ });
227
183
 
228
- act(() => {
229
- confirmButton.simulate('click');
184
+ it(`'Advanced' mode changes the background color when clicked for the first time`, async () => {
185
+ const spy = jest.fn();
186
+ const wrapper = mount(
187
+ <PageHeaderAction
188
+ {...defaultProps}
189
+ label={'test-label'}
190
+ confirmationMode="Advanced"
191
+ onClick={spy}
192
+ />,
193
+ );
194
+ let container = wrapper.find('.container').first();
195
+ expect(container.hasClass('hasConfirm')).toBe(false);
196
+
197
+ await act(async () => {
198
+ await wrapper.simulate('click');
199
+ });
200
+ wrapper.update();
201
+
202
+ container = wrapper.find('.container').first();
203
+
204
+ expect(container.hasClass('hasConfirm')).toBe(true);
230
205
  });
231
- wrapper.update();
232
206
 
233
- confirmation = wrapper.find(ConfirmDialog);
207
+ it(`'Advanced' mode confirmation pop up, raises the 'onClick' event after the 'Confirm' button is clicked, and finally dismisses the confirmation pop up`, async () => {
208
+ const spy = jest.fn();
209
+ const wrapper = mount(
210
+ <PageHeaderAction
211
+ {...defaultProps}
212
+ label={'test-label'}
213
+ confirmationMode="Advanced"
214
+ onClick={spy}
215
+ />,
216
+ );
217
+ let confirmation = wrapper.find(ConfirmDialog);
234
218
 
235
- expect(confirmation.exists()).toBe(false);
236
- expect(spy).toHaveBeenCalledTimes(1);
237
- });
219
+ expect(confirmation.exists()).toBe(false);
238
220
 
239
- it(`'Advanced' mode confirmation pop up, does not raise the 'onClick' event after the 'Cancel' button is clicked, and finally dismisses the confirmation pop up`, async () => {
240
- const spy = jest.fn();
241
- const wrapper = mount(
242
- <PageHeaderAction
243
- {...defaultProps}
244
- label={'test-label'}
245
- confirmationMode="Advanced"
246
- onClick={spy}
247
- />,
248
- );
249
- let confirmation = wrapper.find(ConfirmDialog);
221
+ await act(async () => {
222
+ await wrapper.simulate('click');
223
+ });
224
+ wrapper.update();
250
225
 
251
- expect(confirmation.exists()).toBe(false);
226
+ confirmation = wrapper.find(ConfirmDialog);
252
227
 
253
- await act(async () => {
254
- await wrapper.simulate('click');
255
- });
256
- wrapper.update();
228
+ expect(confirmation.exists()).toBe(true);
257
229
 
258
- confirmation = wrapper.find(ConfirmDialog);
230
+ const confirmButton = wrapper.find(TextButton).last();
259
231
 
260
- expect(confirmation.exists()).toBe(true);
232
+ act(() => {
233
+ confirmButton.simulate('click');
234
+ });
235
+ wrapper.update();
261
236
 
262
- const confirmButton = wrapper.find(TextButton).first();
237
+ confirmation = wrapper.find(ConfirmDialog);
263
238
 
264
- act(() => {
265
- confirmButton.simulate('click');
239
+ expect(confirmation.exists()).toBe(false);
240
+ expect(spy).toHaveBeenCalledTimes(1);
266
241
  });
267
- wrapper.update();
268
242
 
269
- confirmation = wrapper.find(ConfirmDialog);
243
+ it(`'Advanced' mode confirmation pop up, does not raise the 'onClick' event after the 'Cancel' button is clicked, and finally dismisses the confirmation pop up`, async () => {
244
+ const spy = jest.fn();
245
+ const wrapper = mount(
246
+ <PageHeaderAction
247
+ {...defaultProps}
248
+ label={'test-label'}
249
+ confirmationMode="Advanced"
250
+ onClick={spy}
251
+ />,
252
+ );
253
+ let confirmation = wrapper.find(ConfirmDialog);
270
254
 
271
- expect(confirmation.exists()).toBe(false);
272
- expect(spy).not.toHaveBeenCalled();
273
- });
255
+ expect(confirmation.exists()).toBe(false);
274
256
 
275
- it(`'Advanced' mode renders a confirmation pop up, does not raise the 'onClick' event when the mouse leaves component, and finally dismisses the confirmation pop up`, async () => {
276
- const spy = jest.fn();
277
- jest.useFakeTimers();
257
+ await act(async () => {
258
+ await wrapper.simulate('click');
259
+ });
260
+ wrapper.update();
278
261
 
279
- const wrapper = mount(
280
- <PageHeaderAction
281
- {...defaultProps}
282
- label={'test-label'}
283
- confirmationMode="Advanced"
284
- onClick={spy}
285
- />,
286
- );
287
- let confirmation = wrapper.find(ConfirmDialog);
262
+ confirmation = wrapper.find(ConfirmDialog);
288
263
 
289
- expect(confirmation.exists()).toBe(false);
264
+ expect(confirmation.exists()).toBe(true);
290
265
 
291
- await act(async () => {
292
- await wrapper.simulate('click');
293
- });
294
- wrapper.update();
266
+ const confirmButton = wrapper.find(TextButton).first();
295
267
 
296
- confirmation = wrapper.find(ConfirmDialog);
268
+ act(() => {
269
+ confirmButton.simulate('click');
270
+ });
271
+ wrapper.update();
297
272
 
298
- expect(confirmation.exists()).toBe(true);
273
+ confirmation = wrapper.find(ConfirmDialog);
299
274
 
300
- await act(async () => {
301
- await wrapper.simulate('mouseleave');
275
+ expect(confirmation.exists()).toBe(false);
276
+ expect(spy).not.toHaveBeenCalled();
302
277
  });
303
- wrapper.update();
304
278
 
305
- await act(async () => {
306
- jest.runAllTimers();
307
- });
308
- wrapper.update();
279
+ it(`'Advanced' mode renders a confirmation pop up, does not raise the 'onClick' event when the mouse leaves component, and finally dismisses the confirmation pop up`, async () => {
280
+ const spy = jest.fn();
281
+ jest.useFakeTimers();
309
282
 
310
- confirmation = wrapper.find(ConfirmDialog);
283
+ const wrapper = mount(
284
+ <PageHeaderAction
285
+ {...defaultProps}
286
+ label={'test-label'}
287
+ confirmationMode="Advanced"
288
+ onClick={spy}
289
+ />,
290
+ );
291
+ let confirmation = wrapper.find(ConfirmDialog);
311
292
 
312
- // TODO: Debug why this isn't passing
313
- // expect(confirmation.exists()).toBe(false);
314
- expect(spy).not.toHaveBeenCalled();
315
- });
293
+ expect(confirmation.exists()).toBe(false);
316
294
 
317
- it(`'Advanced' mode accepts a 'confirmationConfig' object`, async () => {
318
- const mockConfig: ConfirmationConfig = {
319
- title: 'test-title',
320
- body: 'test-body',
321
- cancelButtonText: 'test-cancel',
322
- confirmButtonText: 'test-confirm',
323
- };
295
+ await act(async () => {
296
+ await wrapper.simulate('click');
297
+ });
298
+ wrapper.update();
324
299
 
325
- const wrapper = mount(
326
- <PageHeaderAction
327
- {...defaultProps}
328
- label={'test-label'}
329
- confirmationMode="Advanced"
330
- confirmationConfig={mockConfig}
331
- />,
332
- );
300
+ confirmation = wrapper.find(ConfirmDialog);
333
301
 
334
- await act(async () => {
335
- await wrapper.simulate('click');
336
- });
337
- wrapper.update();
302
+ expect(confirmation.exists()).toBe(true);
338
303
 
339
- const confirmation = wrapper.find(ConfirmDialog);
304
+ await act(async () => {
305
+ await wrapper.simulate('mouseleave');
306
+ });
307
+ wrapper.update();
340
308
 
341
- expect(confirmation.prop('title')).toBe(mockConfig.title);
342
- expect(confirmation.prop('children')).toBe(mockConfig.body);
343
- expect(confirmation.prop('cancelButtonText')).toBe(
344
- mockConfig.cancelButtonText,
345
- );
346
- expect(confirmation.prop('confirmButtonText')).toBe(
347
- mockConfig.confirmButtonText,
348
- );
349
- });
309
+ await act(async () => {
310
+ jest.runAllTimers();
311
+ });
312
+ wrapper.update();
350
313
 
351
- it(`'Simple' raises onConfirmOpen if set`, () => {
352
- const confirmToggleSpy = jest.fn();
314
+ confirmation = wrapper.find(ConfirmDialog);
353
315
 
354
- const wrapper = mount(
355
- <PageHeaderAction
356
- {...defaultProps}
357
- label={'test-label'}
358
- confirmationMode="Simple"
359
- confirmationConfig={{ onConfirmOpen: confirmToggleSpy }}
360
- />,
361
- );
316
+ // TODO: Debug why this isn't passing
317
+ // expect(confirmation.exists()).toBe(false);
318
+ expect(spy).not.toHaveBeenCalled();
319
+ });
362
320
 
363
- // toggle confirmation on
364
- act(() => {
365
- wrapper.simulate('click');
321
+ it(`'Advanced' mode accepts a 'confirmationConfig' object`, async () => {
322
+ const mockConfig: ConfirmationConfig = {
323
+ title: 'test-title',
324
+ body: 'test-body',
325
+ cancelButtonText: 'test-cancel',
326
+ confirmButtonText: 'test-confirm',
327
+ };
328
+
329
+ const wrapper = mount(
330
+ <PageHeaderAction
331
+ {...defaultProps}
332
+ label={'test-label'}
333
+ confirmationMode="Advanced"
334
+ confirmationConfig={mockConfig}
335
+ />,
336
+ );
337
+
338
+ await act(async () => {
339
+ await wrapper.simulate('click');
340
+ });
341
+ wrapper.update();
342
+
343
+ const confirmation = wrapper.find(ConfirmDialog);
344
+
345
+ expect(confirmation.prop('title')).toBe(mockConfig.title);
346
+ expect(confirmation.prop('children')).toBe(mockConfig.body);
347
+ expect(confirmation.prop('cancelButtonText')).toBe(
348
+ mockConfig.cancelButtonText,
349
+ );
350
+ expect(confirmation.prop('confirmButtonText')).toBe(
351
+ mockConfig.confirmButtonText,
352
+ );
366
353
  });
367
354
 
368
- expect(confirmToggleSpy).toHaveBeenCalledTimes(1);
355
+ it(`'Simple' raises onConfirmOpen if set`, () => {
356
+ const confirmToggleSpy = jest.fn();
357
+
358
+ const wrapper = mount(
359
+ <PageHeaderAction
360
+ {...defaultProps}
361
+ label={'test-label'}
362
+ confirmationMode="Simple"
363
+ confirmationConfig={{ onConfirmOpen: confirmToggleSpy }}
364
+ />,
365
+ );
366
+
367
+ // toggle confirmation on
368
+ act(() => {
369
+ wrapper.simulate('click');
370
+ });
371
+
372
+ expect(confirmToggleSpy).toHaveBeenCalledTimes(1);
373
+
374
+ // toggle confirmation off
375
+ act(() => {
376
+ wrapper.simulate('click');
377
+ });
378
+
379
+ expect(confirmToggleSpy).toHaveBeenCalledTimes(2);
380
+ expect(confirmToggleSpy).toHaveBeenNthCalledWith(1, true, {
381
+ mode: 'Simple',
382
+ });
383
+ expect(confirmToggleSpy).toHaveBeenNthCalledWith(2, false, {
384
+ mode: 'Simple',
385
+ });
386
+ });
369
387
 
370
- // toggle confirmation off
371
- act(() => {
372
- wrapper.simulate('click');
388
+ it(`'Simple' raises onConfirmOpen when 'mouseleave' if set`, async () => {
389
+ const confirmToggleSpy = jest.fn();
390
+
391
+ jest.useFakeTimers();
392
+
393
+ const wrapper = mount(
394
+ <PageHeaderAction
395
+ {...defaultProps}
396
+ label={'test-label'}
397
+ confirmationMode="Simple"
398
+ confirmationConfig={{ onConfirmOpen: confirmToggleSpy }}
399
+ />,
400
+ );
401
+
402
+ await act(async () => {
403
+ wrapper.simulate('click');
404
+ });
405
+ wrapper.update();
406
+
407
+ await act(async () => {
408
+ await wrapper.simulate('mouseleave');
409
+ });
410
+ wrapper.update();
411
+
412
+ await act(async () => {
413
+ jest.runAllTimers();
414
+ });
415
+ wrapper.update();
416
+
417
+ expect(confirmToggleSpy).toHaveBeenCalledTimes(2);
418
+ expect(confirmToggleSpy).toHaveBeenNthCalledWith(1, true, {
419
+ mode: 'Simple',
420
+ });
421
+ expect(confirmToggleSpy).toHaveBeenNthCalledWith(2, false, {
422
+ mode: 'Simple',
423
+ });
373
424
  });
374
425
 
375
- expect(confirmToggleSpy).toHaveBeenCalledTimes(2);
376
- expect(confirmToggleSpy).toHaveBeenNthCalledWith(1, true, {
377
- mode: 'Simple',
426
+ it(`'Advanced' raises onConfirmOpen when 'Cancel' is clicked, if set`, () => {
427
+ const confirmToggleSpy = jest.fn();
428
+
429
+ const wrapper = mount(
430
+ <PageHeaderAction
431
+ {...defaultProps}
432
+ label={'test-label'}
433
+ confirmationMode="Advanced"
434
+ confirmationConfig={{ onConfirmOpen: confirmToggleSpy }}
435
+ />,
436
+ );
437
+
438
+ // toggle confirmation on
439
+ act(() => {
440
+ wrapper.simulate('click');
441
+ });
442
+ wrapper.update();
443
+
444
+ const cancelButton = wrapper.find(TextButton).first();
445
+
446
+ act(() => {
447
+ cancelButton.simulate('click');
448
+ });
449
+ wrapper.update();
450
+
451
+ expect(confirmToggleSpy).toHaveBeenCalledTimes(2);
452
+ expect(confirmToggleSpy).toHaveBeenNthCalledWith(1, true, {
453
+ mode: 'Advanced',
454
+ });
455
+ expect(confirmToggleSpy).toHaveBeenNthCalledWith(2, false, {
456
+ mode: 'Advanced',
457
+ });
378
458
  });
379
- expect(confirmToggleSpy).toHaveBeenNthCalledWith(2, false, {
380
- mode: 'Simple',
459
+
460
+ it(`'Advanced' raises onConfirmOpen when 'Confirm' is clicked, if set`, () => {
461
+ const confirmToggleSpy = jest.fn();
462
+
463
+ const wrapper = mount(
464
+ <PageHeaderAction
465
+ {...defaultProps}
466
+ label={'test-label'}
467
+ confirmationMode="Advanced"
468
+ confirmationConfig={{ onConfirmOpen: confirmToggleSpy }}
469
+ />,
470
+ );
471
+
472
+ // toggle confirmation on
473
+ act(() => {
474
+ wrapper.simulate('click');
475
+ });
476
+ wrapper.update();
477
+
478
+ const confirmButton = wrapper.find(TextButton).last();
479
+
480
+ act(() => {
481
+ confirmButton.simulate('click');
482
+ });
483
+ wrapper.update();
484
+
485
+ expect(confirmToggleSpy).toHaveBeenCalledTimes(2);
486
+ expect(confirmToggleSpy).toHaveBeenNthCalledWith(1, true, {
487
+ mode: 'Advanced',
488
+ });
489
+ expect(confirmToggleSpy).toHaveBeenNthCalledWith(2, false, {
490
+ mode: 'Advanced',
491
+ });
381
492
  });
382
493
  });
383
494
 
384
- it(`'Simple' raises onConfirmOpen when 'mouseleave' if set`, async () => {
385
- const confirmToggleSpy = jest.fn();
386
-
387
- jest.useFakeTimers();
388
-
495
+ it(`sets background color when actionType is 'Context'`, () => {
496
+ const spy = jest.fn();
389
497
  const wrapper = mount(
390
498
  <PageHeaderAction
391
- {...defaultProps}
392
- label={'test-label'}
393
- confirmationMode="Simple"
394
- confirmationConfig={{ onConfirmOpen: confirmToggleSpy }}
499
+ label={'action-label'}
500
+ actionType={PageHeaderActionType.Context}
501
+ onClick={spy}
395
502
  />,
396
503
  );
397
504
 
398
- await act(async () => {
399
- wrapper.simulate('click');
400
- });
401
- wrapper.update();
402
-
403
- await act(async () => {
404
- await wrapper.simulate('mouseleave');
405
- });
406
- wrapper.update();
407
-
408
- await act(async () => {
409
- jest.runAllTimers();
410
- });
411
- wrapper.update();
505
+ const container = wrapper.find('.container');
412
506
 
413
- expect(confirmToggleSpy).toHaveBeenCalledTimes(2);
414
- expect(confirmToggleSpy).toHaveBeenNthCalledWith(1, true, {
415
- mode: 'Simple',
416
- });
417
- expect(confirmToggleSpy).toHaveBeenNthCalledWith(2, false, {
418
- mode: 'Simple',
419
- });
507
+ expect(container.hasClass('context')).toBe(true);
420
508
  });
421
509
 
422
- it(`'Advanced' raises onConfirmOpen when 'Cancel' is clicked, if set`, () => {
423
- const confirmToggleSpy = jest.fn();
424
-
510
+ it(`sets background color when actionType is 'Active'`, () => {
511
+ const spy = jest.fn();
425
512
  const wrapper = mount(
426
513
  <PageHeaderAction
427
- {...defaultProps}
428
- label={'test-label'}
429
- confirmationMode="Advanced"
430
- confirmationConfig={{ onConfirmOpen: confirmToggleSpy }}
514
+ label={'action-label'}
515
+ actionType={PageHeaderActionType.Active}
516
+ onClick={spy}
431
517
  />,
432
518
  );
433
519
 
434
- // toggle confirmation on
435
- act(() => {
436
- wrapper.simulate('click');
437
- });
438
- wrapper.update();
439
-
440
- const cancelButton = wrapper.find(TextButton).first();
520
+ const container = wrapper.find('.container');
441
521
 
442
- act(() => {
443
- cancelButton.simulate('click');
444
- });
445
- wrapper.update();
446
-
447
- expect(confirmToggleSpy).toHaveBeenCalledTimes(2);
448
- expect(confirmToggleSpy).toHaveBeenNthCalledWith(1, true, {
449
- mode: 'Advanced',
450
- });
451
- expect(confirmToggleSpy).toHaveBeenNthCalledWith(2, false, {
452
- mode: 'Advanced',
453
- });
522
+ expect(container.hasClass('active')).toBe(true);
454
523
  });
455
524
 
456
- it(`'Advanced' raises onConfirmOpen when 'Confirm' is clicked, if set`, () => {
457
- const confirmToggleSpy = jest.fn();
458
-
525
+ it(`disallows interactions when action is set to disabled`, () => {
526
+ const spy = jest.fn();
459
527
  const wrapper = mount(
460
528
  <PageHeaderAction
461
- {...defaultProps}
462
- label={'test-label'}
463
- confirmationMode="Advanced"
464
- confirmationConfig={{ onConfirmOpen: confirmToggleSpy }}
529
+ label={'action-label'}
530
+ disabled={true}
531
+ onClick={spy}
465
532
  />,
466
533
  );
467
534
 
468
- // toggle confirmation on
469
- act(() => {
470
- wrapper.simulate('click');
471
- });
472
- wrapper.update();
473
-
474
- const confirmButton = wrapper.find(TextButton).last();
535
+ const disabledAttribute = wrapper.find('.container').prop('disabled');
475
536
 
476
- act(() => {
477
- confirmButton.simulate('click');
478
- });
479
- wrapper.update();
537
+ wrapper.simulate('click');
480
538
 
481
- expect(confirmToggleSpy).toHaveBeenCalledTimes(2);
482
- expect(confirmToggleSpy).toHaveBeenNthCalledWith(1, true, {
483
- mode: 'Advanced',
484
- });
485
- expect(confirmToggleSpy).toHaveBeenNthCalledWith(2, false, {
486
- mode: 'Advanced',
487
- });
539
+ expect(disabledAttribute).toBe(true);
540
+ expect(spy).not.toHaveBeenCalled();
488
541
  });
489
542
  });
490
543
 
491
- it(`sets background color when actionType is 'Context'`, () => {
492
- const spy = jest.fn();
493
- const wrapper = mount(
494
- <PageHeaderAction
495
- label={'action-label'}
496
- actionType={PageHeaderActionType.Context}
497
- onClick={spy}
498
- />,
499
- );
544
+ describe('PageHeaderNavigationAction', () => {
545
+ const defaultProps = {
546
+ label: 'Action Label',
547
+ path: '/action-path',
548
+ };
500
549
 
501
- const container = wrapper.find('.container');
550
+ it('renders the component without crashing', () => {
551
+ const wrapper = shallow(
552
+ <PageHeaderAction {...defaultProps} path="/test" />,
553
+ );
554
+ expect(wrapper).toBeTruthy();
555
+ });
502
556
 
503
- expect(container.hasClass('context')).toBe(true);
504
- });
557
+ it('renders a Link when path is provided', () => {
558
+ const wrapper = mount(
559
+ <Router>
560
+ <PageHeaderAction {...defaultProps} />
561
+ </Router>,
562
+ );
563
+
564
+ expect(wrapper.find(Link)).toHaveLength(1);
565
+ });
505
566
 
506
- it(`sets background color when actionType is 'Active'`, () => {
507
- const spy = jest.fn();
508
- const wrapper = mount(
509
- <PageHeaderAction
510
- label={'action-label'}
511
- actionType={PageHeaderActionType.Active}
512
- onClick={spy}
513
- />,
514
- );
567
+ it('renders a label', () => {
568
+ const mockLabel = 'test-label';
569
+ const wrapper = mount(
570
+ <Router>
571
+ <PageHeaderAction {...defaultProps} label={mockLabel} path="/test" />
572
+ </Router>,
573
+ );
574
+ const label = wrapper.find('span');
575
+ expect(label.text()).toBe(mockLabel);
576
+ });
515
577
 
516
- const container = wrapper.find('.container');
578
+ it('renders an icon, if set', () => {
579
+ const mockLabel = 'test-label';
580
+ const wrapper = mount(
581
+ <Router>
582
+ {' '}
583
+ <PageHeaderAction
584
+ {...defaultProps}
585
+ label={mockLabel}
586
+ icon={IconName.ChevronRight}
587
+ path="/test"
588
+ />
589
+ </Router>,
590
+ );
591
+ const icon = wrapper.find('.icons');
592
+ expect(icon.exists()).toBe(true);
593
+ });
517
594
 
518
- expect(container.hasClass('active')).toBe(true);
519
- });
595
+ it('renders an image instead of icon if icon prop is a string', () => {
596
+ const mockLabel = 'test-label';
597
+ const wrapper = mount(
598
+ <Router>
599
+ <PageHeaderAction
600
+ {...defaultProps}
601
+ label={mockLabel}
602
+ icon="test"
603
+ imgAlt="alt"
604
+ path="/test"
605
+ />
606
+ </Router>,
607
+ );
608
+ const icon = wrapper.find('.icons');
609
+ expect(icon.exists()).toBe(false);
610
+ const image = wrapper.find('img');
611
+ expect(image.exists()).toBe(true);
612
+ });
520
613
 
521
- it(`disallows interactions when action is set to disabled`, () => {
522
- const spy = jest.fn();
523
- const wrapper = mount(
524
- <PageHeaderAction label={'action-label'} disabled={true} onClick={spy} />,
525
- );
614
+ it('renders a link with correct path', () => {
615
+ const mockPath = '/test-path';
616
+ const wrapper = mount(
617
+ <Router>
618
+ <PageHeaderAction {...defaultProps} path={mockPath} />
619
+ </Router>,
620
+ );
621
+ const link = wrapper.find('Link');
622
+ expect(link.prop('to')).toBe(mockPath);
623
+ });
526
624
 
527
- const disabledAttribute = wrapper.find('.container').prop('disabled');
625
+ it('opens link in a new tab if openInNewTab is true', () => {
626
+ const wrapper = mount(
627
+ <Router>
628
+ <PageHeaderAction {...defaultProps} path="/test" openInNewTab />
629
+ </Router>,
630
+ );
631
+ const link = wrapper.find('a');
632
+ expect(link.prop('target')).toBe('_blank');
633
+ });
528
634
 
529
- wrapper.simulate('click');
635
+ it('does not open link in a new tab if openInNewTab is false', () => {
636
+ const wrapper = mount(
637
+ <Router>
638
+ <PageHeaderAction
639
+ {...defaultProps}
640
+ path="/test"
641
+ openInNewTab={false}
642
+ />
643
+ </Router>,
644
+ );
645
+ const link = wrapper.find('Link');
646
+ expect(link.prop('target')).toBeUndefined();
647
+ });
530
648
 
531
- expect(disabledAttribute).toBe(true);
532
- expect(spy).not.toHaveBeenCalled();
649
+ it('renders with disabled class if disabled prop is true', () => {
650
+ const wrapper = mount(
651
+ <Router>
652
+ <PageHeaderAction {...defaultProps} path="/test" disabled />
653
+ </Router>,
654
+ );
655
+ const container = wrapper.find('.container').hostNodes();
656
+ expect(container.hasClass('disabled')).toBe(true);
657
+ });
533
658
  });
534
659
  });
535
660