Skip to content

Commit

Permalink
Chore: Text Viewer e2e tests (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan authored Mar 13, 2019
1 parent 8c2b193 commit eadedf1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"patch": "./build/release.sh -p"
},
"lint-staged": {
"functional-tests/*.js": [
"tests/**/*.js": [
"prettier-eslint --print-width 120 --single-quote --tab-width 4 --write",
"git add"
],
Expand Down
2 changes: 2 additions & 0 deletions test/integration/document/Thumbnails.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ describe('Preview Document Thumbnails', () => {
.should('be.visible')
.click();

cy.wait(301); // Wait for toggle animation to complete

return cy.getByTestId('thumbnails-sidebar');
};
/* eslint-enable */
Expand Down
2 changes: 2 additions & 0 deletions test/integration/sanity/Sanity.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Preview Sanity', () => {
cy.getByTestId('bp-content').find('.bp-loading-wrapper').should('be.visible');
cy.getPreviewPage(1);
cy.contains('The Content Platform for Your Apps');
cy.get('@getFileInfo.all').should('have.length', 1);
});
});

Expand All @@ -35,6 +36,7 @@ describe('Preview Sanity', () => {
win.preview.reload();
cy.getPreviewPage(1);
cy.contains('The Content Platform for Your Apps');
cy.get('@getFileInfo.all').should('have.length', 2);
});
});
});
21 changes: 21 additions & 0 deletions test/integration/text/TextViewers.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <reference types="Cypress" />
describe('Text Viewers', () => {
const token = Cypress.env('ACCESS_TOKEN');

beforeEach(() => {
cy.visit('/');
});

[
{ title: 'html', fileKey: 'FILE_ID_HTML', expectedText: 'Files App' },
{ title: 'js', fileKey: 'FILE_ID_JS', expectedText: 'class PlainText extends TextBase' },
{ title: 'json', fileKey: 'FILE_ID_JSON', expectedText: 'Standard Generalized Markup Language' },
{ title: 'txt', fileKey: 'FILE_ID_TXT', expectedText: 'XSS Locator' }
].forEach((testcase) => {
it(`Should load a ${testcase.title} preview`, () => {
const fileId = Cypress.env(testcase.fileKey);
cy.showPreview(token, fileId);
cy.contains(testcase.expectedText);
});
});
});
11 changes: 8 additions & 3 deletions test/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Cypress.Commands.add('getByTestId', (testId) => cy.get(`[data-testid="${testId}"]`));
Cypress.Commands.add('getByTitle', (title) => cy.get(`[title="${title}"]`));
Cypress.Commands.add('getByTestId', (testId, options = {}) => cy.get(`[data-testid="${testId}"]`, options));
Cypress.Commands.add('getByTitle', (title, options = {}) => cy.get(`[title="${title}"]`, options));
Cypress.Commands.add('getPreviewPage', (pageNum) => {
cy
.get(`.page[data-page-number=${pageNum}]`)
Expand All @@ -16,6 +16,9 @@ Cypress.Commands.add('showDocumentControls', () => {
return cy.getByTestId('controls-wrapper').should('be.visible');
});
Cypress.Commands.add('showPreview', (token, fileId, options) => {
cy.server();
cy.route('**/files/*').as('getFileInfo');

cy.getByTestId('token').type(token);
cy.getByTestId('token-set').click();
cy.getByTestId('fileid').type(fileId);
Expand All @@ -25,8 +28,10 @@ Cypress.Commands.add('showPreview', (token, fileId, options) => {
win.loadPreview(options);
});

cy.wait('@getFileInfo');

// Wait for .bp to load viewer
return cy.getByTestId('bp').should('have.class', 'bp-loaded');
return cy.getByTestId('bp', { timeout: 15000 }).should('have.class', 'bp-loaded');
});


Expand Down
12 changes: 8 additions & 4 deletions test/support/constants.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
Cypress.env({
ACCESS_TOKEN: 'S8wjvjOL9GEK5VtXsQNVMOwSrx1g55oC',
FILE_ID_DOC: '415542803939',
FILE_ID_PRESENTATION: '415537552367',
FILE_ID_PRESENTATION_WITH_LINKS: '416052594867',
FILE_ID_HTML: '420872247534',
FILE_ID_JS: '416043839991',
FILE_ID_JSON: '420868959262',
FILE_ID_MP3: '415542687401',
FILE_ID_VIDEO: '416047501580',
FILE_ID_PRESENTATION_WITH_LINKS: '416052594867',
FILE_ID_PRESENTATION: '415537552367',
FILE_ID_TXT: '420870357452',
FILE_ID_VIDEO_SMALL: '415542846356',
FILE_ID_VIDEO_SUBTITLES_TRACKS: '415542245854',
FILE_ID_VIDEO_SMALL: '415542846356'
FILE_ID_VIDEO: '416047501580'
});

0 comments on commit eadedf1

Please sign in to comment.