-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: Adding Cypress tests to cover existing functional tests #912
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a29b464
Chore: Adding Cypress tests to cover existing functional tests
b2fc624
Merge branch 'master' into cypress-migration
65a970d
Chore: address PR comments
b8b15b0
Chore: merge with origin
567c44f
Merge branch 'master' into cypress-migration
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: '' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably be an |
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What rules are we breaking here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think jsdoc comments for the functions