@openneuro/app 4.2.4 → 4.3.0-alpha.1

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.
Files changed (75) hide show
  1. package/jestsetup.ts +0 -5
  2. package/package.json +7 -12
  3. package/src/scripts/common/forms/__tests__/__snapshots__/warn-button.spec.jsx.snap +26 -26
  4. package/src/scripts/common/forms/__tests__/warn-button.spec.jsx +7 -5
  5. package/src/scripts/datalad/dataset/dataset-query-fragments.js +6 -0
  6. package/src/scripts/datalad/subscriptions/__tests__/__snapshots__/files-subscription.spec.jsx.snap +1 -159
  7. package/src/scripts/datalad/subscriptions/__tests__/files-subscription.spec.jsx +6 -3
  8. package/src/scripts/errors/errorRoute.jsx +4 -23
  9. package/src/scripts/faq/__tests__/__snapshots__/faq.spec.jsx.snap +183 -154
  10. package/src/scripts/faq/__tests__/faq.spec.jsx +3 -3
  11. package/src/scripts/refactor_2021/admin/admin.jsx +1 -7
  12. package/src/scripts/refactor_2021/dataset/comments/__tests__/__snapshots__/comments.spec.jsx.snap +12 -110
  13. package/src/scripts/refactor_2021/dataset/comments/__tests__/comments.spec.jsx +7 -5
  14. package/src/scripts/refactor_2021/dataset/dataset-query.jsx +2 -4
  15. package/src/scripts/refactor_2021/dataset/dataset-routes.jsx +6 -11
  16. package/src/scripts/refactor_2021/dataset/download/__tests__/__snapshots__/download-command-line.spec.jsx.snap +8 -9
  17. package/src/scripts/refactor_2021/dataset/download/__tests__/__snapshots__/download-link.spec.jsx.snap +46 -1255
  18. package/src/scripts/refactor_2021/dataset/download/__tests__/__snapshots__/shell-example.spec.jsx.snap +3 -4
  19. package/src/scripts/refactor_2021/dataset/download/__tests__/download-command-line.spec.jsx +10 -11
  20. package/src/scripts/refactor_2021/dataset/download/__tests__/download-link.spec.jsx +3 -3
  21. package/src/scripts/refactor_2021/dataset/download/__tests__/shell-example.spec.jsx +3 -3
  22. package/src/scripts/refactor_2021/dataset/download/download-command-line.jsx +1 -1
  23. package/src/scripts/refactor_2021/dataset/draft-container.tsx +6 -23
  24. package/src/scripts/refactor_2021/dataset/draft-snapshot-routes.tsx +1 -6
  25. package/src/scripts/refactor_2021/dataset/files/__tests__/__snapshots__/file-tree.spec.jsx.snap +24 -49
  26. package/src/scripts/refactor_2021/dataset/files/__tests__/__snapshots__/file.spec.jsx.snap +74 -54
  27. package/src/scripts/refactor_2021/dataset/files/__tests__/file-tree-unloaded-directory.spec.jsx +4 -3
  28. package/src/scripts/refactor_2021/dataset/files/__tests__/file-tree.spec.jsx +23 -19
  29. package/src/scripts/refactor_2021/dataset/files/__tests__/file-viewer-type.spec.jsx +5 -3
  30. package/src/scripts/refactor_2021/dataset/files/__tests__/file.spec.jsx +21 -21
  31. package/src/scripts/refactor_2021/dataset/files/file.jsx +3 -2
  32. package/src/scripts/refactor_2021/dataset/files/viewers/__tests__/__snapshots__/file-viewer-json.spec.jsx.snap +85 -60
  33. package/src/scripts/refactor_2021/dataset/files/viewers/__tests__/file-viewer-json.spec.jsx +5 -5
  34. package/src/scripts/refactor_2021/dataset/fragments/__tests__/__snapshots__/cancel-button.spec.tsx.snap +14 -6
  35. package/src/scripts/refactor_2021/dataset/fragments/__tests__/__snapshots__/edit-button.spec.tsx.snap +14 -6
  36. package/src/scripts/refactor_2021/dataset/fragments/__tests__/__snapshots__/save-button.spec.tsx.snap +14 -6
  37. package/src/scripts/refactor_2021/dataset/fragments/__tests__/__snapshots__/select-input.spec.tsx.snap +178 -105
  38. package/src/scripts/refactor_2021/dataset/fragments/__tests__/cancel-button.spec.tsx +3 -3
  39. package/src/scripts/refactor_2021/dataset/fragments/__tests__/dataset-alert-draft.spec.tsx +72 -0
  40. package/src/scripts/refactor_2021/dataset/fragments/__tests__/edit-button.spec.tsx +3 -3
  41. package/src/scripts/refactor_2021/dataset/fragments/__tests__/edit-list.spec.jsx +0 -1
  42. package/src/scripts/refactor_2021/dataset/fragments/__tests__/save-button.spec.tsx +3 -3
  43. package/src/scripts/refactor_2021/dataset/fragments/__tests__/select-input.spec.tsx +9 -9
  44. package/src/scripts/refactor_2021/dataset/fragments/dataset-alert-draft.tsx +79 -0
  45. package/src/scripts/refactor_2021/dataset/fragments/dataset-alert-version.tsx +24 -0
  46. package/src/scripts/refactor_2021/dataset/fragments/select-input.tsx +1 -1
  47. package/src/scripts/refactor_2021/dataset/mutations/__tests__/__snapshots__/deprecate-snapshot.spec.tsx.snap +14 -0
  48. package/src/scripts/refactor_2021/dataset/mutations/__tests__/__snapshots__/deprecate-version.spec.tsx.snap +14 -0
  49. package/src/scripts/refactor_2021/dataset/mutations/__tests__/__snapshots__/description.spec.jsx.snap +3 -277
  50. package/src/scripts/refactor_2021/dataset/mutations/__tests__/deprecate-snapshot.spec.tsx +71 -0
  51. package/src/scripts/refactor_2021/dataset/mutations/__tests__/deprecate-version.spec.tsx +71 -0
  52. package/src/scripts/refactor_2021/dataset/mutations/__tests__/description.spec.jsx +22 -9
  53. package/src/scripts/refactor_2021/dataset/mutations/deprecate-version.tsx +46 -0
  54. package/src/scripts/refactor_2021/dataset/mutations/description.jsx +1 -1
  55. package/src/scripts/refactor_2021/dataset/mutations/readme.jsx +1 -1
  56. package/src/scripts/refactor_2021/dataset/mutations/submit-metadata.jsx +1 -1
  57. package/src/scripts/refactor_2021/dataset/mutations/undo-deprecate-version.tsx +43 -0
  58. package/src/scripts/refactor_2021/dataset/mutations/update-file.jsx +15 -19
  59. package/src/scripts/refactor_2021/dataset/routes/__tests__/__snapshots__/publish.spec.jsx.snap +3 -0
  60. package/src/scripts/refactor_2021/dataset/routes/__tests__/publish.spec.jsx +13 -0
  61. package/src/scripts/refactor_2021/dataset/routes/add-metadata.jsx +0 -1
  62. package/src/scripts/refactor_2021/dataset/routes/deprecate-snapshot-page.tsx +46 -0
  63. package/src/scripts/refactor_2021/dataset/snapshot-container.tsx +19 -23
  64. package/src/scripts/refactor_2021/routes.tsx +9 -9
  65. package/src/scripts/refactor_2021/uploader/uploader-setup-routes.jsx +4 -24
  66. package/src/scripts/refactor_2021/uploader/uploader-status-routes.jsx +1 -6
  67. package/src/scripts/common/forms/__tests__/__snapshots__/input.spec.jsx.snap +0 -13
  68. package/src/scripts/common/forms/__tests__/input.spec.jsx +0 -25
  69. package/src/scripts/common/forms/input.jsx +0 -98
  70. package/src/scripts/datalad/routes/__tests__/__snapshots__/publish.spec.jsx.snap +0 -14
  71. package/src/scripts/datalad/routes/__tests__/publish.spec.jsx +0 -10
  72. package/src/scripts/datalad/routes/mobile-class.tsx +0 -16
  73. package/src/scripts/datalad/routes/publish.jsx +0 -50
  74. package/src/scripts/refactor_2021/dataset/dataset-query-fragments.js +0 -220
  75. package/src/scripts/refactor_2021/dataset/queries/dataset-query-fragments.js +0 -220
