@openneuro/app 4.2.3 → 4.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/jestsetup.ts +0 -5
  2. package/package.json +8 -13
  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,9 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`dataset/download/ShellExample renders successfully 1`] = `
4
- <Fragment>
5
- <Noop />
4
+ <DocumentFragment>
6
5
  <pre
7
- className="css-xak41w"
6
+ class="css-xak41w"
8
7
  />
9
- </Fragment>
8
+ </DocumentFragment>
10
9
  `;
@@ -1,5 +1,6 @@
1
1
  import React from 'react'
2
- import { shallow } from 'enzyme'
2
+ import { render, screen } from '@testing-library/react'
3
+ import '@testing-library/jest-dom/extend-expect'
3
4
  import { DownloadSampleCommand } from '../download-command-line.jsx'
4
5
 
5
6
  const defProps = { datasetId: 'ds000001' }
@@ -7,20 +8,18 @@ const defProps = { datasetId: 'ds000001' }
7
8
  describe('dataset/download', () => {
8
9
  describe('DownloadSampleCommand component', () => {
9
10
  it('renders successfully', () => {
10
- const wrapper = shallow(<DownloadSampleCommand {...defProps} />)
11
- expect(wrapper).toMatchSnapshot()
11
+ const { asFragment } = render(<DownloadSampleCommand {...defProps} />)
12
+ expect(asFragment()).toMatchSnapshot()
12
13
  })
13
14
  it('drafts show draft flag', () => {
14
- const wrapper = shallow(<DownloadSampleCommand {...defProps} />)
15
- expect(wrapper.text()).toEqual(expect.stringContaining('--draft'))
16
- expect(wrapper.text()).toEqual(expect.not.stringContaining('--snapshot'))
15
+ render(<DownloadSampleCommand {...defProps} />)
16
+ expect(screen.getByRole('figure')).toHaveTextContent('--draft')
17
+ expect(screen.queryByText('--snapshot')).not.toBeInTheDocument()
17
18
  })
18
19
  it('snapshots show snapshot flag', () => {
19
- const wrapper = shallow(
20
- <DownloadSampleCommand {...defProps} snapshotTag="1.0.0" />,
21
- )
22
- expect(wrapper.text()).toEqual(expect.stringContaining('--snapshot'))
23
- expect(wrapper.text()).toEqual(expect.not.stringContaining('--draft'))
20
+ render(<DownloadSampleCommand {...defProps} snapshotTag="1.0.0" />)
21
+ expect(screen.getByRole('figure')).toHaveTextContent('--snapshot')
22
+ expect(screen.queryByText('--draft')).not.toBeInTheDocument()
24
23
  })
25
24
  })
26
25
  })
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { shallow } from 'enzyme'
2
+ import { render } from '@testing-library/react'
3
3
  import DownloadLink from '../download-link.jsx'
4
4
  import { MockedProvider } from '@apollo/client/testing'
