-
Notifications
You must be signed in to change notification settings - Fork 116
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: Add e2e Thumbnail tests for large doc #959
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,41 @@ | ||
// <reference types="Cypress" /> | ||
describe('Preview Document Thumbnails', () => { | ||
const token = Cypress.env('ACCESS_TOKEN'); | ||
const fileId = Cypress.env('FILE_ID_DOC'); | ||
const fileId = Cypress.env('FILE_ID_DOC_LARGE'); | ||
const THUMBNAIL_SELECTED_CLASS = 'bp-thumbnail-is-selected'; | ||
|
||
/* eslint-disable */ | ||
/** | ||
* Gets the thumbnail with the specified page number | ||
* @param {number} pageNum - Page number | ||
* @return {Element} Thumbnail subject | ||
*/ | ||
const getThumbnail = (pageNum) => cy.get(`.bp-thumbnail[data-bp-page-num=${pageNum}]`); | ||
|
||
/** | ||
* Gets the thumbnail and ensures the thumbnail image has rendered | ||
* @param {number} pageNum - Page number | ||
* @return {Element} Thumbnail subject | ||
*/ | ||
const getThumbnailWithRenderedImage = (pageNum) => getThumbnail(pageNum).should(($thumbnail) => { | ||
expect($thumbnail.find('.bp-thumbnail-image')).to.exist; | ||
return $thumbnail; | ||
}); | ||
|
||
/** | ||
* Shows the document preview | ||
* @param {Object} options - Preview options | ||
* @return {void} | ||
*/ | ||
const showDocumentPreview = ({ enableThumbnailsSidebar } = {}) => { | ||
cy.showPreview(token, fileId, { enableThumbnailsSidebar }); | ||
cy.getPreviewPage(1); | ||
cy.contains('The Content Platform for Your Apps'); | ||
cy.contains('IN THE HOUSE OF REPRESENTATIVES'); | ||
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. Not sure if this needs to be checked each time we load the document. Maybe just in a single test? |
||
}; | ||
|
||
/** | ||
* Toggles the thumbnails sidebar | ||
* @return {Element} The thumbnails sidebar subject | ||
*/ | ||
const toggleThumbnails = () => { | ||
cy.showDocumentControls(); | ||
|
||
|
@@ -19,11 +44,27 @@ describe('Preview Document Thumbnails', () => { | |
.should('be.visible') | ||
.click(); | ||
|
||
// eslint-disable-next-line cypress/no-unnecessary-waiting | ||
cy.wait(301); // Wait for toggle animation to complete | ||
|
||
return cy.getByTestId('thumbnails-sidebar'); | ||
}; | ||
/* eslint-enable */ | ||
|
||
/** | ||
* Asserts that the thumbnails sidebar object is visible | ||
* @param {Element} $thumbnailsSidebar - The thumbnails sidebar subject | ||
* @return {Assertion} Chai Assertion | ||
*/ | ||
const beVisible = ($thumbnailsSidebar) => | ||
expect($thumbnailsSidebar).to.have.css('transform', 'matrix(1, 0, 0, 1, 0, 0)'); // translateX(0) | ||
|
||
/** | ||
* Asserts that the thumbnails sidebar object is not visible | ||
* @param {Element} $thumbnailsSidebar - The thumbnails sidebar subject | ||
* @return {Assertion} Chai Assertion | ||
*/ | ||
const notBeVisible = ($thumbnailsSidebar) => | ||
expect($thumbnailsSidebar).to.have.css('transform', 'matrix(1, 0, 0, 1, -201, 0)'); // translateX(-201px) | ||
|
||
beforeEach(() => { | ||
cy.visit('/'); | ||
|
@@ -46,29 +87,29 @@ describe('Preview Document Thumbnails', () => { | |
it('Should render thumbnails when toggled', () => { | ||
showDocumentPreview({ enableThumbnailsSidebar: true }); | ||
|
||
toggleThumbnails().should('have.css', 'transform', 'matrix(1, 0, 0, 1, 0, 0)'); // translateX(0) | ||
toggleThumbnails().should(beVisible); | ||
|
||
toggleThumbnails().should('have.css', 'transform', 'matrix(1, 0, 0, 1, -201, 0)'); // translateX(-201px) | ||
toggleThumbnails().should(notBeVisible); | ||
}); | ||
|
||
it('Should be able to change page by clicking on the thumbnail', () => { | ||
showDocumentPreview({ enableThumbnailsSidebar: true }); | ||
|
||
// Verify we're on page 1 | ||
cy.getByTestId('current-page').as('currentPage') | ||
cy | ||
.getByTestId('current-page') | ||
.as('currentPage') | ||
.invoke('text') | ||
.should('equal', '1'); | ||
|
||
toggleThumbnails().should('be.visible'); | ||
toggleThumbnails().should(beVisible); | ||
|
||
// Verify which thumbnail is selected | ||
getThumbnail(1) | ||
.should('have.class', THUMBNAIL_SELECTED_CLASS) | ||
.as('thumbOne'); | ||
getThumbnail(2) | ||
getThumbnailWithRenderedImage(1).should('have.class', THUMBNAIL_SELECTED_CLASS); | ||
getThumbnailWithRenderedImage(2) | ||
.click() | ||
.should('have.class', THUMBNAIL_SELECTED_CLASS); | ||
cy.get('@thumbOne').should('not.have.class', THUMBNAIL_SELECTED_CLASS); | ||
getThumbnailWithRenderedImage(1).should('not.have.class', THUMBNAIL_SELECTED_CLASS); | ||
cy | ||
.get('@currentPage') | ||
.invoke('text') | ||
|
@@ -83,19 +124,85 @@ describe('Preview Document Thumbnails', () => { | |
.invoke('text') | ||
.should('equal', '1'); | ||
|
||
toggleThumbnails().should('be.visible'); | ||
toggleThumbnails().should(beVisible); | ||
|
||
getThumbnail(1) | ||
.should('have.class', THUMBNAIL_SELECTED_CLASS) | ||
.as('thumbOne'); | ||
getThumbnailWithRenderedImage(1).should('have.class', THUMBNAIL_SELECTED_CLASS); | ||
|
||
cy.getByTitle('Next page').click(); | ||
|
||
getThumbnail(2).should('have.class', THUMBNAIL_SELECTED_CLASS); | ||
cy.get('@thumbOne').should('not.have.class', THUMBNAIL_SELECTED_CLASS); | ||
getThumbnailWithRenderedImage(2).should('have.class', THUMBNAIL_SELECTED_CLASS); | ||
getThumbnailWithRenderedImage(1).should('not.have.class', THUMBNAIL_SELECTED_CLASS); | ||
cy | ||
.get('@currentPage') | ||
.invoke('text') | ||
.should('equal', '2'); | ||
}); | ||
|
||
it('Should reflect the selected page even when thumbnail was not previously in rendered window', () => { | ||
showDocumentPreview({ enableThumbnailsSidebar: true }); | ||
cy | ||
.getByTestId('current-page') | ||
.as('currentPage') | ||
.invoke('text') | ||
.should('equal', '1'); | ||
|
||
toggleThumbnails().should(beVisible); | ||
|
||
getThumbnailWithRenderedImage(1).should('have.class', THUMBNAIL_SELECTED_CLASS); | ||
|
||
cy.showDocumentControls(); | ||
cy.getByTitle('Click to enter page number').click(); | ||
cy | ||
.getByTestId('page-num-input') | ||
.should('be.visible') | ||
.type('200') | ||
.blur(); | ||
|
||
getThumbnailWithRenderedImage(200).should('have.class', THUMBNAIL_SELECTED_CLASS); | ||
|
||
getThumbnail(1).should('not.exist'); | ||
cy | ||
.get('@currentPage') | ||
.invoke('text') | ||
.should('equal', '200'); | ||
}); | ||
|
||
it('Should still reflect the current viewed page when thumbnails sidebar is toggled open', () => { | ||
showDocumentPreview({ enableThumbnailsSidebar: true }); | ||
cy | ||
.getByTestId('current-page') | ||
.as('currentPage') | ||
.invoke('text') | ||
.should('equal', '1'); | ||
|
||
toggleThumbnails().should(beVisible); | ||
|
||
getThumbnailWithRenderedImage(1).should('have.class', THUMBNAIL_SELECTED_CLASS); | ||
|
||
cy.showDocumentControls(); | ||
cy.getByTitle('Click to enter page number').click(); | ||
cy | ||
.getByTestId('page-num-input') | ||
.should('be.visible') | ||
.type('200') | ||
.blur(); | ||
|
||
cy.getPreviewPage(200).should('be.visible'); | ||
getThumbnailWithRenderedImage(200).should('have.class', THUMBNAIL_SELECTED_CLASS); | ||
|
||
toggleThumbnails().should(notBeVisible); | ||
|
||
cy.getByTitle('Click to enter page number').click(); | ||
cy | ||
.getByTestId('page-num-input') | ||
.should('be.visible') | ||
.type('1') | ||
.blur(); | ||
|
||
cy.getPreviewPage(1).should('be.visible'); | ||
|
||
toggleThumbnails().should(beVisible); | ||
|
||
getThumbnailWithRenderedImage(1).should('have.class', THUMBNAIL_SELECTED_CLASS); | ||
}); | ||
}); |
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
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.
Is this not already the default behavior of Preview if no page number options are passed in?