@@ -1,10 +1,10 @@
1
1
  import React from 'react'
2
- import { shallow } from 'enzyme'
2
+ import { render } from '@testing-library/react'
3
3
  import { EditButton } from '../edit-button'
4
4
 
5
5
  describe('EditButton component', () => {
6
6
  it('renders with default props', () => {
7
- const wrapper = shallow(<EditButton action={() => {}} />)
8
- expect(wrapper).toMatchSnapshot()
7
+ const { asFragment } = render(<EditButton action={() => {}} />)
8
+ expect(asFragment()).toMatchSnapshot()
9
9
  })
10
10
  })
@@ -2,7 +2,6 @@ import React from 'react'
2
2
  import { render, fireEvent, screen } from '@testing-library/react'
3
3
  import EditList from '../edit-list.jsx'
4
4
 
5
- // Mount is used because enzyme does not yet support hooks
6
5
  describe('EditList component', () => {
7
6
  it('renders with default props', () => {
8
7
  const { asFragment } = render(<EditList />)
@@ -1,10 +1,10 @@
1
1
  import React from 'react'
2
- import { shallow } from 'enzyme'
2
+ import { render } from '@testing-library/react'
3
3
  import { SaveButton } from '../save-button'
4
4
 
5
5
  describe('SaveButton component', () => {
6
6
  it('renders with default props', () => {
7
- const wrapper = shallow(<SaveButton action={() => {}} />)
8
- expect(wrapper).toMatchSnapshot()
7
+ const { asFragment } = render(<SaveButton action={() => {}} />)
8
+ expect(asFragment()).toMatchSnapshot()
9
9
  })
10
10
  })
@@ -1,10 +1,10 @@
1
1
  import React from 'react'
2
- import { shallow } from 'enzyme'
2
+ import { render, fireEvent, screen } from '@testing-library/react'
3
3
  import SelectInput from '../select-input'
4
4
 
5
5
  describe('SelectInput', () => {
6
6
  it('handles display as disabled', () => {
7
- const wrapper = shallow(
7
+ const { asFragment } = render(
8
8
  <SelectInput
9
9
  {...{
10
10
  name: 'Expected name',
@@ -16,10 +16,10 @@ describe('SelectInput', () => {
16
16
  }}
17
17
  />,
18
18
  )
19
- expect(wrapper).toMatchSnapshot()
19
+ expect(asFragment()).toMatchSnapshot()
20
20
  })
21
21
  it('handles display as not disabled', () => {
22
- const wrapper = shallow(
22
+ const { asFragment } = render(
23
23
  <SelectInput
24
24
  {...{
25
25
  name: 'Expected name',
@@ -31,10 +31,10 @@ describe('SelectInput', () => {
31
31
  }}
32
32
  />,
33
33
  )
34
- expect(wrapper).toMatchSnapshot()
34
+ expect(asFragment()).toMatchSnapshot()
35
35
  })
36
36
  it('handles boolean display', () => {
37
- const wrapper = shallow(
37
+ const { asFragment } = render(
38
38
  <SelectInput
39
39
  {...{
40
40
  name: 'Expected name',
@@ -50,12 +50,12 @@ describe('SelectInput', () => {
50
50
  }}
51
51
  />,
52
52
  )
53
- expect(wrapper).toMatchSnapshot()
53
+ expect(asFragment()).toMatchSnapshot()
54
54
  })
55
55
  it('handles boolean values', () => {
56
56
  let _, value
57
57
  const onChange = (...args) => ([_, value] = args)
58
- const wrapper = shallow(
58
+ render(
59
59
  <SelectInput
60
60
  {...{
61
61
  name: 'Expected name',
@@ -78,7 +78,7 @@ describe('SelectInput', () => {
78
78
  },
79
79
  target: { value: 'false' },
80
80
  }
81
- wrapper.find('styledSelect[name="Expected name"]').simulate('change', event)
81
+ fireEvent.change(screen.getByRole('combobox'), event)
82
82
  expect(value).toBe(false)
83
83
  })
84
84
  })
@@ -0,0 +1,79 @@
1
+ import React from 'react'
2
+ import { Link } from 'react-router-dom'
3
+ import { DatasetAlert } from '@openneuro/components/dataset'
4
+
5
+ export interface DatasetAlertDraftProps {
6
+ isPrivate: boolean
7
+ datasetId: string
8
+ hasDraftChanges: boolean
9
+ hasSnapshot: boolean
10
+ }
11
+
12
+ export const DatasetAlertDraft: React.FC<DatasetAlertDraftProps> = ({
13
+ isPrivate,
14
+ datasetId,
15
+ hasDraftChanges,
16
+ hasSnapshot,
17
+ }) => {
18
+ if (isPrivate) {
19
+ if (hasSnapshot) {
20
+ return (
21
+ <DatasetAlert
22
+ alert="This dataset has not been published!"
23
+ footer={
24
+ hasDraftChanges &&
25
+ '* There have been changes to the draft since your last version'
26
+ }
27
+ level="warning">
28
+ <>
29
+ <Link
30
+ className="dataset-tool"
31
+ to={'/datasets/' + datasetId + '/publish'}>
32
+ Publish this dataset
33
+ </Link>
34
+ &#32; to make all versions available publicly.
35
+ </>
36
+ </DatasetAlert>
37
+ )
38
+ } else {
39
+ return (
40
+ <DatasetAlert
41
+ alert="This dataset has not been published!"
42
+ level="warning">
43
+ Before it can be published, please&#32;
44
+ <Link
45
+ className="dataset-tool"
46
+ to={'/datasets/' + datasetId + '/snapshot'}>
47
+ create a version
48
+ </Link>
49
+ </DatasetAlert>
50
+ )
51
+ }
52
+ } else {
53
+ if (hasDraftChanges) {
54
+ return (
55
+ <DatasetAlert alert="This dataset has been published!" level="warning">
56
+ There are currently unsaved changes to this Draft. Changes made here
57
+ become public when you&#32;
58
+ <Link
59
+ className="dataset-tool"
60
+ to={'/datasets/' + datasetId + '/snapshot'}>
61
+ create a new version.
62
+ </Link>
63
+ </DatasetAlert>
64
+ )
65
+ } else {
66
+ return (
67
+ <DatasetAlert alert="This dataset has been published!">
68
+ You can make changes to this Draft page, then&#32;
69
+ <Link
70
+ className="dataset-tool"
71
+ to={'/datasets/' + datasetId + '/snapshot'}>
72
+ create a new version
73
+ </Link>
74
+ &#32;to make them public.
75
+ </DatasetAlert>
76
+ )
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,24 @@
1
+ import React from 'react'
2
+ import { DatasetAlert } from '@openneuro/components/dataset'
3
+ import { UndoDeprecateVersion } from '../mutations/undo-deprecate-version'
4
+
5
+ export interface DatasetAlertVersionProps {
6
+ datasetId: string
7
+ tag: string
8
+ reason: string
9
+ hasEdit: boolean
10
+ }
11
+
12
+ export const DatasetAlertVersion: React.FC<DatasetAlertVersionProps> = ({
13
+ datasetId,
14
+ tag,
15
+ reason,
16
+ hasEdit,
17
+ }) => (
18
+ <DatasetAlert
19
+ alert="This version has been deprecated!"
20
+ level="error"
21
+ footer={reason}>
22
+ {hasEdit && <UndoDeprecateVersion datasetId={datasetId} tag={tag} />}
23
+ </DatasetAlert>
24
+ )
@@ -70,7 +70,7 @@ const Select = styled.select<ShowOtherProps>(
70
70
  height: '100%',
71
71
  color: 'rgba(0,0,0,0)',
72
72
  backgroundColor: 'rgba(0,0,0,0)',
73
- '-moz-appearance': 'none',
73
+ MozAppearance: 'none',
74
74
  },
75
75
  },
76
76
  ({ showOther }) =>
@@ -0,0 +1,14 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`DeprecateVersion mutation renders with typical props 1`] = `
4
+ <DocumentFragment>
5
+ <button
6
+ aria-label="Deprecate Version"
7
+ class="on-button on-button--small on-button--primary btn-modal-action"
8
+ role="button"
9
+ type="button"
10
+ >
11
+ Deprecate Version
12
+ </button>
13
+ </DocumentFragment>
14
+ `;
@@ -0,0 +1,14 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`DeprecateVersion mutation renders with typical props 1`] = `
4
+ <DocumentFragment>
5
+ <button
6
+ aria-label="Deprecate Version"
7
+ class="on-button on-button--small on-button--primary btn-modal-action"
8
+ role="button"
9
+ type="button"
10
+ >
11
+ Deprecate Version
12
+ </button>
13
+ </DocumentFragment>
14
+ `;
@@ -1,281 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`UpdateDescription mutation renders with common props 1`] = `
4
- <Mutation
5
- mutation={
6
- Object {
7
- "definitions": Array [
8
- Object {
9
- "directives": Array [],
10
- "kind": "OperationDefinition",
11
- "name": Object {
12
- "kind": "Name",
13
- "value": "updateDescription",
14
- },
15
- "operation": "mutation",
16
- "selectionSet": Object {
17
- "kind": "SelectionSet",
18
- "selections": Array [
19
- Object {
20
- "alias": undefined,
21
- "arguments": Array [
22
- Object {
23
- "kind": "Argument",
24
- "name": Object {
25
- "kind": "Name",
26
- "value": "datasetId",
27
- },
28
- "value": Object {
29
- "kind": "Variable",
30
- "name": Object {
31
- "kind": "Name",
32
- "value": "datasetId",
33
- },
34
- },
35
- },
36
- Object {
37
- "kind": "Argument",
38
- "name": Object {
39
- "kind": "Name",
40
- "value": "field",
41
- },
42
- "value": Object {
43
- "kind": "Variable",
44
- "name": Object {
45
- "kind": "Name",
46
- "value": "field",
47
- },
48
- },
49
- },
50
- Object {
51
- "kind": "Argument",
52
- "name": Object {
53
- "kind": "Name",
54
- "value": "value",
55
- },
56
- "value": Object {
57
- "kind": "Variable",
58
- "name": Object {
59
- "kind": "Name",
60
- "value": "value",
61
- },
62
- },
63
- },
64
- ],
65
- "directives": Array [],
66
- "kind": "Field",
67
- "name": Object {
68
- "kind": "Name",
69
- "value": "updateDescription",
70
- },
71
- "selectionSet": Object {
72
- "kind": "SelectionSet",
73
- "selections": Array [
74
- Object {
75
- "alias": undefined,
76
- "arguments": Array [],
77
- "directives": Array [],
78
- "kind": "Field",
79
- "name": Object {
80
- "kind": "Name",
81
- "value": "id",
82
- },
83
- "selectionSet": undefined,
84
- },
85
- Object {
86
- "alias": undefined,
87
- "arguments": Array [],
88
- "directives": Array [],
89
- "kind": "Field",
90
- "name": Object {
91
- "kind": "Name",
92
- "value": "Name",
93
- },
94
- "selectionSet": undefined,
95
- },
96
- Object {
97
- "alias": undefined,
98
- "arguments": Array [],
99
- "directives": Array [],
100
- "kind": "Field",
101
- "name": Object {
102
- "kind": "Name",
103
- "value": "BIDSVersion",
104
- },
105
- "selectionSet": undefined,
106
- },
107
- Object {
108
- "alias": undefined,
109
- "arguments": Array [],
110
- "directives": Array [],
111
- "kind": "Field",
112
- "name": Object {
113
- "kind": "Name",
114
- "value": "License",
115
- },
116
- "selectionSet": undefined,
117
- },
118
- Object {
119
- "alias": undefined,
120
- "arguments": Array [],
121
- "directives": Array [],
122
- "kind": "Field",
123
- "name": Object {
124
- "kind": "Name",
125
- "value": "Authors",
126
- },
127
- "selectionSet": undefined,
128
- },
129
- Object {
130
- "alias": undefined,
131
- "arguments": Array [],
132
- "directives": Array [],
133
- "kind": "Field",
134
- "name": Object {
135
- "kind": "Name",
136
- "value": "Acknowledgements",
137
- },
138
- "selectionSet": undefined,
139
- },
140
- Object {
141
- "alias": undefined,
142
- "arguments": Array [],
143
- "directives": Array [],
144
- "kind": "Field",
145
- "name": Object {
146
- "kind": "Name",
147
- "value": "HowToAcknowledge",
148
- },
149
- "selectionSet": undefined,
150
- },
151
- Object {
152
- "alias": undefined,
153
- "arguments": Array [],
154
- "directives": Array [],
155
- "kind": "Field",
156
- "name": Object {
157
- "kind": "Name",
158
- "value": "Funding",
159
- },
160
- "selectionSet": undefined,
161
- },
162
- Object {
163
- "alias": undefined,
164
- "arguments": Array [],
165
- "directives": Array [],
166
- "kind": "Field",
167
- "name": Object {
168
- "kind": "Name",
169
- "value": "ReferencesAndLinks",
170
- },
171
- "selectionSet": undefined,
172
- },
173
- Object {
174
- "alias": undefined,
175
- "arguments": Array [],
176
- "directives": Array [],
177
- "kind": "Field",
178
- "name": Object {
179
- "kind": "Name",
180
- "value": "DatasetDOI",
181
- },
182
- "selectionSet": undefined,
183
- },
184
- Object {
185
- "alias": undefined,
186
- "arguments": Array [],
187
- "directives": Array [],
188
- "kind": "Field",
189
- "name": Object {
190
- "kind": "Name",
191
- "value": "EthicsApprovals",
192
- },
193
- "selectionSet": undefined,
194
- },
195
- ],
196
- },
197
- },
198
- ],
199
- },
200
- "variableDefinitions": Array [
201
- Object {
202
- "defaultValue": undefined,
203
- "directives": Array [],
204
- "kind": "VariableDefinition",
205
- "type": Object {
206
- "kind": "NonNullType",
207
- "type": Object {
208
- "kind": "NamedType",
209
- "name": Object {
210
- "kind": "Name",
211
- "value": "ID",
212
- },
213
- },
214
- },
215
- "variable": Object {
216
- "kind": "Variable",
217
- "name": Object {
218
- "kind": "Name",
219
- "value": "datasetId",
220
- },
221
- },
222
- },
223
- Object {
224
- "defaultValue": undefined,
225
- "directives": Array [],
226
- "kind": "VariableDefinition",
227
- "type": Object {
228
- "kind": "NonNullType",
229
- "type": Object {
230
- "kind": "NamedType",
231
- "name": Object {
232
- "kind": "Name",
233
- "value": "String",
234
- },
235
- },
236
- },
237
- "variable": Object {
238
- "kind": "Variable",
239
- "name": Object {
240
- "kind": "Name",
241
- "value": "field",
242
- },
243
- },
244
- },
245
- Object {
246
- "defaultValue": undefined,
247
- "directives": Array [],
248
- "kind": "VariableDefinition",
249
- "type": Object {
250
- "kind": "NonNullType",
251
- "type": Object {
252
- "kind": "NamedType",
253
- "name": Object {
254
- "kind": "Name",
255
- "value": "String",
256
- },
257
- },
258
- },
259
- "variable": Object {
260
- "kind": "Variable",
261
- "name": Object {
262
- "kind": "Name",
263
- "value": "value",
264
- },
265
- },
266
- },
267
- ],
268
- },
269
- ],
270
- "kind": "Document",
271
- "loc": Object {
272
- "end": 374,
273
- "start": 0,
274
- },
275
- }
276
- }
277
- update={[Function]}
278
- >
279
- <Component />
280
- </Mutation>
4
+ <DocumentFragment>
5
+ Mutation mock
6
+ </DocumentFragment>
281
7
  `;
@@ -0,0 +1,71 @@
1
+ import React from 'react'
2
+ import { render, fireEvent, screen, waitFor } from '@testing-library/react'
3
+ import { MockedProvider } from '@apollo/client/testing'
4
+ import { Router } from 'react-router-dom'
5
+ import { createMemoryHistory } from 'history'
6
+ import { DeprecateVersion, DEPRECATE_VERSION } from '../deprecate-version'
7
+
8
+ describe('DeprecateVersion mutation', () => {
9
+ it('renders with typical props', () => {
10
+ const { asFragment } = render(
11
+ <MockedProvider>
12
+ <DeprecateVersion
13
+ datasetId="test00001"
14
+ tag="1.0.0"
15
+ reason="This is a test suite."
16
+ />
17
+ </MockedProvider>,
18
+ )
19
+ expect(asFragment()).toMatchSnapshot()
20
+ })
21
+ it('calls the DEPRECATE_VERSION mutation when clicked and navigates to the snapshot on success', async () => {
22
+ const datasetId = 'test00001'
23
+ const tag = '1.0.0'
24
+ const reason = 'This is a test suite.'
25
+ const history = createMemoryHistory({
26
+ initialEntries: [`/datasets/${datasetId}/versions/${tag}/deprecate`],
27
+ })
28
+ const historyPushSpy = jest.spyOn(history, 'push')
29
+ const snapshotId = `${datasetId}:${tag}`
30
+ const deprecateSnapshotMock = {
31
+ request: {
32
+ query: DEPRECATE_VERSION,
33
+ variables: {
34
+ datasetId,
35
+ tag,
36
+ reason,
37
+ },
38
+ },
39
+ result: {
40
+ data: {
41
+ deprecateSnapshot: {
42
+ __typename: 'Snapshot',
43
+ id: snapshotId,
44
+ deprecated: {
45
+ __typename: 'DeprecatedSnapshot',
46
+ id: snapshotId,
47
+ user: '1245',
48
+ reason,
49
+ },
50
+ },
51
+ },
52
+ },
53
+ }
54
+
55
+ render(
56
+ <Router history={history}>
57
+ <MockedProvider mocks={[deprecateSnapshotMock]} addTypename={false}>
58
+ <DeprecateVersion datasetId={datasetId} tag={tag} reason={reason} />
59
+ </MockedProvider>
60
+ </Router>,
61
+ )
62
+
63
+ fireEvent.click(screen.getByLabelText(/Deprecate Version/i))
64
+
65
+ await waitFor(() => expect(historyPushSpy).toHaveBeenCalledTimes(1))
66
+
67
+ expect(history.location.pathname).toBe(
68
+ `/datasets/${datasetId}/versions/${tag}`,
69
+ )
70
+ })
71
+ })
@@ -0,0 +1,71 @@
1
+ import React from 'react'
2
+ import { render, fireEvent, screen, waitFor } from '@testing-library/react'
3
+ import { MockedProvider } from '@apollo/client/testing'
4
+ import { Router } from 'react-router-dom'
5
+ import { createMemoryHistory } from 'history'
6
+ import { DeprecateVersion, DEPRECATE_VERSION } from '../deprecate-version'
7
+
8
+ describe('DeprecateVersion mutation', () => {
9
+ it('renders with typical props', () => {
10
+ const { asFragment } = render(
11
+ <MockedProvider>
12
+ <DeprecateVersion
13
+ datasetId="test00001"
14
+ tag="1.0.0"
15
+ reason="This is a test suite."
16
+ />
17
+ </MockedProvider>,
18
+ )
19
+ expect(asFragment()).toMatchSnapshot()
20
+ })
21
+ it('calls the DEPRECATE_VERSION mutation when clicked and navigates to the snapshot on success', async () => {
22
+ const datasetId = 'test00001'
23
+ const tag = '1.0.0'
24
+ const reason = 'This is a test suite.'
25
+ const history = createMemoryHistory({
26
+ initialEntries: [`/datasets/${datasetId}/versions/${tag}/deprecate`],
27
+ })
28
+ const historyPushSpy = jest.spyOn(history, 'push')
29
+ const snapshotId = `${datasetId}:${tag}`
30
+ const deprecateSnapshotMock = {
31
+ request: {
32
+ query: DEPRECATE_VERSION,
33
+ variables: {
34
+ datasetId,
35
+ tag,
36
+ reason,
37
+ },
38
+ },
39
+ result: {
40
+ data: {
41
+ deprecateSnapshot: {
42
+ __typename: 'Snapshot',
43
+ id: snapshotId,
44
+ deprecated: {
45
+ __typename: 'DeprecatedSnapshot',
46
+ id: snapshotId,
47
+ user: '1245',
48
+ reason,
49
+ },
50
+ },
51
+ },
52
+ },
53
+ }
54
+
55
+ render(
56
+ <Router history={history}>
57
+ <MockedProvider mocks={[deprecateSnapshotMock]} addTypename={false}>
58
+ <DeprecateVersion datasetId={datasetId} tag={tag} reason={reason} />
59
+ </MockedProvider>
60
+ </Router>,
61
+ )
62
+
63
+ fireEvent.click(screen.getByLabelText(/Deprecate Version/i))
64
+
65
+ await waitFor(() => expect(historyPushSpy).toHaveBeenCalledTimes(1))
66
+
67
+ expect(history.location.pathname).toBe(
68
+ `/datasets/${datasetId}/versions/${tag}`,
69
+ )
70
+ })
71
+ })