From cb259a58e18ce1fb696eb5382e7fdb1270e2f276 Mon Sep 17 00:00:00 2001 From: Robbert Gurdeep Singh Date: Sat, 27 Mar 2021 10:42:43 +0100 Subject: [PATCH] cypress: fix download test Signed-off-by: Robbert Gurdeep Singh --- cypress/integration/download.spec.js | 30 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/cypress/integration/download.spec.js b/cypress/integration/download.spec.js index ccdc1940b..c67e78743 100644 --- a/cypress/integration/download.spec.js +++ b/cypress/integration/download.spec.js @@ -21,16 +21,19 @@ */ import { randHash } from '../utils' +import * as path from 'path'; const randUser = randHash() +const fileName = "image.png" +const fileSize = 4531680; // du -b image.png -describe('Download image.png in viewer', function() { +describe(`Download ${fileName} in viewer`, function() { before(function() { // Init user cy.nextcloudCreateUser(randUser, 'password') cy.login(randUser, 'password') // Upload test files - cy.uploadFile('image.png', 'image/png') + cy.uploadFile(fileName, 'image/png') cy.visit('/apps/files') // wait a bit for things to be settled @@ -41,13 +44,13 @@ describe('Download image.png in viewer', function() { cy.logout() }) - it('See image.png in the list', function() { - cy.get('#fileList tr[data-file="image.png"]', { timeout: 10000 }) - .should('contain', 'image.png') + it(`See "${fileName}" in the list`, function() { + cy.get(`#fileList tr[data-file="${fileName}"]`, { timeout: 10000 }) + .should('contain', fileName) }) it('Open the viewer on file click', function() { - cy.openFile('image.png') + cy.openFile(fileName) cy.get('body > .viewer').should('be.visible') }) @@ -61,11 +64,18 @@ describe('Download image.png in viewer', function() { it('Download the image', function() { // open the menu cy.get('body > .viewer .modal-header button.action-item__menutoggle').click() - // delete the file - cy.get('.action-button__icon.icon-download').click() + // download the file + cy.get('.action-link__icon.icon-download').click() }) - it('Compare downloaded file with asset', function() { - // TODO + it('Compare downloaded file with asset by size', function() { + const downloadsFolder = Cypress.config('downloadsFolder') + const downloadedFileName = path.join(downloadsFolder, fileName) + cy.readFile(downloadedFileName, 'binary', { timeout: 15000 }) + .should((buffer) => { + if (buffer.length !== fileSize) { + throw new Error(`File size ${buffer.length} is not ${fileSize}`) + } + }) }) })