-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Adding Cypress tests to cover existing functional tests (#912)
- Loading branch information
Conrad Chan
authored
Feb 5, 2019
1 parent
f4956aa
commit 0093c93
Showing
12 changed files
with
338 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// <reference types="Cypress" /> | ||
describe('Preview Document Controls', () => { | ||
const token = Cypress.env('ACCESS_TOKEN'); | ||
const fileId = Cypress.env('FILE_ID_DOC'); | ||
|
||
/* eslint-disable */ | ||
const showControls = () => { | ||
cy.getByTestId('bp').trigger('mouseover'); | ||
cy.getByTestId('controls-wrapper').should('be.visible'); | ||
}; | ||
/* eslint-enable */ | ||
|
||
beforeEach(() => { | ||
cy.visit('/'); | ||
cy.showPreview(token, fileId); | ||
cy.getByTestId('current-page').as('currentPage'); | ||
}); | ||
|
||
it('Should zoom in and out', () => { | ||
// Assert document content is present | ||
cy.contains('The Content Platform for Your Apps'); | ||
// Get the current dimensions of the page | ||
cy.getPreviewPage(1).then(($page) => { | ||
cy.wrap($page[0].scrollWidth).as('originalWidth'); | ||
cy.wrap($page[0].scrollHeight).as('originalHeight'); | ||
}); | ||
|
||
showControls(); | ||
|
||
cy.getByTitle('Zoom out').click(); | ||
|
||
cy.getPreviewPage(1).then(($page) => { | ||
const zoomedOutWidth = $page[0].scrollWidth; | ||
const zoomedOutHeight = $page[0].scrollHeight; | ||
|
||
cy.get('@originalWidth').then((originalWidth) => expect(originalWidth).to.be.above(zoomedOutWidth)); | ||
cy.get('@originalHeight').then((originalHeight) => expect(originalHeight).to.be.above(zoomedOutHeight)); | ||
|
||
cy.wrap(zoomedOutWidth).as('zoomedOutWidth'); | ||
cy.wrap(zoomedOutHeight).as('zoomedOutHeight'); | ||
}); | ||
|
||
showControls(); | ||
|
||
cy.getByTitle('Zoom in').click(); | ||
|
||
cy.getPreviewPage(1).then(($page) => { | ||
const zoomedInWidth = $page[0].scrollWidth; | ||
const zoomedInHeight = $page[0].scrollHeight; | ||
|
||
cy.get('@zoomedOutWidth').then((zoomedOutWidth) => expect(zoomedOutWidth).to.be.below(zoomedInWidth)); | ||
cy.get('@zoomedOutHeight').then((zoomedOutHeight) => expect(zoomedOutHeight).to.be.below(zoomedInHeight)); | ||
}); | ||
}); | ||
|
||
it('Should handle page navigation via buttons', () => { | ||
cy.getPreviewPage(1).should('be.visible'); | ||
cy.contains('The Content Platform for Your Apps'); | ||
cy.get('@currentPage').invoke('text').should('equal', '1'); | ||
|
||
showControls(); | ||
cy.getByTitle('Next page').click(); | ||
|
||
cy.getPreviewPage(2).should('be.visible'); | ||
cy.contains('Discover how your business can use Box Platform'); | ||
cy.get('@currentPage').invoke('text').should('equal', '2'); | ||
|
||
showControls(); | ||
cy.getByTitle('Previous page').click(); | ||
|
||
cy.getPreviewPage(1).should('be.visible'); | ||
cy.contains('The Content Platform for Your Apps'); | ||
cy.get('@currentPage').invoke('text').should('equal', '1'); | ||
}); | ||
|
||
it('Should handle page navigation via input', () => { | ||
cy.getPreviewPage(1).should('be.visible'); | ||
cy.contains('The Content Platform for Your Apps'); | ||
cy.get('@currentPage').invoke('text').should('equal', '1'); | ||
|
||
showControls(); | ||
cy.getByTitle('Click to enter page number').click(); | ||
cy.getByTestId('page-num-input').should('be.visible').type('2').blur(); | ||
|
||
cy.getPreviewPage(2).should('be.visible'); | ||
cy.contains('Discover how your business can use Box Platform'); | ||
cy.get('@currentPage').invoke('text').should('equal', '2'); | ||
}); | ||
|
||
// Fullscreen won't allow a non user gesture to trigger fullscreen | ||
// There is an open issue for cypress to allow this | ||
// https://github.com/cypress-io/cypress/issues/1213 | ||
// | ||
// it('Should handle going fullscreen', () => { | ||
// cy.getPreviewPage(1).should('be.visible'); | ||
// cy.contains('The Content Platform for Your Apps'); | ||
// showControls(); | ||
// cy.getByTitle('Enter fullscreen').should('be.visible').click(); | ||
// cy.getByTitle('Exit fullscreen').should('be.visible'); | ||
// }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// <reference types="Cypress" /> | ||
describe('Preview File Options', () => { | ||
const token = Cypress.env('ACCESS_TOKEN'); | ||
|
||
const fileIdDoc = Cypress.env('FILE_ID_DOC'); | ||
const fileIdVideo = Cypress.env('FILE_ID_VIDEO'); | ||
const fileIdMp3 = Cypress.env('FILE_ID_MP3'); | ||
|
||
const fileOptions = { | ||
[fileIdDoc]: { | ||
startAt: { | ||
value: 2, | ||
unit: 'pages' | ||
} | ||
}, | ||
[fileIdVideo]: { | ||
startAt: { | ||
value: 15, | ||
unit: 'seconds' | ||
} | ||
}, | ||
[fileIdMp3]: { | ||
startAt: { | ||
value: 3, | ||
unit: 'seconds' | ||
} | ||
} | ||
}; | ||
|
||
/* eslint-disable */ | ||
const showMediaControls = () => { | ||
// Hover over the preview to trigger the controls | ||
cy.getByTestId('bp').trigger('mouseover'); | ||
// Assert that the controls are shown | ||
return cy.getByTestId('media-controls-wrapper').should('be.visible'); | ||
}; | ||
/* eslint-enable */ | ||
|
||
beforeEach(() => { | ||
cy.visit('/'); | ||
}); | ||
|
||
it('Should open document preview on the specified page', () => { | ||
cy.showPreview(token, fileIdDoc, { fileOptions }); | ||
|
||
cy.getPreviewPage(2).should('be.visible'); | ||
cy.contains('Discover how your business can use Box Platform'); | ||
cy.getByTestId('current-page').invoke('text').should('equal', '2'); | ||
}); | ||
|
||
it('Should open video(DASH) to the specified timestamp', () => { | ||
cy.showPreview(token, fileIdVideo, { fileOptions }); | ||
|
||
showMediaControls().contains('0:15'); | ||
}); | ||
|
||
it('Should open video(MP4) to the specified timestamp', () => { | ||
cy.showPreview(token, fileIdVideo, { fileOptions, viewers: { 'Dash': { disabled: true } } }); | ||
|
||
showMediaControls().contains('0:15'); | ||
}); | ||
|
||
it('Should open MP3 to the specified timestamp', () => { | ||
cy.showPreview(token, fileIdMp3, { fileOptions }); | ||
|
||
showMediaControls().contains('0:03'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// <reference types="Cypress" /> | ||
describe('Preview Header', () => { | ||
const token = Cypress.env('ACCESS_TOKEN'); | ||
const fileIdDoc = Cypress.env('FILE_ID_DOC'); | ||
// const urlRegex = /https:\/\/dl[0-9]*\.boxcloud\.com.+\/download/; | ||
|
||
beforeEach(() => { | ||
cy.server(); | ||
cy.route('GET', '**/files/*?fields=download_url', { download_url: '' }); | ||
cy.visit('/'); | ||
cy.showPreview(token, fileIdDoc, { showDownload: true }); | ||
}); | ||
|
||
it('Should see the download button for the file', () => { | ||
cy.getByTestId('download-preview').should('be.visible'); | ||
// TODO: no click() is executed because it will cause the Cypress test execution | ||
// to hang while a dialog waits user input to save the download | ||
// https://github.com/cypress-io/cypress/issues/949 | ||
// cy.getByTestId('downloadiframe').then((iframe) => expect(urlRegex.test(iframe[0].src)).to.be.true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
Cypress.Commands.add('getByTestId', (testId) => cy.get(`[data-testid="${testId}"]`)); | ||
Cypress.Commands.add('getByTitle', (title) => cy.get(`[title="${title}"]`)); | ||
Cypress.Commands.add('showPreview', (token, fileId) => { | ||
cy.get('[data-testid="token"]').type(token); | ||
cy.get('[data-testid="token-set"]').click(); | ||
cy.get('[data-testid="fileid"]').type(fileId); | ||
cy.get('[data-testid="fileid-set"]').click(); | ||
Cypress.Commands.add('getPreviewPage', (pageNum) => { | ||
cy | ||
.get(`.page[data-page-number=${pageNum}]`) | ||
.as('previewPage') | ||
.find('[data-testid="page-loading-indicator"]') | ||
.should('not.exist'); | ||
|
||
return cy.get('@previewPage'); | ||
}); | ||
Cypress.Commands.add('showPreview', (token, fileId, options) => { | ||
cy.getByTestId('token').type(token); | ||
cy.getByTestId('token-set').click(); | ||
cy.getByTestId('fileid').type(fileId); | ||
cy.getByTestId('fileid-set').click(); | ||
|
||
if (options) { | ||
cy.window().then((win) => { | ||
win.loadPreview(options); | ||
}); | ||
} | ||
|
||
// Wait for .bp to load viewer | ||
return cy.getByTestId('bp').should('have.class', 'bp-loaded'); | ||
}); |
Oops, something went wrong.