@dhis2/analytics 28.0.4 → 28.0.5

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 (81) hide show
  1. package/build/cjs/__demo__/OpenFileDialog.stories.js +19 -1
  2. package/build/cjs/components/DimensionsPanel/List/DimensionList.js +3 -1
  3. package/build/cjs/components/DimensionsPanel/List/__tests__/DimensionItem.spec.js +48 -41
  4. package/build/cjs/components/DimensionsPanel/List/__tests__/__snapshots__/DimensionItem.spec.js.snap +110 -114
  5. package/build/cjs/components/DimensionsPanel/__tests__/DimensionsPanel.spec.js +36 -33
  6. package/build/cjs/components/FileMenu/__tests__/DeleteDialog.spec.js +24 -27
  7. package/build/cjs/components/FileMenu/__tests__/FileMenu.spec.js +51 -31
  8. package/build/cjs/components/FileMenu/__tests__/GetLinkDialog.spec.js +28 -31
  9. package/build/cjs/components/FileMenu/__tests__/RenameDialog.spec.js +17 -11
  10. package/build/cjs/components/FileMenu/__tests__/SaveAsDialog.spec.js +44 -37
  11. package/build/cjs/components/Filter/__tests__/Filter.spec.js +29 -34
  12. package/build/cjs/components/OpenFileDialog/CreatedByFilter.js +9 -1
  13. package/build/cjs/components/OpenFileDialog/OpenFileDialog.js +14 -34
  14. package/build/cjs/components/OpenFileDialog/VisTypeFilter.js +39 -1
  15. package/build/cjs/components/OpenFileDialog/__tests__/OpenFileDialog.spec.js +51 -0
  16. package/build/cjs/components/OrgUnitDimension/__tests__/OrgUnitDimension.spec.js +78 -44
  17. package/build/cjs/components/PeriodDimension/FixedPeriodFilter.js +1 -0
  18. package/build/cjs/components/PeriodDimension/RelativePeriodFilter.js +3 -2
  19. package/build/cjs/components/PeriodDimension/__tests__/FixedPeriodSingleSelect.spec.js +14 -21
  20. package/build/cjs/components/PeriodDimension/__tests__/PeriodDimension.spec.js +27 -23
  21. package/build/cjs/components/RichText/Editor/__tests__/Editor.spec.js +6 -7
  22. package/build/cjs/components/RichText/Parser/__tests__/MdParser.spec.js +1 -1
  23. package/build/cjs/components/RichText/Parser/__tests__/Parser.spec.js +22 -23
  24. package/build/cjs/components/Toolbar/HoverMenuBar/__tests__/HoverMenuBar.spec.js +52 -42
  25. package/build/cjs/components/Toolbar/HoverMenuBar/__tests__/HoverMenuDropdown.spec.js +8 -8
  26. package/build/cjs/components/Toolbar/HoverMenuBar/__tests__/HoverMenuList.spec.js +23 -18
  27. package/build/cjs/components/Toolbar/HoverMenuBar/__tests__/HoverMenuListItem.spec.js +23 -17
  28. package/build/cjs/components/Toolbar/HoverMenuBar/__tests__/__snapshots__/HoverMenuList.spec.js.snap +63 -0
  29. package/build/cjs/components/Toolbar/InterpretationsAndDetailsToggler.js +3 -1
  30. package/build/cjs/components/Toolbar/__tests__/InterpretationsAndDetailsToggler.spec.js +19 -18
  31. package/build/cjs/components/Toolbar/__tests__/Toolbar.spec.js +8 -8
  32. package/build/cjs/components/Toolbar/__tests__/ToolbarSidebar.spec.js +14 -11
  33. package/build/cjs/components/Toolbar/__tests__/UpdateButton.spec.js +16 -14
  34. package/build/cjs/components/TranslationDialog/TranslationModal/TranslationModal.js +2 -1
  35. package/build/cjs/components/TranslationDialog/TranslationModal/__tests__/TranslationModal.spec.js +25 -16
  36. package/build/es/__demo__/OpenFileDialog.stories.js +17 -0
  37. package/build/es/components/DimensionsPanel/List/DimensionList.js +3 -1
  38. package/build/es/components/DimensionsPanel/List/__tests__/DimensionItem.spec.js +47 -40
  39. package/build/es/components/DimensionsPanel/List/__tests__/__snapshots__/DimensionItem.spec.js.snap +110 -114
  40. package/build/es/components/DimensionsPanel/__tests__/DimensionsPanel.spec.js +35 -32
  41. package/build/es/components/FileMenu/__tests__/DeleteDialog.spec.js +23 -26
  42. package/build/es/components/FileMenu/__tests__/FileMenu.spec.js +52 -32
  43. package/build/es/components/FileMenu/__tests__/GetLinkDialog.spec.js +27 -30
  44. package/build/es/components/FileMenu/__tests__/RenameDialog.spec.js +18 -12
  45. package/build/es/components/FileMenu/__tests__/SaveAsDialog.spec.js +43 -36
  46. package/build/es/components/Filter/__tests__/Filter.spec.js +28 -33
  47. package/build/es/components/OpenFileDialog/CreatedByFilter.js +7 -0
  48. package/build/es/components/OpenFileDialog/OpenFileDialog.js +14 -35
  49. package/build/es/components/OpenFileDialog/VisTypeFilter.js +38 -1
  50. package/build/es/components/OpenFileDialog/__tests__/OpenFileDialog.spec.js +49 -0
  51. package/build/es/components/OrgUnitDimension/__tests__/OrgUnitDimension.spec.js +77 -43
  52. package/build/es/components/PeriodDimension/FixedPeriodFilter.js +1 -0
  53. package/build/es/components/PeriodDimension/RelativePeriodFilter.js +3 -2
  54. package/build/es/components/PeriodDimension/__tests__/FixedPeriodSingleSelect.spec.js +13 -20
  55. package/build/es/components/PeriodDimension/__tests__/PeriodDimension.spec.js +26 -22
  56. package/build/es/components/RichText/Editor/__tests__/Editor.spec.js +7 -8
  57. package/build/es/components/RichText/Parser/__tests__/MdParser.spec.js +1 -1
  58. package/build/es/components/RichText/Parser/__tests__/Parser.spec.js +21 -22
  59. package/build/es/components/Toolbar/HoverMenuBar/__tests__/HoverMenuBar.spec.js +53 -43
  60. package/build/es/components/Toolbar/HoverMenuBar/__tests__/HoverMenuDropdown.spec.js +7 -7
  61. package/build/es/components/Toolbar/HoverMenuBar/__tests__/HoverMenuList.spec.js +23 -18
  62. package/build/es/components/Toolbar/HoverMenuBar/__tests__/HoverMenuListItem.spec.js +21 -15
  63. package/build/es/components/Toolbar/HoverMenuBar/__tests__/__snapshots__/HoverMenuList.spec.js.snap +63 -0
  64. package/build/es/components/Toolbar/InterpretationsAndDetailsToggler.js +3 -1
  65. package/build/es/components/Toolbar/__tests__/InterpretationsAndDetailsToggler.spec.js +18 -17
  66. package/build/es/components/Toolbar/__tests__/Toolbar.spec.js +7 -7
  67. package/build/es/components/Toolbar/__tests__/ToolbarSidebar.spec.js +13 -10
  68. package/build/es/components/Toolbar/__tests__/UpdateButton.spec.js +15 -13
  69. package/build/es/components/TranslationDialog/TranslationModal/TranslationModal.js +2 -1
  70. package/build/es/components/TranslationDialog/TranslationModal/__tests__/TranslationModal.spec.js +24 -15
  71. package/package.json +2 -4
  72. package/build/cjs/components/OrgUnitDimension/__tests__/__snapshots__/OrgUnitDimension.spec.js.snap +0 -89
  73. package/build/cjs/components/PeriodDimension/__tests__/PeriodSelector.spec.js +0 -29
  74. package/build/cjs/components/PeriodDimension/__tests__/__snapshots__/FixedPeriodSingleSelect.spec.js.snap +0 -92
  75. package/build/cjs/components/PeriodDimension/__tests__/__snapshots__/PeriodDimension.spec.js.snap +0 -16
  76. package/build/cjs/components/PeriodDimension/__tests__/__snapshots__/PeriodSelector.spec.js.snap +0 -89
  77. package/build/es/components/OrgUnitDimension/__tests__/__snapshots__/OrgUnitDimension.spec.js.snap +0 -89
  78. package/build/es/components/PeriodDimension/__tests__/PeriodSelector.spec.js +0 -26
  79. package/build/es/components/PeriodDimension/__tests__/__snapshots__/FixedPeriodSingleSelect.spec.js.snap +0 -92
  80. package/build/es/components/PeriodDimension/__tests__/__snapshots__/PeriodDimension.spec.js.snap +0 -16
  81. package/build/es/components/PeriodDimension/__tests__/__snapshots__/PeriodSelector.spec.js.snap +0 -89
