@truedat/qx 7.5.7 → 7.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/package.json +4 -4
  2. package/src/components/__tests__/__fixtures__/helper.js +6 -7
  3. package/src/components/common/expressions/__tests__/Expression.spec.js +3 -22
  4. package/src/components/common/expressions/__tests__/ShapeSelector.spec.js +6 -18
  5. package/src/components/dataViews/queryableProperties/__tests__/SelectField.spec.js +0 -5
  6. package/src/components/qualityControls/ControlProperties.js +4 -3
  7. package/src/components/qualityControls/ControlPropertiesView.js +5 -4
  8. package/src/components/qualityControls/QualityBadge.js +11 -2
  9. package/src/components/qualityControls/QualityControlEditor.js +1 -1
  10. package/src/components/qualityControls/ScoreCriteria.js +4 -0
  11. package/src/components/qualityControls/ScoreCriteriaView.js +34 -53
  12. package/src/components/qualityControls/__tests__/ControlProperties.spec.js +6 -6
  13. package/src/components/qualityControls/__tests__/ControlPropertiesView.spec.js +5 -5
  14. package/src/components/qualityControls/__tests__/NewQualityControl.spec.js +15 -2
  15. package/src/components/qualityControls/__tests__/QualityBadge.spec.js +6 -6
  16. package/src/components/qualityControls/__tests__/QualityControlEditor.spec.js +1 -1
  17. package/src/components/qualityControls/__tests__/QualityControlQueryModal.spec.js +1 -1
  18. package/src/components/qualityControls/__tests__/ScoreCriteria.spec.js +3 -3
  19. package/src/components/qualityControls/__tests__/ScoreCriteriaView.spec.js +18 -2
  20. package/src/components/qualityControls/__tests__/__fixtures__/qualityControlHelper.js +1 -1
  21. package/src/components/qualityControls/__tests__/__snapshots__/ControlProperties.spec.js.snap +1 -1
  22. package/src/components/qualityControls/__tests__/__snapshots__/ControlPropertiesView.spec.js.snap +53 -53
  23. package/src/components/qualityControls/__tests__/__snapshots__/EditQualityControl.spec.js.snap +14 -1
  24. package/src/components/qualityControls/__tests__/__snapshots__/NewDraftQualityControl.spec.js.snap +14 -1
  25. package/src/components/qualityControls/__tests__/__snapshots__/NewQualityControl.spec.js.snap +14 -1
  26. package/src/components/qualityControls/__tests__/__snapshots__/QualityBadge.spec.js.snap +1 -1
  27. package/src/components/qualityControls/__tests__/__snapshots__/QualityControl.spec.js.snap +2 -4
  28. package/src/components/qualityControls/__tests__/__snapshots__/QualityControlEditor.spec.js.snap +28 -2
  29. package/src/components/qualityControls/__tests__/__snapshots__/ScoreCriteria.spec.js.snap +1 -1
  30. package/src/components/qualityControls/__tests__/__snapshots__/ScoreCriteriaView.spec.js.snap +2 -4
  31. package/src/components/qualityControls/__tests__/qualityByControlMode.spec.js +16 -16
  32. package/src/components/qualityControls/controlProperties/{ErrorCount.js → Count.js} +2 -2
  33. package/src/components/qualityControls/controlProperties/__tests__/{ErrorCount.spec.js → Count.spec.js} +3 -14
  34. package/src/components/qualityControls/controlProperties/__tests__/__snapshots__/{ErrorCount.spec.js.snap → Count.spec.js.snap} +5 -5
  35. package/src/components/qualityControls/qualityByControlMode.js +29 -6
  36. package/src/components/qualityControls/scoreCriterias/Count.js +88 -0
  37. package/src/components/qualityControls/scoreCriterias/ErrorCount.js +1 -0
  38. package/src/components/qualityControls/scoreCriterias/__tests__/Count.spec.js +62 -0
  39. package/src/components/qualityControls/scoreCriterias/__tests__/ErrorCount.spec.js +16 -4
  40. package/src/components/qualityControls/scoreCriterias/__tests__/__snapshots__/Count.spec.js.snap +58 -0
  41. package/src/components/scores/__tests__/MyScoreGroups.spec.js +2 -2
