@truedat/ai 7.2.0 → 7.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/ai",
3
- "version": "7.2.0",
3
+ "version": "7.2.2",
4
4
  "description": "Truedat Web Artificial Intelligence package",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -35,7 +35,7 @@
35
35
  "@testing-library/react": "^12.0.0",
36
36
  "@testing-library/react-hooks": "^8.0.1",
37
37
  "@testing-library/user-event": "^13.2.1",
38
- "@truedat/test": "7.2.0",
38
+ "@truedat/test": "7.2.2",
39
39
  "babel-jest": "^28.1.0",
40
40
  "babel-plugin-dynamic-import-node": "^2.3.3",
41
41
  "babel-plugin-lodash": "^3.3.4",
@@ -85,7 +85,7 @@
85
85
  ]
86
86
  },
87
87
  "dependencies": {
88
- "@truedat/core": "7.2.0",
88
+ "@truedat/core": "7.2.2",
89
89
  "prop-types": "^15.8.1",
90
90
  "react-hook-form": "^7.45.4",
91
91
  "react-intl": "^5.20.10",
@@ -97,5 +97,5 @@
97
97
  "react-dom": ">= 16.8.6 < 17",
98
98
  "semantic-ui-react": ">= 2.0.3 < 2.2"
99
99
  },
100
- "gitHead": "b1bd3e485d5ab8fb5a46051a8f16b5a0d593440c"
100
+ "gitHead": "9033c57eccb9e6785c0a0c5aa6078c34788d6e7d"
101
101
  }
@@ -12,7 +12,7 @@ import {
12
12
  } from "semantic-ui-react";
13
13
  import { FormProvider, useForm, Controller } from "react-hook-form";
14
14
  import { ConfirmModal } from "@truedat/core/components";
15
- import { useLocales } from "@truedat/core/hooks";
15
+ import { useLanguage } from "@truedat/core/i18n";
16
16
  import { useResourceTypeOptions } from "../constants";
17
17
 
