|
1 | 1 | // dist file might not be built when running eslint only |
2 | | -// eslint-disable-next-line import/no-unresolved,node/no-missing-import |
| 2 | +// eslint-disable-next-line import/no-unresolved,n/no-missing-import |
| 3 | +import { addNewFileMenuEntry } from '@nextcloud/files' |
3 | 4 | import { UploadPicker } from '../../dist/index.js' |
4 | 5 |
|
5 | 6 | describe('UploadPicker rendering', () => { |
6 | 7 | it('Renders default UploadPicker', () => { |
7 | 8 | cy.mount(UploadPicker) |
8 | 9 | cy.get('form').should('have.class', 'upload-picker') |
9 | 10 | cy.get('form input[type="file"]').should('exist') |
| 11 | + cy.screenshot() |
| 12 | + }) |
| 13 | +}) |
| 14 | + |
| 15 | +describe('NewFileMenu handling', () => { |
| 16 | + const propsData = { |
| 17 | + context: { |
| 18 | + basename: 'Folder', |
| 19 | + etag: '63071eedd82fe', |
| 20 | + fileid: '56', |
| 21 | + filename: '/Folder', |
| 22 | + hasPreview: false, |
| 23 | + lastmod: 1661410576, |
| 24 | + mime: 'httpd/unix-directory', |
| 25 | + month: '197001', |
| 26 | + permissions: 'CKGWDR', |
| 27 | + showShared: false, |
| 28 | + size: 2610077102, |
| 29 | + timestamp: 1661410, |
| 30 | + type: 'dir', |
| 31 | + }, |
| 32 | + } |
| 33 | + const entry = { |
| 34 | + id: 'empty-file', |
| 35 | + displayName: 'Create empty file', |
| 36 | + templateName: 'New file', |
| 37 | + iconClass: 'icon-file', |
| 38 | + if: fileInfo => fileInfo.permissions.includes('CK'), |
| 39 | + handler() {}, |
| 40 | + } |
| 41 | + |
| 42 | + before(() => { |
| 43 | + cy.spy(entry, 'handler') |
| 44 | + addNewFileMenuEntry(entry) |
| 45 | + }) |
| 46 | + |
| 47 | + it('Open the New File Menu', () => { |
| 48 | + // Mount picker |
| 49 | + cy.mount(UploadPicker, { propsData }) |
| 50 | + |
| 51 | + // Check and init aliases |
| 52 | + cy.get('form input[type="file"]').as('input').should('exist') |
| 53 | + cy.get('form .upload-picker__progress').as('progress').should('exist') |
| 54 | + cy.get('form .action-item__menutoggle').as('menuButton').should('exist') |
| 55 | + |
| 56 | + cy.get('@menuButton').click() |
| 57 | + cy.get('[data-upload-picker-add]').should('have.length', 1) |
| 58 | + cy.get('.upload-picker__menu-entry').should('have.length', 1) |
| 59 | + |
| 60 | + cy.screenshot() |
| 61 | + |
| 62 | + cy.get('.upload-picker__menu-entry') |
| 63 | + .click() |
| 64 | + .then(() => { |
| 65 | + expect(entry.handler).to.be.called |
| 66 | + cy.screenshot() |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + it('Changes the context', () => { |
| 71 | + // Mount picker |
| 72 | + cy.mount(UploadPicker, { propsData }) |
| 73 | + |
| 74 | + // Check and init aliases |
| 75 | + cy.get('form input[type="file"]').as('input').should('exist') |
| 76 | + cy.get('form .upload-picker__progress').as('progress').should('exist') |
| 77 | + cy.get('form .action-item__menutoggle').as('menuButton').should('exist') |
| 78 | + |
| 79 | + cy.get('@menuButton').click() |
| 80 | + cy.get('[data-upload-picker-add]').should('have.length', 1) |
| 81 | + cy.get('.upload-picker__menu-entry').should('have.length', 1) |
| 82 | + cy.screenshot() |
| 83 | + |
| 84 | + // Close menu |
| 85 | + cy.get('body').click() |
| 86 | + cy.get('[data-upload-picker-add]').should('not.exist') |
| 87 | + cy.get('.upload-picker__menu-entry').should('not.exist') |
| 88 | + |
| 89 | + cy.get('@component').then(component => { |
| 90 | + component.setContext(Object.assign({}, propsData.context, { permissions: 'GR' })) |
| 91 | + }) |
| 92 | + cy.get('form .action-item__menutoggle').as('menuButton').should('not.exist') |
| 93 | + cy.get('[data-upload-picker-add]').should('have.length', 1) |
| 94 | + cy.get('.upload-picker__menu-entry').should('not.exist') |
| 95 | + cy.screenshot() |
10 | 96 | }) |
11 | 97 | }) |
12 | 98 |
|
@@ -65,6 +151,7 @@ describe('UploadPicker valid uploads', () => { |
65 | 151 | cy.wait('@chunks').then(() => { |
66 | 152 | cy.get('form .upload-picker__progress').as('progress').should('be.visible') |
67 | 153 | cy.get('@progress').children('progress').should('not.have.value', '0') |
| 154 | + cy.screenshot() |
68 | 155 | }) |
69 | 156 | cy.wait('@assembly', { timeout: 60000 }).then(() => { |
70 | 157 | cy.get('form .upload-picker__progress').as('progress').should('not.be.visible') |
@@ -103,7 +190,6 @@ describe('Destination management', () => { |
103 | 190 | // Mount picker |
104 | 191 | cy.mount(UploadPicker, { propsData }) |
105 | 192 |
|
106 | | - |
107 | 193 | // Check and init aliases |
108 | 194 | cy.get('form input[type="file"]').as('input').should('exist') |
109 | 195 | cy.get('form .upload-picker__progress').as('progress').should('exist') |
|
0 commit comments