Skip to content

Commit

Permalink
chore(cypress): Upgrade to latest version of cypress (#3557)
Browse files Browse the repository at this point in the history
* chore(cypress): Upgrade to latest version of cypress

* chore(cypress): updates
  • Loading branch information
greg-in-a-box authored May 22, 2024
1 parent e47892f commit 23f2693
Show file tree
Hide file tree
Showing 13 changed files with 513 additions and 390 deletions.
23 changes: 23 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineConfig } from 'cypress';

export default defineConfig({
defaultCommandTimeout: 8000,
fileServerFolder: 'test',
fixturesFolder: 'test/fixtures',
screenshotsFolder: 'test/screenshots',
video: false,
videosFolder: 'test/videos',
viewportHeight: 1260,
viewportWidth: 1600,
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
// eslint-disable-next-line global-require,@typescript-eslint/no-var-requires
return require('./test/plugins/index.js')(on, config);
},
baseUrl: 'http://localhost:6060/#',
specPattern: 'test/integration/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'test/support/index.js',
},
});
14 changes: 0 additions & 14 deletions cypress.json

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"copy:flow": "flow-copy-source --ignore \"**/__tests__/**\" --ignore \"**/__mocks__/**\" --ignore \"**/*.ts\" ./src ./es && copyfiles './src/**/*.js.flow' es --up 1",
"copy:styles": "copyfiles './src/**/*.scss' es --up 1",
"cy:open": "yarn cy:wait; yarn cypress open",
"cy:run": "yarn cy:wait; yarn cypress run --spec \"test/integration/**/*.test.js\"",
"cy:run": "yarn cy:wait; yarn cypress run --spec \"test/integration/**/*.cy.js\"",
"cy:wait": "wait-on http-get://127.0.0.1:6060/#",
"lint": "npm-run-all lint:*",
"lint:js": "eslint --max-warnings=0 .",
Expand Down Expand Up @@ -212,7 +212,7 @@
"cosmiconfig": "^6.0.0",
"css-loader": "^3.4.2",
"cssnano": "^4.1.10",
"cypress": "3.8.2",
"cypress": "^13.7.3",
"deepmerge": "^4.2.2",
"draft-js": "^0.10.1",
"enzyme": "^3.11.0",
Expand All @@ -221,7 +221,7 @@
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-cypress": "^2.8.1",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-flowtype": "^4.6.0",
"eslint-plugin-formatjs": "^1.5.11",
"eslint-plugin-import": "^2.19.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,15 @@ const helpers = {