@@ -1,33 +1,30 @@
1
- import { Button, Modal, ModalTitle } from '@dhis2/ui';
2
- import { shallow } from 'enzyme';
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
3
  import React from 'react';
4
4
  import { DeleteDialog } from '../DeleteDialog.js';
5
- describe('The FileMenu - DeleteDialog component', () => {
6
- let shallowDeleteDialog;
7
- let props;
8
- const onClose = jest.fn();
9
- const getDeleteDialogComponent = props => {
10
- if (!shallowDeleteDialog) {
11
- shallowDeleteDialog = shallow(/*#__PURE__*/React.createElement(DeleteDialog, props));
12
- }
13
- return shallowDeleteDialog;
5
+ describe('FileMenu - DeleteDialog component', () => {
6
+ const props = {
7
+ type: 'visualization',
8
+ id: 'delete-test',
9
+ onClose: jest.fn()
14
10
  };
15
- beforeEach(() => {
16
- shallowDeleteDialog = undefined;
17
- props = {
18
- type: 'visualization',
19
- id: 'delete-test',
20
- onClose
21
- };
11
+ test('renders a Modal component', () => {
12
+ render(/*#__PURE__*/React.createElement(DeleteDialog, props));
13
+ const modalComponent = screen.getByTestId('file-menu-delete-modal');
14
+ expect(modalComponent).toBeInTheDocument();
22
15
  });
23
- it('renders a Modal component', () => {
24
- expect(getDeleteDialogComponent(props).find(Modal)).toHaveLength(1);
16
+ test('renders a ModalTitle containing the type prop', () => {
17
+ render(/*#__PURE__*/React.createElement(DeleteDialog, props));
18
+ const modalTitleComponent = screen.getByText(`Delete ${props.type}`);
19
+ expect(modalTitleComponent).toBeInTheDocument();
25
20
  });
26
- it('renders a ModalTitle containing the type prop', () => {
27
- expect(getDeleteDialogComponent(props).find(ModalTitle).childAt(0).text()).toEqual(`Delete ${props.type}`);
28
- });
29
- it('calls the onClose callback when the Cancel button is clicked', () => {
30
- getDeleteDialogComponent(props).find(Button).first().simulate('click');
31
- expect(onClose).toHaveBeenCalled();
21
+ test('calls the onClose callback when the Cancel button is clicked', async () => {
22
+ const user = userEvent.setup();
23
+ render(/*#__PURE__*/React.createElement(DeleteDialog, props));
24
+ const cancelButton = screen.getByRole('button', {
25
+ name: 'Cancel'
26
+ });
27
+ await user.click(cancelButton);
28
+ expect(props.onClose).toHaveBeenCalledTimes(1);
32
29
  });
33
30
  });
@@ -1,5 +1,6 @@
1
1
  import { CustomDataProvider } from '@dhis2/app-runtime';
2
- import { render, fireEvent, screen, getByText } from '@testing-library/react';
2
+ import { render, screen, getByText } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
3
4
  import '@testing-library/jest-dom';
4
5
  import React from 'react';
5
6
  import { HoverMenuBar } from '../../Toolbar/index.js';
@@ -13,7 +14,7 @@ jest.mock('../../TranslationDialog/TranslationModal/useTranslationsResults.js',
13
14
  fetching: true
14
15
  })
15
16
  }));
16
- describe('The FileMenu component ', () => {
17
+ describe('FileMenu component ', () => {
17
18
  const onDelete = jest.fn();
18
19
  const onError = jest.fn();
19
20
  const onNew = jest.fn();
@@ -71,8 +72,16 @@ describe('The FileMenu component ', () => {
71
72
  },
72
73
  visualizations: {
73
74
  pager: {
74
- page: 1
75
- }
75
+ page: 1,
76
+ pageSize: 50
77
+ },
78
+ visualizations: [{
79
+ id: 'vis1',
80
+ displayName: 'Visualization 1',
81
+ type: 'VISUALIZATION',
82
+ created: '2025-07-23T15:04:16.864',
83
+ lastUpdated: '2025-07-23T15:04:16.864'
84
+ }]
76
85
  }
77
86
  };
78
87
  return render(/*#__PURE__*/React.createElement(CustomDataProvider, {
@@ -80,7 +89,8 @@ describe('The FileMenu component ', () => {
80
89
  }, /*#__PURE__*/React.createElement(HoverMenuBar, null, /*#__PURE__*/React.createElement(FileMenu, props))));
81
90
  };
82
91
  const openDropdown = async () => {
83
- fireEvent.click(screen.getByTestId('dhis2-analytics-hovermenudropdown'));
92
+ const user = userEvent.setup();
93
+ await user.click(screen.getByTestId('dhis2-analytics-hovermenudropdown'));
84
94
  expect(await screen.findByTestId('file-menu-container')).toBeVisible();
85
95
  };
86
96
  const MENU_ITEMS = {
@@ -132,20 +142,20 @@ describe('The FileMenu component ', () => {
132
142
  }
133
143
  }
134
144
  };
135
- it('renders a button', () => {
145
+ test('renders a button', () => {
136
146
  renderFileMenu();
137
147
  expect(screen.getAllByTestId('dhis2-analytics-hovermenudropdown')).toHaveLength(1);
138
148
  const button = screen.getByTestId('dhis2-analytics-hovermenudropdown');
139
149
  expect(button).toBeVisible();
140
150
  expect(button).toHaveTextContent('File');
141
151
  });
142
- it('opens when clicking the button', async () => {
152
+ test('opens when clicking the button', async () => {
143
153
  renderFileMenu();
144
154
  expect(screen.queryByTestId('file-menu-container')).not.toBeInTheDocument();
145
155
  await openDropdown();
146
156
  expect(await screen.findByTestId('file-menu-container')).toBeVisible();
147
157
  });
148
- it('renders some enabled buttons regardless of the access settings', async () => {
158
+ test('renders some enabled buttons regardless of the access settings', async () => {
149
159
  renderFileMenu();
150
160
  await openDropdown();
151
161
  assertMenuItemsDisabledState([{
@@ -156,7 +166,7 @@ describe('The FileMenu component ', () => {
156
166
  disabled: false
157
167
  }]);
158
168
  });
159
- it('renders some disabled buttons when no fileObject is present', async () => {
169
+ test('renders some disabled buttons when no fileObject is present', async () => {
160
170
  renderFileMenu();
161
171
  await openDropdown();
162
172
  assertMenuItemsDisabledState([{
@@ -179,7 +189,7 @@ describe('The FileMenu component ', () => {
179
189
  disabled: true
180
190
  }]);
181
191
  });
182
- it('renders some enabled buttons when update access is granted', async () => {
192
+ test('renders some enabled buttons when update access is granted', async () => {
183
193
  const customProps = {
184
194
  fileObject: {
185
195
  id: 'test',
@@ -203,7 +213,7 @@ describe('The FileMenu component ', () => {
203
213
  disabled: false
204
214
  }]);
205
215
  });
206
- it('renders enabled Delete button when delete access is granted', async () => {
216
+ test('renders enabled Delete button when delete access is granted', async () => {
207
217
  const customProps = {
208
218
  fileObject: {
209
219
  id: 'test',
@@ -221,7 +231,7 @@ describe('The FileMenu component ', () => {
221
231
  disabled: false
222
232
  }]);
223
233
  });
224
- it('renders enabled Share button when manage access is granted', async () => {
234
+ test('renders enabled Share button when manage access is granted', async () => {
225
235
  const customProps = {
226
236
  fileObject: {
227
237
  id: 'test',
@@ -239,50 +249,56 @@ describe('The FileMenu component ', () => {
239
249
  disabled: false
240
250
  }]);
241
251
  });
242
- it('renders the OpenFileDialog component when the Open button is clicked', async () => {
252
+ test('renders the OpenFileDialog component when the Open button is clicked', async () => {
253
+ const user = userEvent.setup();
243
254
  renderFileMenu();
244
255
  await openDropdown();
245
- fireEvent.click(screen.getByTestId(MENU_ITEMS.OPEN.testId));
256
+ await user.click(screen.getByTestId(MENU_ITEMS.OPEN.testId));
246
257
  expect(await screen.findByText('Open a visualization', {
247
258
  selector: 'h1'
248
259
  })).toBeVisible();
249
260
  });
250
- it('renders the RenameDialog when the Rename button is clicked', async () => {
261
+ test('renders the RenameDialog when the Rename button is clicked', async () => {
262
+ const user = userEvent.setup();
251
263
  renderFileMenu(fullAccessProps);
252
264
  await openDropdown();
253
- fireEvent.click(screen.getByTestId(MENU_ITEMS.RENAME.testId));
265
+ await user.click(screen.getByTestId(MENU_ITEMS.RENAME.testId));
254
266
  expect(await screen.findByText('Rename visualization', {
255
267
  selector: 'h1'
256
268
  })).toBeVisible();
257
269
  });
258
- it('renders the TranslationDialog when the Translate button is clicked', async () => {
270
+ test('renders the TranslationDialog when the Translate button is clicked', async () => {
271
+ const user = userEvent.setup();
259
272
  renderFileMenu(fullAccessProps);
260
273
  await openDropdown();
261
- fireEvent.click(screen.getByTestId(MENU_ITEMS.TRANSLATE.testId));
274
+ await user.click(screen.getByTestId(MENU_ITEMS.TRANSLATE.testId));
262
275
  expect(await screen.findByText('Translate', {
263
276
  exact: false,
264
277
  selector: 'h1'
265
278
  })).toBeVisible();
266
279
  });
267
- it('renders the SharingDialog when the Share button is clicked', async () => {
280
+ test('renders the SharingDialog when the Share button is clicked', async () => {
281
+ const user = userEvent.setup();
268
282
  renderFileMenu(fullAccessProps);
269
283
  await openDropdown();
270
- fireEvent.click(screen.getByTestId(MENU_ITEMS.SHARE.testId));
284
+ await user.click(screen.getByTestId(MENU_ITEMS.SHARE.testId));
271
285
  expect(await screen.findByText('Sharing and access', {
272
286
  selector: 'h1'
273
287
  })).toBeVisible();
274
288
  });
275
- it('renders the GetLinkDialog when the Get link button is clicked', async () => {
289
+ test('renders the GetLinkDialog when the Get link button is clicked', async () => {
290
+ const user = userEvent.setup();
276
291
  const url = 'http://localhost/dhis-web-data-visualizer/#/test';
277
292
  renderFileMenu(fullAccessProps);
278
293
  await openDropdown();
279
- fireEvent.click(screen.getByTestId(MENU_ITEMS.GET_LINK.testId));
294
+ await user.click(screen.getByTestId(MENU_ITEMS.GET_LINK.testId));
280
295
  expect(await screen.findByTestId('dhis2-uicore-modal')).toBeVisible();
281
296
  expect(screen.getByRole('link', {
282
297
  name: url
283
298
  })).toHaveAttribute('href', url);
284
299
  });
285
- it('renders the DeleteDialog when the Delete button is clicked', async () => {
300
+ test('renders the DeleteDialog when the Delete button is clicked', async () => {
301
+ const user = userEvent.setup();
286
302
  const customProps = {
287
303
  fileObject: {
288
304
  id: 'delete-test',
@@ -295,20 +311,22 @@ describe('The FileMenu component ', () => {
295
311
  };
296
312
  renderFileMenu(customProps);
297
313
  await openDropdown();
298
- fireEvent.click(screen.getByTestId(MENU_ITEMS.DELETE.testId));
314
+ await user.click(screen.getByTestId(MENU_ITEMS.DELETE.testId));
299
315
  expect(await screen.findByText('Delete visualization', {
300
316
  selector: 'h1'
301
317
  })).toBeVisible();
302
318
  });
303
- it('renders the SaveAsDialog when the Save as… button is clicked', async () => {
319
+ test('renders the SaveAsDialog when the Save as… button is clicked', async () => {
320
+ const user = userEvent.setup();
304
321
  renderFileMenu(fullAccessProps);
305
322
  await openDropdown();
306
- fireEvent.click(screen.getByTestId(MENU_ITEMS.SAVE_AS.testId));
323
+ await user.click(screen.getByTestId(MENU_ITEMS.SAVE_AS.testId));
307
324
  expect(await screen.findByText('Save visualization as', {
308
325
  selector: 'h1'
309
326
  })).toBeVisible();
310
327
  });
311
- it('renders the SaveAsDialog when the Save… button is clicked but no fileObject is present', async () => {
328
+ test('renders the SaveAsDialog when the Save… button is clicked but no fileObject is present', async () => {
329
+ const user = userEvent.setup();
312
330
  const customProps = {
313
331
  fileObject: {
314
332
  // NOTE: no `id` field
@@ -319,22 +337,24 @@ describe('The FileMenu component ', () => {
319
337
  };
320
338
  renderFileMenu(customProps);
321
339
  await openDropdown();
322
- fireEvent.click(screen.getByTestId(MENU_ITEMS.SAVE.testId));
340
+ await user.click(screen.getByTestId(MENU_ITEMS.SAVE.testId));
323
341
  expect(await screen.findByText('Save visualization as', {
324
342
  selector: 'h1'
325
343
  })).toBeVisible();
326
344
  });
327
- it('calls the onSave callback when the Save button is clicked and a fileObject is present', async () => {
345
+ test('calls the onSave callback when the Save button is clicked and a fileObject is present', async () => {
346
+ const user = userEvent.setup();
328
347
  renderFileMenu(fullAccessProps);
329
348
  await openDropdown();
330
- fireEvent.click(screen.getByTestId(MENU_ITEMS.SAVE.testId));
349
+ await user.click(screen.getByTestId(MENU_ITEMS.SAVE.testId));
331
350
  expect(screen.queryByText('Open a visualization')).not.toBeVisible();
332
351
  expect(onSave).toHaveBeenCalledTimes(1);
333
352
  });
334
- it('calls the onNew callback when the New button is clicked', async () => {
353
+ test('calls the onNew callback when the New button is clicked', async () => {
354
+ const user = userEvent.setup();
335
355
  renderFileMenu();
336
356
  await openDropdown();
337
- fireEvent.click(screen.getByTestId(MENU_ITEMS.NEW.testId));
357
+ await user.click(screen.getByTestId(MENU_ITEMS.NEW.testId));
338
358
  expect(screen.queryByText('Open a visualization')).not.toBeVisible();
339
359
  expect(onNew).toHaveBeenCalledTimes(1);
340
360
  });
@@ -1,5 +1,5 @@
1
- import { Button, Modal } from '@dhis2/ui';
2
- import { shallow } from 'enzyme';
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
3
  import React from 'react';
4
4
  import { GetLinkDialog } from '../GetLinkDialog.js';
5
5
  const testBaseUrl = 'http://host.tld/test/';
@@ -42,23 +42,27 @@ const tests = [{
42
42
  id: 'map-id-2',
43
43
  expected: 'http://localhost/dhis-web-maps/#/map-id-2'
44
44
  }];
45
- describe('The FileMenu - GetLinkDialog component', () => {
46
- let shallowGetLinkDialog;
45
+ describe('FileMenu - GetLinkDialog component', () => {
47
46
  const onClose = jest.fn();
48
- const getGetLinkDialogComponent = props => {
49
- if (!shallowGetLinkDialog) {
50
- shallowGetLinkDialog = shallow(/*#__PURE__*/React.createElement(GetLinkDialog, props));
51
- }
52
- return shallowGetLinkDialog;
47
+ const props = {
48
+ type: tests[0].type,
49
+ id: tests[0].id,
50
+ onClose
53
51
  };
54
- beforeEach(() => {
55
- shallowGetLinkDialog = undefined;
52
+ test('renders a Modal component', () => {
53
+ render(/*#__PURE__*/React.createElement(GetLinkDialog, props));
54
+ const modalComponent = screen.getByTestId('dhis2-uicore-modal');
55
+ expect(modalComponent).toBeInTheDocument();
56
+ expect(screen.getByLabelText('Close modal dialog')).toBeInTheDocument();
56
57
  });
57
- it('renders a Modal component', () => {
58
- expect(getGetLinkDialogComponent({
59
- type: tests[0].type,
60
- id: tests[0].id
61
- }).find(Modal)).toHaveLength(1);
58
+ test('calls the onClose callback when the Close button is clicked', async () => {
59
+ const user = userEvent.setup();
60
+ render(/*#__PURE__*/React.createElement(GetLinkDialog, props));
61
+ const closeButton = screen.getByRole('button', {
62
+ name: 'Close'
63
+ });
64
+ await user.click(closeButton);
65
+ expect(onClose).toHaveBeenCalledTimes(1);
62
66
  });
63
67
  test.each(tests)('renders a <a> tag containing the correct app path and id', ({
64
68
  apiVersion,
@@ -71,19 +75,12 @@ describe('The FileMenu - GetLinkDialog component', () => {
71
75
  apiVersion: apiVersion || 42,
72
76
  baseUrl
73
77
  });
74
- const href = getGetLinkDialogComponent({
75
- type,
76
- id,
77
- onClose
78
- }).find('a').prop('href');
79
- expect(href).toMatch(expected);
80
- });
81
- it('calls the onClose callback when the Close button is clicked', () => {
82
- getGetLinkDialogComponent({
83
- type: tests[0].type,
84
- id: tests[0].id,
85
- onClose
86
- }).find(Button).at(1).simulate('click');
87
- expect(onClose).toHaveBeenCalled();
78
+ render(/*#__PURE__*/React.createElement(GetLinkDialog, {
79
+ onClose: onClose,
80
+ type: type,
81
+ id: id
82
+ }));
83
+ const anchorElement = screen.getByRole('link');
84
+ expect(anchorElement.href).toMatch(expected);
88
85
  });
89
86
  });
@@ -1,9 +1,9 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import '@testing-library/jest-dom';
3
- import { render, fireEvent, screen, within } from '@testing-library/react';
2
+ import { render, screen, within } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
4
  import React from 'react';
5
5
  import { RenameDialog } from '../RenameDialog.js';
6
- describe('The FileMenu - RenameDialog component', () => {
6
+ describe('FileMenu - RenameDialog component', () => {
7
7
  const onClose = jest.fn();
8
8
  const onRename = jest.fn();
9
9
  const props = {
@@ -18,18 +18,18 @@ describe('The FileMenu - RenameDialog component', () => {
18
18
  jest.resetAllMocks();
19
19
  jest.clearAllMocks();
20
20
  });
21
- it('renders a Modal component with the correct heading', () => {
21
+ test('renders a Modal component with the correct heading', () => {
22
22
  render(/*#__PURE__*/React.createElement(RenameDialog, props));
23
23
  expect(screen.getAllByTestId('file-menu-rename-modal')).toHaveLength(1);
24
24
  expect(screen.getByRole('heading')).toHaveTextContent('Rename visualization');
25
25
  });
26
- it('renders a InputField for name', () => {
26
+ test('renders a InputField for name', () => {
27
27
  render(/*#__PURE__*/React.createElement(RenameDialog, props));
28
28
  expect(screen.getByTestId('file-menu-rename-modal-name')).toBeInTheDocument();
29
29
  expect(screen.getByText('Name')).toBeInTheDocument();
30
30
  expect(screen.getByText('Name')).toBeVisible();
31
31
  });
32
- it('renders a InputField for name with prefilled value if name is in object prop', () => {
32
+ test('renders a InputField for name with prefilled value if name is in object prop', () => {
33
33
  render(/*#__PURE__*/React.createElement(RenameDialog, _extends({}, props, {
34
34
  object: {
35
35
  ...props.object,
@@ -41,7 +41,7 @@ describe('The FileMenu - RenameDialog component', () => {
41
41
  expect(inputElement).toBeInTheDocument();
42
42
  expect(inputElement).toHaveValue('Vis test');
43
43
  });
44
- it('renders a TextAreaField for description', () => {
44
+ test('renders a TextAreaField for description', () => {
45
45
  render(/*#__PURE__*/React.createElement(RenameDialog, props));
46
46
 
47
47
  // Locate the label by its text
@@ -52,7 +52,7 @@ describe('The FileMenu - RenameDialog component', () => {
52
52
  expect(descriptionField).toBeInTheDocument();
53
53
  expect(descriptionField).toBeVisible();
54
54
  });
55
- it('renders a TextAreaField for description with prefilled value if description is in object prop', () => {
55
+ test('renders a TextAreaField for description with prefilled value if description is in object prop', () => {
56
56
  render(/*#__PURE__*/React.createElement(RenameDialog, _extends({}, props, {
57
57
  object: {
58
58
  ...props.object,
@@ -68,15 +68,21 @@ describe('The FileMenu - RenameDialog component', () => {
68
68
  expect(descriptionField).toBeInTheDocument();
69
69
  expect(descriptionField).toHaveValue('Long explanation of the visualization');
70
70
  });
71
- it('calls the onClose callback when the Cancel button is clicked', async () => {
71
+ test('calls the onClose callback when the Cancel button is clicked', async () => {
72
+ const user = userEvent.setup();
72
73
  render(/*#__PURE__*/React.createElement(RenameDialog, props));
73
- await fireEvent.click(screen.getByTestId('file-menu-rename-modal-cancel'));
74
+ await user.click(screen.getByRole('button', {
75
+ name: 'Cancel'
76
+ }));
74
77
  expect(onClose).toHaveBeenCalled();
75
78
  expect(onRename).not.toHaveBeenCalled();
76
79
  });
77
- it('calls the onRename callback when the Rename button is clicked', async () => {
80
+ test('calls the onRename callback when the Rename button is clicked', async () => {
81
+ const user = userEvent.setup();
78
82
  render(/*#__PURE__*/React.createElement(RenameDialog, props));
79
- await fireEvent.click(screen.getByTestId('file-menu-rename-modal-rename'));
83
+ await user.click(screen.getByRole('button', {
84
+ name: 'Rename'
85
+ }));
80
86
  expect(onRename).toHaveBeenCalled();
81
87
  expect(onClose).toHaveBeenCalled();
82
88
  });
@@ -1,53 +1,60 @@
1
- import { Button, Modal, ModalTitle } from '@dhis2/ui';
2
- import { shallow } from 'enzyme';
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
3
  import React from 'react';
4
4
  import { SaveAsDialog } from '../SaveAsDialog.js';
5
- describe('The FileMenu - SaveAsDialog component', () => {
6
- let shallowSaveAsDialog;
7
- let props;
5
+ describe('FileMenu - SaveAsDialog component', () => {
8
6
  const onClose = jest.fn();
9
7
  const onSaveAs = jest.fn();
10
- const getSaveAsDialogComponent = props => {
11
- if (!shallowSaveAsDialog) {
12
- shallowSaveAsDialog = shallow(/*#__PURE__*/React.createElement(SaveAsDialog, props));
13
- }
14
- return shallowSaveAsDialog;
8
+ const props = {
9
+ type: 'visualization',
10
+ object: {
11
+ name: 'Save as name test',
12
+ description: 'Save as description test'
13
+ },
14
+ onClose,
15
+ onSaveAs
15
16
  };
16
- beforeEach(() => {
17
- shallowSaveAsDialog = undefined;
18
- props = {
19
- type: 'visualization',
20
- object: {
21
- name: 'Save as name test',
22
- description: 'Save as description test'
23
- },
24
- onClose,
25
- onSaveAs
26
- };
17
+ test('renders a Modal component', () => {
18
+ render(/*#__PURE__*/React.createElement(SaveAsDialog, props));
19
+ expect(screen.getByTestId('file-menu-saveas-modal')).toBeInTheDocument();
27
20
  });
28
- it('renders a Modal component', () => {
29
- expect(getSaveAsDialogComponent(props).find(Modal)).toHaveLength(1);
21
+ test('renders a ModalTitle containing the type prop', () => {
22
+ render(/*#__PURE__*/React.createElement(SaveAsDialog, props));
23
+ expect(screen.getByRole('heading')).toHaveTextContent(`Save ${props.type} as`);
30
24
  });
31
- it('renders a ModalTitle containing the type prop', () => {
32
- expect(getSaveAsDialogComponent(props).find(ModalTitle).childAt(0).text()).toEqual(`Save ${props.type} as`);
25
+ test('renders a InputField for name with prefilled value from the object prop', () => {
26
+ render(/*#__PURE__*/React.createElement(SaveAsDialog, props));
27
+ expect(screen.getByTestId('file-menu-saveas-modal-name')).toBeInTheDocument();
28
+ expect(screen.getByText('Name')).toBeInTheDocument();
29
+ expect(screen.getByText('Name')).toBeVisible();
30
+ expect(screen.getByDisplayValue('Save as name test (copy)')).toBeInTheDocument();
33
31
  });
34
- it('renders a InputField for name with prefilled value from the object prop', () => {
35
- const nameInputField = getSaveAsDialogComponent(props).findWhere(n => n.prop('label') === 'Name');
36
- expect(nameInputField.prop('value')).toEqual('Save as name test (copy)');
32
+ test('renders a TextAreaField for description with prefilled value from the object prop', () => {
33
+ render(/*#__PURE__*/React.createElement(SaveAsDialog, props));
34
+ expect(screen.getByTestId('file-menu-saveas-modal-description')).toBeInTheDocument();
35
+ expect(screen.getByText('Description')).toBeInTheDocument();
36
+ expect(screen.getByText('Description')).toBeVisible();
37
+ expect(screen.getByDisplayValue(props.object.description)).toBeInTheDocument();
37
38
  });
38
- it('renders a TextAreaField for description with prefilled value from the object prop', () => {
39
- const descriptionInputField = getSaveAsDialogComponent(props).findWhere(n => n.prop('label') === 'Description');
40
- expect(descriptionInputField.prop('value')).toEqual(props.object.description);
41
- });
42
- it('calls the onSaveAs callback when the Save button is clicked', () => {
43
- getSaveAsDialogComponent(props).find(Button).at(1).simulate('click');
39
+ test('calls the onSaveAs callback when the Save button is clicked', async () => {
40
+ const user = userEvent.setup();
41
+ render(/*#__PURE__*/React.createElement(SaveAsDialog, props));
42
+ const saveButton = screen.getByRole('button', {
43
+ name: 'Save'
44
+ });
45
+ await user.click(saveButton);
44
46
  expect(onSaveAs).toHaveBeenCalledWith({
45
47
  name: 'Save as name test (copy)',
46
48
  description: props.object.description
47
49
  });
48
50
  });
49
- it('calls the onClose callback when the Cancel button is clicked', () => {
50
- getSaveAsDialogComponent(props).find(Button).first().simulate('click');
51
+ test('calls the onClose callback when the Cancel button is clicked', async () => {
52
+ const user = userEvent.setup();
53
+ render(/*#__PURE__*/React.createElement(SaveAsDialog, props));
54
+ const cancelButton = screen.getByRole('button', {
55
+ name: 'Cancel'
56
+ });
57
+ await user.click(cancelButton);
51
58
  expect(onClose).toHaveBeenCalled();
52
59
  });
53
60
  });
@@ -1,36 +1,31 @@
1
- import { InputField } from '@dhis2/ui';
2
- import { shallow } from 'enzyme';
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
3
  import React from 'react';
4
4
  import Filter from '../Filter.js';
5
- describe('The Filter component ', () => {
6
- let shallowFilter;
7
- let props;
8
- const filterComp = () => {
9
- if (!shallowFilter) {
10
- shallowFilter = shallow(/*#__PURE__*/React.createElement(Filter, props));
11
- }
12
- return shallowFilter;
13
- };
14
- beforeEach(() => {
15
- props = {
16
- placeholder: 'testplaceholder',
17
- text: '',
18
- onChange: jest.fn(),
19
- onClear: jest.fn()
20
- };
21
- shallowFilter = undefined;
22
- });
23
- it('renders a InputField component', () => {
24
- expect(filterComp().find(InputField).length).toEqual(1);
25
- });
26
- it('should call prop onClear if onChange receives text string with length < 1 (Ctrl-A + BackSpace)', () => {
27
- props.text = 'anotherTestString';
28
- const filter = filterComp().find(InputField);
29
- const mockEvent = {
30
- value: '',
31
- preventDefault: jest.fn()
32
- };
33
- filter.props().onChange(mockEvent);
34
- expect(props.onClear).toHaveBeenCalledTimes(1);
35
- });
5
+ const props = {
6
+ placeholder: 'testplaceholder',
7
+ text: '',
8
+ onChange: jest.fn(),
9
+ onClear: jest.fn()
10
+ };
11
+ test('Filter renders an InputField component ', () => {
12
+ render(/*#__PURE__*/React.createElement(Filter, props));
13
+ const inputField = screen.getByTestId('dhis2-uiwidgets-inputfield');
14
+ expect(inputField).toBeInTheDocument();
15
+ });
16
+ test('Filter renders an input field with the given placeholder', () => {
17
+ render(/*#__PURE__*/React.createElement(Filter, props));
18
+ const inputField = screen.getByPlaceholderText(props.placeholder);
19
+ expect(inputField).toBeInTheDocument();
20
+ });
21
+ test('Filter should call prop onClear if onChange receives text string with length < 1 (Ctrl-A + BackSpace)', async () => {
22
+ const user = userEvent.setup();
23
+ props.text = 'anotherTestString';
24
+ render(/*#__PURE__*/React.createElement(Filter, props));
25
+ const inputField = screen.getByPlaceholderText(props.placeholder);
26
+
27
+ // focus on the input field in order to interact with it
28
+ await user.click(inputField);
29
+ await user.keyboard('{Control>}A{/Control}{Backspace}');
30
+ expect(props.onClear).toHaveBeenCalledTimes(1);
36
31
  });
@@ -8,6 +8,13 @@ import React from 'react';
8
8
  export const CREATED_BY_ALL = 'all';
9
9
  export const CREATED_BY_ALL_BUT_CURRENT_USER = 'allButCurrentUser';
10
10
  export const CREATED_BY_CURRENT_USER = 'currentUser';
11
+ export const formatUserFilter = (createdBy, userId) => {
12
+ if (createdBy === CREATED_BY_ALL_BUT_CURRENT_USER) {
13
+ return `user.id:!eq:${userId}`;
14
+ } else if (createdBy === CREATED_BY_CURRENT_USER) {
15
+ return `user.id:eq:${userId}`;
16
+ }
17
+ };
11
18
  export const CreatedByFilter = ({
12
19
  selected,
13
20
  onChange