@truedat/dd 4.49.10 → 4.50.4
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 +12 -0
- package/package.json +5 -5
- package/src/api/queries.js +16 -0
- package/src/api.js +2 -0
- package/src/components/GrantChangeRequest.js +32 -0
- package/src/components/GrantRequestCancel.js +47 -0
- package/src/components/GrantRequestHeader.js +9 -1
- package/src/components/MyGrantRequests.js +1 -0
- package/src/components/StructureGrantButton.js +24 -44
- package/src/components/StructureGrantCart.js +2 -2
- package/src/components/StructureGrantCartCheckout.js +20 -15
- package/src/components/StructureGrantCartTemplate.js +15 -61
- package/src/components/StructureGrantDropdown.js +201 -0
- package/src/components/StructureGrantRequestButton.js +15 -14
- package/src/components/StructureGrants.js +1 -1
- package/src/components/StructureSummary.js +13 -6
- package/src/components/StructureView.js +7 -8
- package/src/components/TagForm.js +1 -0
- package/src/components/__tests__/MyGrantRequests.spec.js +5 -0
- package/src/components/__tests__/StructureGrantButton.spec.js +107 -34
- package/src/components/__tests__/StructureGrantCartTemplate.spec.js +11 -100
- package/src/components/__tests__/StructureGrantDropdown.spec.js +148 -0
- package/src/components/__tests__/StructureGrantRequestButton.spec.js +9 -10
- package/src/components/__tests__/__snapshots__/MyGrantRequests.spec.js.snap +14 -0
- package/src/components/__tests__/__snapshots__/StructureGrantButton.spec.js.snap +162 -16
- package/src/components/__tests__/__snapshots__/StructureGrantCartTemplate.spec.js.snap +0 -3
- package/src/components/__tests__/__snapshots__/StructureGrantDropdown.spec.js.snap +271 -0
- package/src/components/__tests__/__snapshots__/StructureGrantRequestButton.spec.js.snap +11 -10
- package/src/components/__tests__/__snapshots__/StructureSummary.spec.js.snap +6 -0
- package/src/messages/en.js +17 -1
- package/src/messages/es.js +17 -3
- package/src/reducers/__tests__/grantRequestsCart.spec.js +223 -9
- package/src/reducers/grantRequestsCart.js +20 -26
- package/src/routines.js +2 -1
- package/src/sagas/__tests__/createGrantRequestStatus.spec.js +82 -0
- package/src/sagas/createGrantRequestStatus.js +32 -0
- package/src/sagas/index.js +3 -0
- package/src/sagas/operateGrantRequestCart.js +2 -27
- package/src/selectors/getGrantRequestsColumns.js +18 -3
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
import { Button, Dropdown, Popup, Header } from "semantic-ui-react";
|
|
5
|
+
import { connect } from "react-redux";
|
|
6
|
+
import { useIntl } from "react-intl";
|
|
7
|
+
import { useHistory } from "react-router-dom";
|
|
8
|
+
import { linkTo } from "@truedat/core/routes";
|
|
9
|
+
import { Date } from "@truedat/core/components";
|
|
10
|
+
|
|
11
|
+
import GrantChangeRequest from "./GrantChangeRequest";
|
|
12
|
+
import GrantRemoval from "./GrantRemoval";
|
|
13
|
+
import GrantRequestCancel from "./GrantRequestCancel";
|
|
14
|
+
|
|
15
|
+
const isNilOrEmpty = (value) => _.isEmpty(value) || _.isNil(value);
|
|
16
|
+
export const StructureGrantDropdown = ({
|
|
17
|
+
grantRequest,
|
|
18
|
+
structure,
|
|
19
|
+
structureGrantPopup,
|
|
20
|
+
}) => {
|
|
21
|
+
const history = useHistory();
|
|
22
|
+
const { formatMessage } = useIntl();
|
|
23
|
+
const { grant } = structure;
|
|
24
|
+
|
|
25
|
+
const hasPendingGrantRequest = _.includes(
|
|
26
|
+
_.prop("status.status")(grantRequest)
|
|
27
|
+
)(["pending", "approved"]);
|
|
28
|
+
|
|
29
|
+
const hasProcessingGrantRequest =
|
|
30
|
+
_.prop("status.status")(grantRequest) === "processing";
|
|
31
|
+
|
|
32
|
+
const isModification = _.prop("group.grant")(grantRequest);
|
|
33
|
+
|
|
34
|
+
const actions = {
|
|
35
|
+
viewRequest: (
|
|
36
|
+
<Dropdown.Item
|
|
37
|
+
onClick={() =>
|
|
38
|
+
history.push(linkTo.GRANT_REQUEST({ id: grantRequest.id }))
|
|
39
|
+
}
|
|
40
|
+
icon="info"
|
|
41
|
+
text={formatMessage({
|
|
42
|
+
id: `grant.actions.view_request.confirmation.header`,
|
|
43
|
+
})}
|
|
44
|
+
/>
|
|
45
|
+
),
|
|
46
|
+
requestRemoval: (
|
|
47
|
+
<GrantRemoval grant={grant}>
|
|
48
|
+
<Dropdown.Item
|
|
49
|
+
icon="delete"
|
|
50
|
+
text={formatMessage({
|
|
51
|
+
id: `grant.actions.request_removal.confirmation.header`,
|
|
52
|
+
})}
|
|
53
|
+
/>
|
|
54
|
+
</GrantRemoval>
|
|
55
|
+
),
|
|
56
|
+
cancelRemoval: (
|
|
57
|
+
<GrantRemoval grant={grant}>
|
|
58
|
+
<Dropdown.Item
|
|
59
|
+
icon="delete"
|
|
60
|
+
text={formatMessage({
|
|
61
|
+
id: `grant.actions.cancel_removal.confirmation.header`,
|
|
62
|
+
})}
|
|
63
|
+
/>
|
|
64
|
+
</GrantRemoval>
|
|
65
|
+
),
|
|
66
|
+
requestChange: (
|
|
67
|
+
<GrantChangeRequest structure={structure} grant={grant}>
|
|
68
|
+
<Dropdown.Item
|
|
69
|
+
icon="edit"
|
|
70
|
+
text={formatMessage({
|
|
71
|
+
id: "structure.grant.request_grant_change",
|
|
72
|
+
})}
|
|
73
|
+
/>
|
|
74
|
+
</GrantChangeRequest>
|
|
75
|
+
),
|
|
76
|
+
cancelRequest: (
|
|
77
|
+
<GrantRequestCancel
|
|
78
|
+
structureId={structure.id}
|
|
79
|
+
grantRequest={grantRequest}
|
|
80
|
+
>
|
|
81
|
+
<Dropdown.Item
|
|
82
|
+
icon="delete"
|
|
83
|
+
text={formatMessage({
|
|
84
|
+
id: "structure.grant.cancel_grant_request",
|
|
85
|
+
})}
|
|
86
|
+
/>
|
|
87
|
+
</GrantRequestCancel>
|
|
88
|
+
),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const dropdownStates = {
|
|
92
|
+
pendingRequest: {
|
|
93
|
+
color: "yellow",
|
|
94
|
+
options: (
|
|
95
|
+
<>
|
|
96
|
+
{actions["viewRequest"]}
|
|
97
|
+
{actions["cancelRequest"]}
|
|
98
|
+
</>
|
|
99
|
+
),
|
|
100
|
+
header: isModification
|
|
101
|
+
? "structure.grant.requested_modification"
|
|
102
|
+
: "structure.grant.requested_access",
|
|
103
|
+
},
|
|
104
|
+
processingRequest: {
|
|
105
|
+
color: "grey",
|
|
106
|
+
options: actions["viewRequest"],
|
|
107
|
+
header: isModification
|
|
108
|
+
? "structure.grant.modification.attended"
|
|
109
|
+
: "structure.grant.access.attended",
|
|
110
|
+
},
|
|
111
|
+
pendingRemovalGrant: {
|
|
112
|
+
color: "red",
|
|
113
|
+
options: actions["cancelRemoval"],
|
|
114
|
+
header: "structure.grant.has_grant_pending_removal",
|
|
115
|
+
},
|
|
116
|
+
activeGrant: {
|
|
117
|
+
color: "green",
|
|
118
|
+
options: (
|
|
119
|
+
<>
|
|
120
|
+
{actions["requestChange"]}
|
|
121
|
+
{actions["requestRemoval"]}
|
|
122
|
+
</>
|
|
123
|
+
),
|
|
124
|
+
header: "structure.grant.has_grant",
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const currentState = hasPendingGrantRequest
|
|
129
|
+
? "pendingRequest"
|
|
130
|
+
: hasProcessingGrantRequest
|
|
131
|
+
? "processingRequest"
|
|
132
|
+
: grant?.pending_removal
|
|
133
|
+
? "pendingRemovalGrant"
|
|
134
|
+
: "activeGrant";
|
|
135
|
+
|
|
136
|
+
const stateProps = dropdownStates[currentState];
|
|
137
|
+
|
|
138
|
+
const grantDetails = _.flow(
|
|
139
|
+
_.reject(({ field }) => isNilOrEmpty(_.get(field)(grant))),
|
|
140
|
+
_.map(({ field, type }) => {
|
|
141
|
+
switch (type) {
|
|
142
|
+
case "date":
|
|
143
|
+
return <Date value={_.get(field)(grant)} key={field} />;
|
|
144
|
+
default:
|
|
145
|
+
return <div key={field}>{_.get(field)(grant)}</div>;
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
)(structureGrantPopup);
|
|
149
|
+
|
|
150
|
+
const status = _.prop("status.status")(grantRequest);
|
|
151
|
+
|
|
152
|
+
const grantRequestDetails = status ? (
|
|
153
|
+
<>{formatMessage({ id: `grantRequest.content.${status}` })}</>
|
|
154
|
+
) : null;
|
|
155
|
+
|
|
156
|
+
const popupContent = (
|
|
157
|
+
<>
|
|
158
|
+
<Header as="h6">{formatMessage({ id: stateProps.header })}</Header>
|
|
159
|
+
{grantRequest ? grantRequestDetails : grantDetails}
|
|
160
|
+
</>
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const trigger = (
|
|
164
|
+
<Dropdown
|
|
165
|
+
icon={null}
|
|
166
|
+
floating
|
|
167
|
+
direction="left"
|
|
168
|
+
trigger={
|
|
169
|
+
<Button
|
|
170
|
+
color={stateProps.color}
|
|
171
|
+
className="button basic icon group-actions"
|
|
172
|
+
icon="shield"
|
|
173
|
+
/>
|
|
174
|
+
}
|
|
175
|
+
>
|
|
176
|
+
<Dropdown.Menu>{stateProps.options}</Dropdown.Menu>
|
|
177
|
+
</Dropdown>
|
|
178
|
+
);
|
|
179
|
+
return <Popup content={popupContent} trigger={trigger} />;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
StructureGrantDropdown.propTypes = {
|
|
183
|
+
grantRequest: PropTypes.object,
|
|
184
|
+
structure: PropTypes.object,
|
|
185
|
+
structureGrantPopup: PropTypes.array,
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const mapStateToProps = ({
|
|
189
|
+
structure,
|
|
190
|
+
structureFields,
|
|
191
|
+
structureGrantPopup,
|
|
192
|
+
}) => ({
|
|
193
|
+
structure: {
|
|
194
|
+
...structure,
|
|
195
|
+
hasDataFields: _.negate(_.isEmpty)(structureFields),
|
|
196
|
+
structureFields,
|
|
197
|
+
},
|
|
198
|
+
structureGrantPopup,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
export default connect(mapStateToProps)(StructureGrantDropdown);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
|
-
import { Icon,
|
|
4
|
+
import { Button, Icon, Popup } from "semantic-ui-react";
|
|
5
5
|
import { connect } from "react-redux";
|
|
6
6
|
import { useIntl } from "react-intl";
|
|
7
7
|
import { addGrantRequestToCart, removeGrantRequestFromCart } from "../routines";
|
|
@@ -21,21 +21,22 @@ export const StructureGrantRequestButton = ({
|
|
|
21
21
|
const removeRequest = () => {
|
|
22
22
|
removeGrantRequestFromCart(structure);
|
|
23
23
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const content = formatMessage({
|
|
25
|
+
id: requested
|
|
26
|
+
? "structure.grant.requested_grant"
|
|
27
|
+
: "structure.grant.request_grant",
|
|
28
|
+
});
|
|
29
|
+
const trigger = (
|
|
30
|
+
<Button
|
|
31
|
+
icon={<Icon name="shield" />}
|
|
32
|
+
className="button basic icon group-actions"
|
|
29
33
|
color={requested ? "blue" : "orange"}
|
|
30
34
|
onClick={requested ? removeRequest : addRequest}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
: "structure.grant.request_grant",
|
|
37
|
-
})}
|
|
38
|
-
</Label>
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return authorized ? (
|
|
39
|
+
<Popup content={content} position="top center" trigger={trigger} />
|
|
39
40
|
) : null;
|
|
40
41
|
};
|
|
41
42
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
|
-
import { Header, Icon, Label, Grid } from "semantic-ui-react";
|
|
4
|
+
import { Header, Icon, Label, Grid, Divider } from "semantic-ui-react";
|
|
5
5
|
import Moment from "react-moment";
|
|
6
6
|
import { connect } from "react-redux";
|
|
7
7
|
import { useIntl } from "react-intl";
|
|
@@ -74,7 +74,6 @@ export const StructureSummary = ({
|
|
|
74
74
|
<Header as="h2">
|
|
75
75
|
<Header.Content>
|
|
76
76
|
{_.defaultTo(name)(alias)}
|
|
77
|
-
{structureClasses?._grantable ? <StructureGrantButton /> : null}
|
|
78
77
|
{_.isEmpty(alias) ? null : (
|
|
79
78
|
<Header.Subheader>{name}</Header.Subheader>
|
|
80
79
|
)}
|
|
@@ -85,6 +84,8 @@ export const StructureSummary = ({
|
|
|
85
84
|
{(deleted_at || updatedAt) && (
|
|
86
85
|
<Date {...dateProperties(deleted_at, updatedAt)} />
|
|
87
86
|
)}
|
|
87
|
+
<Divider hidden fitted />
|
|
88
|
+
{structureClasses?._grantable ? <StructureGrantButton /> : null}
|
|
88
89
|
<ShareLinkPopup
|
|
89
90
|
url={shareUrl}
|
|
90
91
|
title={shareTitle}
|
|
@@ -92,11 +93,17 @@ export const StructureSummary = ({
|
|
|
92
93
|
description={description}
|
|
93
94
|
/>
|
|
94
95
|
{userPermissions.profile_permission &&
|
|
95
|
-
|
|
96
|
+
structureClass === "field" ? (
|
|
97
|
+
<StructureProfileButton />
|
|
98
|
+
) : null}
|
|
96
99
|
{userPermissions.profile_permission &&
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
structureClass !== "field" ? (
|
|
101
|
+
<StructuresProfileButton />
|
|
102
|
+
) : null}
|
|
103
|
+
{userPermissions.confidential ? (
|
|
104
|
+
<StructureConfidentialButton />
|
|
105
|
+
) : null}
|
|
106
|
+
{isAdmin && !deleted_at ? <StructureDeleteButton /> : null}
|
|
100
107
|
</Grid.Column>
|
|
101
108
|
</Grid.Row>
|
|
102
109
|
</Grid>
|
|
@@ -13,7 +13,7 @@ import StructureTabRoutes from "./StructureTabRoutes";
|
|
|
13
13
|
export const StructureView = ({
|
|
14
14
|
structureLoading,
|
|
15
15
|
structure,
|
|
16
|
-
|
|
16
|
+
showGrantRequestCart,
|
|
17
17
|
}) => (
|
|
18
18
|
<Segment loading={structureLoading} className="structures">
|
|
19
19
|
{structure && structure.id && !structureLoading && (
|
|
@@ -29,14 +29,14 @@ export const StructureView = ({
|
|
|
29
29
|
<FilteredNav />
|
|
30
30
|
</Segment>
|
|
31
31
|
</Grid.Column>
|
|
32
|
-
<Grid.Column width={
|
|
32
|
+
<Grid.Column width={showGrantRequestCart ? 8 : 12}>
|
|
33
33
|
<Segment>
|
|
34
34
|
<StructureSummary />
|
|
35
35
|
<StructureTabRoutes />
|
|
36
36
|
<StructureTabPaneRoutes />
|
|
37
37
|
</Segment>
|
|
38
38
|
</Grid.Column>
|
|
39
|
-
{
|
|
39
|
+
{showGrantRequestCart && (
|
|
40
40
|
<Grid.Column width={4}>
|
|
41
41
|
<StructureGrantCart />
|
|
42
42
|
</Grid.Column>
|
|
@@ -50,7 +50,7 @@ export const StructureView = ({
|
|
|
50
50
|
StructureView.propTypes = {
|
|
51
51
|
structureLoading: PropTypes.bool,
|
|
52
52
|
structure: PropTypes.object,
|
|
53
|
-
|
|
53
|
+
showGrantRequestCart: PropTypes.bool,
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
const mapStateToProps = ({
|
|
@@ -60,10 +60,9 @@ const mapStateToProps = ({
|
|
|
60
60
|
}) => ({
|
|
61
61
|
structureLoading,
|
|
62
62
|
structure,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_.negate(_.isEmpty)
|
|
66
|
-
)(grantRequestsCart),
|
|
63
|
+
showGrantRequestCart:
|
|
64
|
+
!grantRequestsCart.modificationGrant &&
|
|
65
|
+
_.flow(_.pathOr([], "structures"), _.negate(_.isEmpty))(grantRequestsCart),
|
|
67
66
|
});
|
|
68
67
|
|
|
69
68
|
export default connect(mapStateToProps)(StructureView);
|
|
@@ -15,6 +15,7 @@ describe("<MyGrantRequests />", () => {
|
|
|
15
15
|
"grantRequest.content.failed": "failed",
|
|
16
16
|
"grantRequest.content.pending": "pending",
|
|
17
17
|
"grantRequest.content.approved": "approved",
|
|
18
|
+
"grantRequest.content.cancelled": "cancelled",
|
|
18
19
|
"grantRequest.content.rejected": "rejected",
|
|
19
20
|
"grantRequest.content.processing": "processing",
|
|
20
21
|
"grantRequest.content.processed": "processed",
|
|
@@ -62,5 +63,9 @@ describe("<MyGrantRequests />", () => {
|
|
|
62
63
|
expect(setGrantRequestsQuery).toHaveBeenCalledWith({
|
|
63
64
|
status: "pending,approved,rejected,processing,failed",
|
|
64
65
|
});
|
|
66
|
+
userEvent.click(await findByText(/cancelled/));
|
|
67
|
+
expect(setGrantRequestsQuery).toHaveBeenCalledWith({
|
|
68
|
+
status: "pending,approved,rejected,processing,failed,cancelled",
|
|
69
|
+
});
|
|
65
70
|
});
|
|
66
71
|
});
|
|
@@ -1,52 +1,125 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { waitFor } from "@testing-library/react";
|
|
4
4
|
import { render } from "@truedat/test/render";
|
|
5
|
+
import { LATEST_GRANT_REQUEST_QUERY } from "../../api/queries";
|
|
5
6
|
import StructureGrantButton from "../StructureGrantButton";
|
|
7
|
+
import en from "../../messages/en";
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const latestGrantMockBuilder = (status) => ({
|
|
10
|
+
request: { query: LATEST_GRANT_REQUEST_QUERY },
|
|
11
|
+
result: {
|
|
12
|
+
data: {
|
|
13
|
+
latestGrantRequest: status
|
|
14
|
+
? {
|
|
15
|
+
id: 1,
|
|
16
|
+
group: {
|
|
17
|
+
grant: {
|
|
18
|
+
id: 1,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
status: { status },
|
|
22
|
+
}
|
|
23
|
+
: null,
|
|
14
24
|
},
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const renderOptsBuilder = (status, grant) => ({
|
|
29
|
+
mocks: [latestGrantMockBuilder(status)],
|
|
30
|
+
state: {
|
|
31
|
+
structure: { grant },
|
|
32
|
+
userPermissions: { request_grant: true },
|
|
33
|
+
},
|
|
34
|
+
messages: { en },
|
|
35
|
+
fallback: "lazy",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const expectToRenderDropdownComponent = (container) =>
|
|
39
|
+
expect(container.getElementsByClassName("dropdown")).toHaveLength(1);
|
|
40
|
+
|
|
41
|
+
const expectToRenderRequestButton = async (container, getByRole) => {
|
|
42
|
+
expect(container.getElementsByClassName("dropdown")).toHaveLength(0);
|
|
43
|
+
expect(await getByRole("button")).toBeTruthy();
|
|
44
|
+
};
|
|
45
|
+
describe("<StructureGrantButton />", () => {
|
|
46
|
+
it("matches snapshot for active grant and inactive grantRequest", async () => {
|
|
47
|
+
const renderOpts = renderOptsBuilder("processed", {});
|
|
48
|
+
|
|
49
|
+
const { container, queryByText } = render(
|
|
50
|
+
<StructureGrantButton />,
|
|
51
|
+
renderOpts
|
|
52
|
+
);
|
|
53
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
54
|
+
await waitFor(() =>
|
|
55
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expectToRenderDropdownComponent(container);
|
|
59
|
+
expect(container).toMatchSnapshot();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("matches snapshot for active grant and active grantRequest", async () => {
|
|
63
|
+
const renderOpts = renderOptsBuilder("pending", {});
|
|
64
|
+
|
|
65
|
+
const { container, queryByText } = render(
|
|
66
|
+
<StructureGrantButton />,
|
|
67
|
+
renderOpts
|
|
68
|
+
);
|
|
69
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
70
|
+
await waitFor(() =>
|
|
71
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
72
|
+
);
|
|
17
73
|
|
|
18
|
-
|
|
19
|
-
const { findByText, container } = render(<StructureGrantButton />, {
|
|
20
|
-
state,
|
|
21
|
-
});
|
|
74
|
+
expectToRenderDropdownComponent(container);
|
|
22
75
|
expect(container).toMatchSnapshot();
|
|
23
|
-
expect(
|
|
24
|
-
await findByText("You have granted access on this structure")
|
|
25
|
-
).toBeTruthy();
|
|
26
76
|
});
|
|
27
77
|
|
|
28
|
-
it("matches
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
78
|
+
it("matches snapshot for no grant and active grantRequest", async () => {
|
|
79
|
+
const renderOpts = renderOptsBuilder("approved", null);
|
|
80
|
+
|
|
81
|
+
const { container, queryByText } = render(
|
|
82
|
+
<StructureGrantButton />,
|
|
83
|
+
renderOpts
|
|
84
|
+
);
|
|
85
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
86
|
+
await waitFor(() =>
|
|
87
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
expectToRenderDropdownComponent(container);
|
|
33
91
|
expect(container).toMatchSnapshot();
|
|
34
|
-
expect(
|
|
35
|
-
await findByText("You have granted access pending removal")
|
|
36
|
-
).toBeTruthy();
|
|
37
92
|
});
|
|
38
93
|
|
|
39
|
-
it("matches
|
|
40
|
-
const
|
|
41
|
-
|
|
94
|
+
it("matches snapshot for no grant and inactive grantRequest", async () => {
|
|
95
|
+
const renderOpts = renderOptsBuilder("cancelled", null);
|
|
96
|
+
|
|
97
|
+
const { container, getByRole, queryByText } = render(
|
|
98
|
+
<StructureGrantButton />,
|
|
99
|
+
renderOpts
|
|
100
|
+
);
|
|
101
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
102
|
+
await waitFor(() =>
|
|
103
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
42
104
|
);
|
|
43
|
-
const { findByText } = render(<StructureGrantButton />, {
|
|
44
|
-
state: customState,
|
|
45
|
-
});
|
|
46
105
|
|
|
47
|
-
|
|
48
|
-
|
|
106
|
+
await expectToRenderRequestButton(container, getByRole);
|
|
107
|
+
expect(container).toMatchSnapshot();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("matches snapshot for no grant and no grantRequest", async () => {
|
|
111
|
+
const renderOpts = renderOptsBuilder(null, null);
|
|
112
|
+
|
|
113
|
+
const { container, getByRole, queryByText } = render(
|
|
114
|
+
<StructureGrantButton />,
|
|
115
|
+
renderOpts
|
|
49
116
|
);
|
|
50
|
-
|
|
117
|
+
await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
|
|
118
|
+
await waitFor(() =>
|
|
119
|
+
expect(queryByText(/loading/i)).not.toBeInTheDocument()
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
await expectToRenderRequestButton(container, getByRole);
|
|
123
|
+
expect(container).toMatchSnapshot();
|
|
51
124
|
});
|
|
52
125
|
});
|
|
@@ -1,41 +1,20 @@
|
|
|
1
1
|
import React, { Suspense } from "react";
|
|
2
|
-
import { waitFor } from "@testing-library/react";
|
|
3
2
|
import { render } from "@truedat/test/render";
|
|
3
|
+
import { singleTemplateMock } from "@truedat/test/mocks";
|
|
4
4
|
import { StructureGrantCartTemplate } from "../StructureGrantCartTemplate";
|
|
5
5
|
|
|
6
6
|
describe("<StructureGrantCartTemplate />", () => {
|
|
7
|
-
const fetchGrantRequestTemplates = jest.fn();
|
|
8
7
|
const selectGrantRequestTemplate = jest.fn();
|
|
9
8
|
const updateGrantRequestTemplateContent = jest.fn();
|
|
10
9
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
content: [
|
|
14
|
-
{
|
|
15
|
-
name: "foo",
|
|
16
|
-
fields: [
|
|
17
|
-
{
|
|
18
|
-
type: "string",
|
|
19
|
-
name: "foo",
|
|
20
|
-
label: "Label",
|
|
21
|
-
cardinality: "1",
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
};
|
|
27
|
-
const templates = [template];
|
|
28
|
-
const templatesLoading = false;
|
|
10
|
+
const variables = { scope: "gr" };
|
|
11
|
+
|
|
29
12
|
const templateContent = { foo: "bar" };
|
|
30
13
|
const grantRequestsCart = {
|
|
31
|
-
|
|
32
|
-
template,
|
|
33
|
-
templates,
|
|
14
|
+
templateContent,
|
|
34
15
|
};
|
|
35
16
|
const props = {
|
|
36
17
|
grantRequestsCart,
|
|
37
|
-
templateContent,
|
|
38
|
-
fetchGrantRequestTemplates,
|
|
39
18
|
selectGrantRequestTemplate,
|
|
40
19
|
updateGrantRequestTemplateContent,
|
|
41
20
|
};
|
|
@@ -48,87 +27,19 @@ describe("<StructureGrantCartTemplate />", () => {
|
|
|
48
27
|
},
|
|
49
28
|
};
|
|
50
29
|
|
|
30
|
+
const renderOpts = {
|
|
31
|
+
mocks: [singleTemplateMock(variables)],
|
|
32
|
+
messages,
|
|
33
|
+
fallback: "lazy",
|
|
34
|
+
};
|
|
35
|
+
|
|
51
36
|
it("matches the latest snapshot", () => {
|
|
52
37
|
const { container } = render(
|
|
53
38
|
<Suspense fallback={null}>
|
|
54
39
|
<StructureGrantCartTemplate {...props} />
|
|
55
40
|
</Suspense>,
|
|
56
|
-
|
|
57
|
-
messages,
|
|
58
|
-
}
|
|
41
|
+
renderOpts
|
|
59
42
|
);
|
|
60
43
|
expect(container).toMatchSnapshot();
|
|
61
44
|
});
|
|
62
|
-
|
|
63
|
-
it("it calls fetchGrantRequestTemplates on render and selects template by default", async () => {
|
|
64
|
-
fetchGrantRequestTemplates.mockClear();
|
|
65
|
-
const { findByText } = render(
|
|
66
|
-
<Suspense fallback={null}>
|
|
67
|
-
<StructureGrantCartTemplate {...props} />
|
|
68
|
-
</Suspense>,
|
|
69
|
-
{
|
|
70
|
-
messages,
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
await waitFor(() => {
|
|
74
|
-
expect(fetchGrantRequestTemplates).toHaveBeenCalledTimes(1);
|
|
75
|
-
});
|
|
76
|
-
await waitFor(() => {
|
|
77
|
-
expect(selectGrantRequestTemplate).toHaveBeenCalledWith(template.id);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
await waitFor(() => {
|
|
81
|
-
expect(findByText(/template/)).toBeTruthy();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("it renders templates dropdown when there are many", async () => {
|
|
86
|
-
fetchGrantRequestTemplates.mockClear();
|
|
87
|
-
selectGrantRequestTemplate.mockClear();
|
|
88
|
-
const templates = [
|
|
89
|
-
template,
|
|
90
|
-
{
|
|
91
|
-
id: 2,
|
|
92
|
-
name: "bar",
|
|
93
|
-
content: [
|
|
94
|
-
{
|
|
95
|
-
fields: [
|
|
96
|
-
{
|
|
97
|
-
type: "string",
|
|
98
|
-
name: "bar",
|
|
99
|
-
label: "Label",
|
|
100
|
-
cardinality: "1",
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
];
|
|
107
|
-
const { findByRole } = render(
|
|
108
|
-
<Suspense fallback={null}>
|
|
109
|
-
<StructureGrantCartTemplate
|
|
110
|
-
{...{
|
|
111
|
-
...props,
|
|
112
|
-
grantRequestsCart: {
|
|
113
|
-
...grantRequestsCart,
|
|
114
|
-
template: null,
|
|
115
|
-
templates,
|
|
116
|
-
},
|
|
117
|
-
}}
|
|
118
|
-
/>
|
|
119
|
-
</Suspense>,
|
|
120
|
-
{
|
|
121
|
-
messages,
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
await waitFor(() => {
|
|
125
|
-
expect(fetchGrantRequestTemplates).toHaveBeenCalledTimes(1);
|
|
126
|
-
});
|
|
127
|
-
await waitFor(() => {
|
|
128
|
-
expect(selectGrantRequestTemplate).toHaveBeenCalledTimes(0);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
expect(findByRole("option", { name: "foo" })).toBeTruthy();
|
|
132
|
-
expect(findByRole("option", { name: "bar" })).toBeTruthy();
|
|
133
|
-
});
|
|
134
45
|
});
|