@reltio/dashboard 1.4.1584 → 1.4.1586-mui5
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.
- package/.DS_Store +0 -0
- package/index.ts +12 -0
- package/package.json +42 -25
- package/public/bundle.js +205 -0
- package/public/bundle.js.LICENSE.txt +59 -0
- package/public/package.json +26 -0
- package/public/types/components/DashboardConfigItem/styles.d.ts +1 -0
- package/{types → public/types}/components/DashboardError/styles.d.ts +1 -1
- package/public/types/components/DashboardLayout/styles.d.ts +1 -0
- package/public/types/components/DashboardLayoutItem/styles.d.ts +1 -0
- package/public/types/components/DashboardLayoutPanel/styles.d.ts +1 -0
- package/public/types/components/DashboardLinearLoader/styles.d.ts +1 -0
- package/{types → public/types}/components/DashboardNoData/styles.d.ts +1 -1
- package/public/types/components/DashboardPerspectiveHeader/styles.d.ts +2 -0
- package/{types → public/types}/components/DashboardPopupMenu/DashboardPopupMenu.d.ts +1 -1
- package/public/types/components/DashboardPopupMenu/styles.d.ts +1 -0
- package/public/types/components/EntityTable/cell-renderers/styles.d.ts +1 -0
- package/{types → public/types}/components/EntityTable/styles.d.ts +1 -1
- package/public/types/components/LayoutItemContent/styles.d.ts +1 -0
- package/public/types/components/LayoutItemHeader/styles.d.ts +1 -0
- package/public/types/components/LayoutItemView/styles.d.ts +1 -0
- package/public/types/components/StatsChart/customized/styles.d.ts +1 -0
- package/public/types/components/WorkflowTaskItem/styles.d.ts +1 -0
- package/public/types/perspective/styles.d.ts +1 -0
- package/public/types/views/chartBased/styles.d.ts +1 -0
- package/public/types/views/custom/styles.d.ts +1 -0
- package/public/types/views/tableBased/styles.d.ts +1 -0
- package/scripts/build/index.js +21 -0
- package/src/HOCs/withPagination.tsx +39 -0
- package/src/components/DashboardConfigItem/DashboardConfigItem.tsx +101 -0
- package/src/components/DashboardConfigItem/__tests__/DashboardConfigItem.specs.tsx +81 -0
- package/src/components/DashboardConfigItem/icons/barChart.svg +12 -0
- package/src/components/DashboardConfigItem/icons/bubbleChart.svg +18 -0
- package/src/components/DashboardConfigItem/icons/customChart.svg +66 -0
- package/src/components/DashboardConfigItem/icons/donutChart.svg +33 -0
- package/src/components/DashboardConfigItem/icons/geomap.svg +23 -0
- package/src/components/DashboardConfigItem/icons/lineChart.svg +16 -0
- package/src/components/DashboardConfigItem/icons/pieChart.svg +27 -0
- package/src/components/DashboardConfigItem/icons/tableWithBars.svg +27 -0
- package/src/components/DashboardConfigItem/icons/treemap.svg +15 -0
- package/src/components/DashboardConfigItem/icons/wordCloud.svg +27 -0
- package/src/components/DashboardConfigItem/styles.ts +56 -0
- package/src/components/DashboardError/DashboardError.tsx +34 -0
- package/src/components/DashboardError/__tests__/DashboardError.test.js +34 -0
- package/src/components/DashboardError/icons/error.svg +113 -0
- package/src/components/DashboardError/styles.ts +30 -0
- package/src/components/DashboardLayout/DashboardLayout.tsx +59 -0
- package/src/components/DashboardLayout/__tests__/DashboardLayout.specs.tsx +56 -0
- package/src/components/DashboardLayout/styles.ts +30 -0
- package/src/components/DashboardLayoutItem/DashboardLayoutItem.tsx +59 -0
- package/src/components/DashboardLayoutItem/__tests__/DashboardLayoutItem.specs.tsx +145 -0
- package/src/components/DashboardLayoutItem/styles.ts +10 -0
- package/src/components/DashboardLayoutPanel/DashboardLayoutPanel.tsx +59 -0
- package/src/components/DashboardLayoutPanel/__tests__/DashboardLayoutPanel.specs.tsx +58 -0
- package/src/components/DashboardLayoutPanel/styles.ts +43 -0
- package/src/components/DashboardLinearLoader/DashboardLinearLoader.tsx +10 -0
- package/src/components/DashboardLinearLoader/__tests__/DashboardLinearLoader.test.js +12 -0
- package/src/components/DashboardLinearLoader/styles.ts +11 -0
- package/src/components/DashboardNoData/.DS_Store +0 -0
- package/src/components/DashboardNoData/DashboardNoData.tsx +21 -0
- package/src/components/DashboardNoData/__tests__/DashboardNoData.test.js +15 -0
- package/src/components/DashboardNoData/icons/noData.svg +68 -0
- package/src/components/DashboardNoData/styles.ts +21 -0
- package/src/components/DashboardPerspectiveHeader/DashboardPerspectiveHeader.tsx +43 -0
- package/src/components/DashboardPerspectiveHeader/__tests__/DashboardPerspectiveHeader.specs.tsx +41 -0
- package/src/components/DashboardPerspectiveHeader/styles.ts +24 -0
- package/src/components/DashboardPopupMenu/DashboardPopupMenu.tsx +75 -0
- package/src/components/DashboardPopupMenu/__tests__/DashboardPopupMenu.test.tsx +51 -0
- package/src/components/DashboardPopupMenu/styles.ts +20 -0
- package/src/components/EntityTable/EntityTable.tsx +49 -0
- package/src/components/EntityTable/__tests__/EntityTable.test.tsx +33 -0
- package/src/components/EntityTable/cell-renderers/EntityLabelRenderer.tsx +24 -0
- package/src/components/EntityTable/cell-renderers/HeadCellRenderer.tsx +34 -0
- package/src/components/EntityTable/cell-renderers/__tests__/EntityLabelRenderer.test.tsx +25 -0
- package/src/components/EntityTable/cell-renderers/styles.ts +46 -0
- package/src/components/EntityTable/styles.ts +19 -0
- package/src/components/LayoutItemContent/LayoutItemContent.tsx +63 -0
- package/src/components/LayoutItemContent/__tests__/LayoutItemContent.test.tsx +71 -0
- package/src/components/LayoutItemContent/styles.ts +36 -0
- package/src/components/LayoutItemHeader/LayoutItemHeader.tsx +86 -0
- package/src/components/LayoutItemHeader/__tests__/LayoutItemHeader.specs.tsx +48 -0
- package/src/components/LayoutItemHeader/styles.ts +44 -0
- package/src/components/LayoutItemView/LayoutItemView.tsx +24 -0
- package/src/components/LayoutItemView/styles.ts +11 -0
- package/src/components/StatsChart/StatsChart.tsx +77 -0
- package/src/components/StatsChart/__tests__/StatsChart.test.tsx +106 -0
- package/src/components/StatsChart/customized/CustomAxisTick.tsx +28 -0
- package/src/components/StatsChart/customized/CustomLegend.tsx +37 -0
- package/src/components/StatsChart/customized/CustomTooltip.tsx +41 -0
- package/src/components/StatsChart/customized/styles.ts +53 -0
- package/src/components/StatsChart/getStatsChartSettings.ts +65 -0
- package/src/components/WorkflowTaskItem/WorkflowTaskItem.tsx +67 -0
- package/src/components/WorkflowTaskItem/WorkflowTaskObject.tsx +54 -0
- package/src/components/WorkflowTaskItem/__tests__/WorkflowTaskItem.test.tsx +73 -0
- package/src/components/WorkflowTaskItem/__tests__/WorkflowTaskObject.test.tsx +95 -0
- package/src/components/WorkflowTaskItem/styles.ts +74 -0
- package/src/components/WorkflowTasksList/WorkflowTasksList.tsx +34 -0
- package/src/components/WorkflowTasksList/__tests__/WorkflowTasksList.test.tsx +98 -0
- package/src/components/index.ts +8 -0
- package/src/contexts/DashboardViewIdContext/index.ts +5 -0
- package/src/hooks/__tests__/useActivititesRequest.specs.tsx +106 -0
- package/src/hooks/__tests__/useEntityByTypeRequest.specs.tsx +280 -0
- package/src/hooks/__tests__/useFacetRequest.specs.tsx +437 -0
- package/src/hooks/__tests__/useFilteredEntitiesRequest.specs.tsx +103 -0
- package/src/hooks/__tests__/useSavedSearchesRequest.specs.tsx +201 -0
- package/src/hooks/__tests__/useStatsRequest.specs.tsx +212 -0
- package/src/hooks/__tests__/useWorkflowTasksRequest.specs.tsx +388 -0
- package/src/hooks/useActivitiesRequest.ts +50 -0
- package/src/hooks/useEntityByTypeRequest.ts +67 -0
- package/src/hooks/useFacetRequest.ts +117 -0
- package/src/hooks/useFilteredEntitiesRequest.ts +57 -0
- package/src/hooks/useSavedSearchesRequest.ts +82 -0
- package/src/hooks/useStatsRequest.ts +47 -0
- package/src/hooks/useWorkflowTasksRequest.ts +66 -0
- package/src/index.ts +25 -0
- package/src/perspective/DashboardPerspectiveView.tsx +132 -0
- package/src/perspective/__tests__/DashboardPerspectiveView.specs.tsx +276 -0
- package/src/perspective/__tests__/data/metadata.data.ts +33 -0
- package/src/perspective/__tests__/data/store.data.ts +15 -0
- package/src/perspective/__tests__/helpers.specs.ts +33 -0
- package/src/perspective/helpers.ts +19 -0
- package/src/perspective/index.tsx +65 -0
- package/src/perspective/styles.ts +16 -0
- package/src/services/__tests__/facets.specs.ts +42 -0
- package/src/services/__tests__/filters.specs.ts +60 -0
- package/src/services/__tests__/period.test.ts +33 -0
- package/src/services/__tests__/stats.test.ts +319 -0
- package/src/services/entityTypes.ts +66 -0
- package/src/services/facets.ts +178 -0
- package/src/services/filters.ts +87 -0
- package/src/services/period.ts +33 -0
- package/src/services/savedSearches.ts +20 -0
- package/src/services/stats.ts +191 -0
- package/src/services/workflowTasks.ts +116 -0
- package/src/types/ActivitiesViewFacetConfig.ts +5 -0
- package/src/types/CustomActionViewFacetConfig.ts +5 -0
- package/src/types/DashboardPerspectiveConfig.ts +18 -0
- package/src/types/DashboardSavedState.ts +7 -0
- package/src/types/EntityByTypeViewFacetConfig.ts +7 -0
- package/src/types/EntityData.ts +4 -0
- package/src/types/FilteredEntitiesFacetConfig.ts +6 -0
- package/src/types/FilteredSavedSearchesFacetConfig.ts +6 -0
- package/src/types/PeriodStep.ts +4 -0
- package/src/types/SavedSearchData.ts +6 -0
- package/src/types/SearchOptions.ts +10 -0
- package/src/types/StatsData.ts +14 -0
- package/src/types/WorkflowTasks.ts +26 -0
- package/src/types/index.ts +14 -0
- package/src/views/ViewsFactory.tsx +79 -0
- package/src/views/__tests__/ViewsFactory.specs.tsx +70 -0
- package/src/views/chartBased/DashboardFacet.tsx +71 -0
- package/src/views/chartBased/EntitiesByTypeViewFacet.tsx +60 -0
- package/src/views/chartBased/ProfileStatsFacet.tsx +54 -0
- package/src/views/chartBased/__tests__/DashboardFacet.specs.tsx +358 -0
- package/src/views/chartBased/__tests__/EntitiesByTypeViewFacet.specs.tsx +101 -0
- package/src/views/chartBased/__tests__/ProfileStatsFacet.specs.tsx +106 -0
- package/src/views/chartBased/styles.ts +13 -0
- package/src/views/custom/CustomActionViewFacet.tsx +36 -0
- package/src/views/custom/NotificationInboxFacet.tsx +86 -0
- package/src/views/custom/__tests__/CustomActionViewFacet.specs.tsx +35 -0
- package/src/views/custom/__tests__/NotificationInboxFacet.specs.tsx +144 -0
- package/src/views/custom/styles.ts +31 -0
- package/src/views/tableBased/ActivitiesViewFacet.tsx +79 -0
- package/src/views/tableBased/FilteredEntitiesViewFacet.tsx +67 -0
- package/src/views/tableBased/FilteredSavedSearchesFacet.tsx +85 -0
- package/src/views/tableBased/__tests__/ActivitiesViewFacet.specs.tsx +113 -0
- package/src/views/tableBased/__tests__/FIlteredEntitiesViewFacet.specs.tsx +90 -0
- package/src/views/tableBased/__tests__/FilteredSavedSearchesFacet.specs.tsx +133 -0
- package/src/views/tableBased/helpers.ts +8 -0
- package/src/views/tableBased/styles.ts +7 -0
- package/stories/Dashboards.stories.js +118 -0
- package/stories/utils/dashboardPerspectiveConfig.js +78 -0
- package/stories/utils/dashboardsViewConfig.js +17 -0
- package/stories/utils/mdmStore.js +73 -0
- package/stories/utils/responses.js +10 -0
- package/tsconfig.json +14 -0
- package/webpack.config.js +10 -0
- package/bundle.js +0 -2
- package/bundle.js.LICENSE.txt +0 -22
- package/types/components/DashboardConfigItem/styles.d.ts +0 -1
- package/types/components/DashboardLayout/styles.d.ts +0 -1
- package/types/components/DashboardLayoutItem/styles.d.ts +0 -1
- package/types/components/DashboardLayoutPanel/styles.d.ts +0 -1
- package/types/components/DashboardLinearLoader/styles.d.ts +0 -1
- package/types/components/DashboardPerspectiveHeader/styles.d.ts +0 -2
- package/types/components/DashboardPopupMenu/styles.d.ts +0 -1
- package/types/components/EntityTable/cell-renderers/styles.d.ts +0 -1
- package/types/components/LayoutItemContent/styles.d.ts +0 -1
- package/types/components/LayoutItemHeader/styles.d.ts +0 -1
- package/types/components/LayoutItemView/styles.d.ts +0 -1
- package/types/components/StatsChart/customized/styles.d.ts +0 -1
- package/types/components/WorkflowTaskItem/styles.d.ts +0 -1
- package/types/perspective/styles.d.ts +0 -1
- package/types/views/chartBased/styles.d.ts +0 -1
- package/types/views/custom/styles.d.ts +0 -1
- package/types/views/tableBased/styles.d.ts +0 -1
- /package/{types → public/types}/HOCs/withPagination.d.ts +0 -0
- /package/{types → public/types}/components/DashboardConfigItem/DashboardConfigItem.d.ts +0 -0
- /package/{types → public/types}/components/DashboardError/DashboardError.d.ts +0 -0
- /package/{types → public/types}/components/DashboardLayout/DashboardLayout.d.ts +0 -0
- /package/{types → public/types}/components/DashboardLayoutItem/DashboardLayoutItem.d.ts +0 -0
- /package/{types → public/types}/components/DashboardLayoutPanel/DashboardLayoutPanel.d.ts +0 -0
- /package/{types → public/types}/components/DashboardLinearLoader/DashboardLinearLoader.d.ts +0 -0
- /package/{types → public/types}/components/DashboardNoData/DashboardNoData.d.ts +0 -0
- /package/{types → public/types}/components/DashboardPerspectiveHeader/DashboardPerspectiveHeader.d.ts +0 -0
- /package/{types → public/types}/components/EntityTable/EntityTable.d.ts +0 -0
- /package/{types → public/types}/components/EntityTable/cell-renderers/EntityLabelRenderer.d.ts +0 -0
- /package/{types → public/types}/components/EntityTable/cell-renderers/HeadCellRenderer.d.ts +0 -0
- /package/{types → public/types}/components/LayoutItemContent/LayoutItemContent.d.ts +0 -0
- /package/{types → public/types}/components/LayoutItemHeader/LayoutItemHeader.d.ts +0 -0
- /package/{types → public/types}/components/LayoutItemView/LayoutItemView.d.ts +0 -0
- /package/{types → public/types}/components/StatsChart/StatsChart.d.ts +0 -0
- /package/{types → public/types}/components/StatsChart/customized/CustomAxisTick.d.ts +0 -0
- /package/{types → public/types}/components/StatsChart/customized/CustomLegend.d.ts +0 -0
- /package/{types → public/types}/components/StatsChart/customized/CustomTooltip.d.ts +0 -0
- /package/{types → public/types}/components/StatsChart/getStatsChartSettings.d.ts +0 -0
- /package/{types → public/types}/components/WorkflowTaskItem/WorkflowTaskItem.d.ts +0 -0
- /package/{types → public/types}/components/WorkflowTaskItem/WorkflowTaskObject.d.ts +0 -0
- /package/{types → public/types}/components/WorkflowTasksList/WorkflowTasksList.d.ts +0 -0
- /package/{types → public/types}/components/index.d.ts +0 -0
- /package/{types → public/types}/contexts/DashboardViewIdContext/index.d.ts +0 -0
- /package/{types → public/types}/hooks/useActivitiesRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useEntityByTypeRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useFacetRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useFilteredEntitiesRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useSavedSearchesRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useStatsRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useWorkflowTasksRequest.d.ts +0 -0
- /package/{types → public/types}/index.d.ts +0 -0
- /package/{types → public/types}/perspective/DashboardPerspectiveView.d.ts +0 -0
- /package/{types → public/types}/perspective/helpers.d.ts +0 -0
- /package/{types → public/types}/perspective/index.d.ts +0 -0
- /package/{types → public/types}/services/entityTypes.d.ts +0 -0
- /package/{types → public/types}/services/facets.d.ts +0 -0
- /package/{types → public/types}/services/filters.d.ts +0 -0
- /package/{types → public/types}/services/period.d.ts +0 -0
- /package/{types → public/types}/services/savedSearches.d.ts +0 -0
- /package/{types → public/types}/services/stats.d.ts +0 -0
- /package/{types → public/types}/services/workflowTasks.d.ts +0 -0
- /package/{types → public/types}/types/ActivitiesViewFacetConfig.d.ts +0 -0
- /package/{types → public/types}/types/CustomActionViewFacetConfig.d.ts +0 -0
- /package/{types → public/types}/types/DashboardPerspectiveConfig.d.ts +0 -0
- /package/{types → public/types}/types/DashboardSavedState.d.ts +0 -0
- /package/{types → public/types}/types/EntityByTypeViewFacetConfig.d.ts +0 -0
- /package/{types → public/types}/types/EntityData.d.ts +0 -0
- /package/{types → public/types}/types/FilteredEntitiesFacetConfig.d.ts +0 -0
- /package/{types → public/types}/types/FilteredSavedSearchesFacetConfig.d.ts +0 -0
- /package/{types → public/types}/types/PeriodStep.d.ts +0 -0
- /package/{types → public/types}/types/SavedSearchData.d.ts +0 -0
- /package/{types → public/types}/types/SearchOptions.d.ts +0 -0
- /package/{types → public/types}/types/StatsData.d.ts +0 -0
- /package/{types → public/types}/types/WorkflowTasks.d.ts +0 -0
- /package/{types → public/types}/types/index.d.ts +0 -0
- /package/{types → public/types}/views/ViewsFactory.d.ts +0 -0
- /package/{types → public/types}/views/chartBased/DashboardFacet.d.ts +0 -0
- /package/{types → public/types}/views/chartBased/EntitiesByTypeViewFacet.d.ts +0 -0
- /package/{types → public/types}/views/chartBased/ProfileStatsFacet.d.ts +0 -0
- /package/{types → public/types}/views/custom/CustomActionViewFacet.d.ts +0 -0
- /package/{types → public/types}/views/custom/NotificationInboxFacet.d.ts +0 -0
- /package/{types → public/types}/views/tableBased/ActivitiesViewFacet.d.ts +0 -0
- /package/{types → public/types}/views/tableBased/FilteredEntitiesViewFacet.d.ts +0 -0
- /package/{types → public/types}/views/tableBased/FilteredSavedSearchesFacet.d.ts +0 -0
- /package/{types → public/types}/views/tableBased/helpers.d.ts +0 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import * as mdmSdkModule from '@reltio/mdm-sdk';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import {act} from 'react-dom/test-utils';
|
|
4
|
+
import {asyncCheck} from '../../../../../__mocks__/test-utils';
|
|
5
|
+
import {mount} from 'enzyme';
|
|
6
|
+
import {useSavedSearchesRequest} from '../useSavedSearchesRequest';
|
|
7
|
+
|
|
8
|
+
jest.mock('@reltio/mdm-sdk', () => ({
|
|
9
|
+
...jest.requireActual<Record<string, unknown>>('@reltio/mdm-sdk'),
|
|
10
|
+
getSavedSearches: jest.fn(),
|
|
11
|
+
getTotalsForQuery: jest.fn<Promise<any>, [string]>()
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
describe('useSavedSearchesRequest behavior', () => {
|
|
15
|
+
const TestComponent = ({payload}) => {
|
|
16
|
+
const {data, state, reload, total} = useSavedSearchesRequest(payload);
|
|
17
|
+
return state ? <div data-test={{state, data, reload, total}} /> : null;
|
|
18
|
+
};
|
|
19
|
+
const savedSearchResponseCommonPart = {
|
|
20
|
+
favoriteOnly: true,
|
|
21
|
+
max: 10,
|
|
22
|
+
offset: 0,
|
|
23
|
+
sortBy: 'NAME',
|
|
24
|
+
sortOrder: 'ASC',
|
|
25
|
+
total: 10
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const getHooksValues = (component) => component.find('TestComponent').childAt(0).prop('data-test');
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
jest.restoreAllMocks();
|
|
31
|
+
});
|
|
32
|
+
it('should send request and be in the loading state, and be in loaded state once data is loaded', (done) => {
|
|
33
|
+
const payload = {
|
|
34
|
+
max: 10,
|
|
35
|
+
options: {
|
|
36
|
+
favoriteOnly: true,
|
|
37
|
+
countResults: false
|
|
38
|
+
},
|
|
39
|
+
offset: 0
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const hookResponse = {
|
|
43
|
+
...savedSearchResponseCommonPart,
|
|
44
|
+
result: [
|
|
45
|
+
{name: 'Crazy-mini', uri: 'savedSavedSearch/1'},
|
|
46
|
+
{name: 'crazySS', count: 18900000, uri: 'savedSearch/2'}
|
|
47
|
+
]
|
|
48
|
+
};
|
|
49
|
+
jest.spyOn(mdmSdkModule, 'getSavedSearches').mockImplementation(() => {
|
|
50
|
+
return Promise.resolve(hookResponse);
|
|
51
|
+
});
|
|
52
|
+
let component;
|
|
53
|
+
act(() => {
|
|
54
|
+
component = mount(<TestComponent payload={payload} />);
|
|
55
|
+
});
|
|
56
|
+
act(() => {
|
|
57
|
+
component.update();
|
|
58
|
+
const {state} = getHooksValues(component);
|
|
59
|
+
expect(state).toBe('loading');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
asyncCheck(() => {
|
|
63
|
+
act(() => {
|
|
64
|
+
component.update();
|
|
65
|
+
});
|
|
66
|
+
const {state, data} = getHooksValues(component);
|
|
67
|
+
expect(state).toBe('loaded');
|
|
68
|
+
expect(data).toStrictEqual(hookResponse.result);
|
|
69
|
+
}, done);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should send total requests if option countResults is true', (done) => {
|
|
73
|
+
const payload = {
|
|
74
|
+
max: 10,
|
|
75
|
+
options: {
|
|
76
|
+
favoriteOnly: true,
|
|
77
|
+
countResults: true
|
|
78
|
+
},
|
|
79
|
+
offset: 0
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const hookResponse = {
|
|
83
|
+
...savedSearchResponseCommonPart,
|
|
84
|
+
result: [
|
|
85
|
+
{
|
|
86
|
+
name: 'Crazy-mini',
|
|
87
|
+
uri: 'savedSavedSearch/1',
|
|
88
|
+
query: encodeURIComponent("savedSearch1 range(activeness.startDate,'${lastDay}','${now}')")
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'crazySS',
|
|
92
|
+
uri: 'savedSearch/2',
|
|
93
|
+
query: encodeURIComponent("savedSearch2 equals(type,'configuration/entityTypes/People')")
|
|
94
|
+
},
|
|
95
|
+
{name: 'wrong', uri: 'savedSearch/2', query: encodeURIComponent('wrong query')}
|
|
96
|
+
]
|
|
97
|
+
};
|
|
98
|
+
jest.spyOn(mdmSdkModule, 'getSavedSearches').mockImplementation(() => {
|
|
99
|
+
return Promise.resolve(hookResponse);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const getTotalsForQuerySpy = jest
|
|
103
|
+
.spyOn(mdmSdkModule, 'getTotalsForQuery')
|
|
104
|
+
.mockImplementation((query: string) => {
|
|
105
|
+
if (query.includes('savedSearch1')) {
|
|
106
|
+
return Promise.resolve({total: 1});
|
|
107
|
+
}
|
|
108
|
+
if (query.includes('savedSearch2')) {
|
|
109
|
+
return Promise.resolve({total: 2});
|
|
110
|
+
}
|
|
111
|
+
return Promise.reject('Error from total');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
let component;
|
|
115
|
+
act(() => {
|
|
116
|
+
component = mount(<TestComponent payload={payload} />);
|
|
117
|
+
});
|
|
118
|
+
act(() => {
|
|
119
|
+
component.update();
|
|
120
|
+
const {state} = getHooksValues(component);
|
|
121
|
+
expect(state).toBe('loading');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
asyncCheck(() => {
|
|
125
|
+
act(() => {
|
|
126
|
+
component.update();
|
|
127
|
+
});
|
|
128
|
+
const {state, data} = getHooksValues(component);
|
|
129
|
+
expect(state).toBe('loaded');
|
|
130
|
+
expect(data).toStrictEqual([
|
|
131
|
+
{...hookResponse.result[0], count: 1},
|
|
132
|
+
{...hookResponse.result[1], count: 2},
|
|
133
|
+
hookResponse.result[2]
|
|
134
|
+
]);
|
|
135
|
+
expect(getTotalsForQuerySpy.mock.calls.length).toBe(3);
|
|
136
|
+
expect(getTotalsForQuerySpy.mock.calls[0][0]).not.toContain('lastDay');
|
|
137
|
+
expect(getTotalsForQuerySpy.mock.calls[0][0]).not.toContain('now');
|
|
138
|
+
}, done);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should not fail with nil options', async () => {
|
|
142
|
+
const payload = {
|
|
143
|
+
max: 10,
|
|
144
|
+
offset: 0
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const hookResponse = {
|
|
148
|
+
...savedSearchResponseCommonPart,
|
|
149
|
+
result: [
|
|
150
|
+
{
|
|
151
|
+
name: 'Crazy-mini',
|
|
152
|
+
uri: 'savedSavedSearch/1',
|
|
153
|
+
query: encodeURIComponent("savedSearch1 range(activeness.startDate,'${lastDay}','${now}')")
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: 'crazySS',
|
|
157
|
+
uri: 'savedSearch/2',
|
|
158
|
+
query: encodeURIComponent("savedSearch2 equals(type,'configuration/entityTypes/People')")
|
|
159
|
+
},
|
|
160
|
+
{name: 'wrong', uri: 'savedSearch/2', query: encodeURIComponent('wrong query')}
|
|
161
|
+
]
|
|
162
|
+
};
|
|
163
|
+
jest.spyOn(mdmSdkModule, 'getSavedSearches').mockImplementation(() => {
|
|
164
|
+
return Promise.resolve(hookResponse);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
let component;
|
|
168
|
+
await act(async () => {
|
|
169
|
+
component = mount(<TestComponent payload={payload} />);
|
|
170
|
+
});
|
|
171
|
+
component.update();
|
|
172
|
+
|
|
173
|
+
const {state, data} = getHooksValues(component);
|
|
174
|
+
expect(state).toBe('loaded');
|
|
175
|
+
expect(data).toStrictEqual(hookResponse.result);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should not fail when response.result is undefined', async () => {
|
|
179
|
+
const payload = {
|
|
180
|
+
max: 10,
|
|
181
|
+
options: {
|
|
182
|
+
favoriteOnly: true,
|
|
183
|
+
countResults: true
|
|
184
|
+
},
|
|
185
|
+
offset: 0
|
|
186
|
+
};
|
|
187
|
+
jest.spyOn(mdmSdkModule, 'getSavedSearches').mockImplementation(() => {
|
|
188
|
+
return Promise.resolve(savedSearchResponseCommonPart);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
let component;
|
|
192
|
+
await act(async () => {
|
|
193
|
+
component = mount(<TestComponent payload={payload} />);
|
|
194
|
+
});
|
|
195
|
+
component.update();
|
|
196
|
+
|
|
197
|
+
const {state, data} = getHooksValues(component);
|
|
198
|
+
expect(state).toBe('loaded');
|
|
199
|
+
expect(data).toStrictEqual([]);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import {renderHook, act} from '@testing-library/react-hooks';
|
|
2
|
+
import * as mdmSdkModule from '@reltio/mdm-sdk';
|
|
3
|
+
import {DateRangeValue} from '@reltio/mdm-sdk';
|
|
4
|
+
import {RequestStates} from '@reltio/components';
|
|
5
|
+
import {PeriodStep} from '../../types/PeriodStep';
|
|
6
|
+
import {useStatsRequest} from '../useStatsRequest';
|
|
7
|
+
|
|
8
|
+
jest.mock('@reltio/mdm-sdk', () => ({
|
|
9
|
+
...jest.requireActual<Record<string, unknown>>('@reltio/mdm-sdk'),
|
|
10
|
+
getEntitiesStats: jest.fn(),
|
|
11
|
+
getDateRangeByDatePeriod: jest.fn()
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const START_TIME = 123;
|
|
15
|
+
const END_TIME = 456;
|
|
16
|
+
|
|
17
|
+
describe('useStatsRequest behavior', () => {
|
|
18
|
+
const getEntitiesStats = jest.spyOn(mdmSdkModule, 'getEntitiesStats');
|
|
19
|
+
const getDateRangeByDatePeriod = jest.spyOn(mdmSdkModule, 'getDateRangeByDatePeriod');
|
|
20
|
+
|
|
21
|
+
const getEmptyEventData = (event: string) => ({
|
|
22
|
+
event,
|
|
23
|
+
total: 0,
|
|
24
|
+
data: [
|
|
25
|
+
{term: START_TIME, count: 0},
|
|
26
|
+
{term: END_TIME, count: 0}
|
|
27
|
+
]
|
|
28
|
+
});
|
|
29
|
+
const fullStatsRequest = {
|
|
30
|
+
facet: 'type',
|
|
31
|
+
types: [
|
|
32
|
+
'CREATED',
|
|
33
|
+
'UPDATED',
|
|
34
|
+
'DELETED',
|
|
35
|
+
'POTENTIAL_MATCHES_FOUND',
|
|
36
|
+
'MERGED',
|
|
37
|
+
'MERGED_ON_THE_FLY',
|
|
38
|
+
'MERGED_MANUALLY',
|
|
39
|
+
'SPLITTED',
|
|
40
|
+
'NOT_MATCHES_SET'
|
|
41
|
+
],
|
|
42
|
+
startTime: START_TIME,
|
|
43
|
+
endTime: END_TIME
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
let resolveRequest;
|
|
47
|
+
let rejectRequest;
|
|
48
|
+
beforeAll(() => {
|
|
49
|
+
getEntitiesStats.mockImplementation(({facet, types}) => {
|
|
50
|
+
switch (facet) {
|
|
51
|
+
case 'type': {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
resolveRequest = resolve;
|
|
54
|
+
rejectRequest = reject;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
case PeriodStep.HOUR: {
|
|
58
|
+
if (types.includes('CREATED')) {
|
|
59
|
+
return Promise.resolve({
|
|
60
|
+
total: 150,
|
|
61
|
+
facets: {
|
|
62
|
+
hour: [{term: '2021-04-05T04', count: 150}]
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (types.includes('DELETED')) {
|
|
67
|
+
return Promise.resolve({
|
|
68
|
+
total: 50,
|
|
69
|
+
facets: {
|
|
70
|
+
hour: [{term: '2021-04-05T09', count: 50}]
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return Promise.reject();
|
|
75
|
+
}
|
|
76
|
+
default: {
|
|
77
|
+
return Promise.reject();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
getDateRangeByDatePeriod.mockImplementation(() => [START_TIME, END_TIME]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
afterEach(() => {
|
|
85
|
+
jest.clearAllMocks();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should send request and be in the loading state, and be in loaded state once data is loaded', async () => {
|
|
89
|
+
const {result} = renderHook(useStatsRequest, {initialProps: DateRangeValue.LAST_DAY});
|
|
90
|
+
expect(result.current).toMatchObject({
|
|
91
|
+
state: RequestStates.LOADING,
|
|
92
|
+
step: PeriodStep.HOUR,
|
|
93
|
+
data: []
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await act(async () => {
|
|
97
|
+
resolveRequest({
|
|
98
|
+
total: 200,
|
|
99
|
+
facets: {
|
|
100
|
+
type: [
|
|
101
|
+
{term: 'CREATED', count: 150},
|
|
102
|
+
{term: 'DELETED', count: 50}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(mdmSdkModule.getDateRangeByDatePeriod).toBeCalledWith(DateRangeValue.LAST_DAY, expect.anything());
|
|
109
|
+
expect(getEntitiesStats).toBeCalledWith(fullStatsRequest);
|
|
110
|
+
expect(getEntitiesStats).toBeCalledWith({
|
|
111
|
+
facet: PeriodStep.HOUR,
|
|
112
|
+
types: ['CREATED'],
|
|
113
|
+
startTime: START_TIME,
|
|
114
|
+
endTime: END_TIME
|
|
115
|
+
});
|
|
116
|
+
expect(getEntitiesStats).toBeCalledWith({
|
|
117
|
+
facet: PeriodStep.HOUR,
|
|
118
|
+
types: ['DELETED'],
|
|
119
|
+
startTime: START_TIME,
|
|
120
|
+
endTime: END_TIME
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
expect(result.current).toMatchObject({
|
|
124
|
+
state: RequestStates.LOADED,
|
|
125
|
+
step: PeriodStep.HOUR,
|
|
126
|
+
data: [
|
|
127
|
+
{
|
|
128
|
+
event: 'created',
|
|
129
|
+
total: 150,
|
|
130
|
+
data: [
|
|
131
|
+
{term: START_TIME, count: 0},
|
|
132
|
+
{term: 1617595200000, count: 150},
|
|
133
|
+
{term: END_TIME, count: 0}
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
getEmptyEventData('updated'),
|
|
137
|
+
{
|
|
138
|
+
event: 'deleted',
|
|
139
|
+
total: 50,
|
|
140
|
+
data: [
|
|
141
|
+
{term: START_TIME, count: 0},
|
|
142
|
+
{term: 1617613200000, count: 50},
|
|
143
|
+
{term: END_TIME, count: 0}
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
getEmptyEventData('matched'),
|
|
147
|
+
getEmptyEventData('autoMerged'),
|
|
148
|
+
getEmptyEventData('mergedManually'),
|
|
149
|
+
getEmptyEventData('unmerged'),
|
|
150
|
+
getEmptyEventData('notMatch')
|
|
151
|
+
]
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should resend request when invoke reload', () => {
|
|
156
|
+
const {result} = renderHook(useStatsRequest, {initialProps: DateRangeValue.LAST_DAY});
|
|
157
|
+
expect(getEntitiesStats).toBeCalledWith(fullStatsRequest);
|
|
158
|
+
|
|
159
|
+
getEntitiesStats.mockClear();
|
|
160
|
+
act(() => {
|
|
161
|
+
result.current.reload();
|
|
162
|
+
});
|
|
163
|
+
expect(getEntitiesStats).toBeCalledWith(fullStatsRequest);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('should clear data before load new and return ERROR state if request rejected', async () => {
|
|
167
|
+
const {result} = renderHook(useStatsRequest, {initialProps: DateRangeValue.LAST_DAY});
|
|
168
|
+
expect(result.current).toMatchObject({
|
|
169
|
+
state: RequestStates.LOADING,
|
|
170
|
+
step: PeriodStep.HOUR,
|
|
171
|
+
data: []
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
await act(async () => {
|
|
175
|
+
resolveRequest({
|
|
176
|
+
total: 200,
|
|
177
|
+
facets: {
|
|
178
|
+
type: [
|
|
179
|
+
{term: 'CREATED', count: 150},
|
|
180
|
+
{term: 'DELETED', count: 50}
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
expect(result.current).toMatchObject({
|
|
187
|
+
state: RequestStates.LOADED,
|
|
188
|
+
step: PeriodStep.HOUR,
|
|
189
|
+
data: expect.arrayContaining([getEmptyEventData('matched')])
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
act(() => {
|
|
193
|
+
result.current.reload();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
expect(result.current).toMatchObject({
|
|
197
|
+
state: RequestStates.LOADING,
|
|
198
|
+
step: PeriodStep.HOUR,
|
|
199
|
+
data: []
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
await act(async () => {
|
|
203
|
+
rejectRequest('Error');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
expect(result.current).toMatchObject({
|
|
207
|
+
state: RequestStates.ERROR,
|
|
208
|
+
step: PeriodStep.HOUR,
|
|
209
|
+
data: []
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|