@@ -9,19 +9,19 @@ export default function qualityByControlMode(score) {
9
9
  if (!scoreContent) return { isEmpty: true };
10
10
 
11
11
  switch (controlMode) {
12
- case "error_count":
12
+ case "count":
13
13
  return {
14
14
  color:
15
- scoreContent.error_count < scoreCriteria.goal
15
+ scoreContent.count < scoreCriteria.goal
16
16
  ? "green"
17
- : scoreContent.error_count < scoreCriteria.maximum
17
+ : scoreContent.count < scoreCriteria.maximum
18
18
  ? "yellow"
19
19
  : "red",
20
- label1: "quality_control.score_criteria.error_count.goal",
20
+ label1: "quality_control.score_criteria.count.goal",
21
21
  value1: scoreCriteria.goal,
22
- label2: "quality_control.score_criteria.error_count.maximum",
22
+ label2: "quality_control.score_criteria.count.maximum",
23
23
  value2: scoreCriteria.maximum,
24
- text: scoreContent.error_count,
24
+ text: scoreContent.count,
25
25
  };
26
26
  case "deviation":
27
27
  const deviationRatio =
@@ -72,7 +72,30 @@ export default function qualityByControlMode(score) {
72
72
  value2: scoreCriteria.goal,
73
73
  text: percentageResult,
74
74
  };
75
+ case "error_count":
76
+ const errorCount =
77
+ scoreContent.total_count == 0 ? null : scoreContent.validation_count;
78
+
79
+ const errorCountResult =
80
+ scoreContent.total_count == 0
81
+ ? noResultsMessage
82
+ : scoreContent.validation_count;
75
83
 
84
+ return {
85
+ color:
86
+ scoreContent.total_count == 0
87
+ ? "grey"
88
+ : errorCount > scoreCriteria.goal
89
+ ? "green"
90
+ : errorCount > scoreCriteria.maximum
91
+ ? "yellow"
92
+ : "red",
93
+ label1: "quality_control.score_criteria.error_count.goal",
94
+ value1: scoreCriteria.goal,
95
+ label2: "quality_control.score_criteria.error_count.maximum",
96
+ value2: scoreCriteria.maximum,
97
+ text: errorCountResult,
98
+ };
76
99
  default:
77
100
  return {};
78
101
  }
@@ -0,0 +1,88 @@
1
+ import React, { useContext } from "react";
2
+ import { useIntl } from "react-intl";
3
+ import { Controller, useFormContext } from "react-hook-form";
4
+ import { Form } from "semantic-ui-react";
5
+ import QxContext from "@truedat/qx/components/QxContext";
6
+ import { FieldLabel } from "@truedat/core/components";
7
+ import { numberRules } from "@truedat/core/services/formRules";
8
+
9
+ export default function Count() {
10
+ const { formatMessage } = useIntl();
11
+ const { field } = useContext(QxContext);
12
+ const { control, watch } = useFormContext();
13
+
14
+ const maximumField = `${field}.maximum`;
15
+ const goalField = `${field}.goal`;
16
+ const maximum = watch(maximumField);
17
+ const goal = watch(goalField);
18
+
19
+ return (
20
+ <>
21
+ <Controller
22
+ name={goalField}
23
+ control={control}
24
+ rules={numberRules({
25
+ formatMessage,
26
+ minValue: 0,
27
+ maxValue: maximum,
28
+ required: true,
29
+ })}
30
+ render={({
31
+ field: { onBlur, onChange, value },
32
+ fieldState: { error },
33
+ }) => (
34
+ <FieldLabel
35
+ label={formatMessage({
36
+ id: "quality_control.score_criteria.count.goal",
37
+ })}
38
+ required
39
+ error={error?.message}
40
+ >
41
+ <Form.Input
42
+ autoComplete="off"
43
+ placeholder={formatMessage({
44
+ id: "quality_control.score_criteria.count.goal",
45
+ })}
46
+ error={!!error}
47
+ onBlur={onBlur}
48
+ onChange={(_e, { value }) => onChange(value)}
49
+ value={value || ""}
50
+ />
51
+ </FieldLabel>
52
+ )}
53
+ />
54
+ <Controller
55
+ name={maximumField}
56
+ control={control}
57
+ rules={numberRules({
58
+ formatMessage,
59
+ minValue: goal,
60
+ required: true,
61
+ })}
62
+ render={({
63
+ field: { onBlur, onChange, value },
64
+ fieldState: { error },
65
+ }) => (
66
+ <FieldLabel
67
+ label={formatMessage({
68
+ id: "quality_control.score_criteria.count.maximum",
69
+ })}
70
+ required
71
+ error={error?.message}
72
+ >
73
+ <Form.Input
74
+ autoComplete="off"
75
+ placeholder={formatMessage({
76
+ id: "quality_control.score_criteria.count.maximum",
77
+ })}
78
+ error={!!error}
79
+ onBlur={onBlur}
80
+ onChange={(_e, { value }) => onChange(value)}
81
+ value={value || ""}
82
+ />
83
+ </FieldLabel>
84
+ )}
85
+ />
86
+ </>
87
+ );
88
+ }
@@ -57,6 +57,7 @@ export default function ErrorCount() {
57
57
  rules={numberRules({
58
58
  formatMessage,
59
59
  minValue: goal,
60
+ maxValue: 100,
60
61
  required: true,
61
62
  })}
62
63
  render={({
@@ -0,0 +1,62 @@
1
+ import React from "react";
2
+ import { render } from "@truedat/test/render";
3
+ import { waitFor } from "@testing-library/react";
4
+ import { fireEvent } from "@testing-library/react";
5
+ import TestFormWrapper from "@truedat/qx/components/common/TestFormWrapper";
6
+ import { messages } from "@truedat/qx/components/__tests__/__fixtures__/helper";
7
+ import Count from "../Count";
8
+
9
+ const renderOpts = { messages };
10
+
11
+ describe("<Count />", () => {
12
+ it("matches the latest snapshot", async () => {
13
+ const { container } = render(
14
+ <TestFormWrapper>
15
+ <Count />
16
+ </TestFormWrapper>,
17
+ renderOpts
18
+ );
19
+ expect(container).toMatchSnapshot();
20
+ });
21
+
22
+ it("should update the goal and maximum fields correctly", async () => {
23
+ const defaultValues = { "testField.goal": "", "testField.maximum": "" };
24
+
25
+ const { getByPlaceholderText, queryByText } = render(
26
+ <TestFormWrapper defaultValues={defaultValues}>
27
+ <Count />
28
+ </TestFormWrapper>,
29
+ renderOpts
30
+ );
31
+
32
+ const goalInput = getByPlaceholderText("Goal");
33
+
34
+ const thresholdInput = getByPlaceholderText("Threshold");
35
+
36
+ fireEvent.change(goalInput, { target: { value: "10" } });
37
+ fireEvent.change(thresholdInput, { target: { value: "20" } });
38
+
39
+ await waitFor(() =>
40
+ expect(queryByText(/Must be greater than y/i)).not.toBeInTheDocument()
41
+ );
42
+ });
43
+
44
+ it("Show alert if thresholdInput is less than goal", async () => {
45
+ const { getByPlaceholderText, queryByText } = render(
46
+ <TestFormWrapper>
47
+ <Count />
48
+ </TestFormWrapper>,
49
+ renderOpts
50
+ );
51
+
52
+ const goalInput = getByPlaceholderText("Goal");
53
+ const thresholdInput = getByPlaceholderText("Threshold");
54
+
55
+ fireEvent.change(goalInput, { target: { value: "10" } });
56
+ fireEvent.change(thresholdInput, { target: { value: "1" } });
57
+
58
+ await waitFor(() =>
59
+ expect(queryByText(/Must be greater than 10/i)).toBeInTheDocument()
60
+ );
61
+ });
62
+ });
@@ -3,10 +3,22 @@ import { render } from "@truedat/test/render";
3
3
  import { waitFor } from "@testing-library/react";
4
4
  import { fireEvent } from "@testing-library/react";
5
5
  import TestFormWrapper from "@truedat/qx/components/common/TestFormWrapper";
6
- import { messages } from "@truedat/qx/components/__tests__/__fixtures__/helper";
7
6
  import ErrorCount from "../ErrorCount";
8
7
 
9
- const renderOpts = { messages };
8
+ const messages = {
9
+ en: {
10
+ "form.validation.must_be_a_number": "Must be a number",
11
+ "form.validation.must_be_less_than_or_equal": "Must be less than x",
12
+ "form.validation.must_be_greater_than_or_equal": "Must be greater than y",
13
+ "form.validation.empty_required": "Required field is empty",
14
+ "quality_control.score_criteria.error_count.goal": "Goal",
15
+ "quality_control.score_criteria.error_count.maximum": "Threshold",
16
+ },
17
+ };
18
+
19
+ const renderOpts = {
20
+ messages,
21
+ };
10
22
 
11
23
  describe("<ErrorCount />", () => {
12
24
  it("matches the latest snapshot", async () => {
@@ -16,6 +28,7 @@ describe("<ErrorCount />", () => {
16
28
  </TestFormWrapper>,
17
29
  renderOpts
18
30
  );
31
+
19
32
  expect(container).toMatchSnapshot();
20
33
  });
21
34
 
@@ -35,7 +48,6 @@ describe("<ErrorCount />", () => {
35
48
 
36
49
  fireEvent.change(goalInput, { target: { value: "10" } });
37
50
  fireEvent.change(thresholdInput, { target: { value: "20" } });
38
-
39
51
  await waitFor(() =>
40
52
  expect(queryByText(/Must be greater than y/i)).not.toBeInTheDocument()
41
53
  );
@@ -57,7 +69,7 @@ describe("<ErrorCount />", () => {
57
69
  fireEvent.change(thresholdInput, { target: { value: "1" } });
58
70
 
59
71
  await waitFor(() =>
60
- expect(queryByText(/Must be greater than 10/i)).toBeInTheDocument()
72
+ expect(queryByText(/Must be greater than y/i)).toBeInTheDocument()
61
73
  );
62
74
  });
63
75
  });
@@ -0,0 +1,58 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<Count /> matches the latest snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ class="field"
7
+ >
8
+ <label
9
+ class="field-label"
10
+ >
11
+ Goal
12
+ <span>
13
+ *
14
+ </span>
15
+ </label>
16
+ <div
17
+ class="field"
18
+ >
19
+ <div
20
+ class="ui input"
21
+ >
22
+ <input
23
+ autocomplete="off"
24
+ placeholder="Goal"
25
+ type="text"
26
+ value=""
27
+ />
28
+ </div>
29
+ </div>
30
+ </div>
31
+ <div
32
+ class="field"
33
+ >
34
+ <label
35
+ class="field-label"
36
+ >
37
+ Threshold
38
+ <span>
39
+ *
40
+ </span>
41
+ </label>
42
+ <div
43
+ class="field"
44
+ >
45
+ <div
46
+ class="ui input"
47
+ >
48
+ <input
49
+ autocomplete="off"
50
+ placeholder="Threshold"
51
+ type="text"
52
+ value=""
53
+ />
54
+ </div>
55
+ </div>
56
+ </div>
57
+ </div>
58
+ `;
@@ -51,7 +51,7 @@ describe("<MyScoreGroups />", () => {
51
51
  const { container } = render(<MyScoreGroups />, renderOpts);
52
52
 
53
53
  await waitFor(() => {
54
- expect(container.querySelector(".loading")).toBeNull();
54
+ expect(container.querySelector(".loading")).not.toBeInTheDocument();
55
55
  });
56
56
 
57
57
  expect(container).toMatchSnapshot();
@@ -63,7 +63,7 @@ describe("<MyScoreGroups />", () => {
63
63
  const { container, queryByText } = render(<MyScoreGroups />, renderOpts);
64
64
 
65
65
  await waitFor(() => {
66
- expect(container.querySelector(".loading")).toBeNull();
66
+ expect(container.querySelector(".loading")).not.toBeInTheDocument();
67
67
  });
68
68
 
69
69
  expect(queryByText("Filters")).not.toBeInTheDocument();