Skip to content

Commit

Permalink
feat: Add e2e tests (#273)
Browse files Browse the repository at this point in the history
* Add pagination_test command

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Add open filters command

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Add commands & functions tests

Signed-off-by: Milouu <milan.roustan@owkin.com>

* add log feature to config

Signed-off-by: Milouu <milan.roustan@owkin.com>

* change scripts name

Signed-off-by: Milouu <milan.roustan@owkin.com>

* delete fixture example file

Signed-off-by: Milouu <milan.roustan@owkin.com>

* add cypress commands

Signed-off-by: Milouu <milan.roustan@owkin.com>

* add functions tests

Signed-off-by: Milouu <milan.roustan@owkin.com>

* add users page test to menu tests

Signed-off-by: Milouu <milan.roustan@owkin.com>

* add cps tests

Signed-off-by: Milouu <milan.roustan@owkin.com>

* add cp details tests

Signed-off-by: Milouu <milan.roustan@owkin.com>

* add datasets tests

Signed-off-by: Milouu <milan.roustan@owkin.com>

* add tasks tests

Signed-off-by: Milouu <milan.roustan@owkin.com>

* add support function

Signed-off-by: Milouu <milan.roustan@owkin.com>

* update changelog

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Add comments to commands file

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Increase retries for CI testing

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Fix misc tests

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Add permissions conditions to download function test

Signed-off-by: Milouu <milan.roustan@owkin.com>

* intercept test

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Clean PR

Signed-off-by: Milouu <milan.roustan@owkin.com>

* remove intercept

Signed-off-by: Milouu <milan.roustan@owkin.com>

* skip download function test

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Remove skipped test

Signed-off-by: Milouu <milan.roustan@owkin.com>

* add favorite test in cp details

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Add performance test in cp details

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Add searchbykey test for functions & datasets

Signed-off-by: Milouu <milan.roustan@owkin.com>

* Add CRUD tests for users page

Signed-off-by: Milouu <milan.roustan@owkin.com>

* style(src): run prettier

Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>

* fix: Wait before checking change on user role

Signed-off-by: Milouu <milan.roustan@owkin.com>

* fix: replace wait by built-in retry process

Signed-off-by: Milouu <milan.roustan@owkin.com>

---------

Signed-off-by: Milouu <milan.roustan@owkin.com>
Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
Co-authored-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
  • Loading branch information
Milouu and thbcmlowk committed Mar 6, 2024
1 parent 013ff03 commit 4c8834e
Show file tree
Hide file tree
Showing 44 changed files with 476 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Permissions details in Task I/Os (#280)
- Add e2e tests (#273)

### Changed

Expand Down
14 changes: 14 additions & 0 deletions e2e-tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@ export default defineConfig({
USERNAME: 'org-1',
PASSWORD: 'p@sswr0d44',
BACKEND_API_URL: 'http://substra-backend.org-1.com:8000',
DEFAULT_PAGE_SIZE: 30,
},
viewportWidth: 1440,
viewportHeight: 900,
video: false,
defaultCommandTimeout: 20000,
e2e: {
setupNodeEvents(on) {
on('task', {
// To see log messages in the terminal during cypress run
// cy.task("log", "my message")
log(message) {
// eslint-disable-next-line no-console
console.log(message + '\n\n');
return null;
},
});
},
baseUrl: 'http://substra-frontend.org-1.com:3000',
},
retries: {
Expand Down
72 changes: 72 additions & 0 deletions e2e-tests/cypress/e2e/computePlanDetails.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/// <reference types="Cypress" />

describe('Compute plans page', () => {
before(() => {
cy.login();
});

beforeEach(() => {
cy.visit('/compute_plans');
cy.get('tbody[data-cy=loaded]').get('tr').eq(1).click({ force: true });
});

it('navigates to the dedicated compute plan page', () => {
cy.url().should('match', /compute_plans\/.{36}\/tasks/);
});

it('adds cp to favorites', () => {
cy.getDataCy('favorite-cp').should('not.exist');
cy.getDataCy('favorite-box').first().click();
cy.getDataCy('favorite-cp').should('exist');
});

it('task drawer shows performance', () => {
cy.getDataCy('task-with-performance')
.should('have.length.gte', 0)
.then(($hits) => {
if ($hits.length > 0) {
cy.getDataCy('task-with-performance').first().click();
cy.getDataCy('output-performance').should('exist');
}
});
});

it('navigates to the Workflow page', () => {
cy.getDataCy('Workflow-tab').click({ force: true });
cy.url().should('match', /compute_plans\/.{36}\/workflow/);
cy.getDataCy('workflow-graph').should('exist');
});

it('navigates to the Detail page', () => {
cy.getDataCy('Details-tab').click({ force: true });
cy.url().should('match', /compute_plans\/.{36}\/tasks/);
});

it('navigates to the Performance page', () => {
cy.getDataCy('Performances-tab').click({ force: true });
cy.url().should('match', /compute_plans\/.{36}\/chart/);
cy.getDataCy('cp-chart').should('exist');
});

it('clicks on perf card to display perf details', () => {
cy.getDataCy('Performances-tab').click({ force: true });
cy.getDataCy('perf-list').should('exist');
cy.getDataCy('perf-card').first().click();
cy.getDataCy('perf-details').should('exist');
});

it('can download perf details as jpeg or csv', () => {
cy.getDataCy('Performances-tab').click({ force: true });
cy.getDataCy('perf-card').first().click();
cy.get('[data-cpkey]')
.invoke('data', 'cpkey')
.then((key) => {
cy.getDataCy('download-button').click();
cy.getDataCy('download-as-jpeg').click();
cy.checkDownloadedFile(`cp_${key}.jpeg`);
cy.getDataCy('download-button').click();
cy.getDataCy('download-as-csv').click();
cy.checkDownloadedFile(`${key}.csv`);
});
});
});
53 changes: 35 additions & 18 deletions e2e-tests/cypress/e2e/computePlans.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,48 @@ describe('Compute plans page', () => {
it('lists compute plans', () => {
cy.get('tbody[data-cy=loaded]')
.get('tr')
.should('have.length.greaterThan', 2);
.should('have.length.greaterThan', 1);
});

it('navigates to the dedicated compute plan page', () => {
cy.get('tbody[data-cy=loaded]').get('tr').eq(2).click({ force: true });
cy.url().should('match', /compute_plans\/.{36}\/tasks/);
it('displays tasks count bar in status/task column', () => {
cy.get('tbody[data-cy=loaded]')
.get('tr')
.eq(1)
.within(() => {
cy.getDataCy('cp-tasks-status')
.should('exist')
.trigger('mouseover');
cy.getDataCy('cp-tasks-status-tooltip').should('be.visible');
});
});

it('searches CP with a key', () => {
cy.checkSearchByKey('compute_plans');
});

it('adds a cp to favorites', () => {
cy.getDataCy('favorite-cp').should('not.exist');
cy.getDataCy('favorite-box').first().click();
cy.getDataCy('favorite-cp').should('exist');
});

it('navigates to the Workflow page', () => {
cy.get('tbody[data-cy=loaded]').get('tr').eq(2).click({ force: true });
cy.get('[data-cy=Workflow-tab]').click({ force: true });
cy.url().should('match', /compute_plans\/.{36}\/workflow/);
cy.get('[data-cy=workflow-graph]').should('exist');
it('selects/unselects cp in list', () => {
cy.getDataCy('selection-popover').should('not.exist');
cy.get('[data-cy="selection-box"]>input')
.first()
.check({ force: true });
cy.getDataCy('selection-popover').should('exist');
cy.get('[data-cy="selection-box"]>input')
.first()
.uncheck({ force: true });
cy.getDataCy('selection-popover').should('not.exist');
});

it('navigates back to the Detail page', () => {
cy.get('tbody[data-cy=loaded]').get('tr').eq(2).click({ force: true });
cy.get('[data-cy=Details-tab]').click({ force: true });
cy.url().should('match', /compute_plans\/.{36}\/tasks/);
it('opens filters', () => {
cy.checkOpenFilters(1);
});

it('navigates to the Performance page', () => {
cy.get('tbody[data-cy=loaded]').get('tr').eq(2).click({ force: true });
cy.get('[data-cy=Performances-tab]').click({ force: true });
cy.url().should('match', /compute_plans\/.{36}\/chart/);
cy.get('[data-cy=cp-chart]').should('exist');
it('can filter cps by status', () => {
cy.checkFilterAssetsBy('status');
});
});
14 changes: 13 additions & 1 deletion e2e-tests/cypress/e2e/datasets.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ describe('Datasets page', () => {
.should('have.length.greaterThan', 2);
});

it('opens filters', () => {
cy.checkOpenFilters(0);
});

it('can filter datasets by owner', () => {
cy.checkFilterAssetsBy('owner');
});

it('navigates to the dedicated dataset page', () => {
cy.get('tbody[data-cy=loaded]').get('tr').eq(2).click({ force: true });
cy.get('tbody[data-cy=loaded]').get('tr').eq(1).click({ force: true });
cy.url().should('match', /datasets\/.{36}/);
});

it('searches dataset with a key', () => {
cy.checkSearchByKey('datasets');
});
});
22 changes: 18 additions & 4 deletions e2e-tests/cypress/e2e/functions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,23 @@ describe('Functions page', () => {
.should('have.length.greaterThan', 2);
});

it('displays a function drawer', () => {
cy.get('[data-cy=drawer]').should('not.exist');
cy.get('tbody[data-cy=loaded]').get('tr').eq(2).click({ force: true });
cy.get('[data-cy=drawer]').should('exist');
it('functions pagination', () => {
cy.paginationTest();
});

it('open filters', () => {
cy.checkOpenFilters(0);
});

it('can filter functions by owner', () => {
cy.checkFilterAssetsBy('owner');
});

it('display a function drawer', () => {
cy.checkOpenDrawer();
});

it('searches function with a key', () => {
cy.checkSearchByKey('functions');
});
});
27 changes: 19 additions & 8 deletions e2e-tests/cypress/e2e/menu.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,43 @@ describe('Menu tests', () => {

beforeEach(() => {
cy.visit('/compute_plans');
cy.get('[data-cy=menu-button]').click();
cy.getDataCy('menu-button').click();
});

it('help and feedback modal', () => {
cy.get('[data-cy=help]').click();
cy.get('[data-cy=help-modal]').should('exist');
cy.getDataCy('help').click();
cy.getDataCy('help-modal').should('exist');
});

it('about modal', () => {
cy.get('[data-cy=about]').click();
cy.get('[data-cy=about-modal]').should('exist');
cy.getDataCy('about').click();
cy.getDataCy('about-modal').should('exist');
});

it('documentation link', () => {
cy.get('[data-cy=documentation]')
cy.getDataCy('documentation')
.should('have.attr', 'href', 'https://docs.substra.org/')
.should('have.attr', 'target', '_blank');
});

it('api tokens page', () => {
cy.get('[data-cy=api-tokens]').click();
cy.getDataCy('api-tokens').click();
cy.url().should('include', '/manage_tokens');
});

it('users management page', () => {
cy.get('[data-user-role]')
.invoke('data', 'user-role')
.then((userRole) => {
if (userRole === 'ADMIN') {
cy.getDataCy('users-management').click();
cy.url().should('include', '/users');
}
});
});

it('logout button', () => {
cy.get('[data-cy=logout]').click();
cy.getDataCy('logout').click();
cy.url().should('include', '/login');
});
});
21 changes: 18 additions & 3 deletions e2e-tests/cypress/e2e/tasks.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@ describe('Tasks page', () => {
.should('have.length.greaterThan', 2);
});

it('functions pagination', () => {
cy.paginationTest();
});

it('opens filters', () => {
cy.checkOpenFilters(0);
});

it('can filter tasks by status', () => {
cy.checkFilterAssetsBy('status');
});

it('displays a task drawer', () => {
cy.get('[data-cy=drawer]').should('not.exist');
cy.get('tbody[data-cy=loaded]').get('tr').eq(2).click({ force: true });
cy.get('[data-cy=drawer]').should('exist');
cy.checkOpenDrawer();
});

it('task drawer shows performance', () => {
cy.getDataCy('task-with-performance').first().click();
cy.getDataCy('output-performance').should('exist');
});
});
51 changes: 51 additions & 0 deletions e2e-tests/cypress/e2e/users.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
describe('Users page', () => {
before(() => {
cy.login();
});

beforeEach(() => {
cy.visit('/compute_plans');
cy.getDataCy('menu-button').click();
cy.get('[data-user-role]')
.invoke('data', 'user-role')
.then((userRole) => {
if (userRole === 'ADMIN') {
cy.visit('/users');
}
});
});

it('can create user', () => {
cy.getDataCy('create-user').click();
cy.getDataCy('username-input').type('Test');
cy.getDataCy('password-input').type('Azertyuiop123456789$');
cy.getDataCy('submit-form').click();

cy.get('[data-name="Test"]').first().should('exist');
});

it('can update user', () => {
cy.get('[data-name="Test"]')
.first()
.should('exist')
.then(($el) => {
cy.wrap($el).should('have.data', 'role', 'USER');
cy.wrap($el).click();
});
cy.get('select').eq(0).select('ADMIN');
cy.getDataCy('submit-form').click();

cy.get('[data-name="Test"]')
.first()
.should(($el) => {
expect($el).to.have.data('role', 'ADMIN');
});
});

it('can delete user', () => {
cy.get('[data-name="Test"]').first().click();
cy.getDataCy('delete-user').click();
cy.getDataCy('confirm-delete').click();
cy.get('[data-name="Test"]').should('not.exist');
});
});
5 changes: 0 additions & 5 deletions e2e-tests/cypress/fixtures/example.json

This file was deleted.

Loading

0 comments on commit 4c8834e

Please sign in to comment.