|
| 1 | +/** |
| 2 | + * @copyright Copyright (c) 2020 Florent Fayolle <[email protected]> |
| 3 | + * |
| 4 | + * @author Florent Fayolle <[email protected]> |
| 5 | + * |
| 6 | + * @license GNU AGPL version 3 or any later version |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License as |
| 10 | + * published by the Free Software Foundation, either version 3 of the |
| 11 | + * License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License |
| 19 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +import { randHash } from '../utils' |
| 24 | +import * as path from 'path' |
| 25 | + |
| 26 | +const randUser = randHash() |
| 27 | +const fileName = 'image1.jpg' |
| 28 | + |
| 29 | +describe(`Download ${fileName} from viewer in link share`, function() { |
| 30 | + before(function() { |
| 31 | + // Init user |
| 32 | + cy.nextcloudCreateUser(randUser, 'password') |
| 33 | + cy.login(randUser, 'password') |
| 34 | + |
| 35 | + // Upload test files |
| 36 | + cy.createFolder('Photos') |
| 37 | + cy.uploadFile('image1.jpg', 'image/jpeg', '/Photos') |
| 38 | + cy.uploadFile('image2.jpg', 'image/jpeg', '/Photos') |
| 39 | + cy.visit('/apps/files') |
| 40 | + |
| 41 | + // wait a bit for things to be settled |
| 42 | + cy.wait(1000) |
| 43 | + }) |
| 44 | + after(function() { |
| 45 | + // already logged out after visiting share link |
| 46 | + // cy.logout() |
| 47 | + }) |
| 48 | + |
| 49 | + it('See the default files list', function() { |
| 50 | + cy.get('#fileList tr').should('contain', 'welcome.txt') |
| 51 | + cy.get('#fileList tr').should('contain', 'Photos') |
| 52 | + }) |
| 53 | + |
| 54 | + it('Does not have any visual regression 1', function() { |
| 55 | + // cy.matchImageSnapshot() |
| 56 | + }) |
| 57 | + |
| 58 | + it('See shared files in the list', function() { |
| 59 | + cy.openFile('Photos') |
| 60 | + cy.get('#fileList tr[data-file="image1.jpg"]', { timeout: 10000 }) |
| 61 | + .should('contain', 'image1.jpg') |
| 62 | + cy.get('#fileList tr[data-file="image2.jpg"]', { timeout: 10000 }) |
| 63 | + .should('contain', 'image2.jpg') |
| 64 | + }) |
| 65 | + |
| 66 | + it('Does not have any visual regression 2', function() { |
| 67 | + // cy.matchImageSnapshot() |
| 68 | + }) |
| 69 | + |
| 70 | + it('Share the Photos folder with a share link and access the share link', function() { |
| 71 | + cy.createLinkShare('/Photos').then(token => { |
| 72 | + cy.logout() |
| 73 | + cy.visit(`/s/${token}`) |
| 74 | + }) |
| 75 | + }) |
| 76 | + |
| 77 | + it('Does not have any visual regression 3', function() { |
| 78 | + // cy.matchImageSnapshot() |
| 79 | + }) |
| 80 | + |
| 81 | + it('Open the viewer on file click', function() { |
| 82 | + cy.openFile('image1.jpg') |
| 83 | + cy.get('body > .viewer').should('be.visible') |
| 84 | + }) |
| 85 | + |
| 86 | + it('Does not see a loading animation', function() { |
| 87 | + cy.get('body > .viewer', { timeout: 10000 }) |
| 88 | + .should('be.visible') |
| 89 | + .and('have.class', 'modal-mask') |
| 90 | + .and('not.have.class', 'icon-loading') |
| 91 | + }) |
| 92 | + |
| 93 | + it('See the download icon and title on the viewer header', function() { |
| 94 | + cy.get('body > .viewer .modal-title').should('contain', 'image1.jpg') |
| 95 | + cy.get('body > .viewer .modal-header a.action-item.icon-download').should('be.visible') |
| 96 | + cy.get('body > .viewer .modal-header button.icon-close').should('be.visible') |
| 97 | + }) |
| 98 | + |
| 99 | + it('Download the image', function() { |
| 100 | + // download the file |
| 101 | + cy.get('body > .viewer .modal-header a.action-item.icon-download').click() |
| 102 | + }) |
| 103 | + |
| 104 | + it('Compare downloaded file with asset by size', function() { |
| 105 | + const downloadsFolder = Cypress.config('downloadsFolder') |
| 106 | + const fixturesFolder = Cypress.config('fixturesFolder') |
| 107 | + |
| 108 | + const downloadedFilePath = path.join(downloadsFolder, fileName) |
| 109 | + const fixtureFilePath = path.join(fixturesFolder, fileName) |
| 110 | + |
| 111 | + cy.readFile(fixtureFilePath, 'binary', { timeout: 5000 }).then(fixtureBuffer => { |
| 112 | + cy.readFile(downloadedFilePath, 'binary', { timeout: 5000 }) |
| 113 | + .should(downloadedBuffer => { |
| 114 | + if (downloadedBuffer.length !== fixtureBuffer.length) { |
| 115 | + throw new Error(`File size ${downloadedBuffer.length} is not ${fixtureBuffer.length}`) |
| 116 | + } |
| 117 | + }) |
| 118 | + }) |
| 119 | + }) |
| 120 | +}) |
0 commit comments