Skip to content

Commit d64dc07

Browse files
committed
cypress: fix download test
Signed-off-by: Robbert Gurdeep Singh <[email protected]>
1 parent d24388d commit d64dc07

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

cypress/integration/download.spec.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@
2121
*/
2222

2323
import { randHash } from '../utils'
24+
import * as path from 'path';
2425
const randUser = randHash()
26+
const fileName = "image.png"
27+
const fileSize = 4531680; // du -b image.png
2528

26-
describe('Download image.png in viewer', function() {
29+
describe(`Download ${fileName} in viewer`, function() {
2730
before(function() {
2831
// Init user
2932
cy.nextcloudCreateUser(randUser, 'password')
3033
cy.login(randUser, 'password')
3134

3235
// Upload test files
33-
cy.uploadFile('image.png', 'image/png')
36+
cy.uploadFile(fileName, 'image/png')
3437
cy.visit('/apps/files')
3538

3639
// wait a bit for things to be settled
@@ -41,13 +44,13 @@ describe('Download image.png in viewer', function() {
4144
cy.logout()
4245
})
4346

44-
it('See image.png in the list', function() {
45-
cy.get('#fileList tr[data-file="image.png"]', { timeout: 10000 })
46-
.should('contain', 'image.png')
47+
it(`See "${fileName}" in the list`, function() {
48+
cy.get(`#fileList tr[data-file="${fileName}"]`, { timeout: 10000 })
49+
.should('contain', fileName)
4750
})
4851

4952
it('Open the viewer on file click', function() {
50-
cy.openFile('image.png')
53+
cy.openFile(fileName)
5154
cy.get('body > .viewer').should('be.visible')
5255
})
5356

@@ -61,11 +64,18 @@ describe('Download image.png in viewer', function() {
6164
it('Download the image', function() {
6265
// open the menu
6366
cy.get('body > .viewer .modal-header button.action-item__menutoggle').click()
64-
// delete the file
65-
cy.get('.action-button__icon.icon-download').click()
67+
// download the file
68+
cy.get('.action-link__icon.icon-download').click()
6669
})
6770

68-
it('Compare downloaded file with asset', function() {
69-
// TODO
71+
it('Compare downloaded file with asset by size', function() {
72+
const downloadsFolder = Cypress.config('downloadsFolder')
73+
const downloadedFileName = path.join(downloadsFolder, fileName)
74+
cy.readFile(downloadedFileName, 'binary', { timeout: 15000 })
75+
.should((buffer) => {
76+
if (buffer.length !== fileSize) {
77+
throw new Error(`File size ${buffer.length} is not ${fileSize}`)
78+
}
79+
})
7080
})
7181
})

0 commit comments

Comments
 (0)