@axinom/mosaic-ui 0.32.0-rc.1 → 0.32.0-rc.10

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