Skip to content

Commit

Permalink
cypress: fix download test
Browse files Browse the repository at this point in the history
Signed-off-by: Robbert Gurdeep Singh <git@beardhatcode.be>
  • Loading branch information
beardhatcode committed Mar 27, 2021
1 parent c8e275d commit cb259a5
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions cypress/integration/download.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
})

Expand All @@ -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}`)
}
})
})
})

0 comments on commit cb259a5

Please sign in to comment.