describe('ContentExplorer', () => {
beforeEach(() => {
cy.server();
cy.route('GET', '**/folders/*', 'fixture:content-explorer/root-folder.json');
cy.route('GET', '**/files/319004423111?fields=allowed_shared_link_access_levels,shared_link', {
cy.intercept('GET', '**/folders/*', { fixture: 'content-explorer/root-folder.json' });
cy.intercept('GET', '**/files/319004423111?fields=allowed_shared_link_access_levels,shared_link', {
type: 'file',
id: '319004423111',
etag: '4',
allowed_shared_link_access_levels: ['collaborators', 'open', 'company'],
shared_link: null,
});
cy.route('PUT', '**/files/319004423111', {
cy.intercept('PUT', '**/files/319004423111', {
type: 'file',
id: '319004423111',
etag: '4',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ const helpers = {

describe('ContentPicker', () => {
describe('Pagination', () => {
const FIRST_PAGE = 'fixture:content-picker/folder-page-1.json';
const SECOND_PAGE = 'fixture:content-picker/folder-page-2.json';
const FIRST_PAGE = { fixture: 'content-picker/folder-page-1.json' };
const SECOND_PAGE = { fixture: 'content-picker/folder-page-2.json' };
const FIRST_ITEM_OF_FIRST_PAGE = 'Another Sample Folder';
const FIRST_ITEM_OF_SECOND_PAGE = 'Sample Audio.mp3';

beforeEach(() => {
cy.server();

cy.route('GET', '**/folders/*', FIRST_PAGE);
cy.intercept('GET', '**/folders/*', FIRST_PAGE);
});

it('Should be able to navigate between pages using arrows', () => {
Expand All @@ -75,7 +73,7 @@ describe('ContentPicker', () => {
helpers.getRow(0).contains(FIRST_ITEM_OF_FIRST_PAGE);

// Stub call to second page
cy.route('GET', '**/folders/*', SECOND_PAGE);
cy.intercept('GET', '**/folders/*', SECOND_PAGE);

// Click the right arrow
helpers
Expand All @@ -87,7 +85,7 @@ describe('ContentPicker', () => {
helpers.getRow(0).contains(FIRST_ITEM_OF_SECOND_PAGE);

// Stub call to first page
cy.route('GET', '**/folders/*', 'fixture:content-picker/folder-page-1.json');
cy.intercept('GET', '**/folders/*', { fixture: 'content-picker/folder-page-1.json' });

// Click the left arrow
helpers
Expand All @@ -109,7 +107,7 @@ describe('ContentPicker', () => {
helpers.getPaginationCountButton(1).click();

// Stub call to second page
cy.route('GET', '**/folders/*', SECOND_PAGE);
cy.intercept('GET', '**/folders/*', SECOND_PAGE);

// Click the second option in the dropdown menu
helpers
Expand All @@ -121,7 +119,7 @@ describe('ContentPicker', () => {
helpers.getRow(0).contains(FIRST_ITEM_OF_SECOND_PAGE);

// Stub call to first page
cy.route('GET', '**/folders/*', FIRST_PAGE);
cy.intercept('GET', '**/folders/*', FIRST_PAGE);

// Confirm that the pagination count button says "2 of 2", and click it
helpers.getPaginationCountButton(2).click();
Expand All @@ -141,20 +139,18 @@ describe('ContentPicker', () => {

describe('Selection', () => {
beforeEach(() => {
cy.server();

cy.route('GET', '**/folders/*', 'fixture:content-picker/root-folder.json');
cy.intercept('GET', '**/folders/*', { fixture: 'content-picker/root-folder.json' });

['319004423111', '308566419514', '308409990441'].forEach(fileId => {
cy.fixture('content-picker/get-sharedlink.json').then(getSharedLinkJson => {
cy.route('GET', `**/files/${fileId}?fields=allowed_shared_link_access_levels,shared_link`, {
cy.intercept('GET', `**/files/${fileId}?fields=allowed_shared_link_access_levels,shared_link`, {
...getSharedLinkJson,
id: fileId,
});
});

cy.fixture('content-picker/create-sharedlink.json').then(createSharedLinkJson => {
cy.route('PUT', `**/files/${fileId}`, {
cy.intercept('PUT', `**/files/${fileId}`, {
...createSharedLinkJson,
id: fileId,
});
Expand Down Expand Up @@ -193,7 +189,7 @@ describe('ContentPicker', () => {
helpers.selectRow(2);

// Override the route stubbing for a sub folder
cy.route('GET', '**/folders/*', 'fixture:content-picker/sample-folder.json');
cy.intercept('GET', '**/folders/*', { fixture: 'content-picker/sample-folder.json' });

// Explore folder (row 1)
helpers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Specify Annotations version in command line, otherwise defaults to the latest version
// e.g. CYPRESS_ANNOTATIONS_VERSION=4.0.0-beta.24 yarn test:e2e:open
const ANNOTATIONS_VERSION = Cypress.env('ANNOTATIONS_VERSION') ? `@${Cypress.env('ANNOTATIONS_VERSION')}` : '';
// e.g. CYPRESS_ANNOTATIONS_VERSION=4.1.1-beta.5 yarn test:e2e:open
// const ANNOTATIONS_VERSION = Cypress.env('ANNOTATIONS_VERSION') ? `@${Cypress.env('ANNOTATIONS_VERSION')}` : '';
//
// import(`https://unpkg.com/box-annotations${ANNOTATIONS_VERSION}/dist/annotations.js`);

import(`https://unpkg.com/box-annotations${ANNOTATIONS_VERSION}/dist/annotations.js`);

describe('ContentPreview with Annotations', () => {
xdescribe('ContentPreview with Annotations', () => {
const helpers = {
load({ features, fileId, props } = {}) {
cy.visit('/Elements/ContentPreview', {
Expand All @@ -29,7 +29,7 @@ describe('ContentPreview with Annotations', () => {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = `https://unpkg.com/box-annotations${ANNOTATIONS_VERSION}/dist/annotations.css`;
// link.href = `https://unpkg.com/box-annotations${ANNOTATIONS_VERSION}/dist/annotations.css`;
head.appendChild(link);
},
});
Expand Down Expand Up @@ -102,6 +102,7 @@ describe('ContentPreview with Annotations', () => {
},
});

// eslint-disable-next-line cypress/unsafe-to-chain-command
cy.get('.ba-DrawingTarget')
.should('be.visible')
.rightclick() // prevent jumping to hyperlink of <a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ describe('ContentPreview', () => {
cy.get('.bcpr-PreviewHeader--basic').should('be.visible');
},
selectVersion(versionName) {
cy.getByTestId('versions-item-button').within($versionsItem => {
cy.wrap($versionsItem)
.contains(versionName)
.click();
});
cy.getByTestId('versions-item-button')
.contains(versionName)
.click();
},
};

Expand Down Expand Up @@ -82,13 +80,31 @@ describe('ContentPreview', () => {
[300, 'not.exist'],
];

helpers.load({
fileId: Cypress.env('FILE_ID_DOC'),
props: {
contentSidebarProps: {
hasActivityFeed: true,
},
},
});

breakpoints.forEach(([width, assertion]) => {
cy.viewport(width, 600);
cy.getByTestId('bcs-content').should(assertion);
});
});

it('The sidebar should open on a small screen if a user clicks a tab', () => {
helpers.load({
fileId: Cypress.env('FILE_ID_DOC'),
props: {
contentSidebarProps: {
hasActivityFeed: true,
},
},
});

cy.viewport(800, 600);
cy.getByTestId('bcs-content').should('not.exist');
cy.getByTestId('sidebaractivity').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('additional-tabs', () => {
it('should display nothing when additional tabs are disabled', () => {
helpers.load({ hasAdditionalTabs: false });

cy.getByTestId('additionaltabplaceholder').should('not.be.visible');
cy.getByTestId('additionaltabplaceholder').should('not.exist');
});

it('should display the loading state', () => {
Expand All @@ -71,7 +71,7 @@ describe('additional-tabs', () => {
it('should render the provided icons and tooltips', () => {
helpers.load({ hasAdditionalTabs: true, additionalTabs: tabData });

cy.getByTestId('additionaltabplaceholder').should('not.be.visible');
cy.getByTestId('additionaltabplaceholder').should('not.exist');

helpers
.getTabs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ describe('ContentSidebar', () => {

describe('version history', () => {
beforeEach(() => {
cy.server();
cy.route('GET', '**/files/*', 'fixture:content-sidebar/restored-file.json');
cy.intercept('GET', '**/files/*', { fixture: 'content-sidebar/restored-file.json' });

helpers.load({
fileId: Cypress.env('FILE_ID_DOC_VERSIONED'),
Expand All @@ -101,12 +100,13 @@ describe('ContentSidebar', () => {
cy.getByTestId('versionhistory').click();
cy.contains('[data-testid="bcs-content"]', 'Version History').as('versionHistory');

cy.getByTestId('versions-item-button').within($versionsItem => {
cy.wrap($versionsItem)
.contains('V2')
.click();
cy.wrap($versionsItem).should('have.class', 'bcs-is-selected');
});
cy.getByTestId('versions-item-button')
.contains('V2')
.click();

cy.getByTestId('versions-item-button')
.eq(-2)
.should('have.class', 'bcs-is-selected');

cy.get('@versionHistory')
.contains('Back')
Expand All @@ -115,9 +115,8 @@ describe('ContentSidebar', () => {
});

it('should display the current version as restored', () => {
cy.getByTestId('version').within($versionItem => {
cy.wrap($versionItem).contains('promoted v6 to v10');
});
cy.getByTestId('version').contains('promoted v6 to v10');

cy.getByTestId('sidebardetails').click();
cy.getByTestId('versionhistory').click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ describe('Create Task', () => {

context('Task Form', () => {
beforeEach(() => {
cy.server();
cy.contains(l('be.contentSidebar.addTask')).click();
cy.contains(l('be.contentSidebar.addTask.approval')).click();
});
it('does not allow submitting form without input', () => {
xit('does not allow submitting form without input', () => {
getMessageField()
.type('...')
.clear();
Expand All @@ -61,7 +60,7 @@ describe('Create Task', () => {
});

it('shows error state after receiving server error', () => {
cy.route('POST', '**/undoc/tasks/with_dependencies').as('createTaskWithDeps');
cy.intercept('POST', '**/undoc/tasks/with_dependencies').as('createTaskWithDeps');
getSubmitButton().should('not.have.class', 'is-loading');
cy.getByTestId('create-task-modal').within(() => {
getAssigneeField()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('ContentUploader', () => {
cy.wrap(subject).trigger('change', { force: true });
});

// eslint-disable-next-line cypress/unsafe-to-chain-command
cy.get(dropSelector)
.first()
.trigger('dragenter', {
Expand Down
Loading

0 comments on commit 23f2693

Please sign in to comment.