@truedat/dd 6.8.2 → 6.8.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/package.json +6 -6
- package/src/components/DictionaryRoutes.js +5 -1
- package/src/components/PendingStructureNoteRow.js +18 -26
- package/src/components/PendingStructureNotes.js +58 -111
- package/src/components/PendingStructureNotesLabelResults.js +17 -0
- package/src/components/PendingStructureNotesPagination.js +16 -0
- package/src/components/PendingStructureNotesTable.js +44 -35
- package/src/components/ReferenceDatasetForm.js +1 -1
- package/src/components/TagForm.js +1 -1
- package/src/components/__tests__/PendingStructureNoteRow.spec.js +95 -18
- package/src/components/__tests__/PendingStructureNotes.spec.js +57 -44
- package/src/components/__tests__/PendingStructureNotesLabelResults.spec.js +44 -0
- package/src/components/__tests__/PendingStructureNotesPagination.spec.js +43 -0
- package/src/components/__tests__/PendingStructureNotesTable.spec.js +52 -38
- package/src/components/__tests__/__snapshots__/PendingStructureNoteRow.spec.js.snap +8 -3
- package/src/components/__tests__/__snapshots__/PendingStructureNotes.spec.js.snap +159 -77
- package/src/components/__tests__/__snapshots__/PendingStructureNotesLabelResults.spec.js.snap +11 -0
- package/src/components/__tests__/__snapshots__/PendingStructureNotesPagination.spec.js.snap +96 -0
- package/src/components/__tests__/__snapshots__/PendingStructureNotesTable.spec.js.snap +36 -18
- package/src/selectors/index.js +4 -0
- package/src/selectors/structureNotesColumnsSelector.js +65 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/dd",
|
|
3
|
-
"version": "6.8.
|
|
3
|
+
"version": "6.8.4",
|
|
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": "6.8.
|
|
37
|
+
"@truedat/test": "6.8.4",
|
|
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",
|
|
@@ -88,9 +88,9 @@
|
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
90
|
"@apollo/client": "^3.7.1",
|
|
91
|
-
"@truedat/auth": "6.8.
|
|
92
|
-
"@truedat/core": "6.8.
|
|
93
|
-
"@truedat/df": "6.8.
|
|
91
|
+
"@truedat/auth": "6.8.4",
|
|
92
|
+
"@truedat/core": "6.8.4",
|
|
93
|
+
"@truedat/df": "6.8.4",
|
|
94
94
|
"lodash": "^4.17.21",
|
|
95
95
|
"moment": "^2.29.4",
|
|
96
96
|
"path-to-regexp": "^1.7.0",
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
"react-dom": ">= 16.8.6 < 17",
|
|
116
116
|
"semantic-ui-react": ">= 2.0.3 < 2.2"
|
|
117
117
|
},
|
|
118
|
-
"gitHead": "
|
|
118
|
+
"gitHead": "6a7cb953d1f03f44976f3c98029b91d876e39daf"
|
|
119
119
|
}
|
|
@@ -114,7 +114,11 @@ export const DictionaryRoutes = () => {
|
|
|
114
114
|
render={() => (
|
|
115
115
|
<>
|
|
116
116
|
<SystemsLoader />
|
|
117
|
-
<PendingStructureNotes
|
|
117
|
+
<PendingStructureNotes
|
|
118
|
+
defaultFilters={{
|
|
119
|
+
note_status: ["rejected", "draft", "pending_approval"],
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
118
122
|
</>
|
|
119
123
|
)}
|
|
120
124
|
/>
|
|
@@ -2,41 +2,33 @@ import _ from "lodash/fp";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { Table } from "semantic-ui-react";
|
|
5
|
-
import { useIntl } from "react-intl";
|
|
6
5
|
import { useHistory } from "react-router-dom";
|
|
6
|
+
import { columnDecorator } from "@truedat/core/services";
|
|
7
7
|
import { linkTo } from "@truedat/core/routes";
|
|
8
8
|
|
|
9
|
-
const PendingStructureNoteRow = ({
|
|
10
|
-
const { formatMessage } = useIntl();
|
|
9
|
+
const PendingStructureNoteRow = ({ structure, columns }) => {
|
|
11
10
|
const history = useHistory();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
<Table.Cell
|
|
27
|
-
content={formatMessage({
|
|
28
|
-
id: `structure.notes.status.${structureNote.status}`,
|
|
29
|
-
})}
|
|
30
|
-
/>
|
|
31
|
-
<Table.Cell content={system} />
|
|
32
|
-
<Table.Cell content={domainsNames.join(", ")} />
|
|
33
|
-
<Table.Cell content={path.join(" > ")} />
|
|
11
|
+
return _.isEmpty(columns) || _.isEmpty(structure) ? null : (
|
|
12
|
+
<Table.Row key={structure.id}>
|
|
13
|
+
{columns.map((column, i) => (
|
|
14
|
+
<Table.Cell
|
|
15
|
+
key={i}
|
|
16
|
+
{...(i == 0 && {
|
|
17
|
+
title: columnDecorator(column)(structure),
|
|
18
|
+
className: "structure-cell-overflow",
|
|
19
|
+
})}
|
|
20
|
+
textAlign={column.textAlign}
|
|
21
|
+
content={columnDecorator(column)(structure)}
|
|
22
|
+
onClick={() => history.push(linkTo.STRUCTURE({ id: structure.id }))}
|
|
23
|
+
/>
|
|
24
|
+
))}
|
|
34
25
|
</Table.Row>
|
|
35
26
|
);
|
|
36
27
|
};
|
|
37
28
|
|
|
38
29
|
PendingStructureNoteRow.propTypes = {
|
|
39
|
-
|
|
30
|
+
structure: PropTypes.object.isRequired,
|
|
31
|
+
columns: PropTypes.array.isRequired,
|
|
40
32
|
};
|
|
41
33
|
|
|
42
34
|
export default PendingStructureNoteRow;
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
|
-
import React
|
|
2
|
+
import React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { connect } from "react-redux";
|
|
5
|
-
import { FormattedMessage
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import { FormattedMessage } from "react-intl";
|
|
6
|
+
import { Dimmer, Loader, Header, Icon, Segment } from "semantic-ui-react";
|
|
7
|
+
import {
|
|
8
|
+
SearchContextProvider,
|
|
9
|
+
useSearchContext,
|
|
10
|
+
} from "@truedat/core/search/SearchContext";
|
|
11
|
+
import SearchWidget from "@truedat/core/search/SearchWidget";
|
|
12
|
+
import {
|
|
13
|
+
useDataStructureFilters,
|
|
14
|
+
useDataStructureSearch,
|
|
15
|
+
} from "../hooks/useStructures";
|
|
16
|
+
import translations from "../utils/structureCustomTranslations";
|
|
17
|
+
import PendingStructureNotesPagination from "./PendingStructureNotesPagination";
|
|
18
|
+
import PendingStructureNotesLabelResults from "./PendingStructureNotesLabelResults";
|
|
11
19
|
import PendingStructureNotesTable from "./PendingStructureNotesTable";
|
|
12
20
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
export const PendingStructureNotes = ({ systems }) => {
|
|
16
|
-
const { formatMessage } = useIntl();
|
|
17
|
-
const [domainsLoading, setDomainsLoading] = useState(true);
|
|
18
|
-
const [filter, setFilter] = useState({
|
|
19
|
-
statuses: STATUS,
|
|
20
|
-
});
|
|
21
|
-
const { loading, error, data } = useQuery(STRUCTURE_NOTES_QUERY, {
|
|
22
|
-
variables: { filter },
|
|
23
|
-
fetchPolicy: "cache-and-network",
|
|
24
|
-
});
|
|
25
|
-
const items = loading || error ? [] : data?.structureNotes;
|
|
26
|
-
const { control } = useForm({
|
|
27
|
-
mode: "all",
|
|
28
|
-
defaultValues: {
|
|
29
|
-
status: STATUS,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
21
|
+
export const PendingStructureNotesContent = () => {
|
|
22
|
+
const { loading } = useSearchContext();
|
|
32
23
|
|
|
33
24
|
return (
|
|
34
25
|
<Segment>
|
|
@@ -41,97 +32,53 @@ export const PendingStructureNotes = ({ systems }) => {
|
|
|
41
32
|
</Header.Subheader>
|
|
42
33
|
</Header.Content>
|
|
43
34
|
</Header>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
<label>
|
|
55
|
-
<FormattedMessage id="pendingStructureNotes.props.status" />
|
|
56
|
-
</label>
|
|
57
|
-
{STATUS.map((type, idx) => (
|
|
58
|
-
<Checkbox
|
|
59
|
-
onBlur={onBlur}
|
|
60
|
-
key={idx}
|
|
61
|
-
label={
|
|
62
|
-
<label>
|
|
63
|
-
<FormattedMessage
|
|
64
|
-
id={`structure.notes.status.${type}`}
|
|
65
|
-
defaultMessage={type}
|
|
66
|
-
/>
|
|
67
|
-
</label>
|
|
68
|
-
}
|
|
69
|
-
onChange={() => {
|
|
70
|
-
const statuses = _.includes(type)(value)
|
|
71
|
-
? _.filter((t) => t !== type)(value)
|
|
72
|
-
: [...value, type];
|
|
73
|
-
setFilter({ ...filter, statuses });
|
|
74
|
-
onChange(statuses);
|
|
75
|
-
}}
|
|
76
|
-
checked={_.includes(type)(value)}
|
|
77
|
-
/>
|
|
78
|
-
))}
|
|
79
|
-
</Form.Field>
|
|
80
|
-
)}
|
|
81
|
-
/>
|
|
82
|
-
<Controller
|
|
83
|
-
control={control}
|
|
84
|
-
name="domain_ids"
|
|
85
|
-
render={({ field: { onChange, value } }) => (
|
|
86
|
-
<DomainSelector
|
|
87
|
-
label={formatMessage({ id: "domain.selector.label" })}
|
|
88
|
-
labels
|
|
89
|
-
action="publishStructureNote"
|
|
90
|
-
value={value}
|
|
91
|
-
onChange={(_e, { value }) => {
|
|
92
|
-
const domain_ids = _.isEmpty(value) ? [] : [value];
|
|
93
|
-
setFilter({ ...filter, domain_ids });
|
|
94
|
-
onChange(value);
|
|
95
|
-
}}
|
|
96
|
-
onLoad={() => setDomainsLoading(false)}
|
|
97
|
-
/>
|
|
98
|
-
)}
|
|
99
|
-
/>
|
|
100
|
-
<Controller
|
|
101
|
-
control={control}
|
|
102
|
-
name="system_ids"
|
|
103
|
-
render={({ field: { onBlur, onChange, value } }) => (
|
|
104
|
-
<Form.Dropdown
|
|
105
|
-
label={formatMessage({
|
|
106
|
-
id: "pendingStructureNotes.props.system",
|
|
107
|
-
})}
|
|
108
|
-
onBlur={onBlur}
|
|
109
|
-
onChange={(e, { value }) => {
|
|
110
|
-
setFilter({ ...filter, system_ids: value });
|
|
111
|
-
onChange(value);
|
|
112
|
-
}}
|
|
113
|
-
options={systems.map(({ name, id }) => ({
|
|
114
|
-
text: name,
|
|
115
|
-
key: id,
|
|
116
|
-
value: id,
|
|
117
|
-
}))}
|
|
118
|
-
selection
|
|
119
|
-
clearable
|
|
120
|
-
multiple
|
|
121
|
-
value={value || []}
|
|
122
|
-
/>
|
|
123
|
-
)}
|
|
124
|
-
/>
|
|
125
|
-
</Form>
|
|
126
|
-
<PendingStructureNotesTable structureNotes={items} loading={loading} />
|
|
35
|
+
|
|
36
|
+
<SearchWidget />
|
|
37
|
+
<Dimmer.Dimmable dimmed={loading}>
|
|
38
|
+
<Dimmer active={loading} inverted>
|
|
39
|
+
<Loader />
|
|
40
|
+
</Dimmer>
|
|
41
|
+
<PendingStructureNotesLabelResults />
|
|
42
|
+
<PendingStructureNotesTable />
|
|
43
|
+
<PendingStructureNotesPagination />
|
|
44
|
+
</Dimmer.Dimmable>
|
|
127
45
|
</Segment>
|
|
128
46
|
);
|
|
129
47
|
};
|
|
130
48
|
|
|
49
|
+
export const PendingStructureNotes = (props) => {
|
|
50
|
+
const defaultFilters = _.propOr({}, "defaultFilters")(props);
|
|
51
|
+
const filtersGroup = _.propOr([], "filtersGroup")(props);
|
|
52
|
+
const enrichSearchPayload = {
|
|
53
|
+
my_grant_requests: false,
|
|
54
|
+
with_data_fields: false,
|
|
55
|
+
};
|
|
56
|
+
const searchProps = {
|
|
57
|
+
initialSortColumn: "name.raw",
|
|
58
|
+
initialSortDirection: "ascending",
|
|
59
|
+
useSearch: useDataStructureSearch,
|
|
60
|
+
useFilters: useDataStructureFilters,
|
|
61
|
+
pageSize: 20,
|
|
62
|
+
userFiltersType: "user_search_filters",
|
|
63
|
+
userFilterScope: "data_structure",
|
|
64
|
+
translations,
|
|
65
|
+
filtersGroup,
|
|
66
|
+
defaultFilters,
|
|
67
|
+
enrichSearchPayload,
|
|
68
|
+
};
|
|
69
|
+
return (
|
|
70
|
+
<SearchContextProvider {...searchProps} defaultFilters={defaultFilters}>
|
|
71
|
+
<PendingStructureNotesContent />
|
|
72
|
+
</SearchContextProvider>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
131
76
|
PendingStructureNotes.propTypes = {
|
|
132
|
-
|
|
77
|
+
defaultFilters: PropTypes.object,
|
|
133
78
|
};
|
|
134
79
|
|
|
135
|
-
|
|
80
|
+
const mapStateToProps = (state) => ({
|
|
81
|
+
filtersGroup: state?.pendingStructureNotesFiltersGroup,
|
|
82
|
+
});
|
|
136
83
|
|
|
137
84
|
export default connect(mapStateToProps)(PendingStructureNotes);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FormattedMessage, useIntl } from "react-intl";
|
|
3
|
+
import { Label } from "semantic-ui-react";
|
|
4
|
+
import { useSearchContext } from "@truedat/core/search/SearchContext";
|
|
5
|
+
|
|
6
|
+
export const PendingStructureNotesLabelResults = () => {
|
|
7
|
+
const { formatNumber } = useIntl();
|
|
8
|
+
const { count: originalCount } = useSearchContext();
|
|
9
|
+
const count = formatNumber(originalCount);
|
|
10
|
+
return (
|
|
11
|
+
<Label className="structures-notes-label-results">
|
|
12
|
+
<FormattedMessage id="structures.retrieved.results" values={{ count }} />
|
|
13
|
+
</Label>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default PendingStructureNotesLabelResults;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Pagination } from "@truedat/core/components";
|
|
3
|
+
import { useSearchContext } from "@truedat/core/search/SearchContext";
|
|
4
|
+
|
|
5
|
+
export default function PendingStructureNotesPagination() {
|
|
6
|
+
const { count, size, page, selectPage } = useSearchContext();
|
|
7
|
+
const totalPages = Math.ceil(count / size);
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<Pagination
|
|
11
|
+
totalPages={totalPages}
|
|
12
|
+
activePage={page}
|
|
13
|
+
selectPage={selectPage}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
|
-
import {
|
|
4
|
+
import { connect } from "react-redux";
|
|
5
|
+
import { FormattedMessage } from "react-intl";
|
|
5
6
|
import { Table, Header, Icon } from "semantic-ui-react";
|
|
7
|
+
import { useSearchContext } from "@truedat/core/search/SearchContext";
|
|
8
|
+
import { getStructureNotesColumnsSelector } from "../selectors/";
|
|
6
9
|
import PendingStructureNoteRow from "./PendingStructureNoteRow";
|
|
7
10
|
|
|
8
|
-
const PendingStructureNotesTable = ({
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
+
const PendingStructureNotesTable = ({ columns }) => {
|
|
12
|
+
const { searchData, sortColumn, sortDirection, handleSortSelection } =
|
|
13
|
+
useSearchContext();
|
|
14
|
+
const structures = searchData?.data;
|
|
15
|
+
|
|
16
|
+
return _.isEmpty(structures) ? (
|
|
11
17
|
<Header as="h4">
|
|
12
18
|
<Icon name="search" />
|
|
13
19
|
<Header.Content>
|
|
@@ -15,48 +21,51 @@ const PendingStructureNotesTable = ({ structureNotes, loading }) => {
|
|
|
15
21
|
</Header.Content>
|
|
16
22
|
</Header>
|
|
17
23
|
) : (
|
|
18
|
-
<Table selectable>
|
|
24
|
+
<Table selectable sortable>
|
|
19
25
|
<Table.Header>
|
|
20
26
|
<Table.Row>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
content={formatMessage({
|
|
43
|
-
id: "pendingStructureNotes.props.path",
|
|
44
|
-
})}
|
|
45
|
-
/>
|
|
27
|
+
{columns &&
|
|
28
|
+
columns.map((column, key) => (
|
|
29
|
+
<Table.HeaderCell
|
|
30
|
+
key={key}
|
|
31
|
+
width={column.width}
|
|
32
|
+
content={
|
|
33
|
+
<FormattedMessage
|
|
34
|
+
id={`pendingStructureNotes.props.${
|
|
35
|
+
column.header || column.name
|
|
36
|
+
}`}
|
|
37
|
+
/>
|
|
38
|
+
}
|
|
39
|
+
sorted={
|
|
40
|
+
_.path("sort.name")(column) === sortColumn
|
|
41
|
+
? sortDirection
|
|
42
|
+
: null
|
|
43
|
+
}
|
|
44
|
+
className={_.path("sort.name")(column) ? "" : "disabled"}
|
|
45
|
+
onClick={() => handleSortSelection(_.path("sort.name")(column))}
|
|
46
|
+
/>
|
|
47
|
+
))}
|
|
46
48
|
</Table.Row>
|
|
47
49
|
</Table.Header>
|
|
48
50
|
<Table.Body>
|
|
49
|
-
{
|
|
50
|
-
<PendingStructureNoteRow
|
|
51
|
+
{structures.map((structure, key) => (
|
|
52
|
+
<PendingStructureNoteRow
|
|
53
|
+
key={key}
|
|
54
|
+
structure={structure}
|
|
55
|
+
columns={columns}
|
|
56
|
+
/>
|
|
51
57
|
))}
|
|
52
58
|
</Table.Body>
|
|
53
59
|
</Table>
|
|
54
60
|
);
|
|
55
61
|
};
|
|
56
62
|
|
|
63
|
+
const mapStateToProps = (state) => ({
|
|
64
|
+
columns: getStructureNotesColumnsSelector(state),
|
|
65
|
+
});
|
|
66
|
+
|
|
57
67
|
PendingStructureNotesTable.propTypes = {
|
|
58
|
-
|
|
59
|
-
loading: PropTypes.bool,
|
|
68
|
+
columns: PropTypes.array,
|
|
60
69
|
};
|
|
61
70
|
|
|
62
|
-
export default PendingStructureNotesTable;
|
|
71
|
+
export default connect(mapStateToProps)(PendingStructureNotesTable);
|
|
@@ -24,7 +24,7 @@ export const ReferenceDatasetForm = ({ saving, dataset = {}, onSubmit }) => {
|
|
|
24
24
|
const { formatMessage } = useIntl();
|
|
25
25
|
const [domainsLoading, setDomainsLoading] = useState(true);
|
|
26
26
|
const { handleSubmit, control, formState } = useForm({
|
|
27
|
-
mode: "
|
|
27
|
+
mode: "onTouched",
|
|
28
28
|
defaultValues: {
|
|
29
29
|
name: dataset?.name || "",
|
|
30
30
|
domain_ids: dataset?.domain_ids || [],
|
|
@@ -10,7 +10,7 @@ export const TagForm = ({ loading, onSubmit, saving, tag }) => {
|
|
|
10
10
|
const [domainsLoading, setDomainsLoading] = useState(true);
|
|
11
11
|
const { formatMessage } = useIntl();
|
|
12
12
|
const { handleSubmit, control, formState } = useForm({
|
|
13
|
-
mode: "
|
|
13
|
+
mode: "onTouched",
|
|
14
14
|
defaultValues: _.pick(["name", "description", "domainIds"])(tag),
|
|
15
15
|
});
|
|
16
16
|
|
|
@@ -1,36 +1,113 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { waitFor } from "@testing-library/react";
|
|
3
2
|
import { render } from "@truedat/test/render";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { getStructureNotesColumnsSelector } from "../../selectors";
|
|
4
5
|
import PendingStructureNoteRow from "../PendingStructureNoteRow";
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
const mockHistory = {
|
|
8
|
+
push: jest.fn(),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
jest.mock("react-router-dom", () => ({
|
|
12
|
+
...jest.requireActual("react-router-dom"),
|
|
13
|
+
useHistory: () => mockHistory,
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
const columns = getStructureNotesColumnsSelector({});
|
|
17
|
+
|
|
18
|
+
const structure = {
|
|
19
|
+
id: "7207",
|
|
20
|
+
note: { status: "draft" },
|
|
21
|
+
name: "bar",
|
|
22
|
+
path: ["bar rute"],
|
|
23
|
+
domains: [{ name: "bar domain" }, { name: "baz domain" }],
|
|
24
|
+
system: { name: "bar system" },
|
|
25
|
+
non_published_note: { id: 1, status: "draft" },
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const messages = {
|
|
29
|
+
en: {
|
|
30
|
+
"pendingStructureNotes.props.domain": "Domain",
|
|
31
|
+
"pendingStructureNotes.props.status": "Status",
|
|
32
|
+
"pendingStructureNotes.props.name": "Name",
|
|
33
|
+
"search.placeholder": "Search...",
|
|
34
|
+
"pendingStructureNotes.props.path": "Path",
|
|
35
|
+
"pendingStructureNotes.props.system": "System",
|
|
36
|
+
"pendingStructureNotes.search.results.empty": "Empty",
|
|
37
|
+
"structures.retrieved.results": "{count} structures found",
|
|
38
|
+
"pendingStructureNotes.subheader": "Subheader",
|
|
39
|
+
"pendingStructureNotes.header": "Header",
|
|
40
|
+
"pendingStructureNotes.status.rejected": "Rejected",
|
|
41
|
+
"pendingStructureNotes.status.draft": "Draft",
|
|
18
42
|
},
|
|
19
43
|
};
|
|
20
44
|
|
|
45
|
+
const renderOpts = { messages };
|
|
46
|
+
|
|
47
|
+
const props = {
|
|
48
|
+
structure,
|
|
49
|
+
columns,
|
|
50
|
+
};
|
|
51
|
+
|
|
21
52
|
describe("<PendingStructureNoteRow />", () => {
|
|
22
53
|
it("matches the latest snapshot", async () => {
|
|
23
|
-
const { container
|
|
54
|
+
const { container } = render(
|
|
24
55
|
<table>
|
|
25
56
|
<tbody>
|
|
26
57
|
<PendingStructureNoteRow {...props} />
|
|
27
58
|
</tbody>
|
|
28
|
-
</table
|
|
59
|
+
</table>,
|
|
60
|
+
renderOpts
|
|
29
61
|
);
|
|
62
|
+
|
|
30
63
|
expect(container).toMatchSnapshot();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("navigates to the job route when row is clicked", () => {
|
|
67
|
+
const props = { columns, structure };
|
|
68
|
+
const { getByText } = render(
|
|
69
|
+
<table>
|
|
70
|
+
<tbody>
|
|
71
|
+
<PendingStructureNoteRow {...props} />
|
|
72
|
+
</tbody>
|
|
73
|
+
</table>,
|
|
74
|
+
renderOpts
|
|
75
|
+
);
|
|
76
|
+
userEvent.click(getByText(/bar system/));
|
|
77
|
+
expect(mockHistory.push.mock.calls.length).toBe(1);
|
|
78
|
+
expect(mockHistory.push.mock.calls[0][0]).toBe("/structures/7207");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("renders empty table if structure is empty", () => {
|
|
82
|
+
const emptyStructure = {};
|
|
83
|
+
const { queryByText } = render(
|
|
84
|
+
<table>
|
|
85
|
+
<tbody>
|
|
86
|
+
<PendingStructureNoteRow
|
|
87
|
+
structure={emptyStructure}
|
|
88
|
+
columns={columns}
|
|
89
|
+
/>
|
|
90
|
+
</tbody>
|
|
91
|
+
</table>,
|
|
92
|
+
renderOpts
|
|
93
|
+
);
|
|
94
|
+
expect(queryByText("bar system")).not.toBeInTheDocument();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("renders empty table columns are empty", () => {
|
|
98
|
+
const emptyColumns = [];
|
|
99
|
+
const { queryByText } = render(
|
|
100
|
+
<table>
|
|
101
|
+
<tbody>
|
|
102
|
+
<PendingStructureNoteRow
|
|
103
|
+
structure={structure}
|
|
104
|
+
columns={emptyColumns}
|
|
105
|
+
/>
|
|
106
|
+
</tbody>
|
|
107
|
+
</table>,
|
|
108
|
+
renderOpts
|
|
109
|
+
);
|
|
31
110
|
|
|
32
|
-
|
|
33
|
-
expect(queryByText(/bar system/)).toBeTruthy();
|
|
34
|
-
});
|
|
111
|
+
expect(queryByText("bar system")).not.toBeInTheDocument();
|
|
35
112
|
});
|
|
36
113
|
});
|