@truedat/ai 7.5.9 → 7.5.10
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 +39 -59
- package/src/components/AiRoutes.js +39 -46
- package/src/components/TranslationModal.js +8 -10
- package/src/components/__tests__/TranslationModal.spec.js +0 -1
- package/src/components/actions/Action.js +1 -2
- package/src/components/actions/ActionActions.js +4 -5
- package/src/components/actions/ActionBreadcrumbs.js +1 -2
- package/src/components/actions/ActionDetail.js +4 -3
- package/src/components/actions/ActionEdit.js +3 -3
- package/src/components/actions/ActionForm.js +7 -7
- package/src/components/actions/ActionNew.js +1 -1
- package/src/components/actions/Actions.js +1 -2
- package/src/components/actions/ActionsContext.js +3 -7
- package/src/components/actions/ActionsTable.js +1 -2
- package/src/components/actions/__tests__/Action.spec.js +14 -36
- package/src/components/actions/__tests__/ActionActions.spec.js +2 -20
- package/src/components/actions/__tests__/ActionBreadcrumbs.spec.js +1 -10
- package/src/components/actions/__tests__/ActionDetail.spec.js +5 -23
- package/src/components/actions/__tests__/ActionEdit.spec.js +7 -31
- package/src/components/actions/__tests__/ActionForm.spec.js +11 -27
- package/src/components/actions/__tests__/ActionNew.spec.js +7 -53
- package/src/components/actions/__tests__/Actions.spec.js +6 -15
- package/src/components/actions/__tests__/ActionsTable.spec.js +3 -23
- package/src/components/actions/__tests__/__snapshots__/Action.spec.js.snap +39 -11
- package/src/components/actions/__tests__/__snapshots__/ActionActions.spec.js.snap +4 -4
- package/src/components/actions/__tests__/__snapshots__/ActionBreadcrumbs.spec.js.snap +2 -1
- package/src/components/actions/__tests__/__snapshots__/ActionDetail.spec.js.snap +26 -3
- package/src/components/actions/__tests__/__snapshots__/ActionEdit.spec.js.snap +11 -73
- package/src/components/actions/__tests__/__snapshots__/ActionForm.spec.js.snap +91 -13
- package/src/components/actions/__tests__/__snapshots__/ActionNew.spec.js.snap +16 -263
- package/src/components/actions/__tests__/__snapshots__/Actions.spec.js.snap +5 -4
- package/src/components/actions/__tests__/__snapshots__/ActionsTable.spec.js.snap +7 -5
- package/src/components/aiSandbox/AiSandbox.js +3 -6
- package/src/components/aiSandbox/RequestForm.js +6 -4
- package/src/components/prompts/PromptEditor.js +1 -8
- package/src/components/prompts/Prompts.js +2 -6
- package/src/components/prompts/__tests__/PromptEditor.spec.js +62 -54
- package/src/components/prompts/__tests__/Prompts.spec.js +0 -2
- package/src/components/prompts/__tests__/__snapshots__/PromptEditor.spec.js.snap +115 -10
- package/src/components/providers/ProviderEditor.js +1 -5
- package/src/components/providers/Providers.js +1 -2
- package/src/components/providers/__tests__/ProviderEditor.spec.js +54 -75
- package/src/components/providers/__tests__/Providers.spec.js +0 -2
- package/src/components/providers/__tests__/__snapshots__/ProviderEditor.spec.js.snap +0 -4
- package/src/components/providers/providerProperties/AzureOpenai.js +0 -1
- package/src/components/providers/providerProperties/BedrockClaude.js +0 -1
- package/src/components/providers/providerProperties/Gemini.js +0 -1
- package/src/components/providers/providerProperties/Openai.js +0 -1
- package/src/components/resourceMappings/ResourceMappingEditor.js +2 -5
- package/src/components/resourceMappings/ResourceMappingFields.js +3 -2
- package/src/components/resourceMappings/ResourceMappings.js +4 -2
- package/src/components/resourceMappings/__tests__/ResourceMappingEditor.spec.js +51 -93
- package/src/components/resourceMappings/__tests__/ResourceMappings.spec.js +0 -2
- package/src/components/resourceMappings/__tests__/__snapshots__/ResourceMappingEditor.spec.js.snap +4 -4
- package/src/components/resourceMappings/selectors/DataStructureSelector.js +0 -1
- package/src/components/resourceMappings/selectors/index.js +0 -1
- package/src/components/suggestions/SuggestionsWidget.js +1 -1
- package/src/components/suggestions/__tests__/SuggestionsWidget.spec.js +3 -3
- package/src/components/suggestions/__tests__/__snapshots__/SuggestionsWidget.spec.js.snap +0 -3
- package/src/hooks/__mocks__/useActions.js +44 -0
- package/src/hooks/__mocks__/useSuggestions.js +5 -0
- package/src/hooks/__tests__/usePrompts.spec.js +5 -5
- package/src/hooks/__tests__/{useProviders.js → useProviders.spec.js} +5 -5
- package/src/hooks/__tests__/useResourceMappings.spec.js +5 -5
- package/src/hooks/useActions.js +5 -4
- package/src/hooks/usePrompts.js +6 -6
- package/src/hooks/useProviders.js +5 -5
- package/src/hooks/useResourceMappings.js +4 -4
- package/src/index.js +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
|
-
import
|
|
2
|
+
import { Fragment, useEffect } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { useIntl } from "react-intl";
|
|
5
5
|
import {
|
|
@@ -66,7 +66,6 @@ export default function ProviderEditor({
|
|
|
66
66
|
<Header as="h3" dividing>
|
|
67
67
|
{name}
|
|
68
68
|
</Header>
|
|
69
|
-
|
|
70
69
|
<Controller
|
|
71
70
|
control={control}
|
|
72
71
|
name="name"
|
|
@@ -100,7 +99,6 @@ export default function ProviderEditor({
|
|
|
100
99
|
/>
|
|
101
100
|
)}
|
|
102
101
|
/>
|
|
103
|
-
|
|
104
102
|
<Controller
|
|
105
103
|
control={control}
|
|
106
104
|
name="type"
|
|
@@ -131,9 +129,7 @@ export default function ProviderEditor({
|
|
|
131
129
|
</Form.Field>
|
|
132
130
|
)}
|
|
133
131
|
/>
|
|
134
|
-
|
|
135
132
|
{providerPropertiesComponents[type]}
|
|
136
|
-
|
|
137
133
|
<Divider hidden />
|
|
138
134
|
<Container textAlign="right">
|
|
139
135
|
<Button
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
|
-
import
|
|
2
|
+
import { useState } from "react";
|
|
3
3
|
import { useIntl, FormattedMessage } from "react-intl";
|
|
4
4
|
import {
|
|
5
5
|
Button,
|
|
@@ -81,7 +81,6 @@ export default function Providers() {
|
|
|
81
81
|
</Header.Subheader>
|
|
82
82
|
</Header.Content>
|
|
83
83
|
</Header>
|
|
84
|
-
|
|
85
84
|
<Grid>
|
|
86
85
|
<GridColumn width={4}>
|
|
87
86
|
<Button fluid onClick={setStateNewProvider} disabled={isDirty}>
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { act } from "react-dom/test-utils";
|
|
3
|
-
import { waitFor } from "@testing-library/react";
|
|
4
|
-
import { render } from "@truedat/test/render";
|
|
5
1
|
import userEvent from "@testing-library/user-event";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
3
|
+
import { render, waitForLoad } from "@truedat/test/render";
|
|
6
4
|
import ProviderEditor from "../ProviderEditor";
|
|
7
5
|
|
|
8
6
|
jest.mock("@truedat/core/hooks", () => ({
|
|
@@ -13,34 +11,9 @@ jest.mock("@truedat/core/hooks", () => ({
|
|
|
13
11
|
}));
|
|
14
12
|
|
|
15
13
|
const renderOpts = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"actions.save": "actions.save",
|
|
20
|
-
"actions.cancel": "actions.cancel",
|
|
21
|
-
"actions.delete": "actions.delete",
|
|
22
|
-
"functions.action.delete.header": "functions.action.delete.header",
|
|
23
|
-
"functions.action.delete.content": "functions.action.delete.content",
|
|
24
|
-
"providers.form.name": "providers.form.name",
|
|
25
|
-
"providers.form.name": "providers.form.name",
|
|
26
|
-
"providers.form.type": "providers.form.type",
|
|
27
|
-
"form.validation.required": "form.validation.required",
|
|
28
|
-
"actions.discard.confirmation.content":
|
|
29
|
-
"actions.discard.confirmation.content",
|
|
30
|
-
"actions.discard.confirmation.header":
|
|
31
|
-
"actions.discard.confirmation.header",
|
|
32
|
-
"confirmation.yes": "confirmation.yes",
|
|
33
|
-
"confirmation.no": "confirmation.no",
|
|
34
|
-
"providers.type.openai": "providers.type.openai",
|
|
35
|
-
"providers.type.azure_openai": "providers.type.azure_openai",
|
|
36
|
-
"providers.type.bedrock_claude": "providers.type.bedrock_claude",
|
|
37
|
-
"providerProperties.form.model": "providerProperties.form.model",
|
|
38
|
-
"providerProperties.form.organizationKey":
|
|
39
|
-
"providerProperties.form.organizationKey",
|
|
40
|
-
"providerProperties.form.apiKey": "providerProperties.form.apiKey",
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
fallback: "lazy",
|
|
14
|
+
state: {},
|
|
15
|
+
mocks: [],
|
|
16
|
+
dispatch: jest.fn(),
|
|
44
17
|
};
|
|
45
18
|
|
|
46
19
|
const props = {
|
|
@@ -67,20 +40,18 @@ const props = {
|
|
|
67
40
|
|
|
68
41
|
describe("<ProviderEditor />", () => {
|
|
69
42
|
it("matches the latest snapshot", async () => {
|
|
70
|
-
const
|
|
71
|
-
await
|
|
72
|
-
|
|
73
|
-
|
|
43
|
+
const rendered = render(<ProviderEditor {...props} />, renderOpts);
|
|
44
|
+
await waitForLoad(rendered);
|
|
45
|
+
|
|
46
|
+
expect(rendered.container).toMatchSnapshot();
|
|
74
47
|
});
|
|
75
48
|
|
|
76
49
|
it("matches snapshot without selected resource mapping", async () => {
|
|
77
50
|
const props = { setDirty: jest.fn() };
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
);
|
|
82
|
-
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
83
|
-
expect(container).toMatchSnapshot();
|
|
51
|
+
const rendered = render(<ProviderEditor {...props} />, renderOpts);
|
|
52
|
+
await waitForLoad(rendered);
|
|
53
|
+
|
|
54
|
+
expect(rendered.container).toMatchSnapshot();
|
|
84
55
|
});
|
|
85
56
|
|
|
86
57
|
it("matches snapshot without onDelete", async () => {
|
|
@@ -88,17 +59,20 @@ describe("<ProviderEditor />", () => {
|
|
|
88
59
|
...props,
|
|
89
60
|
onDelete: null,
|
|
90
61
|
};
|
|
91
|
-
const
|
|
62
|
+
const rendered = render(<ProviderEditor {...thisProps} />, renderOpts);
|
|
63
|
+
await waitForLoad(rendered);
|
|
92
64
|
|
|
93
|
-
|
|
65
|
+
expect(rendered.container).toMatchSnapshot();
|
|
94
66
|
});
|
|
95
67
|
|
|
96
68
|
it("test cancel button", async () => {
|
|
97
69
|
const onCancel = jest.fn();
|
|
98
70
|
const thisProps = { ...props, onCancel };
|
|
99
|
-
const
|
|
71
|
+
const rendered = render(<ProviderEditor {...thisProps} />, renderOpts);
|
|
72
|
+
await waitForLoad(rendered);
|
|
100
73
|
|
|
101
|
-
userEvent.
|
|
74
|
+
const user = userEvent.setup({ delay: null });
|
|
75
|
+
await user.click(rendered.getByRole("button", { name: /cancel/i }));
|
|
102
76
|
|
|
103
77
|
await waitFor(() => expect(onCancel).toHaveBeenCalled());
|
|
104
78
|
});
|
|
@@ -106,75 +80,80 @@ describe("<ProviderEditor />", () => {
|
|
|
106
80
|
it("test cancel button with confirm", async () => {
|
|
107
81
|
const onCancel = jest.fn();
|
|
108
82
|
const thisProps = { ...props, onCancel };
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
renderOpts
|
|
112
|
-
);
|
|
83
|
+
const rendered = render(<ProviderEditor {...thisProps} />, renderOpts);
|
|
84
|
+
await waitForLoad(rendered);
|
|
113
85
|
|
|
114
|
-
userEvent.
|
|
86
|
+
const user = userEvent.setup({ delay: null });
|
|
87
|
+
await user.type(rendered.getAllByRole("textbox")[0], "name");
|
|
115
88
|
|
|
116
89
|
await waitFor(() =>
|
|
117
|
-
expect(getByRole("button", { name: /save/i })).toBeEnabled()
|
|
90
|
+
expect(rendered.getByRole("button", { name: /save/i })).toBeEnabled()
|
|
118
91
|
);
|
|
119
92
|
|
|
120
|
-
|
|
93
|
+
await user.click(rendered.getByRole("button", { name: /cancel/i }));
|
|
121
94
|
expect(onCancel).toHaveBeenCalledTimes(0);
|
|
122
95
|
|
|
123
|
-
|
|
96
|
+
await user.click(
|
|
97
|
+
rendered.getByRole("button", { name: /modal-negative-action/i })
|
|
98
|
+
);
|
|
124
99
|
expect(onCancel).toHaveBeenCalledTimes(0);
|
|
125
100
|
|
|
126
|
-
|
|
101
|
+
await user.click(rendered.getByRole("button", { name: /cancel/i }));
|
|
127
102
|
expect(onCancel).toHaveBeenCalledTimes(0);
|
|
128
103
|
|
|
129
|
-
expect(container).toMatchSnapshot();
|
|
104
|
+
expect(rendered.container).toMatchSnapshot();
|
|
130
105
|
|
|
131
|
-
|
|
106
|
+
await user.click(
|
|
107
|
+
rendered.getByRole("button", { name: /modal-affirmative-action/i })
|
|
108
|
+
);
|
|
132
109
|
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
133
110
|
});
|
|
134
111
|
|
|
135
112
|
it("test delete button", async () => {
|
|
136
113
|
const onDelete = jest.fn();
|
|
137
114
|
const thisProps = { ...props, onDelete };
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
renderOpts
|
|
141
|
-
);
|
|
115
|
+
const rendered = render(<ProviderEditor {...thisProps} />, renderOpts);
|
|
116
|
+
await waitForLoad(rendered);
|
|
142
117
|
|
|
143
|
-
userEvent.
|
|
118
|
+
const user = userEvent.setup({ delay: null });
|
|
119
|
+
await user.click(rendered.getByRole("button", { name: /delete/i }));
|
|
144
120
|
expect(onDelete).toHaveBeenCalledTimes(0);
|
|
145
121
|
|
|
146
|
-
|
|
122
|
+
await user.click(
|
|
123
|
+
rendered.getByRole("button", { name: /modal-negative-action/i })
|
|
124
|
+
);
|
|
147
125
|
expect(onDelete).toHaveBeenCalledTimes(0);
|
|
148
126
|
|
|
149
|
-
|
|
127
|
+
await user.click(rendered.getByRole("button", { name: /delete/i }));
|
|
150
128
|
expect(onDelete).toHaveBeenCalledTimes(0);
|
|
151
129
|
|
|
152
|
-
|
|
130
|
+
expect(rendered.container).toMatchSnapshot();
|
|
153
131
|
|
|
154
|
-
|
|
132
|
+
await user.click(
|
|
133
|
+
rendered.getByRole("button", { name: /modal-affirmative-action/i })
|
|
134
|
+
);
|
|
155
135
|
expect(onDelete).toHaveBeenCalledTimes(1);
|
|
156
136
|
});
|
|
157
137
|
|
|
158
138
|
it("test submit", async () => {
|
|
159
139
|
const onSubmit = jest.fn();
|
|
160
140
|
const thisProps = { ...props, onSubmit };
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
renderOpts
|
|
164
|
-
);
|
|
141
|
+
const rendered = render(<ProviderEditor {...thisProps} />, renderOpts);
|
|
142
|
+
await waitForLoad(rendered);
|
|
165
143
|
|
|
166
|
-
|
|
144
|
+
const user = userEvent.setup({ delay: null });
|
|
145
|
+
expect(rendered.getByRole("button", { name: /save/i })).toBeDisabled();
|
|
167
146
|
|
|
168
|
-
|
|
147
|
+
await user.type(rendered.getAllByRole("textbox")[0], "name");
|
|
169
148
|
|
|
170
149
|
await waitFor(() =>
|
|
171
|
-
expect(getByRole("button", { name: /save/i })).toBeEnabled()
|
|
150
|
+
expect(rendered.getByRole("button", { name: /save/i })).toBeEnabled()
|
|
172
151
|
);
|
|
173
152
|
|
|
174
|
-
|
|
153
|
+
await user.click(rendered.getByRole("button", { name: /save/i }));
|
|
175
154
|
|
|
176
155
|
await waitFor(() =>
|
|
177
|
-
expect(getByRole("button", { name: /save/i })).toBeEnabled()
|
|
156
|
+
expect(rendered.getByRole("button", { name: /save/i })).toBeEnabled()
|
|
178
157
|
);
|
|
179
158
|
|
|
180
159
|
expect(onSubmit.mock.calls[0][0]).toEqual({
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import { waitFor } from "@testing-library/react";
|
|
3
2
|
import { render } from "@truedat/test/render";
|
|
4
3
|
import Providers from "../Providers";
|
|
@@ -66,7 +65,6 @@ describe("<Providers />", () => {
|
|
|
66
65
|
"providers.action.new": "providers.action.new",
|
|
67
66
|
},
|
|
68
67
|
},
|
|
69
|
-
fallback: "lazy",
|
|
70
68
|
};
|
|
71
69
|
|
|
72
70
|
it("matches the latest snapshot", async () => {
|
|
@@ -159,7 +159,6 @@ exports[`<ProviderEditor /> matches snapshot without onDelete 1`] = `
|
|
|
159
159
|
autocomplete="off"
|
|
160
160
|
placeholder="providerProperties.form.apiKey"
|
|
161
161
|
type="password"
|
|
162
|
-
value=""
|
|
163
162
|
/>
|
|
164
163
|
</div>
|
|
165
164
|
</div>
|
|
@@ -347,7 +346,6 @@ exports[`<ProviderEditor /> matches the latest snapshot 1`] = `
|
|
|
347
346
|
autocomplete="off"
|
|
348
347
|
placeholder="providerProperties.form.apiKey"
|
|
349
348
|
type="password"
|
|
350
|
-
value=""
|
|
351
349
|
/>
|
|
352
350
|
</div>
|
|
353
351
|
</div>
|
|
@@ -538,7 +536,6 @@ exports[`<ProviderEditor /> test cancel button with confirm 1`] = `
|
|
|
538
536
|
autocomplete="off"
|
|
539
537
|
placeholder="providerProperties.form.apiKey"
|
|
540
538
|
type="password"
|
|
541
|
-
value=""
|
|
542
539
|
/>
|
|
543
540
|
</div>
|
|
544
541
|
</div>
|
|
@@ -727,7 +724,6 @@ exports[`<ProviderEditor /> test delete button 1`] = `
|
|
|
727
724
|
autocomplete="off"
|
|
728
725
|
placeholder="providerProperties.form.apiKey"
|
|
729
726
|
type="password"
|
|
730
|
-
value=""
|
|
731
727
|
/>
|
|
732
728
|
</div>
|
|
733
729
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Fragment, useEffect } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import { useIntl } from "react-intl";
|
|
4
4
|
import {
|
|
@@ -116,22 +116,19 @@ export default function ResourceMappingEditor({
|
|
|
116
116
|
</Form.Field>
|
|
117
117
|
)}
|
|
118
118
|
/>
|
|
119
|
-
|
|
120
119
|
<Header as="h5" dividing>
|
|
121
120
|
{formatMessage({ id: "resourceMappings.form.selector" })}
|
|
122
121
|
</Header>
|
|
123
122
|
<Grid>
|
|
124
123
|
<Grid.Row>
|
|
125
|
-
<Grid.Column
|
|
124
|
+
<Grid.Column />
|
|
126
125
|
<Grid.Column width={15}>{selectorFor(resourceType)}</Grid.Column>
|
|
127
126
|
</Grid.Row>
|
|
128
127
|
</Grid>
|
|
129
|
-
|
|
130
128
|
<Header as="h5" dividing>
|
|
131
129
|
{formatMessage({ id: "resourceMappings.form.fields" })}
|
|
132
130
|
</Header>
|
|
133
131
|
<ResourceMappingFields />
|
|
134
|
-
|
|
135
132
|
<Divider hidden />
|
|
136
133
|
<Container textAlign="right">
|
|
137
134
|
<Button
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useState } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import { useIntl } from "react-intl";
|
|
4
4
|
import { Controller, useFormContext, useFieldArray } from "react-hook-form";
|
|
@@ -36,6 +36,7 @@ const FieldItem = ({ index, onDelete }) => {
|
|
|
36
36
|
const { formatMessage } = useIntl();
|
|
37
37
|
const { control } = useFormContext();
|
|
38
38
|
const [isShownDelete, setIsShownDelete] = useState();
|
|
39
|
+
|
|
39
40
|
return (
|
|
40
41
|
<div
|
|
41
42
|
onMouseEnter={() => setIsShownDelete(true)}
|
|
@@ -43,7 +44,7 @@ const FieldItem = ({ index, onDelete }) => {
|
|
|
43
44
|
>
|
|
44
45
|
<Grid>
|
|
45
46
|
<Grid.Row>
|
|
46
|
-
<Grid.Column
|
|
47
|
+
<Grid.Column />
|
|
47
48
|
<Grid.Column width={15}>
|
|
48
49
|
<Grid.Row>
|
|
49
50
|
<Form.Group inline className="no-margin">
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
|
-
import
|
|
2
|
+
import { useState } from "react";
|
|
3
3
|
import { useIntl, FormattedMessage } from "react-intl";
|
|
4
4
|
import {
|
|
5
5
|
Button,
|
|
@@ -51,6 +51,7 @@ export default function ResourceMappings() {
|
|
|
51
51
|
useResourceMappingDelete(selectedResourceMapping);
|
|
52
52
|
|
|
53
53
|
const isSubmitting = isCreating || isUpdating || isDeleting;
|
|
54
|
+
|
|
54
55
|
const onResourceMappingCreate = async (resource_mapping) => {
|
|
55
56
|
const mutateResourceMapping = selectedResourceMapping?.id
|
|
56
57
|
? updateResourceMapping
|
|
@@ -59,11 +60,13 @@ export default function ResourceMappings() {
|
|
|
59
60
|
clearForm();
|
|
60
61
|
mutate();
|
|
61
62
|
};
|
|
63
|
+
|
|
62
64
|
const onResourceMappingDelete = async (resource_mapping) => {
|
|
63
65
|
await deleteResourceMapping({ resource_mapping });
|
|
64
66
|
clearForm();
|
|
65
67
|
mutate();
|
|
66
68
|
};
|
|
69
|
+
|
|
67
70
|
return (
|
|
68
71
|
<Segment loading={loading}>
|
|
69
72
|
<Header as="h2">
|
|
@@ -81,7 +84,6 @@ export default function ResourceMappings() {
|
|
|
81
84
|
</Header.Subheader>
|
|
82
85
|
</Header.Content>
|
|
83
86
|
</Header>
|
|
84
|
-
|
|
85
87
|
<Grid>
|
|
86
88
|
<GridColumn width={4}>
|
|
87
89
|
<Button fluid onClick={setStateNewResourceMapping} disabled={isDirty}>
|
|
@@ -1,47 +1,8 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { act } from "react-dom/test-utils";
|
|
3
|
-
import { waitFor } from "@testing-library/react";
|
|
4
|
-
import { render } from "@truedat/test/render";
|
|
5
1
|
import userEvent from "@testing-library/user-event";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
3
|
+
import { render, waitForLoad } from "@truedat/test/render";
|
|
6
4
|
import ResourceMappingEditor from "../ResourceMappingEditor";
|
|
7
5
|
|
|
8
|
-
const renderOpts = {
|
|
9
|
-
messages: {
|
|
10
|
-
en: {
|
|
11
|
-
"resourceMappings.resourceType.data_structure":
|
|
12
|
-
"resourceMappings.resourceType.data_structure",
|
|
13
|
-
"form.validation.required": "form.validation.required",
|
|
14
|
-
"resourceMappings.form.selector": "resourceMappings.form.selector",
|
|
15
|
-
"resourceMappings.form.fields": "resourceMappings.form.fields",
|
|
16
|
-
"actions.save": "actions.save",
|
|
17
|
-
"actions.cancel": "actions.cancel",
|
|
18
|
-
"actions.delete": "actions.delete",
|
|
19
|
-
"functions.action.delete.header": "functions.action.delete.header",
|
|
20
|
-
"functions.action.delete.content": "functions.action.delete.content",
|
|
21
|
-
"resourceMappings.form.name": "resourceMappings.form.name",
|
|
22
|
-
"resourceMappings.form.name": "resourceMappings.form.name",
|
|
23
|
-
"resourceMappings.form.resource_type":
|
|
24
|
-
"resourceMappings.form.resource_type",
|
|
25
|
-
"resourceMappings.form.fields.add": "resourceMappings.form.fields.add",
|
|
26
|
-
"resourceMappings.form.fields.source":
|
|
27
|
-
"resourceMappings.form.fields.source",
|
|
28
|
-
"form.validation.required": "form.validation.required",
|
|
29
|
-
"resourceMappings.form.fields.source":
|
|
30
|
-
"resourceMappings.form.fields.source",
|
|
31
|
-
"resourceMappings.form.fields.target":
|
|
32
|
-
"resourceMappings.form.fields.target",
|
|
33
|
-
"actions.discard.confirmation.content":
|
|
34
|
-
"actions.discard.confirmation.content",
|
|
35
|
-
"actions.discard.confirmation.header":
|
|
36
|
-
"actions.discard.confirmation.header",
|
|
37
|
-
"confirmation.yes": "confirmation.yes",
|
|
38
|
-
"confirmation.no": "confirmation.no",
|
|
39
|
-
"resourceMappings.resourceType.business_concept": "business concept",
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
fallback: "lazy",
|
|
43
|
-
};
|
|
44
|
-
|
|
45
6
|
const props = {
|
|
46
7
|
selectedResourceMapping: {
|
|
47
8
|
id: 1,
|
|
@@ -68,23 +29,18 @@ const props = {
|
|
|
68
29
|
|
|
69
30
|
describe("<ResourceMappingEditor />", () => {
|
|
70
31
|
it("matches the latest snapshot", async () => {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
);
|
|
75
|
-
await act(async () => {
|
|
76
|
-
expect(container).toMatchSnapshot();
|
|
77
|
-
});
|
|
32
|
+
const rendered = render(<ResourceMappingEditor {...props} />);
|
|
33
|
+
await waitForLoad(rendered);
|
|
34
|
+
|
|
35
|
+
expect(rendered.container).toMatchSnapshot();
|
|
78
36
|
});
|
|
79
37
|
|
|
80
38
|
it("matches snapshot without selected resource mapping", async () => {
|
|
81
39
|
const props = { setDirty: jest.fn() };
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
86
|
-
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
87
|
-
expect(container).toMatchSnapshot();
|
|
40
|
+
const rendered = render(<ResourceMappingEditor {...props} />);
|
|
41
|
+
await waitForLoad(rendered);
|
|
42
|
+
|
|
43
|
+
expect(rendered.container).toMatchSnapshot();
|
|
88
44
|
});
|
|
89
45
|
|
|
90
46
|
it("matches snapshot without onDelete", async () => {
|
|
@@ -92,23 +48,20 @@ describe("<ResourceMappingEditor />", () => {
|
|
|
92
48
|
...props,
|
|
93
49
|
onDelete: null,
|
|
94
50
|
};
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
renderOpts
|
|
98
|
-
);
|
|
51
|
+
const rendered = render(<ResourceMappingEditor {...thisProps} />);
|
|
52
|
+
await waitForLoad(rendered);
|
|
99
53
|
|
|
100
|
-
|
|
54
|
+
expect(rendered.container).toMatchSnapshot();
|
|
101
55
|
});
|
|
102
56
|
|
|
103
57
|
it("test cancel button", async () => {
|
|
104
58
|
const onCancel = jest.fn();
|
|
105
59
|
const thisProps = { ...props, onCancel };
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
renderOpts
|
|
109
|
-
);
|
|
60
|
+
const rendered = render(<ResourceMappingEditor {...thisProps} />);
|
|
61
|
+
await waitForLoad(rendered);
|
|
110
62
|
|
|
111
|
-
userEvent.
|
|
63
|
+
const user = userEvent.setup({ delay: null });
|
|
64
|
+
await user.click(rendered.getByRole("button", { name: /cancel/i }));
|
|
112
65
|
|
|
113
66
|
await waitFor(() => expect(onCancel).toHaveBeenCalled());
|
|
114
67
|
});
|
|
@@ -116,75 +69,80 @@ describe("<ResourceMappingEditor />", () => {
|
|
|
116
69
|
it("test cancel button with confirm", async () => {
|
|
117
70
|
const onCancel = jest.fn();
|
|
118
71
|
const thisProps = { ...props, onCancel };
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
renderOpts
|
|
122
|
-
);
|
|
72
|
+
const rendered = render(<ResourceMappingEditor {...thisProps} />);
|
|
73
|
+
await waitForLoad(rendered);
|
|
123
74
|
|
|
124
|
-
userEvent.
|
|
75
|
+
const user = userEvent.setup({ delay: null });
|
|
76
|
+
await user.type(rendered.getAllByRole("textbox")[0], "name");
|
|
125
77
|
|
|
126
78
|
await waitFor(() =>
|
|
127
|
-
expect(getByRole("button", { name: /save/i })).toBeEnabled()
|
|
79
|
+
expect(rendered.getByRole("button", { name: /save/i })).toBeEnabled()
|
|
128
80
|
);
|
|
129
81
|
|
|
130
|
-
|
|
82
|
+
await user.click(rendered.getByRole("button", { name: /cancel/i }));
|
|
131
83
|
expect(onCancel).toHaveBeenCalledTimes(0);
|
|
132
84
|
|
|
133
|
-
|
|
85
|
+
await user.click(
|
|
86
|
+
rendered.getByRole("button", { name: /modal-negative-action/i })
|
|
87
|
+
);
|
|
134
88
|
expect(onCancel).toHaveBeenCalledTimes(0);
|
|
135
89
|
|
|
136
|
-
|
|
90
|
+
await user.click(rendered.getByRole("button", { name: /cancel/i }));
|
|
137
91
|
expect(onCancel).toHaveBeenCalledTimes(0);
|
|
138
92
|
|
|
139
|
-
expect(container).toMatchSnapshot();
|
|
93
|
+
expect(rendered.container).toMatchSnapshot();
|
|
140
94
|
|
|
141
|
-
|
|
95
|
+
await user.click(
|
|
96
|
+
rendered.getByRole("button", { name: /modal-affirmative-action/i })
|
|
97
|
+
);
|
|
142
98
|
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
143
99
|
});
|
|
144
100
|
|
|
145
101
|
it("test delete button", async () => {
|
|
146
102
|
const onDelete = jest.fn();
|
|
147
103
|
const thisProps = { ...props, onDelete };
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
renderOpts
|
|
151
|
-
);
|
|
104
|
+
const rendered = render(<ResourceMappingEditor {...thisProps} />);
|
|
105
|
+
await waitForLoad(rendered);
|
|
152
106
|
|
|
153
|
-
userEvent.
|
|
107
|
+
const user = userEvent.setup({ delay: null });
|
|
108
|
+
await user.click(rendered.getByRole("button", { name: /delete/i }));
|
|
154
109
|
expect(onDelete).toHaveBeenCalledTimes(0);
|
|
155
110
|
|
|
156
|
-
|
|
111
|
+
await user.click(
|
|
112
|
+
rendered.getByRole("button", { name: /modal-negative-action/i })
|
|
113
|
+
);
|
|
157
114
|
expect(onDelete).toHaveBeenCalledTimes(0);
|
|
158
115
|
|
|
159
|
-
|
|
116
|
+
await user.click(rendered.getByRole("button", { name: /delete/i }));
|
|
160
117
|
expect(onDelete).toHaveBeenCalledTimes(0);
|
|
161
118
|
|
|
162
|
-
|
|
119
|
+
expect(rendered.container).toMatchSnapshot();
|
|
163
120
|
|
|
164
|
-
|
|
121
|
+
await user.click(
|
|
122
|
+
rendered.getByRole("button", { name: /modal-affirmative-action/i })
|
|
123
|
+
);
|
|
165
124
|
expect(onDelete).toHaveBeenCalledTimes(1);
|
|
166
125
|
});
|
|
167
126
|
|
|
168
127
|
it("test submit", async () => {
|
|
169
128
|
const onSubmit = jest.fn();
|
|
170
129
|
const thisProps = { ...props, onSubmit };
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
renderOpts
|
|
174
|
-
);
|
|
130
|
+
const rendered = render(<ResourceMappingEditor {...thisProps} />);
|
|
131
|
+
await waitForLoad(rendered);
|
|
175
132
|
|
|
176
|
-
expect(getByRole("button", { name: /save/i })).toBeDisabled();
|
|
133
|
+
expect(rendered.getByRole("button", { name: /save/i })).toBeDisabled();
|
|
177
134
|
|
|
178
|
-
userEvent.
|
|
135
|
+
const user = userEvent.setup({ delay: null });
|
|
136
|
+
await user.type(rendered.getAllByRole("textbox")[0], "name");
|
|
179
137
|
|
|
180
138
|
await waitFor(() =>
|
|
181
|
-
expect(getByRole("button", { name: /save/i })).toBeEnabled()
|
|
139
|
+
expect(rendered.getByRole("button", { name: /save/i })).toBeEnabled()
|
|
182
140
|
);
|
|
183
141
|
|
|
184
|
-
|
|
142
|
+
await user.click(rendered.getByRole("button", { name: /save/i }));
|
|
185
143
|
|
|
186
144
|
await waitFor(() =>
|
|
187
|
-
expect(getByRole("button", { name: /save/i })).toBeEnabled()
|
|
145
|
+
expect(rendered.getByRole("button", { name: /save/i })).toBeEnabled()
|
|
188
146
|
);
|
|
189
147
|
|
|
190
148
|
expect(onSubmit.mock.calls[0][0]).toEqual({
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import { waitFor } from "@testing-library/react";
|
|
3
2
|
import { render } from "@truedat/test/render";
|
|
4
3
|
import ResourceMappings from "../ResourceMappings";
|
|
@@ -69,7 +68,6 @@ describe("<ResourceMappings />", () => {
|
|
|
69
68
|
"resourceMappings.resourceType.business_concept": "business concept",
|
|
70
69
|
},
|
|
71
70
|
},
|
|
72
|
-
fallback: "lazy",
|
|
73
71
|
};
|
|
74
72
|
|
|
75
73
|
it("matches the latest snapshot", async () => {
|