5
5
  const defProps = {
@@ -9,11 +9,11 @@ const defProps = {
9
9
 
10
10
  describe('dataset/download/DownloadLink', () => {
11
11
  it('renders successfully', () => {
12
- const wrapper = shallow(
12
+ const { asFragment } = render(
13
13
  <MockedProvider>
14
14
  <DownloadLink {...defProps} />
15
15
  </MockedProvider>,
16
16
  )
17
- expect(wrapper).toMatchSnapshot()
17
+ expect(asFragment()).toMatchSnapshot()
18
18
  })
19
19
  })
@@ -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 ShellExample from '../shell-example.jsx'
4
4
 
5
5
  describe('dataset/download/ShellExample', () => {
6
6
  it('renders successfully', () => {
7
- const wrapper = shallow(<ShellExample />)
8
- expect(wrapper).toMatchSnapshot()
7
+ const { asFragment } = render(<ShellExample />)
8
+ expect(asFragment()).toMatchSnapshot()
9
9
  })
10
10
  })
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
3
3
  import ShellExample from './shell-example.jsx'
4
4
 
5
5
  export const DownloadSampleCommand = ({ datasetId, snapshotTag }) => (
6
- <ShellExample>
6
+ <ShellExample role="figure">
7
7
  openneuro download {snapshotTag ? `--snapshot ${snapshotTag}` : '--draft'}{' '}
8
8
  {datasetId} {datasetId}
9
9
  -download/
@@ -11,9 +11,11 @@ import { config } from '../../config'
11
11
  import {
12
12
  getUnexpiredProfile,
13
13
  hasEditPermissions,
14
+ hasDatasetAdminPermissions,
14
15
  } from '../authentication/profile'
15
16
  import { useCookies } from 'react-cookie'
16
17
  import Comments from './comments/comments.jsx'
18
+ import { DatasetAlertDraft } from './fragments/dataset-alert-draft'
17
19
  import {
18
20
  MetaDataBlock,
19
21
  ModalitiesMetaDataBlock,
@@ -21,14 +23,12 @@ import {
21
23
  ValidationBlock,
22
24
  CloneDropdown,
23
25
  DatasetHeader,
24
- DatasetAlert,
25
26
  DatasetHeaderMeta,
26
27
  DatasetPage,
27
28
  DatasetGitAccess,
28
29
  VersionList,
29
30
  DatasetTools,
30
31
  } from '@openneuro/components/dataset'
31
- import { Modal } from '@openneuro/components/modal'
32
32
  import { ReadMore } from '@openneuro/components/read-more'
33
33
 
34
34
  import { FollowDataset } from './mutations/follow'
@@ -56,8 +56,6 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
56
56
  const activeDataset = snapshotVersion(location) || 'draft'
57
57
 
58
58
  const [selectedVersion, setSelectedVersion] = React.useState(activeDataset)
59
- const [deprecatedmodalIsOpen, setDeprecatedModalIsOpen] =
60
- React.useState(false)
61
59
 
62
60
  const summary = dataset.draft.summary
63
61
  const description = dataset.draft.description
@@ -73,12 +71,7 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
73
71
  parseISO(dataset.draft.modified),
74
72
  )
75
73
  const isSnapshot = activeDataset !== 'draft'
76
- const rootPath = isSnapshot
77
- ? `/datasets/${datasetId}/versions/${activeDataset}`
78
- : `/datasets/${datasetId}`
79
74
 
80
- //TODO deprecated needs to be added to the dataset snapshot obj and an admin needs to be able to say a version is deprecated somehow.
81
- const isPublic = dataset.public === true
82
75
  const [cookies] = useCookies()
83
76
  const profile = getUnexpiredProfile(cookies)
84
77
  const isAdmin = profile?.admin
@@ -88,6 +81,8 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
88
81
  dataset.snapshots.length === 0 ||
89
82
  dataset.draft.head !==
90
83
  dataset.snapshots[dataset.snapshots.length - 1].hexsha
84
+ const isDatasetAdmin =
85
+ hasDatasetAdminPermissions(dataset.permissions, profile?.sub) || isAdmin
91
86
 
92
87
  return (
93
88
  <>
@@ -122,7 +117,7 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
122
117
  renderAlert={() => (
123
118
  <>
124
119
  {hasEdit && (
125
- <DatasetAlert
120
+ <DatasetAlertDraft
126
121
  isPrivate={!dataset.public}
127
122
  datasetId={dataset.id}
128
123
  hasDraftChanges={hasDraftChanges}
@@ -191,6 +186,7 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
191
186
  datasetId={datasetId}
192
187
  isAdmin={isAdmin}
193
188
  hasSnapshot={dataset.snapshots.length !== 0}
189
+ isDatasetAdmin={isDatasetAdmin}
194
190
  />
195
191
  )}
196
192
  renderFiles={() => (
@@ -263,7 +259,6 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
263
259
  dateModified={dateModified}
264
260
  selected={selectedVersion}
265
261
  setSelected={setSelectedVersion}
266
- setDeprecatedModalIsOpen={setDeprecatedModalIsOpen}
267
262
  />
268
263
  </div>
269
264
  }
@@ -427,18 +422,6 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
427
422
  </EditDescriptionList>
428
423
  </>
429
424
  )}
430
- renderDeprecatedModal={() => (
431
- <Modal
432
- isOpen={deprecatedmodalIsOpen}
433
- toggle={() => setDeprecatedModalIsOpen(prevIsOpen => !prevIsOpen)}
434
- closeText={'close'}
435
- className="deprecated-modal">
436
- <p>
437
- You have selected a deprecated version. The author of the dataset
438
- does not recommend this specific version.
439
- </p>
440
- </Modal>
441
- )}
442
425
  renderComments={() => (
443
426
  <Comments
444
427
  datasetId={dataset.id}
@@ -6,15 +6,10 @@ const Dataset = () => {
6
6
  return (
7
7
  <Switch>
8
8
  <Route
9
- name="datalad-snapshot"
10
9
  path="/datasets/:datasetId/versions/:snapshotId"
11
10
  component={DatasetQuery}
12
11
  />
13
- <Route
14
- name="datalad-dataset"
15
- path="/datasets/:datasetId/"
16
- component={DatasetQuery}
17
- />
12
+ <Route path="/datasets/:datasetId/" component={DatasetQuery} />
18
13
  </Switch>
19
14
  )
20
15
  }
@@ -1,59 +1,34 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`FileTree component renders with default props 1`] = `
4
- <FileTree>
5
- <AccordionTab
6
- accordionStyle="file-tree"
7
- className=""
8
- label=""
9
- startOpen={false}
4
+ <DocumentFragment>
5
+ <article
6
+ class="file-tree accordion "
10
7
  >
11
- <article
12
- className="file-tree accordion "
8
+ <div
9
+ class="accordion-title "
13
10
  >
14
- <div
15
- className="accordion-title "
16
- onClick={[Function]}
11
+ <span
12
+ aria-label=""
13
+ class="file-icon on-icon "
14
+ role="img"
17
15
  >
18
- <Icon
19
- className="file-icon"
20
- icon="fas fa-folder"
21
- label=""
22
- >
23
- <span
24
- aria-label=""
25
- className="file-icon on-icon "
26
- role="img"
27
- style={
28
- Object {
29
- "backgroundColor": undefined,
30
- "color": undefined,
31
- }
32
- }
33
- >
34
- <i
35
- className="fas fa-folder"
36
- style={
37
- Object {
38
- "fontSize": undefined,
39
- }
40
- }
41
- />
42
- </span>
43
- </Icon>
44
- </div>
16
+ <i
17
+ class="fas fa-folder"
18
+ />
19
+ </span>
20
+ </div>
21
+ <div
22
+ class="accordion-item collapsed "
23
+ >
45
24
  <div
46
- className="accordion-item collapsed "
25
+ class="accordion-content"
47
26
  >
48
- <div
49
- className="accordion-content"
50
- >
51
- <ul
52
- className="child-files"
53
- />
54
- </div>
27
+ <ul
28
+ class="child-files"
29
+ />
55
30
  </div>
56
- </article>
57
- </AccordionTab>
58
- </FileTree>
31
+ </div>
32
+ </article>
33
+ </DocumentFragment>
59
34
  `;
@@ -1,103 +1,123 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`File component renders for dataset snapshots 1`] = `
4
- <Fragment>
5
- <Icon
6
- color="deepskyblue"
7
- icon="fab fa-markdown"
8
- />
9
-   
10
- README
4
+ <DocumentFragment>
11
5
  <span
12
- className="filetree-editfile"
6
+ aria-label=""
7
+ class=" on-icon "
8
+ role="img"
9
+ style="color: deepskyblue;"
13
10
  >
14
- <Media
15
- className=""
16
- greaterThanOrEqual="medium"
11
+ <i
12
+ class="fab fa-markdown"
13
+ />
14
+ </span>
15
+   README
16
+ <span
17
+ class="filetree-editfile"
18
+ >
19
+ <div
20
+ class="fresnel-container fresnel-greaterThanOrEqual-medium "
17
21
  >
18
- <Tooltip
19
- tooltip="Download"
22
+ <span
23
+ class=" "
24
+ data-flow="up"
25
+ data-tooltip="Download"
20
26
  >
21
27
  <span
22
- className="edit-file download-file"
28
+ class="edit-file download-file"
23
29
  >
24
30
  <a
25
- download={true}
31
+ aria-label="download file"
32
+ download=""
26
33
  href="/crn/datasets/ds001/snapshots/1.0.0/files/README"
27
34
  >
28
35
  <i
29
- className="fa fa-download"
36
+ class="fa fa-download"
30
37
  />
31
38
  </a>
32
39
  </span>
33
- </Tooltip>
34
- </Media>
35
- <Tooltip
36
- tooltip="View"
40
+ </span>
41
+ </div>
42
+ <span
43
+ class=" "
44
+ data-flow="up"
45
+ data-tooltip="View"
37
46
  >
38
47
  <span
39
- className="edit-file view-file"
48
+ class="edit-file view-file"
40
49
  >
41
- <Link
42
- to="/datasets/ds001/versions/1.0.0/file-display/README"
50
+ <a
51
+ aria-label="view file"
52
+ href="/datasets/ds001/versions/1.0.0/file-display/README"
43
53
  >
44
54
  <i
45
- className="fa fa-eye"
55
+ class="fa fa-eye"
46
56
  />
47
- </Link>
57
+ </a>
48
58
  </span>
49
- </Tooltip>
59
+ </span>
50
60
  </span>
51
- </Fragment>
61
+ </DocumentFragment>
52
62
  `;
53
63
 
54
64
  exports[`File component renders with common props 1`] = `
55
- <Fragment>
56
- <Icon
57
- color="deepskyblue"
58
- icon="fab fa-markdown"
59
- />
60
-   
61
- README
65
+ <DocumentFragment>
62
66
  <span
63
- className="filetree-editfile"
67
+ aria-label=""
68
+ class=" on-icon "
69
+ role="img"
70
+ style="color: deepskyblue;"
64
71
  >
65
- <Media
66
- className=""
67
- greaterThanOrEqual="medium"
72
+ <i
73
+ class="fab fa-markdown"
74
+ />
75
+ </span>
76
+   README
77
+ <span
78
+ class="filetree-editfile"
79
+ >
80
+ <div
81
+ class="fresnel-container fresnel-greaterThanOrEqual-medium "
68
82
  >
69
- <Tooltip
70
- tooltip="Download"
83
+ <span
84
+ class=" "
85
+ data-flow="up"
86
+ data-tooltip="Download"
71
87
  >
72
88
  <span
73
- className="edit-file download-file"
89
+ class="edit-file download-file"
74
90
  >
75
91
  <a
76
- download={true}
92
+ aria-label="download file"
93
+ download=""
77
94
  href="/crn/datasets/ds001/files/README"
78
95
  >
79
96
  <i
80
- className="fa fa-download"
97
+ class="fa fa-download"
81
98
  />
82
99
  </a>
83
100
  </span>
84
- </Tooltip>
85
- </Media>
86
- <Tooltip
87
- tooltip="View"
101
+ </span>
102
+ </div>
103
+ <span
104
+ class=" "
105
+ data-flow="up"
106
+ data-tooltip="View"
88
107
  >
89
108
  <span
90
- className="edit-file view-file"
109
+ class="edit-file view-file"
91
110
  >
92
- <Link
93
- to="/datasets/ds001/file-display/README"
111
+ <a
112
+ aria-label="view file"
113
+ href="/datasets/ds001/file-display/README"
94
114
  >
95
115
  <i
96
- className="fa fa-eye"
116
+ class="fa fa-eye"
97
117
  />
98
- </Link>
118
+ </a>
99
119
  </span>
100
- </Tooltip>
120
+ </span>
101
121
  </span>
102
- </Fragment>
122
+ </DocumentFragment>
103
123
  `;
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { mount } from 'enzyme'
2
+ import { render, screen, fireEvent } from '@testing-library/react'
3
3
  import DatasetQueryContext from '../../../../datalad/dataset/dataset-query-context.js'
4
4
  import FileTreeUnloadedDirectory, {
5
5
  mergeNewFiles,
@@ -12,12 +12,13 @@ const dir = {
12
12
  describe('FileTreeUnloadedDirectory component', () => {
13
13
  it('calls fetchMoreDirectory when clicked', () => {
14
14
  const fetchMore = jest.fn()
15
- const wrapper = mount(
15
+ render(
16
16
  <DatasetQueryContext.Provider value={{ fetchMore }}>
17
17
  <FileTreeUnloadedDirectory datasetId={'ds000001'} directory={dir} />
18
18
  </DatasetQueryContext.Provider>,
19
19
  )
20
- wrapper.find('div.accordion-title').simulate('click')
20
+ // Label is filename
21
+ fireEvent.click(screen.getByLabelText(dir.filename))
21
22
  expect(fetchMore).toHaveBeenCalled()
22
23
  })
23
24
  describe('mergeNewFiles', () => {
@@ -1,6 +1,6 @@
1
1
  import React from 'react'
2
- import { mount } from 'enzyme'
3
- import { ApolloProvider } from '@apollo/client'
2
+ import { render, screen, fireEvent } from '@testing-library/react'
3
+ import { MockedProvider } from '@apollo/client/testing'
4
4
  import FileTree, {
5
5
  sortByFilename,
6
6
  sortByName,
@@ -30,27 +30,31 @@ jest.mock('react-spring', () => ({
30
30
 
31
31
  describe('FileTree component', () => {
32
32
  it('renders with default props', () => {
33
- expect(mount(<FileTree />)).toMatchSnapshot()
33
+ const { asFragment } = render(<FileTree />)
34
+ expect(asFragment()).toMatchSnapshot()
34
35
  })
35
36
  it('expands and closes when clicked', () => {
36
- // ApolloProvider isn't used in this test but must exist
37
- // When enzyme supports hooks, this can be simplified
38
- const wrapper = mount(
39
- <ApolloProvider client={{}}>
37
+ render(
38
+ <MockedProvider>
40
39
  <FileTree name="Top Level" />
41
- </ApolloProvider>,
40
+ </MockedProvider>,
41
+ )
42
+ // Test the folder icon is closed
43
+ expect(screen.getByLabelText('Top Level').firstChild).toHaveClass(
44
+ 'fa-folder',
45
+ )
46
+ expect(screen.getByLabelText('Top Level').firstChild).not.toHaveClass(
47
+ 'fa-folder-open',
48
+ )
49
+ // Click it
50
+ fireEvent.click(screen.getByLabelText('Top Level'))
51
+ // Test that it is now open
52
+ expect(screen.getByLabelText('Top Level').firstChild).toHaveClass(
53
+ 'fa-folder-open',
54
+ )
55
+ expect(screen.getByLabelText('Top Level').firstChild).not.toHaveClass(
56
+ 'fa-folder',
42
57
  )
43
- expect(
44
- wrapper.find('div.accordion-title i').hasClass('fa-folder-open'),
45
- ).toBe(false)
46
- wrapper.find('div.accordion-title').simulate('click')
47
- expect(
48
- wrapper.find('div.accordion-title i').hasClass('fa-folder-open'),
49
- ).toBe(true)
50
- wrapper.find('div.accordion-title').simulate('click')
51
- expect(
52
- wrapper.find('div.accordion-title i').hasClass('fa-folder-open'),
53
- ).toBe(false)
54
58
  })
55
59
  describe('sortByFilename()', () => {
56
60
  it('sorts the expected filename properties', () => {
@@ -1,15 +1,17 @@
1
1
  import React from 'react'
2
- import { shallow } from 'enzyme'
2
+ import { render, screen } from '@testing-library/react'
3
3
  import FileViewerType from '../file-viewer-type.jsx'
4
4
 
5
5
  describe('FileViewerType component', () => {
6
6
  it('displays a fallback when an unknown file is specified', () => {
7
- const wrapper = shallow(
7
+ const component = render(
8
8
  <FileViewerType
9
9
  path="unknown-file-extension.xyz"
10
10
  data={new ArrayBuffer(128)}
11
11
  />,
12
12
  )
13
- expect(wrapper.at(0).hasClass('file-viewer-fallback')).toBe(true)
13
+ expect(
14
+ screen.getByText(/this file must be downloaded to view it/i),
15
+ ).toHaveClass('file-viewer-fallback')
14
16
  })
15
17
  })
@@ -1,43 +1,43 @@
1
1
  import React from 'react'
2
- import { shallow } from 'enzyme'
2
+ import { render, screen } from '@testing-library/react'
3
+ import { MemoryRouter } from 'react-router-dom'
3
4
  import File from '../file.jsx'
4
- import { CookiesProvider, Cookies } from 'react-cookie'
5
5
 
6
6
  describe('File component', () => {
7
7
  it('renders with common props', () => {
8
- expect(
9
- shallow(<File datasetId="ds001" path="" filename="README" />),
10
- ).toMatchSnapshot()
8
+ const { asFragment } = render(
9
+ <File datasetId="ds001" path="" filename="README" />,
10
+ { wrapper: MemoryRouter },
11
+ )
12
+ expect(asFragment()).toMatchSnapshot()
11
13
  })
12
14
  it('renders for dataset snapshots', () => {
13
- expect(
14
- shallow(
15
- <File
16
- datasetId="ds001"
17
- snapshotTag="1.0.0"
18
- path=""
19
- filename="README"
20
- />,
21
- ),
22
- ).toMatchSnapshot()
15
+ const { asFragment } = render(
16
+ <File datasetId="ds001" snapshotTag="1.0.0" path="" filename="README" />,
17
+ { wrapper: MemoryRouter },
18
+ )
19
+ expect(asFragment()).toMatchSnapshot()
23
20
  })
24
21
  it('generates correct download links for top level files', () => {
25
- const wrapper = shallow(
26
- <File datasetId="ds001" path="" filename="README" />,
27
- )
28
- expect(wrapper.find('.download-file > a').prop('href')).toEqual(
22
+ render(<File datasetId="ds001" path="" filename="README" />, {
23
+ wrapper: MemoryRouter,
24
+ })
25
+ expect(screen.getByRole('link', { name: 'download file' })).toHaveAttribute(
26
+ 'href',
29
27
  '/crn/datasets/ds001/files/README',
30
28
  )
31
29
  })
32
30
  it('generates correct download links for nested files', () => {
33
- const wrapper = shallow(
31
+ render(
34
32
  <File
35
33
  datasetId="ds001"
36
34
  path="sub-01:anat"
37
35
  filename="sub-01_T1w.nii.gz"
38
36
  />,
37
+ { wrapper: MemoryRouter },
39
38
  )
40
- expect(wrapper.find('.download-file > a').prop('href')).toEqual(
39
+ expect(screen.getByRole('link', { name: 'download file' })).toHaveAttribute(
40
+ 'href',
41
41
  '/crn/datasets/ds001/files/sub-01:anat:sub-01_T1w.nii.gz',
42
42
  )
43
43
  })
@@ -113,7 +113,8 @@ const File = ({
113
113
  <span className="edit-file download-file">
114
114
  <a
115
115
  href={apiPath(datasetId, snapshotTag, filePath(path, filename))}
116
- download>
116
+ download
117
+ aria-label="download file">
117
118
  <i className="fa fa-download" />
118
119
  </a>
119
120
  </span>
@@ -121,7 +122,7 @@ const File = ({
121
122
  </Media>
122
123
  <Tooltip tooltip="View">
123
124
  <span className="edit-file view-file">
124
- <Link to={viewerPath}>
125
+ <Link to={viewerPath} aria-label="view file">
125
126
  <i className="fa fa-eye" />
126
127
  </Link>
127
128
  </span>