@truedat/bg 7.0.5 → 7.0.6
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 +6 -6
- package/src/concepts/components/DomainConcepts.js +1 -4
- package/src/concepts/components/__tests__/__snapshots__/ConceptForm.spec.js.snap +2 -2
- package/src/concepts/components/__tests__/__snapshots__/ConceptsBulkUpdate.spec.js.snap +2 -2
- package/src/concepts/components/__tests__/__snapshots__/SharedToForm.spec.js.snap +2 -2
- package/src/hooks/useDomains.js +77 -0
- package/src/messages/en.js +6 -0
- package/src/messages/es.js +5 -0
- package/src/reducers/index.js +0 -1
- package/src/taxonomy/components/AddDomainMember.js +1 -7
- package/src/taxonomy/components/Domain.js +80 -84
- package/src/taxonomy/components/DomainActions.js +57 -84
- package/src/taxonomy/components/DomainCrumbs.js +51 -43
- package/src/taxonomy/components/DomainDetail.js +88 -46
- package/src/taxonomy/components/DomainForm.js +34 -36
- package/src/taxonomy/components/DomainImplementations.js +1 -4
- package/src/taxonomy/components/DomainMembers.js +8 -1
- package/src/taxonomy/components/DomainRoutes.js +8 -55
- package/src/taxonomy/components/DomainStructures.js +1 -4
- package/src/taxonomy/components/DomainTabs.js +22 -29
- package/src/taxonomy/components/Domains.js +66 -27
- package/src/taxonomy/components/DomainsActions.js +5 -14
- package/src/taxonomy/components/EditDomain.js +35 -21
- package/src/taxonomy/components/NewDomain.js +47 -22
- package/src/taxonomy/components/__tests__/Domain.spec.js +17 -8
- package/src/taxonomy/components/__tests__/DomainActions.spec.js +62 -7
- package/src/taxonomy/components/__tests__/DomainCrumbs.spec.js +18 -5
- package/src/taxonomy/components/__tests__/DomainDetail.spec.js +87 -4
- package/src/taxonomy/components/__tests__/DomainForm.spec.js +189 -4
- package/src/taxonomy/components/__tests__/DomainMembers.spec.js +1 -3
- package/src/taxonomy/components/__tests__/DomainStructures.spec.js +3 -2
- package/src/taxonomy/components/__tests__/Domains.spec.js +103 -6
- package/src/taxonomy/components/__tests__/EditDomain.spec.js +56 -5
- package/src/taxonomy/components/__tests__/NewDomain.spec.js +65 -6
- package/src/taxonomy/components/__tests__/__snapshots__/AddDomainMember.spec.js.snap +0 -10
- package/src/taxonomy/components/__tests__/__snapshots__/Domain.spec.js.snap +35 -48
- package/src/taxonomy/components/__tests__/__snapshots__/DomainActions.spec.js.snap +56 -1
- package/src/taxonomy/components/__tests__/__snapshots__/DomainCrumbs.spec.js.snap +14 -2
- package/src/taxonomy/components/__tests__/__snapshots__/DomainDetail.spec.js.snap +93 -40
- package/src/taxonomy/components/__tests__/__snapshots__/DomainForm.spec.js.snap +7 -7
- package/src/taxonomy/components/__tests__/__snapshots__/Domains.spec.js.snap +75 -10
- package/src/taxonomy/components/__tests__/__snapshots__/DomainsActions.spec.js.snap +20 -1
- package/src/taxonomy/components/__tests__/__snapshots__/EditDomain.spec.js.snap +192 -30
- package/src/taxonomy/components/__tests__/__snapshots__/NewDomain.spec.js.snap +405 -28
- package/src/taxonomy/components/index.js +1 -2
- package/src/taxonomy/index.js +0 -1
- package/src/taxonomy/routines.js +0 -10
- package/src/taxonomy/sagas/index.js +2 -21
- package/src/taxonomy/selectors/getDomainsConcept.js +0 -13
- package/src/taxonomy/selectors/index.js +0 -16
- package/src/taxonomy/components/DomainCards.js +0 -97
- package/src/taxonomy/components/DomainLoader.js +0 -60
- package/src/taxonomy/components/DomainMembersLoader.js +0 -44
- package/src/taxonomy/components/DomainsLoader.js +0 -40
- package/src/taxonomy/components/__tests__/DomainCards.spec.js +0 -30
- package/src/taxonomy/components/__tests__/DomainsLoader.spec.js +0 -38
- package/src/taxonomy/components/__tests__/__snapshots__/DomainCards.spec.js.snap +0 -160
- package/src/taxonomy/reducers/__tests__/domain.spec.js +0 -58
- package/src/taxonomy/reducers/__tests__/domainConceptLoading.spec.js +0 -26
- package/src/taxonomy/reducers/__tests__/domainCreating.spec.js +0 -24
- package/src/taxonomy/reducers/__tests__/domainLoading.spec.js +0 -22
- package/src/taxonomy/reducers/__tests__/domainMembersActions.spec.js +0 -38
- package/src/taxonomy/reducers/__tests__/domainMembersLoading.spec.js +0 -26
- package/src/taxonomy/reducers/__tests__/domainRedirect.spec.js +0 -36
- package/src/taxonomy/reducers/__tests__/domainUpdating.spec.js +0 -24
- package/src/taxonomy/reducers/__tests__/domains.spec.js +0 -30
- package/src/taxonomy/reducers/__tests__/domainsActions.spec.js +0 -36
- package/src/taxonomy/reducers/__tests__/domainsConcept.spec.js +0 -30
- package/src/taxonomy/reducers/__tests__/domainsFilter.spec.js +0 -41
- package/src/taxonomy/reducers/__tests__/domainsLoading.spec.js +0 -22
- package/src/taxonomy/reducers/domain.js +0 -32
- package/src/taxonomy/reducers/domainActions.js +0 -19
- package/src/taxonomy/reducers/domainCreating.js +0 -14
- package/src/taxonomy/reducers/domainLoading.js +0 -14
- package/src/taxonomy/reducers/domainMembersActions.js +0 -22
- package/src/taxonomy/reducers/domainMembersLoading.js +0 -12
- package/src/taxonomy/reducers/domainRedirect.js +0 -25
- package/src/taxonomy/reducers/domainUpdating.js +0 -14
- package/src/taxonomy/reducers/domains.js +0 -19
- package/src/taxonomy/reducers/domainsActions.js +0 -20
- package/src/taxonomy/reducers/domainsConcept.js +0 -19
- package/src/taxonomy/reducers/domainsConceptLoading.js +0 -12
- package/src/taxonomy/reducers/domainsFilter.js +0 -24
- package/src/taxonomy/reducers/domainsLoading.js +0 -12
- package/src/taxonomy/reducers/index.js +0 -31
- package/src/taxonomy/sagas/__tests__/fetchDomain.spec.js +0 -69
- package/src/taxonomy/sagas/__tests__/fetchDomains.spec.js +0 -90
- package/src/taxonomy/sagas/createDomain.js +0 -27
- package/src/taxonomy/sagas/deleteDomain.js +0 -34
- package/src/taxonomy/sagas/fetchDomain.js +0 -30
- package/src/taxonomy/sagas/fetchDomains.js +0 -37
- package/src/taxonomy/sagas/updateDomain.js +0 -30
- package/src/taxonomy/selectors/__tests__/domainParentOptionsSelector.spec.js +0 -24
- package/src/taxonomy/selectors/__tests__/getDomainActions.spec.js +0 -46
- package/src/taxonomy/selectors/__tests__/getDomainGroups.spec.js +0 -17
- package/src/taxonomy/selectors/__tests__/getDomainTypes.spec.js +0 -14
- package/src/taxonomy/selectors/domainParentOptionsSelector.js +0 -12
- package/src/taxonomy/selectors/getDomainActions.js +0 -32
- package/src/taxonomy/selectors/getDomainGroups.js +0 -11
|
@@ -1,17 +1,40 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
1
2
|
import React from "react";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
3
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
4
|
+
import { Grid, Header, Icon, Image, Segment } from "semantic-ui-react";
|
|
5
|
+
import HierarchyNodeFinder from "@truedat/core/components/HierarchyNodeFinder";
|
|
6
|
+
import { linkTo } from "@truedat/core/routes";
|
|
7
|
+
import { useHistory, useParams } from "react-router-dom";
|
|
8
|
+
import searchImage from "assets/searching.png";
|
|
9
|
+
import { useDomains } from "../../hooks/useDomains";
|
|
10
|
+
import Domain from "./Domain";
|
|
11
|
+
import DomainCrumbs from "./DomainCrumbs";
|
|
11
12
|
import DomainsActions from "./DomainsActions";
|
|
12
13
|
|
|
13
|
-
export const Domains = (
|
|
14
|
+
export const Domains = () => {
|
|
14
15
|
const { formatMessage } = useIntl();
|
|
16
|
+
const history = useHistory();
|
|
17
|
+
const { data: domains, actions } = useDomains();
|
|
18
|
+
const { id: urlId } = useParams();
|
|
19
|
+
const domainId = !isNaN(parseInt(urlId)) ? parseInt(urlId) : undefined;
|
|
20
|
+
const domain = _.find((d) => d.id == domainId)(domains);
|
|
21
|
+
const EmptyImage = () => (
|
|
22
|
+
<div
|
|
23
|
+
style={{
|
|
24
|
+
textAlign: "center",
|
|
25
|
+
paddingBottom: "100px",
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
<Image className="search" src={searchImage} />
|
|
29
|
+
<span className="system-domains-search__text">
|
|
30
|
+
<FormattedMessage id="domains.general.message" />
|
|
31
|
+
</span>
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const onClick = (id) => {
|
|
36
|
+
history.push(linkTo.DOMAIN_CONCEPTS({ id }));
|
|
37
|
+
};
|
|
15
38
|
return (
|
|
16
39
|
<Segment>
|
|
17
40
|
<Header as="h2">
|
|
@@ -29,26 +52,42 @@ export const Domains = ({ domainsLoading, createDomain }) => {
|
|
|
29
52
|
</Header.Subheader>
|
|
30
53
|
</Header.Content>
|
|
31
54
|
</Header>
|
|
32
|
-
<Segment attached="bottom"
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
<Segment attached="bottom">
|
|
56
|
+
<Grid>
|
|
57
|
+
<Grid.Row>
|
|
58
|
+
<Grid.Column width={16}>
|
|
59
|
+
{domain ? <DomainCrumbs domain={domain} /> : null}
|
|
60
|
+
</Grid.Column>
|
|
61
|
+
</Grid.Row>
|
|
62
|
+
<Grid.Row stretched>
|
|
63
|
+
<Grid.Column width={3}>
|
|
64
|
+
<HierarchyNodeFinder
|
|
65
|
+
nodes={domains}
|
|
66
|
+
onClick={onClick}
|
|
67
|
+
idSelectedNode={domainId}
|
|
68
|
+
/>
|
|
69
|
+
</Grid.Column>
|
|
70
|
+
<Grid.Column width={13}>
|
|
71
|
+
{domainId ? (
|
|
72
|
+
<Domain domainId={domainId} />
|
|
73
|
+
) : (
|
|
74
|
+
<Segment>
|
|
75
|
+
<Grid.Row>
|
|
76
|
+
<Grid.Column style={{ textAlign: "right" }}>
|
|
77
|
+
<DomainsActions actions={actions} />
|
|
78
|
+
</Grid.Column>
|
|
79
|
+
</Grid.Row>
|
|
80
|
+
<Grid.Row>
|
|
81
|
+
<EmptyImage />
|
|
82
|
+
</Grid.Row>
|
|
83
|
+
</Segment>
|
|
84
|
+
)}
|
|
85
|
+
</Grid.Column>
|
|
86
|
+
</Grid.Row>
|
|
87
|
+
</Grid>
|
|
42
88
|
</Segment>
|
|
43
89
|
</Segment>
|
|
44
90
|
);
|
|
45
91
|
};
|
|
46
92
|
|
|
47
|
-
|
|
48
|
-
domainsLoading: PropTypes.bool,
|
|
49
|
-
createDomain: PropTypes.func.isRequired,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const mapStateToProps = ({ domainsLoading }) => ({ domainsLoading });
|
|
53
|
-
|
|
54
|
-
export default connect(mapStateToProps, { createDomain })(Domains);
|
|
93
|
+
export default Domains;
|
|
@@ -2,20 +2,18 @@ import _ from "lodash/fp";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { useIntl } from "react-intl";
|
|
5
|
-
import { connect } from "react-redux";
|
|
6
5
|
import { Link } from "react-router-dom";
|
|
7
6
|
import { Button } from "semantic-ui-react";
|
|
8
7
|
import { DOMAINS_NEW } from "@truedat/core/routes";
|
|
9
|
-
import DomainSearch from "./DomainSearch";
|
|
10
8
|
|
|
11
|
-
export const DomainsActions = ({
|
|
9
|
+
export const DomainsActions = ({ actions }) => {
|
|
10
|
+
const createUrl = () =>
|
|
11
|
+
!_.isEmpty(actions) && _.has("create")(actions) ? DOMAINS_NEW : undefined;
|
|
12
12
|
const { formatMessage } = useIntl();
|
|
13
13
|
return (
|
|
14
14
|
<>
|
|
15
|
-
<DomainSearch />
|
|
16
15
|
{createUrl && (
|
|
17
16
|
<Button
|
|
18
|
-
floated="right"
|
|
19
17
|
primary
|
|
20
18
|
content={formatMessage({ id: "domains.actions.create" })}
|
|
21
19
|
icon="cube"
|
|
@@ -28,14 +26,7 @@ export const DomainsActions = ({ createUrl }) => {
|
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
DomainsActions.propTypes = {
|
|
31
|
-
|
|
29
|
+
actions: PropTypes.object,
|
|
32
30
|
};
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
createUrl:
|
|
36
|
-
!_.isEmpty(domainsActions) && _.has("create")(domainsActions)
|
|
37
|
-
? DOMAINS_NEW
|
|
38
|
-
: undefined
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
export default connect(mapStateToProps)(DomainsActions);
|
|
32
|
+
export default DomainsActions;
|
|
@@ -1,34 +1,48 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
|
-
import { connect } from "react-redux";
|
|
5
4
|
import { Container, Header, Icon, Segment } from "semantic-ui-react";
|
|
6
5
|
import { FormattedMessage } from "react-intl";
|
|
7
|
-
import {
|
|
6
|
+
import { useHistory } from "react-router-dom";
|
|
7
|
+
import { linkTo } from "@truedat/core/routes";
|
|
8
|
+
|
|
9
|
+
import { useQuery } from "@apollo/client";
|
|
10
|
+
import { DOMAINS_QUERY } from "@truedat/core/api/queries";
|
|
11
|
+
|
|
12
|
+
import { useDomainUpdate } from "../../hooks/useDomains";
|
|
8
13
|
import DomainForm from "./DomainForm";
|
|
9
|
-
import DomainCrumbs from "./DomainCrumbs";
|
|
10
14
|
|
|
11
|
-
export const EditDomain = ({ domain
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
export const EditDomain = ({ domain }) => {
|
|
16
|
+
const { trigger: updateDomain } = useDomainUpdate(domain.id);
|
|
17
|
+
const history = useHistory();
|
|
18
|
+
const { client } = useQuery(DOMAINS_QUERY, {
|
|
19
|
+
variables: { action: "viewDomain", fetchPolicy: "no-cache" },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const handleUpdateDomain = async (data) => {
|
|
23
|
+
await updateDomain({ domain: data });
|
|
24
|
+
const response = await updateDomain({ domain: data });
|
|
25
|
+
if (response?.data?.data) {
|
|
26
|
+
history.push(linkTo.DOMAIN_CONCEPTS({ id: response?.data?.data?.id }));
|
|
27
|
+
client.resetStore();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return _.isEmpty(domain) ? null : (
|
|
32
|
+
<Container as={Segment} text>
|
|
33
|
+
<Header as="h2">
|
|
34
|
+
<Icon name="cube" />
|
|
35
|
+
<Header.Content>
|
|
36
|
+
<FormattedMessage id="domain.actions.edit.header" />
|
|
37
|
+
</Header.Content>
|
|
38
|
+
</Header>
|
|
39
|
+
<DomainForm onSubmit={handleUpdateDomain} domain={domain} />
|
|
40
|
+
</Container>
|
|
25
41
|
);
|
|
42
|
+
};
|
|
26
43
|
|
|
27
44
|
EditDomain.propTypes = {
|
|
28
45
|
domain: PropTypes.object,
|
|
29
|
-
updateDomain: PropTypes.func.isRequired,
|
|
30
46
|
};
|
|
31
47
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export default connect(mapStateToProps, { updateDomain })(EditDomain);
|
|
48
|
+
export default EditDomain;
|
|
@@ -1,33 +1,58 @@
|
|
|
1
|
-
import _ from "lodash/fp";
|
|
2
1
|
import React from "react";
|
|
3
2
|
import PropTypes from "prop-types";
|
|
4
|
-
|
|
3
|
+
|
|
5
4
|
import { Container, Header, Icon, Segment } from "semantic-ui-react";
|
|
6
5
|
import { FormattedMessage } from "react-intl";
|
|
7
|
-
import {
|
|
6
|
+
import { linkTo } from "@truedat/core/routes";
|
|
7
|
+
import { useHistory } from "react-router-dom";
|
|
8
|
+
|
|
9
|
+
import { useQuery } from "@apollo/client";
|
|
10
|
+
import { DOMAINS_QUERY } from "@truedat/core/api/queries";
|
|
11
|
+
|
|
12
|
+
import { useDomainCreate } from "../../hooks/useDomains";
|
|
8
13
|
import DomainCrumbs from "./DomainCrumbs";
|
|
9
14
|
import DomainForm from "./DomainForm";
|
|
10
15
|
|
|
11
|
-
export const NewDomain = ({ domain
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<Header.Content>
|
|
18
|
-
<FormattedMessage id="domain.actions.create" />
|
|
19
|
-
</Header.Content>
|
|
20
|
-
</Header>
|
|
21
|
-
<DomainForm onSubmit={createDomain} domain={{ parent_id: domain.id }} />
|
|
22
|
-
</Container>
|
|
23
|
-
</>
|
|
24
|
-
);
|
|
16
|
+
export const NewDomain = ({ domain }) => {
|
|
17
|
+
const { trigger: createDomain } = useDomainCreate();
|
|
18
|
+
const history = useHistory();
|
|
19
|
+
const { client } = useQuery(DOMAINS_QUERY, {
|
|
20
|
+
variables: { action: "viewDomain", fetchPolicy: "no-cache" },
|
|
21
|
+
});
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const handleCreateDomain = async (data) => {
|
|
24
|
+
const response = await createDomain({ domain: data });
|
|
25
|
+
if (response?.data?.data) {
|
|
26
|
+
history.push(linkTo.DOMAIN_CONCEPTS({ id: response?.data?.data?.id }));
|
|
27
|
+
}
|
|
28
|
+
client.resetStore();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
{!domain ? (
|
|
34
|
+
<DomainCrumbs domain={domain} actionCrumb="domains.actions.create" />
|
|
35
|
+
) : null}
|
|
36
|
+
<Container as={Segment} text>
|
|
37
|
+
<Header as="h2">
|
|
38
|
+
<Icon name="cube" />
|
|
39
|
+
<Header.Content>
|
|
40
|
+
<FormattedMessage
|
|
41
|
+
id={!domain ? "domains.actions.create" : "domain.actions.create"}
|
|
42
|
+
/>
|
|
43
|
+
</Header.Content>
|
|
44
|
+
</Header>
|
|
45
|
+
<DomainForm
|
|
46
|
+
onSubmit={handleCreateDomain}
|
|
47
|
+
domain={domain?.id ? { parent_id: domain?.id } : {}}
|
|
48
|
+
/>
|
|
49
|
+
</Container>
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
29
52
|
};
|
|
30
53
|
|
|
31
|
-
|
|
54
|
+
NewDomain.propTypes = {
|
|
55
|
+
domain: PropTypes.object,
|
|
56
|
+
};
|
|
32
57
|
|
|
33
|
-
export default
|
|
58
|
+
export default NewDomain;
|
|
@@ -4,19 +4,28 @@ import Domain from "../Domain";
|
|
|
4
4
|
|
|
5
5
|
jest.mock("@truedat/core/hooks", () => ({
|
|
6
6
|
useAuthorized: jest.fn(() => true),
|
|
7
|
-
usePath: jest.fn(() => "/domains/:id"),
|
|
8
7
|
}));
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
jest.mock("../../../hooks/useDomains", () => ({
|
|
10
|
+
...jest.requireActual("../../../hooks/useDomains"),
|
|
11
|
+
useDomain: jest.fn((domainId) => ({
|
|
12
|
+
data: {
|
|
13
|
+
description: "DOMAIN DESCRIPTION",
|
|
14
|
+
domain_group: null,
|
|
15
|
+
external_id: "EXTERNAL ID",
|
|
16
|
+
id: domainId,
|
|
17
|
+
name: "DOMAIN NAME",
|
|
18
|
+
parent_id: 6,
|
|
19
|
+
parents: null,
|
|
20
|
+
type: null,
|
|
15
21
|
},
|
|
16
|
-
}
|
|
22
|
+
})),
|
|
23
|
+
}));
|
|
17
24
|
|
|
25
|
+
describe("<Domain />", () => {
|
|
26
|
+
const domainId = 3;
|
|
18
27
|
it("matches the latest snapshot", () => {
|
|
19
|
-
const { container } = render(<Domain
|
|
28
|
+
const { container } = render(<Domain domainId={domainId} />);
|
|
20
29
|
expect(container).toMatchSnapshot();
|
|
21
30
|
});
|
|
22
31
|
});
|
|
@@ -1,16 +1,71 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
1
2
|
import React from "react";
|
|
2
3
|
import { render } from "@truedat/test/render";
|
|
3
|
-
import
|
|
4
|
+
import DomainActions from "../DomainActions";
|
|
5
|
+
|
|
6
|
+
const domain = { id: 3, name: "domain" };
|
|
7
|
+
|
|
8
|
+
const domainAllActions = {
|
|
9
|
+
delete: { href: "/api/domains/3", method: "DELETE" },
|
|
10
|
+
create: { href: "/api/domains", method: "POST" },
|
|
11
|
+
update: { href: "/api/domains/3", method: "PATCH" },
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const availableActions = {
|
|
15
|
+
create: {
|
|
16
|
+
id: domain.id,
|
|
17
|
+
order: 1,
|
|
18
|
+
icon: "cube",
|
|
19
|
+
messageId: "domain.actions.create",
|
|
20
|
+
action: jest.fn((id) => `/domains/${id}/edit`),
|
|
21
|
+
},
|
|
22
|
+
update: {
|
|
23
|
+
id: domain.id,
|
|
24
|
+
order: 2,
|
|
25
|
+
icon: "edit",
|
|
26
|
+
messageId: "actions.edit",
|
|
27
|
+
action: jest.fn((id) => `/domains/${id}/new`),
|
|
28
|
+
},
|
|
29
|
+
deleteOption: true,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const renderOpts = {
|
|
33
|
+
messages: {
|
|
34
|
+
en: {
|
|
35
|
+
"domain.actions.delete": "DeleteDomain",
|
|
36
|
+
"domain.actions.delete.question": "WantToDelete?",
|
|
37
|
+
"actions.delete": "ActionDelete",
|
|
38
|
+
"domain.actions.create": "CreateDomain",
|
|
39
|
+
"actions.edit": "EditDomain",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
4
43
|
|
|
5
44
|
describe("<DomainActions />", () => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
45
|
+
const props = {
|
|
46
|
+
availableActions,
|
|
47
|
+
domain,
|
|
48
|
+
domainAllActions,
|
|
49
|
+
onDeleteDomain: jest.fn(),
|
|
50
|
+
};
|
|
11
51
|
|
|
12
52
|
it("matches the latest snapshot", () => {
|
|
13
|
-
const { container } = render(<DomainActions {...props}
|
|
53
|
+
const { container } = render(<DomainActions {...props} />, renderOpts);
|
|
14
54
|
expect(container).toMatchSnapshot();
|
|
15
55
|
});
|
|
56
|
+
|
|
57
|
+
it("When it does not have the delete action", () => {
|
|
58
|
+
const newAvailableActions = _.omit("deleteOption")(availableActions);
|
|
59
|
+
const newProps = { ...props, availableActions: newAvailableActions };
|
|
60
|
+
const { queryByText } = render(<DomainActions {...newProps} />, renderOpts);
|
|
61
|
+
|
|
62
|
+
expect(queryByText(/ActionDelete/i)).not.toBeInTheDocument();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("When it does not have domain actions", () => {
|
|
66
|
+
const newProps = { ...props, domainAllActions: {} };
|
|
67
|
+
const { queryByText } = render(<DomainActions {...newProps} />, renderOpts);
|
|
68
|
+
|
|
69
|
+
expect(queryByText(/ActionDelete/i)).not.toBeInTheDocument();
|
|
70
|
+
});
|
|
16
71
|
});
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { render } from "@truedat/test/render";
|
|
3
|
+
import { useDomains } from "../../../hooks/useDomains";
|
|
3
4
|
import { DomainCrumbs } from "../DomainCrumbs";
|
|
4
5
|
|
|
6
|
+
jest.mock("../../../hooks/useDomains", () => ({
|
|
7
|
+
...jest.requireActual("../../../hooks/useDomains"),
|
|
8
|
+
useDomains: jest.fn(),
|
|
9
|
+
}));
|
|
10
|
+
|
|
5
11
|
describe("<DomainCrumbs />", () => {
|
|
6
|
-
const parents = [
|
|
7
|
-
{ id: 1, name: "p1" },
|
|
8
|
-
{ id: 2, text: "p2" },
|
|
9
|
-
];
|
|
10
12
|
const domain = { id: 3, name: "domain" };
|
|
11
|
-
const props = {
|
|
13
|
+
const props = { domain, actionCrumb: "domain" };
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
require("../../../hooks/useDomains").useDomains.mockReturnValue({
|
|
17
|
+
data: [
|
|
18
|
+
{ id: 1, name: "foo", parent_id: null },
|
|
19
|
+
{ id: 2, name: "bar", parent_id: 1 },
|
|
20
|
+
{ id: 3, name: "baz", parent_id: 2 },
|
|
21
|
+
{ id: 4, name: "qux", parent_id: null },
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
});
|
|
12
25
|
|
|
13
26
|
it("matches the latest snapshot", () => {
|
|
14
27
|
const { container } = render(<DomainCrumbs {...props} />);
|
|
@@ -1,12 +1,95 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { render } from "@truedat/test/render";
|
|
3
3
|
import { DomainDetail } from "../DomainDetail";
|
|
4
4
|
|
|
5
|
+
jest.mock("@apollo/client", () => ({
|
|
6
|
+
...jest.requireActual("@apollo/client"),
|
|
7
|
+
useQuery: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
jest.mock("../../../hooks/useDomains", () => ({
|
|
11
|
+
...jest.requireActual("../../../hooks/useDomains"),
|
|
12
|
+
useDomainDelete: jest.fn(),
|
|
13
|
+
useDomain: jest.fn(),
|
|
14
|
+
}));
|
|
15
|
+
|
|
5
16
|
describe("<DomainDetail />", () => {
|
|
6
|
-
const
|
|
17
|
+
const id = 7;
|
|
18
|
+
const props = { id };
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
require("../../../hooks/useDomains").useDomain.mockReturnValue({
|
|
22
|
+
data: {
|
|
23
|
+
description: "el padre es element_6",
|
|
24
|
+
domain_group: null,
|
|
25
|
+
external_id: "7",
|
|
26
|
+
id: 7,
|
|
27
|
+
name: "element_7",
|
|
28
|
+
parent_id: 6,
|
|
29
|
+
parents: null,
|
|
30
|
+
type: null,
|
|
31
|
+
},
|
|
32
|
+
actions: {
|
|
33
|
+
create: {
|
|
34
|
+
href: "/api/domains",
|
|
35
|
+
input: {},
|
|
36
|
+
method: "POST",
|
|
37
|
+
},
|
|
38
|
+
update: {
|
|
39
|
+
href: "/api/domains/:id",
|
|
40
|
+
input: {},
|
|
41
|
+
method: "PATCH",
|
|
42
|
+
},
|
|
43
|
+
index: {
|
|
44
|
+
href: "/api/domains",
|
|
45
|
+
input: {},
|
|
46
|
+
method: "GET",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
loading: false,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
require("../../../hooks/useDomains").useDomainDelete.mockReturnValue({
|
|
53
|
+
trigger: jest.fn(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
require("@apollo/client").useQuery.mockReturnValue({
|
|
57
|
+
loading: false,
|
|
58
|
+
error: null,
|
|
59
|
+
data: {
|
|
60
|
+
domains: [
|
|
61
|
+
{
|
|
62
|
+
__typename: "Domain",
|
|
63
|
+
id: "5",
|
|
64
|
+
external_id: "element_5",
|
|
65
|
+
name: "element_5",
|
|
66
|
+
parentId: null,
|
|
67
|
+
actions: [],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
__typename: "Domain",
|
|
71
|
+
id: "6",
|
|
72
|
+
external_id: "element_6",
|
|
73
|
+
name: "element_6",
|
|
74
|
+
parentId: "5",
|
|
75
|
+
actions: [],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
__typename: "Domain",
|
|
79
|
+
id: "7",
|
|
80
|
+
external_id: "element_7",
|
|
81
|
+
name: "element_7",
|
|
82
|
+
parentId: "6",
|
|
83
|
+
actions: [],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
});
|
|
7
89
|
|
|
8
90
|
it("matches the latest snapshot", () => {
|
|
9
|
-
const
|
|
10
|
-
|
|
91
|
+
const { container } = render(<DomainDetail {...props} />);
|
|
92
|
+
|
|
93
|
+
expect(container).toMatchSnapshot();
|
|
11
94
|
});
|
|
12
95
|
});
|