|
1 | 1 | import { currentRouteName } from '@ember/test-helpers'; |
| 2 | +import { ModelInstance } from 'ember-cli-mirage'; |
2 | 3 | import { setupMirage } from 'ember-cli-mirage/test-support'; |
3 | | -// import { percySnapshot } from 'ember-percy'; |
| 4 | +import { t } from 'ember-intl/test-support'; |
| 5 | +import { TestContext } from 'ember-test-helpers'; |
| 6 | +import { percySnapshot } from 'ember-percy'; |
4 | 7 | import { module, test } from 'qunit'; |
5 | 8 |
|
6 | | -import { setupOSFApplicationTest, visit } from 'ember-osf-web/tests/helpers'; |
| 9 | +import { click, setupOSFApplicationTest, visit } from 'ember-osf-web/tests/helpers'; |
| 10 | +import NodeModel from 'ember-osf-web/models/node'; |
| 11 | +import FileModel from 'ember-osf-web/models/file'; |
| 12 | +import FileProviderModel from 'ember-osf-web/models/file-provider'; |
| 13 | + |
| 14 | +interface GuidNodeTestContext extends TestContext { |
| 15 | + node: ModelInstance<NodeModel>; |
| 16 | + osfStorage: ModelInstance<FileProviderModel>; |
| 17 | + file: ModelInstance<FileModel>; |
| 18 | +} |
7 | 19 |
|
8 | 20 | module('Acceptance | guid-node/files', hooks => { |
9 | 21 | setupOSFApplicationTest(hooks); |
10 | 22 | setupMirage(hooks); |
11 | 23 |
|
12 | | - test('leftnav for read user', async function(assert) { |
13 | | - const node = server.create('node', 'withFiles', 'withStorage'); |
14 | | - await visit(`/${node.id}/files`); |
| 24 | + hooks.beforeEach(async function(this: GuidNodeTestContext) { |
| 25 | + this.node = server.create('node', 'withFiles','withStorage'); |
| 26 | + this.osfStorage = this.node.files.models.firstObject!; |
| 27 | + this.file = server.create('file', { |
| 28 | + id: 'hello', |
| 29 | + target: this.node, |
| 30 | + parentFolder: this.osfStorage.rootFolder, |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + test('read user', async function(this: GuidNodeTestContext, assert) { |
| 35 | + await visit(`/${this.node.id}/files`); |
15 | 36 |
|
16 | 37 | assert.equal(currentRouteName(), 'guid-node.files.provider', 'Current route is files'); |
| 38 | + |
| 39 | + // Check leftnav |
17 | 40 | assert.dom('[data-test-overview-link]').exists('Overview link exists'); |
18 | 41 | assert.dom('[data-test-files-link]').exists('Files link exists'); |
19 | | - // check active tab + file providers |
| 42 | + assert.dom('[data-test-file-providers-list]') |
| 43 | + .containsText(t('registries.overview.files.storage_providers.osfstorage'), 'Osf Storage shown as provider'); |
20 | 44 | assert.dom('[data-test-analytics-link]').exists('Analytics link exists'); |
21 | 45 | assert.dom('[data-test-registrations-link]').exists('Registrations link exists'); |
22 | 46 | assert.dom('[data-test-contributors-link]').exists('Contributors link exists'); |
23 | 47 | assert.dom('[data-test-settings-link]').exists('Settings link exists'); |
| 48 | + |
| 49 | + // Check file actions |
| 50 | + await click(`[data-test-file-list-item="${this.file.id}"] [data-test-file-download-share-trigger]`); |
| 51 | + await percySnapshot(assert); |
| 52 | + assert.dom('[data-test-copy-button]').exists('Single file copy available'); |
| 53 | + assert.dom('[data-test-move-button]').doesNotExist('Single file move not available'); |
| 54 | + assert.dom('[data-test-delete-button]').doesNotExist('Single file delete not available'); |
| 55 | + assert.dom('[data-test-rename-link]').doesNotExist('Single file rename not available'); |
| 56 | + await click(`[data-test-file-list-item="${this.file.id}"] [data-test-file-download-share-trigger]`); |
| 57 | + |
| 58 | + // Check bulk file actions |
| 59 | + await click(`[data-test-select-file="${this.file.id}"]`); |
| 60 | + assert.dom('[data-test-bulk-copy-trigger]').exists('Bulk copy available'); |
| 61 | + assert.dom('[data-test-bulk-move-trigger]').doesNotExist('Bulk move not available'); |
| 62 | + assert.dom('[data-test-bulk-delete-trigger]').doesNotExist('Bulk delete not available'); |
| 63 | + |
| 64 | + await click('[data-test-bulk-copy-trigger]'); |
| 65 | + assert.dom('[data-test-dialog]').containsText(t('osf-components.move_file_modal.no_write_permission'), |
| 66 | + 'Copy modal has permission-related message'); |
| 67 | + assert.dom('[data-test-move-files-button]').isDisabled('Copy button disabled'); |
| 68 | + assert.dom('[data-test-move-files-button]').containsText(t('general.copy')); |
24 | 69 | }); |
25 | 70 |
|
26 | | - // test no files |
27 | | - // test selecting files + file actions |
28 | | - // test switching providers |
29 | | - // test links for different user permissions and VOL status and wiki enabled |
| 71 | + test('No files', async function(this: GuidNodeTestContext, assert) { |
| 72 | + this.osfStorage!.rootFolder.update({files: []}); |
| 73 | + |
| 74 | + await visit(`/${this.node.id}/files`); |
| 75 | + await percySnapshot(assert); |
| 76 | + assert.dom('[data-test-file-list-item]').doesNotExist('No file or folder items'); |
| 77 | + assert.dom('[data-test-empty-folder]') |
| 78 | + .containsText(t('osf-components.file-browser.empty_folder'), 'Empty folder'); |
| 79 | + }); |
| 80 | + |
| 81 | + test('Multi-file actions', async function(this: GuidNodeTestContext, assert) { |
| 82 | + this.node.update({ currentUserPermissions: ['admin', 'write', 'read'] }); |
| 83 | + await visit(`/${this.node.id}/files`); |
| 84 | + await click(`[data-test-select-file="${this.file.id}"]`); |
| 85 | + await percySnapshot(assert); |
| 86 | + assert.dom('[data-test-bulk-move-trigger]').exists('Bulk move available'); |
| 87 | + assert.dom('[data-test-bulk-copy-trigger]').exists('Bulk copy available'); |
| 88 | + assert.dom('[data-test-bulk-delete-trigger]').exists('Bulk delete available'); |
| 89 | + |
| 90 | + await click('[data-test-bulk-move-trigger]'); |
| 91 | + assert.dom('[data-test-dialog]').doesNotContainText(t('osf-components.move_file_modal.no_write_permission'), |
| 92 | + 'Move modal does not show permission-related message'); |
| 93 | + }); |
| 94 | + |
| 95 | + test('Switching providers', async function(this: GuidNodeTestContext, assert) { |
| 96 | + server.create('file-provider', { |
| 97 | + provider: 'bitbucket', |
| 98 | + name: 'bitbucket', |
| 99 | + target: this.node, |
| 100 | + }); |
| 101 | + await visit(`/${this.node.id}/files`); |
| 102 | + assert.dom('[data-test-files-provider-link="bitbucket"').exists('Bitbucket shown'); |
| 103 | + assert.dom('[data-test-files-provider-link="bitbucket"').hasAttribute('href', |
| 104 | + `/${this.node.id}/files/bitbucket`, 'Links to bitbucket files'); |
| 105 | + }); |
30 | 106 | }); |
0 commit comments