18
18
  export default function PromptEditor({
@@ -27,17 +27,13 @@ export default function PromptEditor({
27
27
  }) {
28
28
  const { formatMessage } = useIntl();
29
29
  const resourceTypeOptions = useResourceTypeOptions();
30
- const locales = useLocales();
30
+ const { enabledLangs } = useLanguage();
31
31
 
32
- const localeOptions = _.flow(
33
- _.prop("locales"),
34
- _.map("lang"),
35
- _.map((key) => ({
36
- key,
37
- text: key,
38
- value: key,
39
- }))
40
- )(locales);
32
+ const localeOptions = _.map((key) => ({
33
+ key,
34
+ text: key,
35
+ value: key,
36
+ }))(enabledLangs);
41
37
 
42
38
  const form = useForm({
43
39
  mode: "onTouched",
@@ -3,55 +3,11 @@ import { act } from "react-dom/test-utils";
3
3
  import { waitFor } from "@testing-library/react";
4
4
  import { render } from "@truedat/test/render";
5
5
  import userEvent from "@testing-library/user-event";
6
+ import { LangProviderWrapper } from "@truedat/core/i18n";
6
7
  import PromptEditor from "../PromptEditor";
7
8
 
8
- jest.mock("@truedat/core/hooks", () => ({
9
- useLocales: jest.fn(() => ({
10
- loading: false,
11
- locales: [{ lang: "es", id: 1 }],
12
- })),
13
- }));
14
-
15
9
  const renderOpts = {
16
- messages: {
17
- en: {
18
- "prompts.resourceType.data_structure":
19
- "prompts.resourceType.data_structure",
20
- "form.validation.required": "form.validation.required",
21
- "prompts.form.selector": "prompts.form.selector",
22
- "prompts.form.fields": "prompts.form.fields",
23
- "actions.save": "actions.save",
24
- "actions.cancel": "actions.cancel",
25
- "actions.delete": "actions.delete",
26
- "functions.action.delete.header": "functions.action.delete.header",
27
- "functions.action.delete.content": "functions.action.delete.content",
28
- "prompts.form.name": "prompts.form.name",
29
- "prompts.form.name": "prompts.form.name",
30
- "prompts.form.resource_type": "prompts.form.resource_type",
31
- "prompts.form.fields.add": "prompts.form.fields.add",
32
- "prompts.form.fields.source": "prompts.form.fields.source",
33
- "form.validation.required": "form.validation.required",
34
- "prompts.form.fields.source": "prompts.form.fields.source",
35
- "prompts.form.fields.target": "prompts.form.fields.target",
36
- "actions.discard.confirmation.content":
37
- "actions.discard.confirmation.content",
38
- "actions.discard.confirmation.header":
39
- "actions.discard.confirmation.header",
40
- "confirmation.yes": "confirmation.yes",
41
- "confirmation.no": "confirmation.no",
42
- "prompts.form.model": "prompts.form.model",
43
- "prompts.form.provider": "prompts.form.provider",
44
- "prompts.form.user_prompt_template": "prompts.form.user_prompt_template",
45
- "prompts.form.system_prompt": "prompts.form.system_prompt",
46
- "prompts.form.language": "prompts.form.language",
47
- "prompts.provider.openai": "prompts.provider.openai",
48
- "resourceMappings.resourceType.data_structure":
49
- "resourceMappings.resourceType.data_structure",
50
- "actions.set_active": "actions.set_active",
51
- "resourceMappings.resourceType.business_concept":
52
- "resourceMappings.resourceType.business_concept",
53
- },
54
- },
10
+ messages: {},
55
11
  fallback: "lazy",
56
12
  };
57
13
 
@@ -84,9 +40,17 @@ const props = {
84
40
  setDirty: jest.fn(),
85
41
  };
86
42
 
43
+ const renderComponent = (props) =>
44
+ render(
45
+ <LangProviderWrapper langs={["es"]}>
46
+ <PromptEditor {...props} />
47
+ </LangProviderWrapper>,
48
+ renderOpts
49
+ );
50
+
87
51
  describe("<PromptEditor />", () => {
88
52
  it("matches the latest snapshot", async () => {
89
- const { container } = render(<PromptEditor {...props} />, renderOpts);
53
+ const { container } = renderComponent(props);
90
54
  await act(async () => {
91
55
  expect(container).toMatchSnapshot();
92
56
  });
@@ -94,10 +58,8 @@ describe("<PromptEditor />", () => {
94
58
 
95
59
  it("matches snapshot without selected resource mapping", async () => {
96
60
  const props = { setDirty: jest.fn() };
97
- const { container, queryByText } = render(
98
- <PromptEditor {...props} />,
99
- renderOpts
100
- );
61
+ const { container, queryByText } = renderComponent(props);
62
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
101
63
  await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
102
64
  expect(container).toMatchSnapshot();
103
65
  });
@@ -107,7 +69,7 @@ describe("<PromptEditor />", () => {
107
69
  ...props,
108
70
  onDelete: null,
109
71
  };
110
- const { container } = render(<PromptEditor {...thisProps} />, renderOpts);
72
+ const { container } = renderComponent(thisProps);
111
73
 
112
74
  await waitFor(() => expect(container).toMatchSnapshot());
113
75
  });
@@ -115,7 +77,7 @@ describe("<PromptEditor />", () => {
115
77
  it("test cancel button", async () => {
116
78
  const onCancel = jest.fn();
117
79
  const thisProps = { ...props, onCancel };
118
- const { getByRole } = render(<PromptEditor {...thisProps} />, renderOpts);
80
+ const { getByRole } = renderComponent(thisProps);
119
81
 
120
82
  userEvent.click(getByRole("button", { name: /cancel/i }));
121
83
 
@@ -125,10 +87,7 @@ describe("<PromptEditor />", () => {
125
87
  it("test cancel button with confirm", async () => {
126
88
  const onCancel = jest.fn();
127
89
  const thisProps = { ...props, onCancel };
128
- const { container, getByRole, getAllByRole } = render(
129
- <PromptEditor {...thisProps} />,
130
- renderOpts
131
- );
90
+ const { container, getByRole, getAllByRole } = renderComponent(thisProps);
132
91
 
133
92
  userEvent.type(getAllByRole("textbox")[0], "name");
134
93
 
@@ -154,10 +113,7 @@ describe("<PromptEditor />", () => {
154
113
  it("test delete button", async () => {
155
114
  const onDelete = jest.fn();
156
115
  const thisProps = { ...props, onDelete };
157
- const { container, getByRole } = render(
158
- <PromptEditor {...thisProps} />,
159
- renderOpts
160
- );
116
+ const { container, getByRole } = renderComponent(thisProps);
161
117
 
162
118
  userEvent.click(getByRole("button", { name: /delete/i }));
163
119
  expect(onDelete).toHaveBeenCalledTimes(0);
@@ -177,10 +133,7 @@ describe("<PromptEditor />", () => {
177
133
  it("test submit", async () => {
178
134
  const onSubmit = jest.fn();
179
135
  const thisProps = { ...props, onSubmit };
180
- const { getByRole, getAllByRole } = render(
181
- <PromptEditor {...thisProps} />,
182
- renderOpts
183
- );
136
+ const { getByRole, getAllByRole } = renderComponent(thisProps);
184
137
 
185
138
  expect(getByRole("button", { name: /save/i })).toBeDisabled();
186
139