@truedat/dd 4.59.10 → 5.0.0
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/CHANGELOG.md +8 -0
- package/package.json +6 -6
- package/src/api/queries.js +5 -0
- package/src/components/ReferenceDatasetActions.js +15 -9
- package/src/components/ReferenceDatasetForm.js +25 -4
- package/src/components/ReferenceDatasetHeader.js +24 -15
- package/src/components/ReferenceDatasetRoutes.js +2 -15
- package/src/components/ReferenceDatasets.js +11 -7
- package/src/components/__tests__/ReferenceDataset.spec.js +23 -7
- package/src/components/__tests__/ReferenceDatasetActions.spec.js +4 -0
- package/src/components/__tests__/ReferenceDatasetCreate.spec.js +12 -2
- package/src/components/__tests__/ReferenceDatasetDetail.spec.js +12 -2
- package/src/components/__tests__/ReferenceDatasetForm.spec.js +17 -6
- package/src/components/__tests__/ReferenceDatasetHeader.spec.js +6 -0
- package/src/components/__tests__/ReferenceDatasetRoutes.spec.js +12 -2
- package/src/components/__tests__/ReferenceDatasets.spec.js +4 -0
- package/src/components/__tests__/__snapshots__/ReferenceDataset.spec.js.snap +241 -129
- package/src/components/__tests__/__snapshots__/ReferenceDatasetActions.spec.js.snap +5 -5
- package/src/components/__tests__/__snapshots__/ReferenceDatasetCreate.spec.js.snap +86 -0
- package/src/components/__tests__/__snapshots__/ReferenceDatasetDetail.spec.js.snap +92 -0
- package/src/components/__tests__/__snapshots__/ReferenceDatasetForm.spec.js.snap +92 -0
- package/src/components/__tests__/__snapshots__/ReferenceDatasetHeader.spec.js.snap +78 -68
- package/src/components/__tests__/__snapshots__/ReferenceDatasetRoutes.spec.js.snap +164 -68
- package/src/messages/en.js +1 -0
- package/src/messages/es.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [5.0.0] 2023-01-24
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- [TD-5300] ReferenceDataset user management
|
|
8
|
+
- Users with `view_data_structure` permission on domain can view and download it's ReferenceDatasets
|
|
9
|
+
- Create, Edit and Delete actions are only available for admin users
|
|
10
|
+
|
|
3
11
|
## [4.59.9] 2023-01-16
|
|
4
12
|
|
|
5
13
|
### Fixed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/dd",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Truedat Web Data Dictionary",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"jsnext:main": "src/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@testing-library/jest-dom": "^5.16.5",
|
|
35
35
|
"@testing-library/react": "^12.0.0",
|
|
36
36
|
"@testing-library/user-event": "^13.2.1",
|
|
37
|
-
"@truedat/test": "
|
|
37
|
+
"@truedat/test": "5.0.0",
|
|
38
38
|
"babel-jest": "^28.1.0",
|
|
39
39
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
40
40
|
"babel-plugin-lodash": "^3.3.4",
|
|
@@ -87,9 +87,9 @@
|
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"@apollo/client": "^3.7.1",
|
|
90
|
-
"@truedat/auth": "
|
|
91
|
-
"@truedat/core": "
|
|
92
|
-
"@truedat/df": "
|
|
90
|
+
"@truedat/auth": "5.0.0",
|
|
91
|
+
"@truedat/core": "5.0.0",
|
|
92
|
+
"@truedat/df": "5.0.0",
|
|
93
93
|
"lodash": "^4.17.21",
|
|
94
94
|
"moment": "^2.29.4",
|
|
95
95
|
"path-to-regexp": "^1.7.0",
|
|
@@ -114,5 +114,5 @@
|
|
|
114
114
|
"react-dom": ">= 16.8.6 < 17",
|
|
115
115
|
"semantic-ui-react": ">= 2.0.3 < 2.2"
|
|
116
116
|
},
|
|
117
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "688cd20866f3c91f8390588f65d8c75402ad06e4"
|
|
118
118
|
}
|
package/src/api/queries.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Link } from "react-router-dom";
|
|
|
4
4
|
import { connect } from "react-redux";
|
|
5
5
|
import { useIntl } from "react-intl";
|
|
6
6
|
import { Button } from "semantic-ui-react";
|
|
7
|
+
import { useAuthorized } from "@truedat/core/hooks";
|
|
7
8
|
import { ConfirmModal, GroupActions } from "@truedat/core/components";
|
|
8
9
|
import { linkTo } from "@truedat/core/routes";
|
|
9
10
|
import { deleteReferenceDataset, downloadReferenceDataset } from "../routines";
|
|
@@ -44,8 +45,9 @@ export const ReferenceDatasetActions = ({
|
|
|
44
45
|
dataset,
|
|
45
46
|
}) => {
|
|
46
47
|
const { formatMessage } = useIntl();
|
|
48
|
+
const isAdmin = useAuthorized();
|
|
47
49
|
const { id, name } = dataset || {};
|
|
48
|
-
const
|
|
50
|
+
const adminActions = [
|
|
49
51
|
{
|
|
50
52
|
key: "edit",
|
|
51
53
|
icon: "edit",
|
|
@@ -54,14 +56,6 @@ export const ReferenceDatasetActions = ({
|
|
|
54
56
|
as: Link,
|
|
55
57
|
to: linkTo.REFERENCE_DATASET_EDIT({ id }),
|
|
56
58
|
},
|
|
57
|
-
{
|
|
58
|
-
key: "download",
|
|
59
|
-
icon: "download",
|
|
60
|
-
text: formatMessage({ id: "actions.download" }),
|
|
61
|
-
value: "download",
|
|
62
|
-
as: "a",
|
|
63
|
-
onClick: () => downloadReferenceDataset({ id, name }),
|
|
64
|
-
},
|
|
65
59
|
{
|
|
66
60
|
key: "delete",
|
|
67
61
|
icon: "trash",
|
|
@@ -73,6 +67,18 @@ export const ReferenceDatasetActions = ({
|
|
|
73
67
|
},
|
|
74
68
|
];
|
|
75
69
|
|
|
70
|
+
const actions = [
|
|
71
|
+
{
|
|
72
|
+
key: "download",
|
|
73
|
+
icon: "download",
|
|
74
|
+
text: formatMessage({ id: "actions.download" }),
|
|
75
|
+
value: "download",
|
|
76
|
+
as: "a",
|
|
77
|
+
onClick: () => downloadReferenceDataset({ id, name }),
|
|
78
|
+
},
|
|
79
|
+
...(isAdmin ? adminActions : []),
|
|
80
|
+
];
|
|
81
|
+
|
|
76
82
|
return <GroupActions availableActions={actions} />;
|
|
77
83
|
};
|
|
78
84
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
|
-
import React from "react";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { useForm, Controller } from "react-hook-form";
|
|
5
5
|
import { connect } from "react-redux";
|
|
6
6
|
import { Button, Form } from "semantic-ui-react";
|
|
7
7
|
import { useIntl } from "react-intl";
|
|
8
|
-
import { HistoryBackButton } from "@truedat/core/components";
|
|
8
|
+
import { DomainSelector, HistoryBackButton } from "@truedat/core/components";
|
|
9
9
|
|
|
10
10
|
const MAX_SIZE_MB = 2;
|
|
11
11
|
const MAX_SIZE = MAX_SIZE_MB * 1024 * 1024; // 2MB
|
|
@@ -22,14 +22,35 @@ const datasetValidator = (formatMessage) => (value) =>
|
|
|
22
22
|
|
|
23
23
|
export const ReferenceDatasetForm = ({ saving, dataset = {}, onSubmit }) => {
|
|
24
24
|
const { formatMessage } = useIntl();
|
|
25
|
+
const [domainsLoading, setDomainsLoading] = useState(true);
|
|
25
26
|
const { handleSubmit, control, formState } = useForm({
|
|
26
27
|
mode: "all",
|
|
27
|
-
defaultValues: {
|
|
28
|
+
defaultValues: {
|
|
29
|
+
name: dataset?.name || "",
|
|
30
|
+
domain_ids: dataset?.domain_ids || [],
|
|
31
|
+
file: null,
|
|
32
|
+
},
|
|
28
33
|
});
|
|
29
34
|
const { isDirty, isValid } = formState;
|
|
30
35
|
const disabled = saving || !isDirty || !isValid;
|
|
31
36
|
return (
|
|
32
|
-
<Form onSubmit={handleSubmit(onSubmit)}>
|
|
37
|
+
<Form loading={domainsLoading} onSubmit={handleSubmit(onSubmit)}>
|
|
38
|
+
<Controller
|
|
39
|
+
control={control}
|
|
40
|
+
name="domain_ids"
|
|
41
|
+
render={({ field: { onChange, value } }) => (
|
|
42
|
+
<DomainSelector
|
|
43
|
+
label={formatMessage({ id: "domain.selector.label" })}
|
|
44
|
+
labels
|
|
45
|
+
action="viewDataStructure"
|
|
46
|
+
value={value}
|
|
47
|
+
multiple
|
|
48
|
+
onChange={(_e, { value }) => onChange(value)}
|
|
49
|
+
onLoad={() => setDomainsLoading(false)}
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
/>
|
|
53
|
+
|
|
33
54
|
<Controller
|
|
34
55
|
control={control}
|
|
35
56
|
name="name"
|
|
@@ -2,26 +2,35 @@ import _ from "lodash/fp";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { FormattedMessage } from "react-intl";
|
|
5
|
-
import { Header, Icon, Grid } from "semantic-ui-react";
|
|
5
|
+
import { Header, Icon, Grid, Label } from "semantic-ui-react";
|
|
6
6
|
import ReferenceDatasetActions from "./ReferenceDatasetActions";
|
|
7
7
|
|
|
8
8
|
export const ReferenceDatasetHeader = ({ dataset }) =>
|
|
9
9
|
_.isEmpty(dataset) ? null : (
|
|
10
10
|
<Grid>
|
|
11
|
-
<Grid.
|
|
12
|
-
<
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
<Grid.Row>
|
|
12
|
+
<Grid.Column width={8}>
|
|
13
|
+
<Header as="h2">
|
|
14
|
+
<Icon circular name="list ol" />
|
|
15
|
+
<Header.Content>
|
|
16
|
+
{dataset.name}
|
|
17
|
+
<Header.Subheader>
|
|
18
|
+
{dataset.domains && !_.isEmpty(dataset.domains) ? (
|
|
19
|
+
<>
|
|
20
|
+
<FormattedMessage id="referenceDataset.domains" />:
|
|
21
|
+
{dataset.domains.map(({ name, id }) => (
|
|
22
|
+
<Label key={id}>{name}</Label>
|
|
23
|
+
))}
|
|
24
|
+
</>
|
|
25
|
+
) : null}
|
|
26
|
+
</Header.Subheader>
|
|
27
|
+
</Header.Content>
|
|
28
|
+
</Header>
|
|
29
|
+
</Grid.Column>
|
|
30
|
+
<Grid.Column width={8} textAlign="right">
|
|
31
|
+
<ReferenceDatasetActions dataset={dataset} />
|
|
32
|
+
</Grid.Column>
|
|
33
|
+
</Grid.Row>
|
|
25
34
|
</Grid>
|
|
26
35
|
);
|
|
27
36
|
|
|
@@ -2,8 +2,7 @@ import _ from "lodash/fp";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { Route, Switch, useParams } from "react-router-dom";
|
|
4
4
|
import { useQuery } from "@apollo/client";
|
|
5
|
-
import {
|
|
6
|
-
import { useAuthorized } from "@truedat/core/hooks";
|
|
5
|
+
import { Loading } from "@truedat/core/components";
|
|
7
6
|
import {
|
|
8
7
|
REFERENCE_DATASETS,
|
|
9
8
|
REFERENCE_DATASET_NEW,
|
|
@@ -25,7 +24,7 @@ export const DatasetLoader = () => {
|
|
|
25
24
|
return _.isEmpty(dataset) ? null : <ReferenceDataset dataset={dataset} />;
|
|
26
25
|
};
|
|
27
26
|
|
|
28
|
-
export const
|
|
27
|
+
export const ReferenceDatasetRoutes = () => (
|
|
29
28
|
<Switch>
|
|
30
29
|
<Route
|
|
31
30
|
path={REFERENCE_DATASET_NEW}
|
|
@@ -41,16 +40,4 @@ export const AuthorizedReferenceDatasetRoutes = () => (
|
|
|
41
40
|
</Switch>
|
|
42
41
|
);
|
|
43
42
|
|
|
44
|
-
export const ReferenceDatasetRoutes = () => {
|
|
45
|
-
const authorized = useAuthorized();
|
|
46
|
-
return (
|
|
47
|
-
<Route
|
|
48
|
-
path={REFERENCE_DATASETS}
|
|
49
|
-
render={() =>
|
|
50
|
-
authorized ? <AuthorizedReferenceDatasetRoutes /> : <Unauthorized />
|
|
51
|
-
}
|
|
52
|
-
/>
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
43
|
export default ReferenceDatasetRoutes;
|
|
@@ -6,6 +6,7 @@ import { Link } from "react-router-dom";
|
|
|
6
6
|
import { Button, Header, Icon, Input, Segment } from "semantic-ui-react";
|
|
7
7
|
import { useQuery } from "@apollo/client";
|
|
8
8
|
import { Loading } from "@truedat/core/components";
|
|
9
|
+
import { useAuthorized } from "@truedat/core/hooks";
|
|
9
10
|
import { REFERENCE_DATASET_NEW } from "@truedat/core/routes";
|
|
10
11
|
import { lowerDeburrTrim } from "@truedat/core/services/sort";
|
|
11
12
|
import { REFERENCE_DATASETS_QUERY } from "../api/queries";
|
|
@@ -16,6 +17,7 @@ const sortByName = _.sortBy([({ name }) => lowerDeburrTrim(name), "name"]);
|
|
|
16
17
|
export const ReferenceDatasets = () => {
|
|
17
18
|
const [searchTerm, setSearchTerm] = useState("");
|
|
18
19
|
const { formatMessage } = useIntl();
|
|
20
|
+
const isAdmin = useAuthorized();
|
|
19
21
|
const { loading, error, data } = useQuery(REFERENCE_DATASETS_QUERY);
|
|
20
22
|
if (error) return null;
|
|
21
23
|
if (loading) return <Loading />;
|
|
@@ -30,13 +32,15 @@ export const ReferenceDatasets = () => {
|
|
|
30
32
|
return (
|
|
31
33
|
<Segment>
|
|
32
34
|
<Header as="h2">
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
{isAdmin ? (
|
|
36
|
+
<Button
|
|
37
|
+
floated="right"
|
|
38
|
+
primary
|
|
39
|
+
as={Link}
|
|
40
|
+
to={REFERENCE_DATASET_NEW}
|
|
41
|
+
content={formatMessage({ id: "referenceDatasets.actions.create" })}
|
|
42
|
+
/>
|
|
43
|
+
) : null}
|
|
40
44
|
<Icon name="list ol" circular />
|
|
41
45
|
<Header.Content>
|
|
42
46
|
<FormattedMessage id="referenceDatasets.header" />
|
|
@@ -2,6 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { waitFor } from "@testing-library/react";
|
|
3
3
|
import userEvent from "@testing-library/user-event";
|
|
4
4
|
import { render } from "@truedat/test/render";
|
|
5
|
+
import { domainsMock } from "@truedat/test/mocks";
|
|
5
6
|
import ReferenceDataset from "../ReferenceDataset";
|
|
6
7
|
|
|
7
8
|
const dataset = {
|
|
@@ -12,8 +13,14 @@ const dataset = {
|
|
|
12
13
|
["foo1", "bar1", "baz1"],
|
|
13
14
|
["foo2", "bar2", "baz2"],
|
|
14
15
|
],
|
|
16
|
+
domain_ids: [1],
|
|
17
|
+
domains: [{ name: "fooDomain", id: 1 }],
|
|
15
18
|
};
|
|
16
19
|
|
|
20
|
+
jest.mock("@truedat/core/hooks", () => ({
|
|
21
|
+
useAuthorized: jest.fn(() => true),
|
|
22
|
+
}));
|
|
23
|
+
|
|
17
24
|
describe("<ReferenceDataset /> show dataset view", () => {
|
|
18
25
|
const renderOpts = { routes: ["/referenceDatasets/123"] };
|
|
19
26
|
const props = { dataset };
|
|
@@ -33,28 +40,37 @@ describe("<ReferenceDataset /> show dataset view", () => {
|
|
|
33
40
|
});
|
|
34
41
|
|
|
35
42
|
describe("<ReferenceDataset /> edit dataset view", () => {
|
|
36
|
-
const renderOpts = {
|
|
43
|
+
const renderOpts = {
|
|
44
|
+
mocks: [domainsMock({ action: "viewDataStructure" })],
|
|
45
|
+
routes: ["/referenceDatasets/123/edit"],
|
|
46
|
+
};
|
|
37
47
|
const props = { dataset };
|
|
38
48
|
|
|
39
49
|
it("matches the latest snapshot", async () => {
|
|
40
|
-
const { container, findByText } = render(
|
|
50
|
+
const { container, findByText, queryByText } = render(
|
|
41
51
|
<ReferenceDataset {...props} />,
|
|
42
52
|
renderOpts
|
|
43
53
|
);
|
|
44
54
|
await findByText("Save");
|
|
55
|
+
|
|
56
|
+
await waitFor(() => {
|
|
57
|
+
expect(queryByText(/barDomain/)).toBeTruthy();
|
|
58
|
+
});
|
|
45
59
|
expect(container).toMatchSnapshot();
|
|
46
60
|
});
|
|
47
61
|
|
|
48
62
|
it("form is disabled until modified", async () => {
|
|
49
|
-
const { findByText,
|
|
50
|
-
<ReferenceDataset {...props} />,
|
|
51
|
-
renderOpts
|
|
52
|
-
);
|
|
63
|
+
const { findByText, queryByText, findAllByRole, getByRole, queryByRole } =
|
|
64
|
+
render(<ReferenceDataset {...props} />, renderOpts);
|
|
53
65
|
await findByText("Save");
|
|
54
66
|
|
|
67
|
+
await waitFor(() => {
|
|
68
|
+
expect(queryByText(/barDomain/)).toBeTruthy();
|
|
69
|
+
});
|
|
70
|
+
|
|
55
71
|
// Form is disabled until modified
|
|
56
72
|
expect(queryByRole("button", { name: /Save/ })).toBeDisabled();
|
|
57
|
-
userEvent.type(await
|
|
73
|
+
userEvent.type((await findAllByRole("textbox"))[1], "bar");
|
|
58
74
|
|
|
59
75
|
// Form is now enabled
|
|
60
76
|
await waitFor(() =>
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
2
3
|
import { render } from "@truedat/test/render";
|
|
4
|
+
import { domainsMock } from "@truedat/test/mocks";
|
|
3
5
|
import ReferenceDatasetCreate from "../ReferenceDatasetCreate";
|
|
4
6
|
|
|
7
|
+
const renderOpts = { mocks: [domainsMock({ action: "viewDataStructure" })] };
|
|
8
|
+
|
|
5
9
|
describe("<ReferenceDatasetCreate />", () => {
|
|
6
10
|
const props = { createReferenceDataset: jest.fn() };
|
|
7
11
|
|
|
8
|
-
it("matches the latest snapshot", () => {
|
|
9
|
-
const { container } = render(
|
|
12
|
+
it("matches the latest snapshot", async () => {
|
|
13
|
+
const { container, queryByText } = render(
|
|
14
|
+
<ReferenceDatasetCreate {...props} />,
|
|
15
|
+
renderOpts
|
|
16
|
+
);
|
|
17
|
+
await waitFor(() => {
|
|
18
|
+
expect(queryByText(/barDomain/)).toBeTruthy();
|
|
19
|
+
});
|
|
10
20
|
expect(container).toMatchSnapshot();
|
|
11
21
|
});
|
|
12
22
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
2
3
|
import { render } from "@truedat/test/render";
|
|
4
|
+
import { domainsMock } from "@truedat/test/mocks";
|
|
3
5
|
import ReferenceDatasetDetail from "../ReferenceDatasetDetail";
|
|
4
6
|
|
|
5
7
|
const dataset = {
|
|
@@ -10,17 +12,25 @@ const dataset = {
|
|
|
10
12
|
["foo1", "bar1", "baz1"],
|
|
11
13
|
["foo2", "bar2", "baz2"],
|
|
12
14
|
],
|
|
15
|
+
domain_ids: [1],
|
|
16
|
+
domains: [{ name: "fooDomain", id: 1 }],
|
|
13
17
|
};
|
|
14
18
|
|
|
15
19
|
describe("<ReferenceDatasetDetail />", () => {
|
|
16
20
|
const props = { dataset };
|
|
17
21
|
|
|
18
22
|
it("matches the latest snapshot (edit route)", async () => {
|
|
19
|
-
const renderOpts = {
|
|
20
|
-
|
|
23
|
+
const renderOpts = {
|
|
24
|
+
routes: ["/referenceDatasets/123/edit"],
|
|
25
|
+
mocks: [domainsMock({ action: "viewDataStructure" })],
|
|
26
|
+
};
|
|
27
|
+
const { container, findByRole, queryByText } = render(
|
|
21
28
|
<ReferenceDatasetDetail {...props} />,
|
|
22
29
|
renderOpts
|
|
23
30
|
);
|
|
31
|
+
await waitFor(() => {
|
|
32
|
+
expect(queryByText(/barDomain/)).toBeTruthy();
|
|
33
|
+
});
|
|
24
34
|
await findByRole("button", { name: "Save" });
|
|
25
35
|
expect(container).toMatchSnapshot();
|
|
26
36
|
});
|
|
@@ -2,6 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { waitFor } from "@testing-library/react";
|
|
3
3
|
import userEvent from "@testing-library/user-event";
|
|
4
4
|
import { render } from "@truedat/test/render";
|
|
5
|
+
import { domainsMock } from "@truedat/test/mocks";
|
|
5
6
|
import ReferenceDatasetForm from "../ReferenceDatasetForm";
|
|
6
7
|
|
|
7
8
|
const dataset = {
|
|
@@ -12,29 +13,39 @@ const dataset = {
|
|
|
12
13
|
["foo1", "bar1", "baz1"],
|
|
13
14
|
["foo2", "bar2", "baz2"],
|
|
14
15
|
],
|
|
16
|
+
domain_ids: [1],
|
|
17
|
+
domains: [{ name: "fooDomain", id: 1 }],
|
|
15
18
|
};
|
|
16
19
|
|
|
20
|
+
const renderOpts = { mocks: [domainsMock({ action: "viewDataStructure" })] };
|
|
21
|
+
|
|
17
22
|
describe("<ReferenceDatasetForm />", () => {
|
|
18
23
|
const onSubmit = jest.fn();
|
|
19
24
|
const props = { dataset, onSubmit };
|
|
20
25
|
|
|
21
26
|
it("matches the latest snapshot", async () => {
|
|
22
|
-
const { container, findByText } = render(
|
|
23
|
-
<ReferenceDatasetForm {...props}
|
|
27
|
+
const { container, findByText, queryByText } = render(
|
|
28
|
+
<ReferenceDatasetForm {...props} />,
|
|
29
|
+
renderOpts
|
|
24
30
|
);
|
|
31
|
+
await waitFor(() => {
|
|
32
|
+
expect(queryByText(/barDomain/)).toBeTruthy();
|
|
33
|
+
});
|
|
25
34
|
await findByText("Save");
|
|
26
35
|
expect(container).toMatchSnapshot();
|
|
27
36
|
});
|
|
28
37
|
|
|
29
38
|
it("form is disabled until modified", async () => {
|
|
30
|
-
const { findByText,
|
|
31
|
-
<ReferenceDatasetForm {...props}
|
|
32
|
-
)
|
|
39
|
+
const { findByText, findAllByRole, getByRole, queryByRole, queryByText } =
|
|
40
|
+
render(<ReferenceDatasetForm {...props} />, renderOpts);
|
|
41
|
+
await waitFor(() => {
|
|
42
|
+
expect(queryByText(/barDomain/)).toBeTruthy();
|
|
43
|
+
});
|
|
33
44
|
await findByText("Save");
|
|
34
45
|
|
|
35
46
|
// Form is disabled until modified
|
|
36
47
|
expect(queryByRole("button", { name: /Save/ })).toBeDisabled();
|
|
37
|
-
userEvent.type(await
|
|
48
|
+
userEvent.type((await findAllByRole("textbox"))[1], "bar");
|
|
38
49
|
|
|
39
50
|
// Form is now enabled
|
|
40
51
|
await waitFor(() =>
|
|
@@ -5,8 +5,14 @@ import ReferenceDatasetHeader from "../ReferenceDatasetHeader";
|
|
|
5
5
|
const dataset = {
|
|
6
6
|
id: "123",
|
|
7
7
|
name: "foo",
|
|
8
|
+
domain_ids: [1],
|
|
9
|
+
domains: [{ name: "fooDomain", id: 1 }],
|
|
8
10
|
};
|
|
9
11
|
|
|
12
|
+
jest.mock("@truedat/core/hooks", () => ({
|
|
13
|
+
useAuthorized: jest.fn(() => true),
|
|
14
|
+
}));
|
|
15
|
+
|
|
10
16
|
describe("<ReferenceDatasetHeader />", () => {
|
|
11
17
|
const props = { dataset };
|
|
12
18
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
2
3
|
import { render } from "@truedat/test/render";
|
|
4
|
+
import { domainsMock } from "@truedat/test/mocks";
|
|
3
5
|
import ReferenceDatasetRoutes from "../ReferenceDatasetRoutes";
|
|
4
6
|
import {
|
|
5
7
|
REFERENCE_DATASET_QUERY,
|
|
@@ -24,6 +26,8 @@ const dataset = {
|
|
|
24
26
|
["foo2", "bar2", "baz2"],
|
|
25
27
|
],
|
|
26
28
|
updatedAt: "2020-01-01T00:00:00.000Z",
|
|
29
|
+
domain_ids: [1],
|
|
30
|
+
domains: [{ name: "fooDomain", id: 1 }],
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
const datasetsMock = {
|
|
@@ -53,11 +57,17 @@ describe("<ReferenceDatasetRoutes />", () => {
|
|
|
53
57
|
});
|
|
54
58
|
|
|
55
59
|
it("matches the latest snapshot (create route)", async () => {
|
|
56
|
-
const renderOpts = {
|
|
57
|
-
|
|
60
|
+
const renderOpts = {
|
|
61
|
+
routes: ["/referenceDatasets/new"],
|
|
62
|
+
mocks: [domainsMock({ action: "viewDataStructure" })],
|
|
63
|
+
};
|
|
64
|
+
const { container, findByRole, queryByText } = render(
|
|
58
65
|
<ReferenceDatasetRoutes {...props} />,
|
|
59
66
|
renderOpts
|
|
60
67
|
);
|
|
68
|
+
await waitFor(() => {
|
|
69
|
+
expect(queryByText(/barDomain/)).toBeTruthy();
|
|
70
|
+
});
|
|
61
71
|
await findByRole("button", { name: "Save" });
|
|
62
72
|
expect(container).toMatchSnapshot();
|
|
63
73
|
});
|
|
@@ -23,6 +23,10 @@ const datasetsMock = {
|
|
|
23
23
|
|
|
24
24
|
const renderOpts = { mocks: [datasetsMock] };
|
|
25
25
|
|
|
26
|
+
jest.mock("@truedat/core/hooks", () => ({
|
|
27
|
+
useAuthorized: jest.fn(() => true),
|
|
28
|
+
}));
|
|
29
|
+
|
|
26
30
|
jest
|
|
27
31
|
.spyOn(global.Date, "now")
|
|
28
32
|
.mockImplementation(() => new Date("2022-01-01T11:01:58.135Z").valueOf());
|