@truedat/qx 5.12.2 → 5.12.7
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 +8 -3
- package/src/api.js +3 -1
- package/src/components/QxContext.js +3 -0
- package/src/components/QxRoutes.js +6 -1
- package/src/components/common/DescriptionInput.js +47 -0
- package/src/components/common/TestFormWrapper.js +33 -0
- package/src/components/common/TypeSelector.js +33 -0
- package/src/components/common/index.js +4 -0
- package/src/components/functions/FunctionEditor.js +200 -0
- package/src/components/functions/FunctionParams.js +122 -0
- package/src/components/functions/Functions.js +152 -0
- package/src/components/functions/__tests__/FunctionEditor.spec.js +195 -0
- package/src/components/functions/__tests__/FunctionParams.spec.js +108 -0
- package/src/components/functions/__tests__/Functions.spec.js +95 -0
- package/src/components/functions/__tests__/__snapshots__/FunctionEditor.spec.js.snap +1563 -0
- package/src/components/functions/__tests__/__snapshots__/FunctionParams.spec.js.snap +228 -0
- package/src/components/functions/__tests__/__snapshots__/Functions.spec.js.snap +86 -0
- package/src/components/functions/__tests__/useWatchParams.spec.js +23 -0
- package/src/components/functions/expressions/ConstantSelector.js +26 -0
- package/src/components/functions/expressions/Expression.js +40 -0
- package/src/components/functions/expressions/FieldSelector.js +56 -0
- package/src/components/functions/expressions/FunctionArgs.js +49 -0
- package/src/components/functions/expressions/FunctionSelector.js +95 -0
- package/src/components/functions/expressions/ParamSelector.js +51 -0
- package/src/components/functions/expressions/ShapeSelector.js +74 -0
- package/src/components/functions/expressions/__tests__/ConstantSelector.spec.js +64 -0
- package/src/components/functions/expressions/__tests__/Expression.spec.js +131 -0
- package/src/components/functions/expressions/__tests__/FunctionArgs.spec.js +86 -0
- package/src/components/functions/expressions/__tests__/FunctionSelector.spec.js +69 -0
- package/src/components/functions/expressions/__tests__/ParamSelector.spec.js +115 -0
- package/src/components/functions/expressions/__tests__/ShapeSelector.spec.js +107 -0
- package/src/components/functions/expressions/__tests__/__snapshots__/ConstantSelector.spec.js.snap +149 -0
- package/src/components/functions/expressions/__tests__/__snapshots__/Expression.spec.js.snap +904 -0
- package/src/components/functions/expressions/__tests__/__snapshots__/FunctionArgs.spec.js.snap +392 -0
- package/src/components/functions/expressions/__tests__/__snapshots__/FunctionSelector.spec.js.snap +377 -0
- package/src/components/functions/expressions/__tests__/__snapshots__/ParamSelector.spec.js.snap +95 -0
- package/src/components/functions/expressions/__tests__/__snapshots__/ShapeSelector.spec.js.snap +290 -0
- package/src/components/functions/expressions/constantInputs/AnySelector.js +29 -0
- package/src/components/functions/expressions/constantInputs/BooleanSelector.js +37 -0
- package/src/components/functions/expressions/constantInputs/DefaultSelector.js +34 -0
- package/src/components/functions/expressions/constantInputs/__tests__/AnySelector.spec.js +63 -0
- package/src/components/functions/expressions/constantInputs/__tests__/BooleanSelector.spec.js +51 -0
- package/src/components/functions/expressions/constantInputs/__tests__/DefaultSelector.spec.js +56 -0
- package/src/components/functions/expressions/constantInputs/__tests__/__snapshots__/AnySelector.spec.js.snap +236 -0
- package/src/components/functions/expressions/constantInputs/__tests__/__snapshots__/BooleanSelector.spec.js.snap +101 -0
- package/src/components/functions/expressions/constantInputs/__tests__/__snapshots__/DefaultSelector.spec.js.snap +39 -0
- package/src/components/functions/expressions/constantInputs/index.js +5 -0
- package/src/components/functions/useWatchParams.js +13 -0
- package/src/hooks/__tests__/useFunctions.spec.js +101 -0
- package/src/hooks/useFunctions.js +33 -0
- package/src/styles/Expression.less +102 -0
- package/src/types.js +38 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import React, { useContext } from "react";
|
|
3
|
+
import { useIntl } from "react-intl";
|
|
4
|
+
import { Controller, useFormContext } from "react-hook-form";
|
|
5
|
+
import { Dropdown } from "semantic-ui-react";
|
|
6
|
+
import QxContext from "@truedat/qx/components/QxContext";
|
|
7
|
+
|
|
8
|
+
const shapeToSymbol = {
|
|
9
|
+
function: "f(x)",
|
|
10
|
+
constant: "[π]",
|
|
11
|
+
param: "[P]",
|
|
12
|
+
field: "[F]",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default function ShapeSelector() {
|
|
16
|
+
const { formatMessage } = useIntl();
|
|
17
|
+
const { fields, field, type } = useContext(QxContext);
|
|
18
|
+
const { control, watch, setValue } = useFormContext();
|
|
19
|
+
|
|
20
|
+
const params = watch("params");
|
|
21
|
+
|
|
22
|
+
const emptyTypeParams = _.flow(
|
|
23
|
+
_.filter((param) => type === "any" || param.type == type),
|
|
24
|
+
_.isEmpty
|
|
25
|
+
)(params);
|
|
26
|
+
const emptyTypeFields = _.flow(
|
|
27
|
+
_.filter((field) => type === "any" || field.type == type),
|
|
28
|
+
_.isEmpty
|
|
29
|
+
)(fields);
|
|
30
|
+
|
|
31
|
+
const shapes = _.reject(
|
|
32
|
+
(shape) =>
|
|
33
|
+
(shape === "param" && emptyTypeParams) ||
|
|
34
|
+
(shape === "field" && emptyTypeFields)
|
|
35
|
+
)(["constant", "function", "param", "field"]);
|
|
36
|
+
|
|
37
|
+
const shapeDropdownOptions = _.map((v) => ({
|
|
38
|
+
key: v,
|
|
39
|
+
value: v,
|
|
40
|
+
content: (
|
|
41
|
+
<div style={{ display: "flex", alignItems: "center" }}>
|
|
42
|
+
<small style={{ marginRight: "5px" }}>
|
|
43
|
+
<b>
|
|
44
|
+
<code>{shapeToSymbol[v]}</code>
|
|
45
|
+
</b>
|
|
46
|
+
</small>
|
|
47
|
+
{formatMessage({ id: `functions.expression.shape.${v}` })}
|
|
48
|
+
</div>
|
|
49
|
+
),
|
|
50
|
+
}))(shapes);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Controller
|
|
54
|
+
name={`${field}.shape`}
|
|
55
|
+
control={control}
|
|
56
|
+
render={({ field: { onBlur, onChange, value } }) => (
|
|
57
|
+
<Dropdown
|
|
58
|
+
onBlur={onBlur}
|
|
59
|
+
options={shapeDropdownOptions}
|
|
60
|
+
onChange={(_e, { value }) => {
|
|
61
|
+
onChange(value);
|
|
62
|
+
setValue(`${field}.value`, undefined);
|
|
63
|
+
}}
|
|
64
|
+
trigger={
|
|
65
|
+
<div className="shape-selector-trigger">{shapeToSymbol[value]}</div>
|
|
66
|
+
}
|
|
67
|
+
value={value}
|
|
68
|
+
pointing="top left"
|
|
69
|
+
icon={null}
|
|
70
|
+
/>
|
|
71
|
+
)}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@truedat/test/render";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import TestFormWrapper from "@truedat/qx/components/common/TestFormWrapper";
|
|
5
|
+
import ConstantSelector from "../ConstantSelector";
|
|
6
|
+
|
|
7
|
+
const renderOpts = {
|
|
8
|
+
messages: {
|
|
9
|
+
en: {
|
|
10
|
+
"functions.expression.constant.false": "false",
|
|
11
|
+
"functions.expression.constant.true": "true",
|
|
12
|
+
"functions.form.required": "required",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
fallback: "lazy",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe("<ConstantSelector />", () => {
|
|
19
|
+
it("matches the latest snapshot", () => {
|
|
20
|
+
const { container } = render(
|
|
21
|
+
<TestFormWrapper>
|
|
22
|
+
<ConstantSelector />
|
|
23
|
+
</TestFormWrapper>,
|
|
24
|
+
renderOpts
|
|
25
|
+
);
|
|
26
|
+
expect(container).toMatchSnapshot();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("user interaction", async () => {
|
|
30
|
+
const watcher = jest.fn();
|
|
31
|
+
|
|
32
|
+
const { container, findByText } = render(
|
|
33
|
+
<TestFormWrapper watcher={watcher} type="any">
|
|
34
|
+
<ConstantSelector />
|
|
35
|
+
</TestFormWrapper>,
|
|
36
|
+
renderOpts
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
userEvent.click(await findByText("boolean"));
|
|
40
|
+
userEvent.click(await findByText("true"));
|
|
41
|
+
|
|
42
|
+
expect(watcher).lastCalledWith({
|
|
43
|
+
test: {
|
|
44
|
+
value: {
|
|
45
|
+
type: "boolean",
|
|
46
|
+
value: "true",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
userEvent.click(await findByText("string"));
|
|
52
|
+
|
|
53
|
+
expect(watcher).lastCalledWith({
|
|
54
|
+
test: {
|
|
55
|
+
value: {
|
|
56
|
+
type: "string",
|
|
57
|
+
value: "",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(container).toMatchSnapshot();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
3
|
+
import { render } from "@truedat/test/render";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import TestFormWrapper from "@truedat/qx/components/common/TestFormWrapper";
|
|
6
|
+
import Expression from "../Expression";
|
|
7
|
+
|
|
8
|
+
const renderOpts = {
|
|
9
|
+
messages: {
|
|
10
|
+
en: {
|
|
11
|
+
"functions.expression.constant.false": "false",
|
|
12
|
+
"functions.expression.constant.true": "true",
|
|
13
|
+
"functions.form.required": "required",
|
|
14
|
+
"functions.expression.shape.function": "function",
|
|
15
|
+
"functions.expression.shape.constant": "constant",
|
|
16
|
+
"functions.expression.shape.param": "param",
|
|
17
|
+
"functions.form.expression.function.placeholder": "function.placeholder",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
fallback: "lazy",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe("<Expression />", () => {
|
|
24
|
+
it("matches the latest snapshot", () => {
|
|
25
|
+
const { container } = render(
|
|
26
|
+
<TestFormWrapper>
|
|
27
|
+
<Expression />
|
|
28
|
+
</TestFormWrapper>,
|
|
29
|
+
renderOpts
|
|
30
|
+
);
|
|
31
|
+
expect(container).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("shape function expression", async () => {
|
|
35
|
+
const watcher = jest.fn();
|
|
36
|
+
|
|
37
|
+
const functions = [
|
|
38
|
+
{
|
|
39
|
+
name: "eq",
|
|
40
|
+
type: "boolean",
|
|
41
|
+
params: [
|
|
42
|
+
{ name: "arg1", type: "any" },
|
|
43
|
+
{ name: "arg2", type: "any" },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const { container, getByRole, getAllByRole, queryByText } = render(
|
|
49
|
+
<TestFormWrapper watcher={watcher} type="boolean" functions={functions}>
|
|
50
|
+
<Expression />
|
|
51
|
+
</TestFormWrapper>,
|
|
52
|
+
renderOpts
|
|
53
|
+
);
|
|
54
|
+
userEvent.click(getAllByRole("listbox")[1]);
|
|
55
|
+
userEvent.click(getByRole("option", { name: /eq/i }));
|
|
56
|
+
|
|
57
|
+
expect(watcher).lastCalledWith({
|
|
58
|
+
test: {
|
|
59
|
+
shape: "function",
|
|
60
|
+
value: {
|
|
61
|
+
name: "eq",
|
|
62
|
+
type: "boolean",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
67
|
+
|
|
68
|
+
expect(container).toMatchSnapshot();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("shape constant expression", async () => {
|
|
72
|
+
const watcher = jest.fn();
|
|
73
|
+
|
|
74
|
+
const { container, getByRole, getAllByRole, queryByText } = render(
|
|
75
|
+
<TestFormWrapper watcher={watcher} type="boolean">
|
|
76
|
+
<Expression />
|
|
77
|
+
</TestFormWrapper>,
|
|
78
|
+
renderOpts
|
|
79
|
+
);
|
|
80
|
+
userEvent.click(getAllByRole("listbox")[0]);
|
|
81
|
+
userEvent.click(getByRole("option", { name: /constant/i }));
|
|
82
|
+
|
|
83
|
+
expect(watcher).lastCalledWith({
|
|
84
|
+
test: {
|
|
85
|
+
shape: "constant",
|
|
86
|
+
value: {
|
|
87
|
+
type: "boolean",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument(), {
|
|
93
|
+
timeout: 10000,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(container).toMatchSnapshot();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("shape param expression", async () => {
|
|
100
|
+
const watcher = jest.fn();
|
|
101
|
+
|
|
102
|
+
const defaultValues = {
|
|
103
|
+
params: [{ name: "param1", type: "boolean", id: 1 }],
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const { container, getByRole, getAllByRole, queryByText } = render(
|
|
107
|
+
<TestFormWrapper
|
|
108
|
+
watcher={watcher}
|
|
109
|
+
type="boolean"
|
|
110
|
+
defaultValues={defaultValues}
|
|
111
|
+
s
|
|
112
|
+
>
|
|
113
|
+
<Expression />
|
|
114
|
+
</TestFormWrapper>,
|
|
115
|
+
renderOpts
|
|
116
|
+
);
|
|
117
|
+
userEvent.click(getAllByRole("listbox")[0]);
|
|
118
|
+
userEvent.click(getByRole("option", { name: /param/i }));
|
|
119
|
+
|
|
120
|
+
expect(watcher).lastCalledWith({
|
|
121
|
+
params: [{ name: "param1", type: "boolean", id: 1 }],
|
|
122
|
+
test: { shape: "param" },
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument(), {
|
|
126
|
+
timeout: 10000,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(container).toMatchSnapshot();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
3
|
+
import { render } from "@truedat/test/render";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import TestFormWrapper from "@truedat/qx/components/common/TestFormWrapper";
|
|
6
|
+
import FunctionArgs from "../FunctionArgs";
|
|
7
|
+
|
|
8
|
+
const renderOpts = {
|
|
9
|
+
messages: {
|
|
10
|
+
en: {
|
|
11
|
+
"functions.expression.shape.function": "function",
|
|
12
|
+
"functions.expression.shape.constant": "constant",
|
|
13
|
+
"functions.form.expression.function.placeholder": "function.placeholder",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
fallback: "lazy",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe("<FunctionArgs />", () => {
|
|
20
|
+
it("matches the latest snapshot", () => {
|
|
21
|
+
const { container } = render(
|
|
22
|
+
<TestFormWrapper>
|
|
23
|
+
<FunctionArgs />
|
|
24
|
+
</TestFormWrapper>,
|
|
25
|
+
renderOpts
|
|
26
|
+
);
|
|
27
|
+
expect(container).toMatchSnapshot();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("user interaction", async () => {
|
|
31
|
+
const watcher = jest.fn();
|
|
32
|
+
|
|
33
|
+
const functions = [
|
|
34
|
+
{
|
|
35
|
+
name: "eq",
|
|
36
|
+
type: "boolean",
|
|
37
|
+
params: [
|
|
38
|
+
{ name: "arg1", type: "any" },
|
|
39
|
+
{ name: "arg2", type: "any" },
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const defaultValues = {
|
|
45
|
+
test: {
|
|
46
|
+
shape: "function",
|
|
47
|
+
value: {
|
|
48
|
+
name: "eq",
|
|
49
|
+
type: "boolean",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const { container, getAllByRole, queryByText } = render(
|
|
55
|
+
<TestFormWrapper
|
|
56
|
+
watcher={watcher}
|
|
57
|
+
type="boolean"
|
|
58
|
+
functions={functions}
|
|
59
|
+
defaultValues={defaultValues}
|
|
60
|
+
>
|
|
61
|
+
<FunctionArgs />
|
|
62
|
+
</TestFormWrapper>,
|
|
63
|
+
renderOpts
|
|
64
|
+
);
|
|
65
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
66
|
+
|
|
67
|
+
userEvent.click(getAllByRole("listbox")[0]);
|
|
68
|
+
userEvent.click(getAllByRole("option", { name: /constant/i })[0]);
|
|
69
|
+
|
|
70
|
+
expect(watcher).lastCalledWith({
|
|
71
|
+
test: {
|
|
72
|
+
shape: "function",
|
|
73
|
+
value: {
|
|
74
|
+
args: {
|
|
75
|
+
arg1: { shape: "constant" },
|
|
76
|
+
arg2: { shape: "function" },
|
|
77
|
+
},
|
|
78
|
+
name: "eq",
|
|
79
|
+
type: "boolean",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(container).toMatchSnapshot();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
3
|
+
import { render } from "@truedat/test/render";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import TestFormWrapper from "@truedat/qx/components/common/TestFormWrapper";
|
|
6
|
+
import FunctionSelector from "../FunctionSelector";
|
|
7
|
+
|
|
8
|
+
const renderOpts = {
|
|
9
|
+
messages: {
|
|
10
|
+
en: {
|
|
11
|
+
"functions.expression.shape.function": "function",
|
|
12
|
+
"functions.expression.shape.constant": "constant",
|
|
13
|
+
"functions.form.expression.function.placeholder": "function.placeholder",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
fallback: "lazy",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe("<FunctionSelector />", () => {
|
|
20
|
+
it("matches the latest snapshot", () => {
|
|
21
|
+
const { container } = render(
|
|
22
|
+
<TestFormWrapper>
|
|
23
|
+
<FunctionSelector />
|
|
24
|
+
</TestFormWrapper>,
|
|
25
|
+
renderOpts
|
|
26
|
+
);
|
|
27
|
+
expect(container).toMatchSnapshot();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("user interaction", async () => {
|
|
31
|
+
const watcher = jest.fn();
|
|
32
|
+
|
|
33
|
+
const functions = [
|
|
34
|
+
{
|
|
35
|
+
name: "eq",
|
|
36
|
+
type: "boolean",
|
|
37
|
+
params: [
|
|
38
|
+
{ name: "arg1", type: "any" },
|
|
39
|
+
{ name: "arg2", type: "any" },
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const { container, getByRole, queryByText } = render(
|
|
45
|
+
<TestFormWrapper watcher={watcher} type="any" functions={functions}>
|
|
46
|
+
<FunctionSelector />
|
|
47
|
+
</TestFormWrapper>,
|
|
48
|
+
renderOpts
|
|
49
|
+
);
|
|
50
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
51
|
+
|
|
52
|
+
userEvent.click(await getByRole("option", { name: /eq/i }));
|
|
53
|
+
|
|
54
|
+
expect(watcher).lastCalledWith({
|
|
55
|
+
test: {
|
|
56
|
+
value: {
|
|
57
|
+
name: "eq",
|
|
58
|
+
type: "boolean",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(container).toMatchSnapshot();
|
|
64
|
+
|
|
65
|
+
userEvent.click(container.getElementsByClassName("no-padding")[0]);
|
|
66
|
+
|
|
67
|
+
expect(container).toMatchSnapshot();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
3
|
+
import { render } from "@truedat/test/render";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import TestFormWrapper from "@truedat/qx/components/common/TestFormWrapper";
|
|
6
|
+
import ParamSelector from "../ParamSelector";
|
|
7
|
+
import FunctionParams from "../../FunctionParams";
|
|
8
|
+
|
|
9
|
+
const renderOpts = {
|
|
10
|
+
messages: {
|
|
11
|
+
en: {
|
|
12
|
+
"functions.form.required": "required",
|
|
13
|
+
"functions.form.add_description": "add_description",
|
|
14
|
+
"functions.form.name": "name",
|
|
15
|
+
"functions.form.add_param": "add_param",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
fallback: "lazy",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe("<ParamSelector />", () => {
|
|
22
|
+
it("matches the latest snapshot", () => {
|
|
23
|
+
const defaultValues = {
|
|
24
|
+
params: [{ name: "param1", type: "boolean", id: 1 }],
|
|
25
|
+
};
|
|
26
|
+
const { container } = render(
|
|
27
|
+
<TestFormWrapper defaultValues={defaultValues}>
|
|
28
|
+
<ParamSelector />
|
|
29
|
+
</TestFormWrapper>,
|
|
30
|
+
renderOpts
|
|
31
|
+
);
|
|
32
|
+
expect(container).toMatchSnapshot();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("user interaction", async () => {
|
|
36
|
+
const watcher = jest.fn();
|
|
37
|
+
|
|
38
|
+
const defaultValues = {
|
|
39
|
+
params: [{ name: "param1", type: "boolean", id: 1 }],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const { container, queryByText, getByRole } = render(
|
|
43
|
+
<TestFormWrapper
|
|
44
|
+
watcher={watcher}
|
|
45
|
+
type="boolean"
|
|
46
|
+
defaultValues={defaultValues}
|
|
47
|
+
>
|
|
48
|
+
<ParamSelector />
|
|
49
|
+
</TestFormWrapper>,
|
|
50
|
+
renderOpts
|
|
51
|
+
);
|
|
52
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
53
|
+
|
|
54
|
+
userEvent.click(getByRole("option", { name: /param1/i }));
|
|
55
|
+
|
|
56
|
+
expect(watcher).lastCalledWith({
|
|
57
|
+
params: [
|
|
58
|
+
{
|
|
59
|
+
id: 1,
|
|
60
|
+
name: "param1",
|
|
61
|
+
type: "boolean",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
test: { value: 1 },
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(container).toMatchSnapshot();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("deleting param will clean field", async () => {
|
|
71
|
+
const watcher = jest.fn();
|
|
72
|
+
|
|
73
|
+
const defaultValues = {
|
|
74
|
+
params: [{ name: "param1", type: "boolean", id: 1 }],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const { container, queryByText, getAllByRole, getByRole, findByRole } =
|
|
78
|
+
render(
|
|
79
|
+
<TestFormWrapper
|
|
80
|
+
watcher={watcher}
|
|
81
|
+
type="boolean"
|
|
82
|
+
defaultValues={defaultValues}
|
|
83
|
+
>
|
|
84
|
+
<FunctionParams />
|
|
85
|
+
<ParamSelector />
|
|
86
|
+
</TestFormWrapper>,
|
|
87
|
+
renderOpts
|
|
88
|
+
);
|
|
89
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
90
|
+
|
|
91
|
+
userEvent.click(await getByRole("option", { name: /param1/i }));
|
|
92
|
+
|
|
93
|
+
expect(watcher).lastCalledWith({
|
|
94
|
+
params: [
|
|
95
|
+
{
|
|
96
|
+
id: 1,
|
|
97
|
+
name: "param1",
|
|
98
|
+
type: "boolean",
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
test: { value: 1 },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
userEvent.hover(await findByRole("textbox"));
|
|
105
|
+
|
|
106
|
+
userEvent.click(getAllByRole("button")[0]);
|
|
107
|
+
|
|
108
|
+
expect(watcher).lastCalledWith({
|
|
109
|
+
params: [],
|
|
110
|
+
test: { value: null },
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
expect(container).toMatchSnapshot();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
3
|
+
import { render } from "@truedat/test/render";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import TestFormWrapper from "@truedat/qx/components/common/TestFormWrapper";
|
|
6
|
+
import ShapeSelector from "../ShapeSelector";
|
|
7
|
+
|
|
8
|
+
const renderOpts = {
|
|
9
|
+
messages: {
|
|
10
|
+
en: {
|
|
11
|
+
"functions.expression.shape.function": "function",
|
|
12
|
+
"functions.expression.shape.constant": "constant",
|
|
13
|
+
"functions.expression.shape.param": "param",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
fallback: "lazy",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe("<ShapeSelector />", () => {
|
|
20
|
+
it("matches the latest snapshot", () => {
|
|
21
|
+
const defaultValues = {
|
|
22
|
+
params: [{ name: "param1", type: "boolean", id: 1 }],
|
|
23
|
+
};
|
|
24
|
+
const { container } = render(
|
|
25
|
+
<TestFormWrapper defaultValues={defaultValues}>
|
|
26
|
+
<ShapeSelector />
|
|
27
|
+
</TestFormWrapper>,
|
|
28
|
+
renderOpts
|
|
29
|
+
);
|
|
30
|
+
expect(container).toMatchSnapshot();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("user interaction select param", async () => {
|
|
34
|
+
const watcher = jest.fn();
|
|
35
|
+
|
|
36
|
+
const defaultValues = {
|
|
37
|
+
params: [{ name: "param1", type: "boolean", id: 1 }],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const { container, queryByText, getByRole } = render(
|
|
41
|
+
<TestFormWrapper
|
|
42
|
+
watcher={watcher}
|
|
43
|
+
type="boolean"
|
|
44
|
+
defaultValues={defaultValues}
|
|
45
|
+
>
|
|
46
|
+
<ShapeSelector />
|
|
47
|
+
</TestFormWrapper>,
|
|
48
|
+
renderOpts
|
|
49
|
+
);
|
|
50
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
51
|
+
|
|
52
|
+
userEvent.click(await getByRole("option", { name: /param/i }));
|
|
53
|
+
|
|
54
|
+
expect(watcher).lastCalledWith({
|
|
55
|
+
params: [
|
|
56
|
+
{
|
|
57
|
+
id: 1,
|
|
58
|
+
name: "param1",
|
|
59
|
+
type: "boolean",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
test: { shape: "param" },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(container).toMatchSnapshot();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("user interaction select constant", async () => {
|
|
69
|
+
const watcher = jest.fn();
|
|
70
|
+
|
|
71
|
+
const { container, queryByText, getByRole } = render(
|
|
72
|
+
<TestFormWrapper watcher={watcher} type="boolean">
|
|
73
|
+
<ShapeSelector />
|
|
74
|
+
</TestFormWrapper>,
|
|
75
|
+
renderOpts
|
|
76
|
+
);
|
|
77
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
78
|
+
|
|
79
|
+
userEvent.click(await getByRole("option", { name: /constant/i }));
|
|
80
|
+
|
|
81
|
+
expect(watcher).lastCalledWith({
|
|
82
|
+
test: { shape: "constant" },
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(container).toMatchSnapshot();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("user interaction select function", async () => {
|
|
89
|
+
const watcher = jest.fn();
|
|
90
|
+
|
|
91
|
+
const { container, queryByText, getByRole } = render(
|
|
92
|
+
<TestFormWrapper watcher={watcher} type="boolean">
|
|
93
|
+
<ShapeSelector />
|
|
94
|
+
</TestFormWrapper>,
|
|
95
|
+
renderOpts
|
|
96
|
+
);
|
|
97
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
98
|
+
|
|
99
|
+
userEvent.click(await getByRole("option", { name: /function/i }));
|
|
100
|
+
|
|
101
|
+
expect(watcher).lastCalledWith({
|
|
102
|
+
test: { shape: "function" },
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(container).toMatchSnapshot();
|
|
106
|
+
});
|
|
107
|
+
});
|