Skip to content

Commit 340cc0a

Browse files
authored
Merge pull request DSpace#1898 from tdonohue/upgrade_latest_cypress_9
E2E test stabilization, and upgrade to latest Cypress v9 and axe-core
2 parents f659e81 + 11154d2 commit 340cc0a

5 files changed

Lines changed: 59 additions & 23 deletions

File tree

cypress/integration/my-dspace.spec.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { testA11y } from 'cypress/support/utils';
44

55
describe('My DSpace page', () => {
66
it('should display recent submissions and pass accessibility tests', () => {
7-
cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
8-
97
cy.visit('/mydspace');
108

9+
// This page is restricted, so we will be shown the login form. Fill it out & submit.
10+
cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
11+
1112
cy.get('ds-my-dspace-page').should('exist');
1213

1314
// At least one recent submission should be displayed
@@ -36,10 +37,11 @@ describe('My DSpace page', () => {
3637
});
3738

3839
it('should have a working detailed view that passes accessibility tests', () => {
39-
cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
40-
4140
cy.visit('/mydspace');
4241

42+
// This page is restricted, so we will be shown the login form. Fill it out & submit.
43+
cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
44+
4345
cy.get('ds-my-dspace-page').should('exist');
4446

4547
// Click button in sidebar to display detailed view
@@ -61,9 +63,11 @@ describe('My DSpace page', () => {
6163

6264
// NOTE: Deleting existing submissions is exercised by submission.spec.ts
6365
it('should let you start a new submission & edit in-progress submissions', () => {
64-
cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
6566
cy.visit('/mydspace');
6667

68+
// This page is restricted, so we will be shown the login form. Fill it out & submit.
69+
cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
70+
6771
// Open the New Submission dropdown
6872
cy.get('button[data-test="submission-dropdown"]').click();
6973
// Click on the "Item" type in that dropdown
@@ -131,9 +135,11 @@ describe('My DSpace page', () => {
131135
});
132136

133137
it('should let you import from external sources', () => {
134-
cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
135138
cy.visit('/mydspace');
136139

140+
// This page is restricted, so we will be shown the login form. Fill it out & submit.
141+
cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
142+
137143
// Open the New Import dropdown
138144
cy.get('button[data-test="import-dropdown"]').click();
139145
// Click on the "Item" type in that dropdown

cypress/integration/submission.spec.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ describe('New Submission page', () => {
66
// NOTE: We already test that new submissions can be started from MyDSpace in my-dspace.spec.ts
77

88
it('should create a new submission when using /submit path & pass accessibility', () => {
9-
cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
10-
119
// Test that calling /submit with collection & entityType will create a new submission
1210
cy.visit('/submit?collection=' + TEST_SUBMIT_COLLECTION_UUID + '&entityType=none');
1311

12+
// This page is restricted, so we will be shown the login form. Fill it out & submit.
13+
cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
14+
1415
// Should redirect to /workspaceitems, as we've started a new submission
1516
cy.url().should('include', '/workspaceitems');
1617

@@ -33,11 +34,12 @@ describe('New Submission page', () => {
3334
});
3435

3536
it('should block submission & show errors if required fields are missing', () => {
36-
cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
37-
3837
// Create a new submission
3938
cy.visit('/submit?collection=' + TEST_SUBMIT_COLLECTION_UUID + '&entityType=none');
4039

40+
// This page is restricted, so we will be shown the login form. Fill it out & submit.
41+
cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
42+
4143
// Attempt an immediate deposit without filling out any fields
4244
cy.get('button#deposit').click();
4345

@@ -92,11 +94,12 @@ describe('New Submission page', () => {
9294
});
9395

9496
it('should allow for deposit if all required fields completed & file uploaded', () => {
95-
cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
96-
9797
// Create a new submission
9898
cy.visit('/submit?collection=' + TEST_SUBMIT_COLLECTION_UUID + '&entityType=none');
9999

100+
// This page is restricted, so we will be shown the login form. Fill it out & submit.
101+
cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD);
102+
100103
// Fill out all required fields (Title, Date)
101104
cy.get('input#dc_title').type('DSpace logo uploaded via e2e tests');
102105
cy.get('input#dc_date_issued_year').type('2022');

cypress/support/commands.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,23 @@ declare global {
1919
* @param password password to login as
2020
*/
2121
login(email: string, password: string): typeof login;
22+
23+
/**
24+
* Login via form before accessing the next page. Useful to fill out login
25+
* form when a cy.visit() call is to an a page which requires authentication.
26+
* @param email email to login as
27+
* @param password password to login as
28+
*/
29+
loginViaForm(email: string, password: string): typeof loginViaForm;
2230
}
2331
}
2432
}
2533

2634
/**
2735
* Login user via REST API directly, and pass authentication token to UI via
2836
* the UI's dsAuthInfo cookie.
37+
* WARNING: WHILE THIS METHOD WORKS, OCCASIONALLY RANDOM AUTHENTICATION ERRORS OCCUR.
38+
* At this time "loginViaForm()" seems more consistent/stable.
2939
* @param email email to login as
3040
* @param password password to login as
3141
*/
@@ -81,3 +91,20 @@ function login(email: string, password: string): void {
8191
}
8292
// Add as a Cypress command (i.e. assign to 'cy.login')
8393
Cypress.Commands.add('login', login);
94+
95+
96+
/**
97+
* Login user via displayed login form
98+
* @param email email to login as
99+
* @param password password to login as
100+
*/
101+
function loginViaForm(email: string, password: string): void {
102+
// Enter email
103+
cy.get('ds-log-in [data-test="email"]').type(email);
104+
// Enter password
105+
cy.get('ds-log-in [data-test="password"]').type(password);
106+
// Click login button
107+
cy.get('ds-log-in [data-test="login-button"]').click();
108+
}
109+
// Add as a Cypress command (i.e. assign to 'cy.loginViaForm')
110+
Cypress.Commands.add('loginViaForm', loginViaForm);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@
162162
"@types/sanitize-html": "^2.6.2",
163163
"@typescript-eslint/eslint-plugin": "5.11.0",
164164
"@typescript-eslint/parser": "5.11.0",
165-
"axe-core": "^4.3.3",
165+
"axe-core": "^4.4.3",
166166
"compression-webpack-plugin": "^9.2.0",
167167
"copy-webpack-plugin": "^6.4.1",
168168
"cross-env": "^7.0.3",
169169
"css-loader": "^6.2.0",
170170
"css-minimizer-webpack-plugin": "^3.4.1",
171171
"cssnano": "^5.0.6",
172-
"cypress": "9.5.1",
172+
"cypress": "9.7.0",
173173
"cypress-axe": "^0.14.0",
174174
"debug-loader": "^0.0.1",
175175
"deep-freeze": "0.0.1",

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,10 +3221,10 @@ aws4@^1.8.0:
32213221
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
32223222
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
32233223

3224-
axe-core@^4.3.3:
3225-
version "4.4.1"
3226-
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.1.tgz#7dbdc25989298f9ad006645cd396782443757413"
3227-
integrity sha512-gd1kmb21kwNuWr6BQz8fv6GNECPBnUasepcoLbekws23NVBLODdsClRZ+bQ8+9Uomf3Sm3+Vwn0oYG9NvwnJCw==
3224+
axe-core@^4.4.3:
3225+
version "4.4.3"
3226+
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.3.tgz#11c74d23d5013c0fa5d183796729bc3482bd2f6f"
3227+
integrity sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w==
32283228

32293229
axios@0.21.4:
32303230
version "0.21.4"
@@ -4686,10 +4686,10 @@ cypress-axe@^0.14.0:
46864686
resolved "https://registry.yarnpkg.com/cypress-axe/-/cypress-axe-0.14.0.tgz#5f5e70fb36b8cb3ba73a8ba01e9262ff1268d5e2"
46874687
integrity sha512-7Rdjnko0MjggCmndc1wECAkvQBIhuy+DRtjF7bd5YPZRFvubfMNvrxfqD8PWQmxm7MZE0ffS4Xr43V6ZmvLopg==
46884688

4689-
cypress@9.5.1:
4690-
version "9.5.1"
4691-
resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.5.1.tgz#51162f3688cedf5ffce311b914ef49a7c1ece076"
4692-
integrity sha512-H7lUWB3Svr44gz1rNnj941xmdsCljXoJa2cDneAltjI9leKLMQLm30x6jLlpQ730tiVtIbW5HdUmBzPzwzfUQg==
4689+
cypress@9.7.0:
4690+
version "9.7.0"
4691+
resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.7.0.tgz#bf55b2afd481f7a113ef5604aa8b693564b5e744"
4692+
integrity sha512-+1EE1nuuuwIt/N1KXRR2iWHU+OiIt7H28jJDyyI4tiUftId/DrXYEwoDa5+kH2pki1zxnA0r6HrUGHV5eLbF5Q==
46934693
dependencies:
46944694
"@cypress/request" "^2.88.10"
46954695
"@cypress/xvfb" "^1.2.4"
@@ -4723,7 +4723,7 @@ cypress@9.5.1:
47234723
listr2 "^3.8.3"
47244724
lodash "^4.17.21"
47254725
log-symbols "^4.0.0"
4726-
minimist "^1.2.5"
4726+
minimist "^1.2.6"
47274727
ospath "^1.2.2"
47284728
pretty-bytes "^5.6.0"
47294729
proxy-from-env "1.0.0"

0 commit comments

Comments
 (0)