@truedat/qx 7.0.7 → 7.1.0
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/package.json +13 -4
- package/src/api.js +29 -20
- package/src/components/QxRoutes.js +18 -16
- package/src/components/__tests__/__fixtures__/helper.js +187 -0
- package/src/components/common/TestFormWrapper.js +38 -0
- package/src/components/common/__tests__/ResourceSelector.spec.js +18 -7
- package/src/components/common/__tests__/__snapshots__/ResourceSelector.spec.js.snap +0 -12
- package/src/components/common/expressions/__tests__/Condition.spec.js +4 -1
- package/src/components/common/expressions/__tests__/FunctionArgs.spec.js +18 -5
- package/src/components/common/expressions/__tests__/ShapeSelector.spec.js +4 -4
- package/src/components/common/expressions/__tests__/__snapshots__/FunctionArgs.spec.js.snap +10 -2
- package/src/components/common/resourceSelectors/__tests__/DataStructureSelector.spec.js +6 -3
- package/src/components/common/resourceSelectors/__tests__/__snapshots__/DataStructureSelector.spec.js.snap +0 -12
- package/src/components/dataViews/__tests__/DataViewEditor.spec.js +83 -53
- package/src/components/dataViews/__tests__/DataViews.spec.js +14 -1
- package/src/components/dataViews/__tests__/__snapshots__/DataViewEditor.spec.js.snap +93 -4
- package/src/components/dataViews/queryableProperties/__tests__/SelectField.spec.js +13 -6
- package/src/components/functions/__tests__/FunctionEditor.spec.js +2 -34
- package/src/components/functions/__tests__/FunctionParams.spec.js +4 -17
- package/src/components/functions/__tests__/Functions.spec.js +2 -34
- package/src/components/functions/__tests__/__snapshots__/FunctionEditor.spec.js.snap +48 -48
- package/src/components/functions/__tests__/__snapshots__/FunctionParams.spec.js.snap +4 -4
- package/src/components/functions/__tests__/__snapshots__/Functions.spec.js.snap +4 -4
- package/src/components/qualityControls/ControlProperties.js +43 -0
- package/src/components/qualityControls/ControlPropertiesView.js +109 -0
- package/src/components/qualityControls/EditQualityControl.js +5 -21
- package/src/components/qualityControls/IconPopup.js +28 -0
- package/src/components/qualityControls/NewDraftQualityControl.js +4 -13
- package/src/components/qualityControls/NewQualityControl.js +10 -25
- package/src/components/qualityControls/QualityBadge.js +33 -0
- package/src/components/qualityControls/QualityControl.js +11 -53
- package/src/components/qualityControls/QualityControlActions.js +133 -46
- package/src/components/qualityControls/QualityControlEditor.js +114 -135
- package/src/components/qualityControls/QualityControlHeader.js +29 -7
- package/src/components/qualityControls/QualityControlHistory.js +6 -12
- package/src/components/qualityControls/QualityControlQueryModal.js +8 -5
- package/src/components/qualityControls/QualityControlRoutes.js +51 -96
- package/src/components/qualityControls/QualityControlRow.js +21 -2
- package/src/components/qualityControls/QualityControlScores.js +140 -0
- package/src/components/qualityControls/QualityControlTabs.js +24 -23
- package/src/components/qualityControls/QualityControls.js +142 -59
- package/src/components/qualityControls/QualityControlsLabelResults.js +51 -0
- package/src/components/qualityControls/QualityControlsTable.js +69 -43
- package/src/components/qualityControls/ScoreCriteria.js +40 -0
- package/src/components/qualityControls/{ResultCriteria.js → ScoreCriteriaView.js} +26 -42
- package/src/components/qualityControls/__tests__/ControlProperties.spec.js +86 -0
- package/src/components/qualityControls/__tests__/ControlPropertiesView.spec.js +86 -0
- package/src/components/qualityControls/__tests__/EditQualityControl.spec.js +219 -0
- package/src/components/qualityControls/__tests__/IconPopup.spec.js +33 -0
- package/src/components/qualityControls/__tests__/NewDraftQualityControl.spec.js +253 -0
- package/src/components/qualityControls/__tests__/NewQualityControl.spec.js +384 -0
- package/src/components/qualityControls/__tests__/QualityBadge.spec.js +30 -0
- package/src/components/qualityControls/__tests__/QualityControl.spec.js +47 -0
- package/src/components/qualityControls/__tests__/QualityControlActions.spec.js +192 -0
- package/src/components/qualityControls/__tests__/QualityControlCrumbs.spec.js +18 -0
- package/src/components/qualityControls/__tests__/QualityControlEditor.spec.js +296 -0
- package/src/components/qualityControls/__tests__/QualityControlHeader.spec.js +68 -0
- package/src/components/qualityControls/__tests__/QualityControlHistory.spec.js +21 -0
- package/src/components/qualityControls/__tests__/QualityControlQueryModal.spec.js +77 -0
- package/src/components/qualityControls/__tests__/QualityControlRow.spec.js +91 -0
- package/src/components/qualityControls/__tests__/QualityControlScores.spec.js +139 -0
- package/src/components/qualityControls/__tests__/QualityControlTabs.spec.js +20 -0
- package/src/components/qualityControls/__tests__/QualityControls.spec.js +202 -0
- package/src/components/qualityControls/__tests__/QualityControlsLabelResults.spec.js +83 -0
- package/src/components/qualityControls/__tests__/QualityControlsTable.spec.js +38 -0
- package/src/components/qualityControls/__tests__/ScoreCriteria.spec.js +77 -0
- package/src/components/qualityControls/__tests__/ScoreCriteriaView.spec.js +62 -0
- package/src/components/qualityControls/__tests__/__fixtures__/qualityControlHelper.js +281 -0
- package/src/components/qualityControls/__tests__/__snapshots__/ControlProperties.spec.js.snap +151 -0
- package/src/components/qualityControls/__tests__/__snapshots__/ControlPropertiesView.spec.js.snap +290 -0
- package/src/components/qualityControls/__tests__/__snapshots__/EditQualityControl.spec.js.snap +672 -0
- package/src/components/qualityControls/__tests__/__snapshots__/IconPopup.spec.js.snap +10 -0
- package/src/components/qualityControls/__tests__/__snapshots__/NewDraftQualityControl.spec.js.snap +648 -0
- package/src/components/qualityControls/__tests__/__snapshots__/NewQualityControl.spec.js.snap +336 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityBadge.spec.js.snap +11 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControl.spec.js.snap +255 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlActions.spec.js.snap +85 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlCrumbs.spec.js.snap +25 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlEditor.spec.js.snap +930 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlHeader.spec.js.snap +127 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlHistory.spec.js.snap +75 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlQueryModal.spec.js.snap +27 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlRow.spec.js.snap +113 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlScores.spec.js.snap +161 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlTabs.spec.js.snap +28 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControls.spec.js.snap +219 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlsLabelResults.spec.js.snap +11 -0
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlsTable.spec.js.snap +121 -0
- package/src/components/qualityControls/__tests__/__snapshots__/ScoreCriteria.spec.js.snap +186 -0
- package/src/components/qualityControls/__tests__/__snapshots__/ScoreCriteriaView.spec.js.snap +76 -0
- package/src/components/qualityControls/__tests__/qualityByControlMode.spec.js +248 -0
- package/src/components/qualityControls/controlProperties/ErrorCount.js +56 -0
- package/src/components/qualityControls/controlProperties/Ratio.js +79 -0
- package/src/components/qualityControls/controlProperties/__tests__/ErrorCount.spec.js +82 -0
- package/src/components/qualityControls/controlProperties/__tests__/Ratio.spec.js +115 -0
- package/src/components/qualityControls/controlProperties/__tests__/__snapshots__/ErrorCount.spec.js.snap +62 -0
- package/src/components/qualityControls/controlProperties/__tests__/__snapshots__/Ratio.spec.js.snap +143 -0
- package/src/components/qualityControls/qualityByControlMode.js +62 -0
- package/src/components/qualityControls/qualityControlScoresColumns.js +52 -0
- package/src/components/qualityControls/{resultCriterias → scoreCriterias}/Deviation.js +6 -6
- package/src/components/qualityControls/{resultCriterias/ErrorsNumber.js → scoreCriterias/ErrorCount.js} +7 -7
- package/src/components/qualityControls/{resultCriterias → scoreCriterias}/Percentage.js +6 -6
- package/src/components/qualityControls/scoreCriterias/__tests__/Deviation.spec.js +75 -0
- package/src/components/qualityControls/scoreCriterias/__tests__/ErrorCount.spec.js +63 -0
- package/src/components/qualityControls/scoreCriterias/__tests__/Percentage.spec.js +61 -0
- package/src/components/qualityControls/scoreCriterias/__tests__/__snapshots__/Deviation.spec.js.snap +58 -0
- package/src/components/qualityControls/scoreCriterias/__tests__/__snapshots__/ErrorCount.spec.js.snap +58 -0
- package/src/components/qualityControls/scoreCriterias/__tests__/__snapshots__/Percentage.spec.js.snap +58 -0
- package/src/components/{executions/ExecutionGroupsHeader.js → scores/MyScoreGroups.js} +5 -3
- package/src/components/scores/QualityBar.js +73 -0
- package/src/components/scores/Score.js +32 -0
- package/src/components/scores/ScoreContext.js +3 -0
- package/src/components/scores/ScoreCrumbs.js +40 -0
- package/src/components/scores/ScoreDetails.js +67 -0
- package/src/components/scores/ScoreEvents.js +59 -0
- package/src/components/scores/ScoreGroup.js +83 -0
- package/src/components/scores/ScoreGroupBreadcrumbs.js +25 -0
- package/src/components/{qualityControls/ExecutionForm.js → scores/ScoreGroupForm.js} +11 -13
- package/src/components/scores/ScoreGroupLink.js +18 -0
- package/src/components/scores/ScoreGroupMessage.js +25 -0
- package/src/components/{qualityControls/ExecutionPopup.js → scores/ScoreGroupPopup.js} +13 -22
- package/src/components/scores/ScoreGroupsTable.js +113 -0
- package/src/components/scores/ScoreRoutes.js +32 -0
- package/src/components/{executions/ExecutionStatusDecorator.js → scores/ScoreStatusDecorator.js} +10 -8
- package/src/components/scores/ScoreTabs.js +32 -0
- package/src/components/scores/__tests__/MyScoreGroups.spec.js +31 -0
- package/src/components/scores/__tests__/QualityBar.spec.js +55 -0
- package/src/components/scores/__tests__/Score.spec.js +41 -0
- package/src/components/scores/__tests__/ScoreCrumbs.spec.js +39 -0
- package/src/components/scores/__tests__/ScoreDetails.spec.js +38 -0
- package/src/components/scores/__tests__/ScoreEvents.spec.js +24 -0
- package/src/components/scores/__tests__/ScoreGroup.spec.js +43 -0
- package/src/components/scores/__tests__/ScoreGroupBreadcrumbs.spec.js +16 -0
- package/src/components/scores/__tests__/ScoreGroupForm.spec.js +78 -0
- package/src/components/scores/__tests__/ScoreGroupLink.spec.js +16 -0
- package/src/components/scores/__tests__/ScoreGroupMessage.spec.js +20 -0
- package/src/components/scores/__tests__/ScoreGroupPopup.spec.js +59 -0
- package/src/components/scores/__tests__/ScoreGroupsTable.spec.js +40 -0
- package/src/components/scores/__tests__/ScoreStatusDecorator.spec.js +21 -0
- package/src/components/scores/__tests__/ScoreTabs.spec.js +27 -0
- package/src/components/scores/__tests__/__fixtures__/scoreHelper.js +182 -0
- package/src/components/scores/__tests__/__snapshots__/MyScoreGroups.spec.js.snap +154 -0
- package/src/components/scores/__tests__/__snapshots__/QualityBar.spec.js.snap +24 -0
- package/src/components/scores/__tests__/__snapshots__/Score.spec.js.snap +92 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreCrumbs.spec.js.snap +39 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreDetails.spec.js.snap +156 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreEvents.spec.js.snap +167 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreGroup.spec.js.snap +103 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreGroupBreadcrumbs.spec.js.snap +29 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreGroupForm.spec.js.snap +145 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreGroupLink.spec.js.snap +15 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreGroupMessage.spec.js.snap +43 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreGroupPopup.spec.js.snap +11 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreGroupsTable.spec.js.snap +147 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreStatusDecorator.spec.js.snap +71 -0
- package/src/components/scores/__tests__/__snapshots__/ScoreTabs.spec.js.snap +43 -0
- package/src/components/scores/index.js +15 -0
- package/src/hooks/useQualityControls.js +3 -9
- package/src/hooks/useScoreGroups.js +23 -0
- package/src/hooks/useScores.js +22 -0
- package/src/styles/Expression.less +16 -0
- package/src/styles/scores.less +63 -0
- package/src/components/executions/ExecutionGroupBreadcrumbs.js +0 -25
- package/src/components/executions/ExecutionGroupContent.js +0 -42
- package/src/components/executions/ExecutionGroupLink.js +0 -18
- package/src/components/executions/ExecutionGroupMessage.js +0 -27
- package/src/components/executions/ExecutionGroupsTable.js +0 -101
- package/src/components/executions/executionGroupDetail.js +0 -87
- package/src/components/qualityControls/ResultType.js +0 -57
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@truedat/test/render";
|
|
3
|
+
import { waitFor } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import { QUALITY_CONTROLS } from "@truedat/core/routes";
|
|
6
|
+
import { SOURCE_OPTIONS_QUERY } from "@truedat/cx/sources/api/queries";
|
|
7
|
+
import { REFERENCE_DATASETS_HEADERS_QUERY } from "@truedat/dd/api/queries";
|
|
8
|
+
import { DOMAINS_QUERY } from "@truedat/core/api/queries";
|
|
9
|
+
import { singleTemplateMock } from "@truedat/test/mocks";
|
|
10
|
+
import { messages } from "@truedat/qx/components/__tests__/__fixtures__/helper";
|
|
11
|
+
import {
|
|
12
|
+
useQualityControlCreateDraft,
|
|
13
|
+
useQualityControl,
|
|
14
|
+
} from "../../../hooks/useQualityControls";
|
|
15
|
+
import NewDraftQualityControl from "../NewDraftQualityControl";
|
|
16
|
+
import {
|
|
17
|
+
sources,
|
|
18
|
+
domains,
|
|
19
|
+
qualityControlData,
|
|
20
|
+
} from "./__fixtures__/qualityControlHelper";
|
|
21
|
+
|
|
22
|
+
const mockHistory = { push: jest.fn() };
|
|
23
|
+
|
|
24
|
+
jest.mock("react-router-dom", () => ({
|
|
25
|
+
...jest.requireActual("react-router-dom"),
|
|
26
|
+
useParams: () => ({ id: "8" }),
|
|
27
|
+
useHistory: () => mockHistory,
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
jest.mock("@truedat/core/hooks/useUserFilters", () => {
|
|
31
|
+
const originalModule = jest.requireActual(
|
|
32
|
+
"@truedat/core/hooks/useUserFilters"
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
__esModule: true,
|
|
37
|
+
...originalModule,
|
|
38
|
+
useUserFilters: jest.fn(() => ({})),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
jest.mock("@truedat/qx/hooks/useFunctions", () => {
|
|
42
|
+
const originalModule = jest.requireActual("@truedat/qx/hooks/useFunctions");
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
__esModule: true,
|
|
46
|
+
...originalModule,
|
|
47
|
+
useFunctions: jest.fn(() => ({})),
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
jest.mock("@truedat/qx/hooks/useDataViews", () => {
|
|
51
|
+
const originalModule = jest.requireActual("@truedat/qx/hooks/useDataViews");
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
__esModule: true,
|
|
55
|
+
...originalModule,
|
|
56
|
+
useDataViews: jest.fn(() => ({})),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
jest.mock("@truedat/qx/hooks/useQualityControls", () => {
|
|
61
|
+
const { qualityControlData } = jest.requireActual(
|
|
62
|
+
"./__fixtures__/qualityControlHelper"
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
useQualityControl: jest.fn(() => ({
|
|
67
|
+
data: {
|
|
68
|
+
data: qualityControlData({
|
|
69
|
+
versions: [],
|
|
70
|
+
status: "published",
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
loading: false,
|
|
74
|
+
})),
|
|
75
|
+
useQualityControlCreateDraft: jest.fn(() => ({
|
|
76
|
+
trigger: jest.fn(() => Promise.resolve()),
|
|
77
|
+
isMutating: false,
|
|
78
|
+
})),
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const sourcesMock = {
|
|
83
|
+
request: { query: SOURCE_OPTIONS_QUERY },
|
|
84
|
+
result: { data: { sources } },
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const referenceDatasetsMock = {
|
|
88
|
+
request: { query: REFERENCE_DATASETS_HEADERS_QUERY },
|
|
89
|
+
result: {
|
|
90
|
+
data: {
|
|
91
|
+
referenceDatasets: [
|
|
92
|
+
{
|
|
93
|
+
id: "7",
|
|
94
|
+
name: "dataset1",
|
|
95
|
+
headers: ["campo1", "campo2"],
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
loading: false,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const publishDomainsMock = {
|
|
104
|
+
request: {
|
|
105
|
+
query: DOMAINS_QUERY,
|
|
106
|
+
variables: { action: "publishQualityControls" },
|
|
107
|
+
},
|
|
108
|
+
result: { data: { domains } },
|
|
109
|
+
};
|
|
110
|
+
const createDomainsMock = {
|
|
111
|
+
request: {
|
|
112
|
+
query: DOMAINS_QUERY,
|
|
113
|
+
variables: { action: "createQualityControls" },
|
|
114
|
+
},
|
|
115
|
+
result: { data: { domains } },
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const variables = { scope: "quality_control", domainIds: [2] };
|
|
119
|
+
|
|
120
|
+
const renderOpts = {
|
|
121
|
+
mocks: [
|
|
122
|
+
singleTemplateMock(variables),
|
|
123
|
+
sourcesMock,
|
|
124
|
+
referenceDatasetsMock,
|
|
125
|
+
publishDomainsMock,
|
|
126
|
+
createDomainsMock,
|
|
127
|
+
],
|
|
128
|
+
messages,
|
|
129
|
+
fallback: "loading",
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
describe("<NewDraftQualityControl />", () => {
|
|
133
|
+
it("matches the latest snapshot", async () => {
|
|
134
|
+
const { container, queryByText } = render(
|
|
135
|
+
<NewDraftQualityControl />,
|
|
136
|
+
renderOpts
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
await waitFor(() =>
|
|
140
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
141
|
+
);
|
|
142
|
+
await waitFor(() =>
|
|
143
|
+
expect(container.querySelector(".loader")).not.toBeInTheDocument()
|
|
144
|
+
);
|
|
145
|
+
expect(container).toMatchSnapshot();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("navigates to quality controls when cancel button is cliked", async () => {
|
|
149
|
+
const { getByText, queryByText } = render(
|
|
150
|
+
<NewDraftQualityControl />,
|
|
151
|
+
renderOpts
|
|
152
|
+
);
|
|
153
|
+
await waitFor(() =>
|
|
154
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const cancelButton = getByText(/Cancel/i);
|
|
158
|
+
expect(cancelButton).toBeInTheDocument();
|
|
159
|
+
|
|
160
|
+
userEvent.click(cancelButton);
|
|
161
|
+
|
|
162
|
+
expect(mockHistory.push.mock.calls.length).toBe(1);
|
|
163
|
+
expect(mockHistory.push.mock.calls[0][0]).toBe(QUALITY_CONTROLS);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("test save submit ", async () => {
|
|
167
|
+
const trigger = jest.fn(() =>
|
|
168
|
+
Promise.resolve({ data: { data: { id: "9" } } })
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
useQualityControlCreateDraft.mockImplementation(() => ({
|
|
172
|
+
trigger,
|
|
173
|
+
}));
|
|
174
|
+
|
|
175
|
+
const { getByText, getByPlaceholderText, queryByText, getByRole } = render(
|
|
176
|
+
<NewDraftQualityControl />,
|
|
177
|
+
renderOpts
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
await waitFor(() =>
|
|
181
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
182
|
+
);
|
|
183
|
+
await waitFor(() =>
|
|
184
|
+
expect(getByRole("button", { name: /Save/ })).toBeDisabled()
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
userEvent.type(getByPlaceholderText("Name"), "_modified");
|
|
188
|
+
|
|
189
|
+
await waitFor(() =>
|
|
190
|
+
expect(getByRole("button", { name: /Save/ })).toBeEnabled()
|
|
191
|
+
);
|
|
192
|
+
userEvent.click(getByText(/Save/));
|
|
193
|
+
|
|
194
|
+
const qualityControl = qualityControlData({
|
|
195
|
+
versions: [],
|
|
196
|
+
status: "draft",
|
|
197
|
+
name: "test_modified",
|
|
198
|
+
});
|
|
199
|
+
await waitFor(() =>
|
|
200
|
+
expect(trigger).toHaveBeenCalledWith({ quality_control: qualityControl })
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("test publish submit ", async () => {
|
|
205
|
+
const trigger = jest.fn(() =>
|
|
206
|
+
Promise.resolve({ data: { data: { id: "9" } } })
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
useQualityControlCreateDraft.mockImplementation(() => ({
|
|
210
|
+
trigger,
|
|
211
|
+
}));
|
|
212
|
+
|
|
213
|
+
const { getByText, getByPlaceholderText, queryByText, getByRole } = render(
|
|
214
|
+
<NewDraftQualityControl />,
|
|
215
|
+
renderOpts
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
await waitFor(() =>
|
|
219
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
220
|
+
);
|
|
221
|
+
await waitFor(() =>
|
|
222
|
+
expect(getByRole("button", { name: /Publish/ })).toBeDisabled()
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
userEvent.type(getByPlaceholderText("Name"), "_modified");
|
|
226
|
+
|
|
227
|
+
await waitFor(() =>
|
|
228
|
+
expect(getByRole("button", { name: /Publish/ })).toBeEnabled()
|
|
229
|
+
);
|
|
230
|
+
userEvent.click(getByText(/Publish/));
|
|
231
|
+
|
|
232
|
+
const qualityControl = qualityControlData({
|
|
233
|
+
versions: [],
|
|
234
|
+
status: "published",
|
|
235
|
+
name: "test_modified",
|
|
236
|
+
});
|
|
237
|
+
await waitFor(() =>
|
|
238
|
+
expect(trigger).toHaveBeenCalledWith({ quality_control: qualityControl })
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("when no quality control is fetched, do not render editor", async () => {
|
|
243
|
+
useQualityControl.mockImplementation(() => ({ data: undefined }));
|
|
244
|
+
|
|
245
|
+
const { queryByText } = render(<NewDraftQualityControl />, renderOpts);
|
|
246
|
+
|
|
247
|
+
await waitFor(() =>
|
|
248
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
await waitFor(() => expect(queryByText(/Save/i)).not.toBeInTheDocument());
|
|
252
|
+
});
|
|
253
|
+
});
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@truedat/test/render";
|
|
3
|
+
import { waitFor } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import { singleTemplateMock } from "@truedat/test/mocks";
|
|
6
|
+
import { DOMAINS_QUERY } from "@truedat/core/api/queries";
|
|
7
|
+
import { SOURCE_OPTIONS_QUERY } from "@truedat/cx/sources/api/queries";
|
|
8
|
+
import { REFERENCE_DATASETS_HEADERS_QUERY } from "@truedat/dd/api/queries";
|
|
9
|
+
import { messages } from "@truedat/qx/components/__tests__/__fixtures__/helper";
|
|
10
|
+
import { useQualityControlCreate } from "@truedat/qx/hooks/useQualityControls";
|
|
11
|
+
import NewQualityControl from "../NewQualityControl";
|
|
12
|
+
import { sources, domains } from "./__fixtures__/qualityControlHelper";
|
|
13
|
+
|
|
14
|
+
const mockHistory = { push: jest.fn() };
|
|
15
|
+
|
|
16
|
+
jest.mock("react-router-dom", () => ({
|
|
17
|
+
...jest.requireActual("react-router-dom"),
|
|
18
|
+
useHistory: () => mockHistory,
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock("@truedat/qx/hooks/useQualityControls", () => ({
|
|
22
|
+
useQualityControlCreate: jest.fn(() => ({
|
|
23
|
+
trigger: jest.fn(() => new Promise(() => {})),
|
|
24
|
+
isMutating: false,
|
|
25
|
+
})),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
jest.mock("@truedat/qx/hooks/useFunctions", () => ({
|
|
29
|
+
useFunctions: jest.fn(() => ({
|
|
30
|
+
data: {
|
|
31
|
+
data: [
|
|
32
|
+
{
|
|
33
|
+
name: "eq",
|
|
34
|
+
type: "boolean",
|
|
35
|
+
params: [
|
|
36
|
+
{ name: "arg1", type: "any" },
|
|
37
|
+
{ name: "arg2", type: "any" },
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
loading: false,
|
|
43
|
+
})),
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
jest.mock("@truedat/qx/hooks/useDataViews", () => ({
|
|
47
|
+
useDataViews: jest.fn(() => ({
|
|
48
|
+
data: { data: [] },
|
|
49
|
+
loading: false,
|
|
50
|
+
})),
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
const sourcesMock = {
|
|
54
|
+
request: { query: SOURCE_OPTIONS_QUERY },
|
|
55
|
+
result: { data: { sources } },
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const referenceDatasetsMock = {
|
|
59
|
+
request: { query: REFERENCE_DATASETS_HEADERS_QUERY },
|
|
60
|
+
result: {
|
|
61
|
+
data: {
|
|
62
|
+
referenceDatasets: [
|
|
63
|
+
{
|
|
64
|
+
id: "7",
|
|
65
|
+
name: "dataset1",
|
|
66
|
+
headers: ["campo1", "campo2"],
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
loading: false,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const domainsMock = {
|
|
75
|
+
request: {
|
|
76
|
+
query: DOMAINS_QUERY,
|
|
77
|
+
variables: { action: "publishQualityControls" },
|
|
78
|
+
},
|
|
79
|
+
result: { data: { domains: domains } },
|
|
80
|
+
};
|
|
81
|
+
const createDomainsMock = {
|
|
82
|
+
request: {
|
|
83
|
+
query: DOMAINS_QUERY,
|
|
84
|
+
variables: { action: "createQualityControls" },
|
|
85
|
+
},
|
|
86
|
+
result: { data: { domains } },
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const renderOpts = {
|
|
90
|
+
mocks: [
|
|
91
|
+
singleTemplateMock({ scope: "quality_control", domainIds: [] }),
|
|
92
|
+
singleTemplateMock({ scope: "quality_control", domainIds: ["2"] }),
|
|
93
|
+
sourcesMock,
|
|
94
|
+
referenceDatasetsMock,
|
|
95
|
+
createDomainsMock,
|
|
96
|
+
domainsMock,
|
|
97
|
+
],
|
|
98
|
+
messages,
|
|
99
|
+
fallback: "loading",
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
describe("<NewQualityControl />", () => {
|
|
103
|
+
it("matches the latest snapshot", async () => {
|
|
104
|
+
const { container, queryByText } = render(
|
|
105
|
+
<NewQualityControl />,
|
|
106
|
+
|
|
107
|
+
renderOpts
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
await waitFor(() =>
|
|
111
|
+
expect(container.querySelector(".loader")).not.toBeInTheDocument()
|
|
112
|
+
);
|
|
113
|
+
await waitFor(() =>
|
|
114
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
115
|
+
);
|
|
116
|
+
expect(container).toMatchSnapshot();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("navigates to qulity controls when cancel button is cliked", async () => {
|
|
120
|
+
const { container, getByText, queryByText } = render(
|
|
121
|
+
<NewQualityControl />,
|
|
122
|
+
renderOpts
|
|
123
|
+
);
|
|
124
|
+
await waitFor(() =>
|
|
125
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
126
|
+
);
|
|
127
|
+
await waitFor(() =>
|
|
128
|
+
expect(container.querySelector(".loader")).not.toBeInTheDocument()
|
|
129
|
+
);
|
|
130
|
+
userEvent.click(getByText(/Cancel/));
|
|
131
|
+
userEvent.click(getByText(/confirm_yes/));
|
|
132
|
+
await waitFor(() => expect(mockHistory.push.mock.calls.length).toBe(1));
|
|
133
|
+
expect(mockHistory.push.mock.calls[0][0]).toBe("/qualityControls");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("test save submit ", async () => {
|
|
137
|
+
const trigger = jest.fn(() =>
|
|
138
|
+
Promise.resolve({ data: { data: { id: "9" } } })
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
useQualityControlCreate.mockImplementation(() => ({
|
|
142
|
+
trigger,
|
|
143
|
+
}));
|
|
144
|
+
|
|
145
|
+
const {
|
|
146
|
+
container,
|
|
147
|
+
getByText,
|
|
148
|
+
getByPlaceholderText,
|
|
149
|
+
queryByText,
|
|
150
|
+
getByRole,
|
|
151
|
+
getAllByRole,
|
|
152
|
+
} = render(<NewQualityControl />, renderOpts);
|
|
153
|
+
|
|
154
|
+
await waitFor(() =>
|
|
155
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
156
|
+
);
|
|
157
|
+
await waitFor(() =>
|
|
158
|
+
expect(getByRole("button", { name: /Save/ })).toBeDisabled()
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
// Fill in the 'Name' field
|
|
162
|
+
userEvent.type(getByPlaceholderText("Name"), "test_modified");
|
|
163
|
+
|
|
164
|
+
// Select a domain
|
|
165
|
+
userEvent.click(getByText(/Select domains/));
|
|
166
|
+
userEvent.click(getByText(/barDomain/));
|
|
167
|
+
|
|
168
|
+
// Select a source
|
|
169
|
+
userEvent.click(getByText(/Select source/));
|
|
170
|
+
userEvent.click(getByRole("option", { name: /external_source_id/i }));
|
|
171
|
+
|
|
172
|
+
// Select a control mode
|
|
173
|
+
userEvent.click(getByRole("option", { name: /Percentage/i }));
|
|
174
|
+
|
|
175
|
+
// Fill in the 'Threshold' field
|
|
176
|
+
userEvent.type(getByPlaceholderText("Threshold"), "10");
|
|
177
|
+
|
|
178
|
+
// Fill in the 'Goal' field
|
|
179
|
+
userEvent.type(getByPlaceholderText("Goal"), "20");
|
|
180
|
+
|
|
181
|
+
await waitFor(() =>
|
|
182
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
183
|
+
);
|
|
184
|
+
await waitFor(() =>
|
|
185
|
+
expect(container.querySelector(".loader")).not.toBeInTheDocument()
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// Select the 'Reference datasets' for the resource type
|
|
189
|
+
userEvent.click(getByText(/Resource type/));
|
|
190
|
+
userEvent.click(getByText(/Reference datasets/));
|
|
191
|
+
userEvent.click(getByRole("option", { name: /dataset1/i }));
|
|
192
|
+
|
|
193
|
+
userEvent.click(getAllByRole("option", { name: /campo1/i })[0]);
|
|
194
|
+
userEvent.click(getByRole("option", { name: /eq/i }));
|
|
195
|
+
userEvent.click(getAllByRole("option", { name: /campo2/i })[1]);
|
|
196
|
+
|
|
197
|
+
await waitFor(() =>
|
|
198
|
+
expect(getByRole("button", { name: /Save/ })).toBeEnabled()
|
|
199
|
+
);
|
|
200
|
+
userEvent.click(getByText(/Save/));
|
|
201
|
+
|
|
202
|
+
await waitFor(() =>
|
|
203
|
+
expect(trigger).toHaveBeenCalledWith({
|
|
204
|
+
quality_control: {
|
|
205
|
+
name: "test_modified",
|
|
206
|
+
active: true,
|
|
207
|
+
domain_ids: ["2"],
|
|
208
|
+
df_type: "template1",
|
|
209
|
+
source_id: 181,
|
|
210
|
+
control_mode: "percentage",
|
|
211
|
+
dynamic_content: {},
|
|
212
|
+
control_properties: {
|
|
213
|
+
resource: {
|
|
214
|
+
type: "reference_dataset",
|
|
215
|
+
id: 7,
|
|
216
|
+
embedded: {
|
|
217
|
+
id: 7,
|
|
218
|
+
name: "dataset1",
|
|
219
|
+
headers: ["campo1", "campo2"],
|
|
220
|
+
fields: [
|
|
221
|
+
{
|
|
222
|
+
id: 0,
|
|
223
|
+
name: "campo1",
|
|
224
|
+
type: "string",
|
|
225
|
+
parent_name: "dataset1",
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
id: 1,
|
|
229
|
+
name: "campo2",
|
|
230
|
+
type: "string",
|
|
231
|
+
parent_name: "dataset1",
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
validation: [
|
|
237
|
+
{
|
|
238
|
+
expressions: [
|
|
239
|
+
{
|
|
240
|
+
shape: "function",
|
|
241
|
+
value: {
|
|
242
|
+
isCondition: true,
|
|
243
|
+
args: {
|
|
244
|
+
arg1: {
|
|
245
|
+
shape: "field",
|
|
246
|
+
value: {
|
|
247
|
+
id: 0,
|
|
248
|
+
name: "campo1",
|
|
249
|
+
type: "string",
|
|
250
|
+
parent_name: "dataset1",
|
|
251
|
+
alias: "dataset1",
|
|
252
|
+
parent_id: 0,
|
|
253
|
+
color: "blue",
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
arg2: {
|
|
257
|
+
shape: "field",
|
|
258
|
+
value: {
|
|
259
|
+
id: 1,
|
|
260
|
+
name: "campo2",
|
|
261
|
+
type: "string",
|
|
262
|
+
parent_name: "dataset1",
|
|
263
|
+
alias: "dataset1",
|
|
264
|
+
parent_id: 0,
|
|
265
|
+
color: "blue",
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
name: "eq",
|
|
270
|
+
type: "boolean",
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
},
|
|
277
|
+
score_criteria: { goal: "20", minimum: "10" },
|
|
278
|
+
status: "draft",
|
|
279
|
+
},
|
|
280
|
+
})
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("test publish submit ", async () => {
|
|
285
|
+
const trigger = jest.fn(() =>
|
|
286
|
+
Promise.resolve({ data: { data: { id: "9" } } })
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
useQualityControlCreate.mockImplementation(() => ({
|
|
290
|
+
trigger,
|
|
291
|
+
}));
|
|
292
|
+
|
|
293
|
+
const {
|
|
294
|
+
container,
|
|
295
|
+
getByText,
|
|
296
|
+
getByPlaceholderText,
|
|
297
|
+
queryByText,
|
|
298
|
+
getByRole,
|
|
299
|
+
} = render(<NewQualityControl />, renderOpts);
|
|
300
|
+
|
|
301
|
+
await waitFor(() =>
|
|
302
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
303
|
+
);
|
|
304
|
+
await waitFor(() =>
|
|
305
|
+
expect(getByRole("button", { name: /Publish/ })).toBeDisabled()
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
// Fill in the 'Name' field
|
|
309
|
+
userEvent.type(getByPlaceholderText("Name"), "test_modified");
|
|
310
|
+
|
|
311
|
+
// Select a domain
|
|
312
|
+
userEvent.click(getByText(/Select domains/));
|
|
313
|
+
userEvent.click(getByText(/barDomain/));
|
|
314
|
+
|
|
315
|
+
// Select a source
|
|
316
|
+
userEvent.click(getByText(/Select source/));
|
|
317
|
+
userEvent.click(getByRole("option", { name: /external_source_id/i }));
|
|
318
|
+
|
|
319
|
+
userEvent.click(getByRole("option", { name: /Error count/i }));
|
|
320
|
+
|
|
321
|
+
// Fill in the 'Goal' field
|
|
322
|
+
userEvent.type(getByPlaceholderText("Goal"), "25");
|
|
323
|
+
// Fill in the 'Threshold' field
|
|
324
|
+
userEvent.type(getByPlaceholderText("Threshold"), "50");
|
|
325
|
+
|
|
326
|
+
await waitFor(() =>
|
|
327
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
328
|
+
);
|
|
329
|
+
await waitFor(() =>
|
|
330
|
+
expect(container.querySelector(".loader")).not.toBeInTheDocument()
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
// // Select the 'Reference datasets' for the resource type
|
|
334
|
+
userEvent.click(getByText(/Resource type/));
|
|
335
|
+
userEvent.click(getByText(/Reference datasets/));
|
|
336
|
+
userEvent.click(getByRole("option", { name: /dataset1/i }));
|
|
337
|
+
|
|
338
|
+
await waitFor(() =>
|
|
339
|
+
expect(getByRole("button", { name: /Publish/i })).toBeEnabled()
|
|
340
|
+
);
|
|
341
|
+
userEvent.click(getByText(/Publish/i));
|
|
342
|
+
|
|
343
|
+
await waitFor(() =>
|
|
344
|
+
expect(trigger).toHaveBeenCalledWith({
|
|
345
|
+
quality_control: {
|
|
346
|
+
name: "test_modified",
|
|
347
|
+
active: true,
|
|
348
|
+
domain_ids: ["2"],
|
|
349
|
+
df_type: "template1",
|
|
350
|
+
source_id: 181,
|
|
351
|
+
control_mode: "error_count",
|
|
352
|
+
dynamic_content: {},
|
|
353
|
+
control_properties: {
|
|
354
|
+
errors_resource: {
|
|
355
|
+
type: "reference_dataset",
|
|
356
|
+
id: 7,
|
|
357
|
+
embedded: {
|
|
358
|
+
id: 7,
|
|
359
|
+
name: "dataset1",
|
|
360
|
+
headers: ["campo1", "campo2"],
|
|
361
|
+
fields: [
|
|
362
|
+
{
|
|
363
|
+
id: 0,
|
|
364
|
+
name: "campo1",
|
|
365
|
+
type: "string",
|
|
366
|
+
parent_name: "dataset1",
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
id: 1,
|
|
370
|
+
name: "campo2",
|
|
371
|
+
type: "string",
|
|
372
|
+
parent_name: "dataset1",
|
|
373
|
+
},
|
|
374
|
+
],
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
score_criteria: { goal: "25", maximum: "50" },
|
|
379
|
+
status: "published",
|
|
380
|
+
},
|
|
381
|
+
})
|
|
382
|
+
);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@truedat/test/render";
|
|
3
|
+
import { messages } from "@truedat/qx/components/__tests__/__fixtures__/helper";
|
|
4
|
+
import { scoreData } from "@truedat/qx/components/scores/__tests__/__fixtures__/scoreHelper";
|
|
5
|
+
import QualityBadge from "../QualityBadge";
|
|
6
|
+
|
|
7
|
+
const renderOpts = { messages };
|
|
8
|
+
|
|
9
|
+
describe("<QualityBadge />", () => {
|
|
10
|
+
it("matches the latest snapshot", () => {
|
|
11
|
+
const score = scoreData();
|
|
12
|
+
const { container } = render(<QualityBadge score={score} />, renderOpts);
|
|
13
|
+
|
|
14
|
+
expect(container).toMatchSnapshot();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("show status failed", () => {
|
|
18
|
+
const score = scoreData({ status: "FAILED" });
|
|
19
|
+
const { queryByText } = render(<QualityBadge score={score} />, renderOpts);
|
|
20
|
+
|
|
21
|
+
expect(queryByText(/Failed/i)).toBeInTheDocument();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("show no results", () => {
|
|
25
|
+
const score = scoreData({ score_content: undefined });
|
|
26
|
+
const { queryByText } = render(<QualityBadge score={score} />, renderOpts);
|
|
27
|
+
|
|
28
|
+
expect(queryByText(/No results/i)).toBeInTheDocument();
|
|
29
|
+
});
|
|
30
|
+
});
|