@truedat/qx 8.5.1 → 8.5.2
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 +3 -3
- package/src/components/common/expressions/Clauses.js +5 -9
- package/src/components/common/expressions/Condition.js +36 -37
- package/src/components/common/expressions/__tests__/Clauses.spec.js +87 -0
- package/src/components/common/expressions/__tests__/Condition.spec.js +220 -1
- package/src/components/common/expressions/__tests__/__snapshots__/Clauses.spec.js.snap +22 -21
- package/src/components/common/expressions/__tests__/__snapshots__/Condition.spec.js.snap +212 -214
- package/src/components/dataViews/queryableProperties/GroupBy.js +4 -2
- package/src/components/dataViews/queryableProperties/__tests__/GroupBy.spec.js +134 -28
- package/src/components/qualityControls/ControlProperties.js +32 -16
- package/src/components/qualityControls/ControlPropertiesForm.js +3 -3
- package/src/components/qualityControls/ControlPropertiesSummary.js +127 -104
- package/src/components/qualityControls/ControlPropertiesView.js +48 -74
- package/src/components/qualityControls/InformationForm.js +181 -180
- package/src/components/qualityControls/ScoreCriteria.js +0 -4
- package/src/components/qualityControls/ScoreCriteriaView.js +6 -9
- package/src/components/qualityControls/__tests__/ControlProperties.spec.js +47 -16
- package/src/components/qualityControls/__tests__/ControlPropertiesForm.spec.js +100 -0
- package/src/components/qualityControls/__tests__/ControlPropertiesSummary.spec.js +141 -0
- package/src/components/qualityControls/__tests__/ControlPropertiesView.spec.js +102 -11
- package/src/components/qualityControls/__tests__/EditQualityControl.spec.js +27 -3
- package/src/components/qualityControls/__tests__/InformationForm.spec.js +342 -0
- package/src/components/qualityControls/__tests__/NewDraftQualityControl.spec.js +26 -6
- package/src/components/qualityControls/__tests__/NewQualityControl.spec.js +66 -20
- package/src/components/qualityControls/__tests__/QualityBadge.spec.js +30 -3
- package/src/components/qualityControls/__tests__/QualityControlEditor.spec.js +282 -45
- package/src/components/qualityControls/__tests__/ScoreCriteria.spec.js +25 -3
- package/src/components/qualityControls/__tests__/ScoreCriteriaView.spec.js +19 -3
- package/src/components/qualityControls/__tests__/__fixtures__/qualityControlHelper.js +1 -1
- package/src/components/qualityControls/__tests__/__snapshots__/ControlProperties.spec.js.snap +13 -1
- package/src/components/qualityControls/__tests__/__snapshots__/ControlPropertiesView.spec.js.snap +70 -40
- package/src/components/qualityControls/__tests__/__snapshots__/EditQualityControl.spec.js.snap +118 -132
- package/src/components/qualityControls/__tests__/__snapshots__/NewDraftQualityControl.spec.js.snap +118 -132
- package/src/components/qualityControls/__tests__/__snapshots__/NewQualityControl.spec.js.snap +0 -13
- package/src/components/qualityControls/__tests__/__snapshots__/QualityBadge.spec.js.snap +15 -5
- package/src/components/qualityControls/__tests__/__snapshots__/QualityControlEditor.spec.js.snap +488 -125
- package/src/components/qualityControls/__tests__/__snapshots__/ScoreCriteria.spec.js.snap +13 -5
- package/src/components/qualityControls/__tests__/qualityByControlMode.spec.js +65 -14
- package/src/components/qualityControls/controlProperties/{Ratio.js → ResourceWithValidation.js} +19 -10
- package/src/components/qualityControls/controlProperties/__tests__/ResourceWithValidation.spec.js +192 -0
- package/src/components/qualityControls/qualityByControlMode.js +6 -30
- package/src/components/qualityControls/scoreCriterias/ErrorCount.js +0 -1
- package/src/components/qualityControls/scoreCriterias/__tests__/ErrorCount.spec.js +4 -4
- package/src/components/dataViews/queryableProperties/__tests__/__snapshots__/GroupBy.spec.js.snap +0 -604
- package/src/components/qualityControls/controlProperties/Count.js +0 -56
- package/src/components/qualityControls/controlProperties/__tests__/Count.spec.js +0 -66
- package/src/components/qualityControls/controlProperties/__tests__/Ratio.spec.js +0 -95
- package/src/components/qualityControls/controlProperties/__tests__/__snapshots__/Count.spec.js.snap +0 -67
- package/src/components/qualityControls/controlProperties/__tests__/__snapshots__/Ratio.spec.js.snap +0 -161
- package/src/components/qualityControls/scoreCriterias/Count.js +0 -88
- package/src/components/qualityControls/scoreCriterias/__tests__/Count.spec.js +0 -62
- package/src/components/qualityControls/scoreCriterias/__tests__/__snapshots__/Count.spec.js.snap +0 -58
|
@@ -63,7 +63,7 @@ exports[`<ScoreCriteria /> matches the latest snapshot for deviation 1`] = `
|
|
|
63
63
|
|
|
64
64
|
exports[`<ScoreCriteria /> matches the latest snapshot for empty controlMode 1`] = `<div />`;
|
|
65
65
|
|
|
66
|
-
exports[`<ScoreCriteria /> matches the latest snapshot for
|
|
66
|
+
exports[`<ScoreCriteria /> matches the latest snapshot for error_count 1`] = `
|
|
67
67
|
<div>
|
|
68
68
|
<div
|
|
69
69
|
class="ui segment"
|
|
@@ -74,7 +74,7 @@ exports[`<ScoreCriteria /> matches the latest snapshot for count 1`] = `
|
|
|
74
74
|
<label
|
|
75
75
|
class="field-label"
|
|
76
76
|
>
|
|
77
|
-
|
|
77
|
+
quality_control.score_criteria.error_count.goal
|
|
78
78
|
<span>
|
|
79
79
|
*
|
|
80
80
|
</span>
|
|
@@ -87,7 +87,7 @@ exports[`<ScoreCriteria /> matches the latest snapshot for count 1`] = `
|
|
|
87
87
|
>
|
|
88
88
|
<input
|
|
89
89
|
autocomplete="off"
|
|
90
|
-
placeholder="
|
|
90
|
+
placeholder="quality_control.score_criteria.error_count.goal"
|
|
91
91
|
type="text"
|
|
92
92
|
value=""
|
|
93
93
|
/>
|
|
@@ -100,7 +100,7 @@ exports[`<ScoreCriteria /> matches the latest snapshot for count 1`] = `
|
|
|
100
100
|
<label
|
|
101
101
|
class="field-label"
|
|
102
102
|
>
|
|
103
|
-
|
|
103
|
+
quality_control.score_criteria.error_count.maximum
|
|
104
104
|
<span>
|
|
105
105
|
*
|
|
106
106
|
</span>
|
|
@@ -113,7 +113,7 @@ exports[`<ScoreCriteria /> matches the latest snapshot for count 1`] = `
|
|
|
113
113
|
>
|
|
114
114
|
<input
|
|
115
115
|
autocomplete="off"
|
|
116
|
-
placeholder="
|
|
116
|
+
placeholder="quality_control.score_criteria.error_count.maximum"
|
|
117
117
|
type="text"
|
|
118
118
|
value=""
|
|
119
119
|
/>
|
|
@@ -184,3 +184,11 @@ exports[`<ScoreCriteria /> matches the latest snapshot for percentage 1`] = `
|
|
|
184
184
|
</div>
|
|
185
185
|
</div>
|
|
186
186
|
`;
|
|
187
|
+
|
|
188
|
+
exports[`<ScoreCriteria /> matches the latest snapshot for unsupported controlMode 1`] = `
|
|
189
|
+
<div>
|
|
190
|
+
<div
|
|
191
|
+
class="ui segment"
|
|
192
|
+
/>
|
|
193
|
+
</div>
|
|
194
|
+
`;
|
|
@@ -154,13 +154,13 @@ describe("qualityByControlMode", () => {
|
|
|
154
154
|
expect(qualityByControlMode(score)).toEqual(result);
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
-
it("returns correct object when controlMode is
|
|
157
|
+
it("returns correct object when controlMode is error_count with green", () => {
|
|
158
158
|
const score = scoreData({
|
|
159
159
|
score_content: {
|
|
160
160
|
count: 10,
|
|
161
161
|
},
|
|
162
162
|
quality_control: {
|
|
163
|
-
control_mode: "
|
|
163
|
+
control_mode: "error_count",
|
|
164
164
|
score_criteria: {
|
|
165
165
|
maximum: 30,
|
|
166
166
|
goal: 20,
|
|
@@ -169,8 +169,8 @@ describe("qualityByControlMode", () => {
|
|
|
169
169
|
});
|
|
170
170
|
const result = {
|
|
171
171
|
color: "green",
|
|
172
|
-
label1: "quality_control.score_criteria.
|
|
173
|
-
label2: "quality_control.score_criteria.
|
|
172
|
+
label1: "quality_control.score_criteria.error_count.goal",
|
|
173
|
+
label2: "quality_control.score_criteria.error_count.maximum",
|
|
174
174
|
text: 10,
|
|
175
175
|
value1: 20,
|
|
176
176
|
value2: 30,
|
|
@@ -178,14 +178,13 @@ describe("qualityByControlMode", () => {
|
|
|
178
178
|
expect(qualityByControlMode(score)).toEqual(result);
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
-
it("returns correct object when controlMode is
|
|
181
|
+
it("returns correct object when controlMode is error_count with yellow", () => {
|
|
182
182
|
const score = scoreData({
|
|
183
183
|
score_content: {
|
|
184
184
|
count: 20,
|
|
185
185
|
},
|
|
186
186
|
quality_control: {
|
|
187
|
-
control_mode: "
|
|
188
|
-
|
|
187
|
+
control_mode: "error_count",
|
|
189
188
|
score_criteria: {
|
|
190
189
|
maximum: 30,
|
|
191
190
|
goal: 20,
|
|
@@ -194,8 +193,8 @@ describe("qualityByControlMode", () => {
|
|
|
194
193
|
});
|
|
195
194
|
const result = {
|
|
196
195
|
color: "yellow",
|
|
197
|
-
label1: "quality_control.score_criteria.
|
|
198
|
-
label2: "quality_control.score_criteria.
|
|
196
|
+
label1: "quality_control.score_criteria.error_count.goal",
|
|
197
|
+
label2: "quality_control.score_criteria.error_count.maximum",
|
|
199
198
|
text: 20,
|
|
200
199
|
value1: 20,
|
|
201
200
|
value2: 30,
|
|
@@ -203,14 +202,13 @@ describe("qualityByControlMode", () => {
|
|
|
203
202
|
expect(qualityByControlMode(score)).toEqual(result);
|
|
204
203
|
});
|
|
205
204
|
|
|
206
|
-
it("returns correct object when controlMode is
|
|
205
|
+
it("returns correct object when controlMode is error_count with red", () => {
|
|
207
206
|
const score = scoreData({
|
|
208
207
|
score_content: {
|
|
209
208
|
count: 40,
|
|
210
209
|
},
|
|
211
210
|
quality_control: {
|
|
212
|
-
control_mode: "
|
|
213
|
-
|
|
211
|
+
control_mode: "error_count",
|
|
214
212
|
score_criteria: {
|
|
215
213
|
maximum: 30,
|
|
216
214
|
goal: 20,
|
|
@@ -219,8 +217,8 @@ describe("qualityByControlMode", () => {
|
|
|
219
217
|
});
|
|
220
218
|
const result = {
|
|
221
219
|
color: "red",
|
|
222
|
-
label1: "quality_control.score_criteria.
|
|
223
|
-
label2: "quality_control.score_criteria.
|
|
220
|
+
label1: "quality_control.score_criteria.error_count.goal",
|
|
221
|
+
label2: "quality_control.score_criteria.error_count.maximum",
|
|
224
222
|
text: 40,
|
|
225
223
|
value1: 20,
|
|
226
224
|
value2: 30,
|
|
@@ -245,4 +243,57 @@ describe("qualityByControlMode", () => {
|
|
|
245
243
|
const result = {};
|
|
246
244
|
expect(qualityByControlMode(score)).toEqual(result);
|
|
247
245
|
});
|
|
246
|
+
|
|
247
|
+
it("returns correct object when controlMode is deviation with no results", () => {
|
|
248
|
+
const score = scoreData({
|
|
249
|
+
noResultsMessage: "No results",
|
|
250
|
+
score_content: {
|
|
251
|
+
total_count: 0,
|
|
252
|
+
validation_count: 0,
|
|
253
|
+
},
|
|
254
|
+
quality_control: {
|
|
255
|
+
control_mode: "deviation",
|
|
256
|
+
score_criteria: {
|
|
257
|
+
maximum: 80,
|
|
258
|
+
goal: 50,
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
const result = {
|
|
263
|
+
color: "grey",
|
|
264
|
+
label1: "quality_control.score_criteria.deviation.goal",
|
|
265
|
+
label2: "quality_control.score_criteria.deviation.maximum",
|
|
266
|
+
text: "No results",
|
|
267
|
+
value1: 50,
|
|
268
|
+
value2: 80,
|
|
269
|
+
};
|
|
270
|
+
expect(qualityByControlMode(score)).toEqual(result);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("returns correct object when controlMode is percentage with no results", () => {
|
|
274
|
+
const score = scoreData({
|
|
275
|
+
noResultsMessage: "No results",
|
|
276
|
+
score_type: "ratio",
|
|
277
|
+
score_content: {
|
|
278
|
+
total_count: 0,
|
|
279
|
+
validation_count: 0,
|
|
280
|
+
},
|
|
281
|
+
quality_control: {
|
|
282
|
+
control_mode: "percentage",
|
|
283
|
+
score_criteria: {
|
|
284
|
+
goal: 30,
|
|
285
|
+
minimum: 20,
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
const result = {
|
|
290
|
+
color: "grey",
|
|
291
|
+
label1: "quality_control.score_criteria.percentage.minimum",
|
|
292
|
+
label2: "quality_control.score_criteria.percentage.goal",
|
|
293
|
+
text: "No results",
|
|
294
|
+
value1: 20,
|
|
295
|
+
value2: 30,
|
|
296
|
+
};
|
|
297
|
+
expect(qualityByControlMode(score)).toEqual(result);
|
|
298
|
+
});
|
|
248
299
|
});
|
package/src/components/qualityControls/controlProperties/{Ratio.js → ResourceWithValidation.js}
RENAMED
|
@@ -10,17 +10,21 @@ import { useDataViews } from "@truedat/qx/hooks/useDataViews";
|
|
|
10
10
|
import { useFunctions } from "@truedat/qx/hooks/useFunctions";
|
|
11
11
|
import ResourceSelector from "@truedat/qx/components/common/ResourceSelector";
|
|
12
12
|
import { Clauses } from "@truedat/qx/components/common/expressions";
|
|
13
|
+
import PropTypes from "prop-types";
|
|
13
14
|
|
|
14
|
-
export default function
|
|
15
|
+
export default function ResourceWithValidation({
|
|
16
|
+
resourceKey,
|
|
17
|
+
resourceLabelId,
|
|
18
|
+
validationLabelId,
|
|
19
|
+
}) {
|
|
15
20
|
const { field, fields } = use(QxContext);
|
|
16
21
|
const { watch } = useFormContext();
|
|
17
22
|
|
|
18
23
|
const formData = watch();
|
|
19
|
-
|
|
20
24
|
const { control_properties: controlProperties, source_id: sourceId } =
|
|
21
25
|
formData;
|
|
22
26
|
|
|
23
|
-
const resource = _.prop(
|
|
27
|
+
const resource = _.prop(resourceKey)(controlProperties);
|
|
24
28
|
|
|
25
29
|
const { data, loading: dataViewsLoading } = useDataViews();
|
|
26
30
|
const { data: functionsData, loading: functionsLoading } = useFunctions();
|
|
@@ -35,7 +39,7 @@ export default function Ratio() {
|
|
|
35
39
|
const referenceDatasets = _.flow(
|
|
36
40
|
_.getOr([], "referenceDatasets"),
|
|
37
41
|
_.sortBy([({ name }) => lowerDeburrTrim(name), "name"]),
|
|
38
|
-
_.map((row) => ({ ...row, id: Number(row?.id) }))
|
|
42
|
+
_.map((row) => ({ ...row, id: Number(row?.id) })),
|
|
39
43
|
)(referenceDatasetsData);
|
|
40
44
|
const context = {
|
|
41
45
|
dataViews,
|
|
@@ -47,11 +51,10 @@ export default function Ratio() {
|
|
|
47
51
|
<Loading />
|
|
48
52
|
) : (
|
|
49
53
|
<>
|
|
50
|
-
<QxContext
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/>
|
|
54
|
+
<QxContext
|
|
55
|
+
value={{ ...context, sourceId, field: `${field}.${resourceKey}` }}
|
|
56
|
+
>
|
|
57
|
+
<ResourceSelector required labelId={resourceLabelId} />
|
|
55
58
|
</QxContext>
|
|
56
59
|
{resource?.id ? (
|
|
57
60
|
<div className="vertical-space">
|
|
@@ -63,10 +66,16 @@ export default function Ratio() {
|
|
|
63
66
|
field: `${field}.validation`,
|
|
64
67
|
}}
|
|
65
68
|
>
|
|
66
|
-
<Clauses labelId=
|
|
69
|
+
<Clauses labelId={validationLabelId} />
|
|
67
70
|
</QxContext>
|
|
68
71
|
</div>
|
|
69
72
|
) : null}
|
|
70
73
|
</>
|
|
71
74
|
);
|
|
72
75
|
}
|
|
76
|
+
|
|
77
|
+
ResourceWithValidation.propTypes = {
|
|
78
|
+
resourceKey: PropTypes.oneOf(["resource", "errors_resource"]).isRequired,
|
|
79
|
+
resourceLabelId: PropTypes.string.isRequired,
|
|
80
|
+
validationLabelId: PropTypes.string.isRequired,
|
|
81
|
+
};
|
package/src/components/qualityControls/controlProperties/__tests__/ResourceWithValidation.spec.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { FormProvider, useForm } from "react-hook-form";
|
|
2
|
+
import { render, waitForLoad } from "@truedat/test/render";
|
|
3
|
+
import QxContext from "@truedat/qx/components/QxContext";
|
|
4
|
+
import ResourceWithValidation from "../ResourceWithValidation";
|
|
5
|
+
|
|
6
|
+
const mockedUseQuery = jest.fn();
|
|
7
|
+
const mockedUseDataViews = jest.fn();
|
|
8
|
+
const mockedUseFunctions = jest.fn();
|
|
9
|
+
|
|
10
|
+
jest.mock("@apollo/client", () => ({
|
|
11
|
+
...jest.requireActual("@apollo/client"),
|
|
12
|
+
useQuery: (...args) => mockedUseQuery(...args),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
jest.mock("@truedat/qx/hooks/useDataViews", () => ({
|
|
16
|
+
useDataViews: () => mockedUseDataViews(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
jest.mock("@truedat/qx/hooks/useFunctions", () => ({
|
|
20
|
+
useFunctions: () => mockedUseFunctions(),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
jest.mock("@truedat/core/components", () => ({
|
|
24
|
+
Loading: () => <div>loading-component</div>,
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
jest.mock("@truedat/qx/components/common/ResourceSelector", () =>
|
|
28
|
+
jest.fn(({ labelId, required }) => (
|
|
29
|
+
<div>
|
|
30
|
+
<div>resource-selector</div>
|
|
31
|
+
<div data-testid="resource-selector-label">{labelId}</div>
|
|
32
|
+
<div data-testid="resource-selector-required">{String(required)}</div>
|
|
33
|
+
</div>
|
|
34
|
+
))
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
jest.mock("@truedat/qx/components/common/expressions", () => ({
|
|
38
|
+
Clauses: jest.fn(({ labelId }) => (
|
|
39
|
+
<div>
|
|
40
|
+
<div>clauses-component</div>
|
|
41
|
+
<div data-testid="clauses-label">{labelId}</div>
|
|
42
|
+
</div>
|
|
43
|
+
)),
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
function ComponentWrapper({ children, defaultValues, contextValue }) {
|
|
47
|
+
const form = useForm({ defaultValues });
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<FormProvider {...form}>
|
|
51
|
+
<QxContext value={contextValue}>{children}</QxContext>
|
|
52
|
+
</FormProvider>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("<ResourceWithValidation />", () => {
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
mockedUseDataViews.mockReturnValue({
|
|
59
|
+
data: { data: [{ id: 9 }, { id: 1 }] },
|
|
60
|
+
loading: false,
|
|
61
|
+
});
|
|
62
|
+
mockedUseFunctions.mockReturnValue({
|
|
63
|
+
data: { data: [{ id: "fn_1" }] },
|
|
64
|
+
loading: false,
|
|
65
|
+
});
|
|
66
|
+
mockedUseQuery.mockReturnValue({
|
|
67
|
+
data: {
|
|
68
|
+
referenceDatasets: [
|
|
69
|
+
{ id: "3", name: "zeta" },
|
|
70
|
+
{ id: "2", name: "Alpha" },
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
loading: false,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
jest.clearAllMocks();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("renders loading while dependencies are still loading", async () => {
|
|
82
|
+
mockedUseFunctions.mockReturnValue({
|
|
83
|
+
data: { data: [] },
|
|
84
|
+
loading: true,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const rendered = render(
|
|
88
|
+
<ComponentWrapper
|
|
89
|
+
defaultValues={{
|
|
90
|
+
source_id: 77,
|
|
91
|
+
control_properties: {},
|
|
92
|
+
}}
|
|
93
|
+
contextValue={{ field: "control_properties", fields: [{ name: "a" }] }}
|
|
94
|
+
>
|
|
95
|
+
<ResourceWithValidation
|
|
96
|
+
resourceKey="resource"
|
|
97
|
+
resourceLabelId="resource.label"
|
|
98
|
+
validationLabelId="validation.label"
|
|
99
|
+
/>
|
|
100
|
+
</ComponentWrapper>
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(rendered.getByText(/loading-component/i)).toBeInTheDocument();
|
|
104
|
+
expect(rendered.queryByText(/resource-selector/i)).not.toBeInTheDocument();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("renders resource selector when loading is completed", async () => {
|
|
108
|
+
const rendered = render(
|
|
109
|
+
<ComponentWrapper
|
|
110
|
+
defaultValues={{
|
|
111
|
+
source_id: 88,
|
|
112
|
+
control_properties: {},
|
|
113
|
+
}}
|
|
114
|
+
contextValue={{
|
|
115
|
+
field: "control_properties",
|
|
116
|
+
fields: [{ name: "one" }],
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
<ResourceWithValidation
|
|
120
|
+
resourceKey="resource"
|
|
121
|
+
resourceLabelId="resource.label"
|
|
122
|
+
validationLabelId="validation.label"
|
|
123
|
+
/>
|
|
124
|
+
</ComponentWrapper>
|
|
125
|
+
);
|
|
126
|
+
await waitForLoad(rendered);
|
|
127
|
+
|
|
128
|
+
expect(rendered.getByText(/resource-selector/i)).toBeInTheDocument();
|
|
129
|
+
expect(rendered.getByTestId("resource-selector-label")).toHaveTextContent(
|
|
130
|
+
"resource.label"
|
|
131
|
+
);
|
|
132
|
+
expect(
|
|
133
|
+
rendered.getByTestId("resource-selector-required")
|
|
134
|
+
).toHaveTextContent("true");
|
|
135
|
+
expect(rendered.queryByText(/clauses-component/i)).not.toBeInTheDocument();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("renders validation clauses when resource has id", async () => {
|
|
139
|
+
const rendered = render(
|
|
140
|
+
<ComponentWrapper
|
|
141
|
+
defaultValues={{
|
|
142
|
+
source_id: 42,
|
|
143
|
+
control_properties: {
|
|
144
|
+
resource: { id: 123 },
|
|
145
|
+
},
|
|
146
|
+
}}
|
|
147
|
+
contextValue={{
|
|
148
|
+
field: "control_properties",
|
|
149
|
+
fields: [{ name: "field_1" }, { name: "field_2" }],
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
<ResourceWithValidation
|
|
153
|
+
resourceKey="resource"
|
|
154
|
+
resourceLabelId="resource.label"
|
|
155
|
+
validationLabelId="validation.label"
|
|
156
|
+
/>
|
|
157
|
+
</ComponentWrapper>
|
|
158
|
+
);
|
|
159
|
+
await waitForLoad(rendered);
|
|
160
|
+
|
|
161
|
+
expect(rendered.getByText(/clauses-component/i)).toBeInTheDocument();
|
|
162
|
+
expect(rendered.getByTestId("clauses-label")).toHaveTextContent(
|
|
163
|
+
"validation.label"
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("uses errors_resource key to decide validation visibility", async () => {
|
|
168
|
+
const rendered = render(
|
|
169
|
+
<ComponentWrapper
|
|
170
|
+
defaultValues={{
|
|
171
|
+
source_id: 99,
|
|
172
|
+
control_properties: {
|
|
173
|
+
errors_resource: { id: 456 },
|
|
174
|
+
},
|
|
175
|
+
}}
|
|
176
|
+
contextValue={{ field: "control_properties", fields: [] }}
|
|
177
|
+
>
|
|
178
|
+
<ResourceWithValidation
|
|
179
|
+
resourceKey="errors_resource"
|
|
180
|
+
resourceLabelId="errors.resource.label"
|
|
181
|
+
validationLabelId="validation.label"
|
|
182
|
+
/>
|
|
183
|
+
</ComponentWrapper>
|
|
184
|
+
);
|
|
185
|
+
await waitForLoad(rendered);
|
|
186
|
+
|
|
187
|
+
expect(rendered.getByTestId("resource-selector-label")).toHaveTextContent(
|
|
188
|
+
"errors.resource.label"
|
|
189
|
+
);
|
|
190
|
+
expect(rendered.getByText(/clauses-component/i)).toBeInTheDocument();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
@@ -9,20 +9,6 @@ export default function qualityByControlMode(score) {
|
|
|
9
9
|
if (!scoreContent) return { isEmpty: true };
|
|
10
10
|
|
|
11
11
|
switch (controlMode) {
|
|
12
|
-
case "count":
|
|
13
|
-
return {
|
|
14
|
-
color:
|
|
15
|
-
scoreContent.count < scoreCriteria.goal
|
|
16
|
-
? "green"
|
|
17
|
-
: scoreContent.count < scoreCriteria.maximum
|
|
18
|
-
? "yellow"
|
|
19
|
-
: "red",
|
|
20
|
-
label1: "quality_control.score_criteria.count.goal",
|
|
21
|
-
value1: scoreCriteria.goal,
|
|
22
|
-
label2: "quality_control.score_criteria.count.maximum",
|
|
23
|
-
value2: scoreCriteria.maximum,
|
|
24
|
-
text: scoreContent.count,
|
|
25
|
-
};
|
|
26
12
|
case "deviation":
|
|
27
13
|
const deviationRatio =
|
|
28
14
|
scoreContent.total_count == 0
|
|
@@ -73,28 +59,18 @@ export default function qualityByControlMode(score) {
|
|
|
73
59
|
text: percentageResult,
|
|
74
60
|
};
|
|
75
61
|
case "error_count":
|
|
76
|
-
const errorCount =
|
|
77
|
-
scoreContent.total_count == 0
|
|
78
|
-
? null
|
|
79
|
-
: (scoreContent.validation_count / scoreContent.total_count) * 100;
|
|
80
|
-
|
|
81
|
-
const errorCountResult =
|
|
82
|
-
scoreContent.total_count == 0 ? noResultsMessage : `${errorCount}%`;
|
|
83
|
-
|
|
84
62
|
return {
|
|
85
63
|
color:
|
|
86
|
-
scoreContent.
|
|
87
|
-
? "
|
|
88
|
-
:
|
|
89
|
-
? "
|
|
90
|
-
:
|
|
91
|
-
? "yellow"
|
|
92
|
-
: "red",
|
|
64
|
+
scoreContent.count < scoreCriteria.goal
|
|
65
|
+
? "green"
|
|
66
|
+
: scoreContent.count < scoreCriteria.maximum
|
|
67
|
+
? "yellow"
|
|
68
|
+
: "red",
|
|
93
69
|
label1: "quality_control.score_criteria.error_count.goal",
|
|
94
70
|
value1: scoreCriteria.goal,
|
|
95
71
|
label2: "quality_control.score_criteria.error_count.maximum",
|
|
96
72
|
value2: scoreCriteria.maximum,
|
|
97
|
-
text:
|
|
73
|
+
text: scoreContent.count,
|
|
98
74
|
};
|
|
99
75
|
default:
|
|
100
76
|
return {};
|
|
@@ -26,10 +26,10 @@ describe("<ErrorCount />", () => {
|
|
|
26
26
|
|
|
27
27
|
const user = userEvent.setup({ delay: null });
|
|
28
28
|
const goalInput = rendered.getByPlaceholderText(
|
|
29
|
-
|
|
29
|
+
/quality_control\.score_criteria\.error_count\.goal/i
|
|
30
30
|
);
|
|
31
31
|
const thresholdInput = rendered.getByPlaceholderText(
|
|
32
|
-
|
|
32
|
+
/quality_control\.score_criteria\.error_count\.maximum/i
|
|
33
33
|
);
|
|
34
34
|
|
|
35
35
|
await user.type(goalInput, "10");
|
|
@@ -52,10 +52,10 @@ describe("<ErrorCount />", () => {
|
|
|
52
52
|
|
|
53
53
|
const user = userEvent.setup({ delay: null });
|
|
54
54
|
const goalInput = rendered.getByPlaceholderText(
|
|
55
|
-
|
|
55
|
+
/quality_control\.score_criteria\.error_count\.goal/i
|
|
56
56
|
);
|
|
57
57
|
const thresholdInput = rendered.getByPlaceholderText(
|
|
58
|
-
|
|
58
|
+
/quality_control\.score_criteria\.error_count\.maximum/i
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
await user.type(goalInput, "10");
|