Skip to content
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

Added a few simple test cases #1041

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,31 @@ jobs:
conda install -c conda-forge mamba
mamba env update --file conda-environment.yml --name base
pip install -e .

- name: Cache UI dependencies
uses: actions/cache@v2
with:
path: |
~/.cache/Cypress
ui/node_modules
key: cache-${{ runner.os }}-${{ hashFiles('ui/package-lock.json') }}

- name: Install UI dependencies
run: npm install --prefix ./ui --legacy-peer-deps

- name: Build UI
run: |
npm install --prefix ./ui
npm run --prefix ./ui build
run: npm run --prefix ./ui build
env:
DISABLE_ESLINT_PLUGIN: true
- name: Run mxcube backend
run: |
mxcubeweb-server -r ./test/HardwareObjectsMockup.xml/ --static-folder $(pwd)/ui/build/ -L debug &
- name: Cypress run
uses: cypress-io/github-action@v5
Copy link
Collaborator

@axelboc axelboc Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This action was also installing dependencies. In fact, it's quite the behemoth: it does the caching, the installation, can even run a dev server ... I prefer to make all these steps explicit for maintainability (e.g. so we won't have to remember to configure it properly if we switch to pnpm in the future, for instance).


- name: Run MXCuBE backend
run: mxcubeweb-server -r ./test/HardwareObjectsMockup.xml/ --static-folder $(pwd)/ui/build/ -L debug &

- name: Run Cypress
run: npm run --prefix ./ui e2e
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not missing cypress though ;) or ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script is called e2e – it runs cypress run. The script cypress runs cypress open, which opens Cypress for local testing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see, sorry for the confusion


- uses: actions/upload-artifact@v3
if: failure()
with:
working-directory: ./ui
name: cypress
path: cypress/debug
4 changes: 2 additions & 2 deletions .github/workflows/format_and_lint_ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Install dependencies
run: |
pip install -e .
npm install --prefix ./ui
npm install --prefix ./ui --legacy-peer-deps
Copy link
Member Author

@marcus-oscarsson marcus-oscarsson Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--legacy-peer-deps because the node version is old ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a flag for NPM to disregard peer deps warnings and install any missing peer deps automatically. With pnpm, I would have added an override in package.json. The warning just comes from @testing-library/cypress which does not allow the latest version of Cypress as peer dep — no problem with ignoring this warning if the tests pass.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, ok

- name: Check formatting
run: npm run --prefix ./ui prettier
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
- name: Install dependencies
run: |
pip install -e .
npm install --prefix ./ui
npm install --prefix ./ui --legacy-peer-deps
- name: Lint
run: npm run --prefix ./ui eslint
2 changes: 1 addition & 1 deletion docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ vncserver :1 -geometry 1680x1050 -depth 24 &

cd /opt/mxcube3

npm install
npm install --legacy-peer-deps
npm start &

redis-server &
Expand Down
10 changes: 10 additions & 0 deletions ui/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,15 @@ module.exports = createConfig({
'jest/require-top-level-describe': 'off', // filename should already be meaningful, extra nesting is unnecessary
},
}),
{
files: ['cypress/**/*.js'],
rules: {
'testing-library/await-async-query': 'off', // Cypress has its own way of dealing with asynchronicity
'testing-library/await-async-utils': 'off', // Cypress has its own way of dealing with asynchronicity
'testing-library/prefer-screen-queries': 'off', // Cypress provides `cy` object instead of `screen`
'sonarjs/no-duplicate-string': 'off', // incompatible with Cypress testing syntax
'unicorn/numeric-separators-style': 'off', // not supported
},
},
],
});
1 change: 1 addition & 0 deletions ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# testing
/coverage
/cypress/debug

# production
/build
Expand Down
6 changes: 3 additions & 3 deletions ui/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
baseUrl: 'http://localhost:8081',
supportFile: 'cypress/support.js',
screenshotsFolder: 'cypress/debug',
},
});
24 changes: 19 additions & 5 deletions ui/cypress/e2e/app.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
describe('login', () => {
it("can't login with invalid credentials", () => {
cy.login('idte0', '0000');
cy.findByText('Could not authenticate').should('be.visible');
});

it('can login with valid credentials', () => {
cy.login();
cy.findByRole('link', { name: 'MXCuBE-Web (OSC)' }).should('be.visible');
});
});

describe('app', () => {
it('loads the login page', () => {
cy.visit('http://localhost:8081');
cy.get('input[placeholder*="Login ID"]').should('be.visible');
cy.get('input[placeholder*="Password"]').should('be.visible');
cy.get('button[type=submit]').should('be.visible');
beforeEach(() => {
cy.login();
cy.findByRole('link', { name: 'MXCuBE-Web (OSC)' }).should('be.visible');
});

it('displays collection page', () => {
cy.findByRole('button', { name: /Beamline Actions/u }).should('be.visible');
});
});
9 changes: 9 additions & 0 deletions ui/cypress/support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import '@testing-library/cypress/add-commands';

Cypress.Commands.add('login', (username = 'idtest0', password = '0000') => {
cy.visit('/');
cy.findByRole('heading', { name: 'MXCuBE' }).should('be.visible');
cy.findByLabelText('Login ID').type(username);
cy.findByLabelText('Password').type(password);
cy.findByRole('button', { name: 'Sign in' }).click();
});
27 changes: 0 additions & 27 deletions ui/cypress/support/commands.js

This file was deleted.

20 changes: 0 additions & 20 deletions ui/cypress/support/e2e.js

This file was deleted.

Loading
Loading