Skip to content

Commit e47593b

Browse files
committed
Fix circular dependency issue by using Cypres env variables directly instead of global constants
1 parent 8d61fa6 commit e47593b

15 files changed

Lines changed: 51 additions & 76 deletions

cypress.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ export default defineConfig({
99
openMode: 0,
1010
},
1111
env: {
12-
// Global constants used in DSpace e2e tests (see also ./cypress/support/e2e.ts)
13-
// May be overridden in our cypress.json config file using specified environment variables.
12+
// Global DSpace environment variables used in all our Cypress e2e tests
13+
// May be modified in this config, or overridden in a variety of ways.
14+
// See Cypress environment variable docs: https://docs.cypress.io/guides/guides/environment-variables
1415
// Default values listed here are all valid for the Demo Entities Data set available at
1516
// https://github.com/DSpace-Labs/AIP-Files/releases/tag/demo-entities-data
1617
// (This is the data set used in our CI environment)

cypress/e2e/breadcrumbs.cy.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e';
21
import { testA11y } from 'cypress/support/utils';
32

43
describe('Breadcrumbs', () => {
54
it('should pass accessibility tests', () => {
65
// Visit an Item, as those have more breadcrumbs
7-
cy.visit('/entities/publication/'.concat(TEST_ENTITY_PUBLICATION));
6+
cy.visit('/entities/publication/'.concat(Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION')));
87

98
// Wait for breadcrumbs to be visible
109
cy.get('ds-breadcrumbs').should('be.visible');

cypress/e2e/collection-page.cy.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { TEST_COLLECTION } from 'cypress/support/e2e';
21
import { testA11y } from 'cypress/support/utils';
32

43
describe('Collection Page', () => {
54

65
it('should pass accessibility tests', () => {
7-
cy.visit('/collections/'.concat(TEST_COLLECTION));
6+
cy.visit('/collections/'.concat(Cypress.env('DSPACE_TEST_COLLECTION')));
87

98
// <ds-collection-page> tag must be loaded
109
cy.get('ds-collection-page').should('be.visible');

cypress/e2e/collection-statistics.cy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { REGEX_MATCH_NON_EMPTY_TEXT, TEST_COLLECTION } from 'cypress/support/e2e';
1+
import { REGEX_MATCH_NON_EMPTY_TEXT } from 'cypress/support/e2e';
22
import { testA11y } from 'cypress/support/utils';
33

44
describe('Collection Statistics Page', () => {
5-
const COLLECTIONSTATISTICSPAGE = '/statistics/collections/'.concat(TEST_COLLECTION);
5+
const COLLECTIONSTATISTICSPAGE = '/statistics/collections/'.concat(Cypress.env('DSPACE_TEST_COLLECTION'));
66

77
it('should load if you click on "Statistics" from a Collection page', () => {
8-
cy.visit('/collections/'.concat(TEST_COLLECTION));
8+
cy.visit('/collections/'.concat(Cypress.env('DSPACE_TEST_COLLECTION')));
99
cy.get('ds-navbar ds-link-menu-item a[title="Statistics"]').click();
1010
cy.location('pathname').should('eq', COLLECTIONSTATISTICSPAGE);
1111
});
@@ -18,7 +18,7 @@ describe('Collection Statistics Page', () => {
1818
it('should contain a "Total visits per month" section', () => {
1919
cy.visit(COLLECTIONSTATISTICSPAGE);
2020
// Check just for existence because this table is empty in CI environment as it's historical data
21-
cy.get('.'.concat(TEST_COLLECTION).concat('_TotalVisitsPerMonth')).should('exist');
21+
cy.get('.'.concat(Cypress.env('DSPACE_TEST_COLLECTION')).concat('_TotalVisitsPerMonth')).should('exist');
2222
});
2323

2424
it('should pass accessibility tests', () => {

cypress/e2e/community-page.cy.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { TEST_COMMUNITY } from 'cypress/support/e2e';
21
import { testA11y } from 'cypress/support/utils';
32

43
describe('Community Page', () => {
54

65
it('should pass accessibility tests', () => {
7-
cy.visit('/communities/'.concat(TEST_COMMUNITY));
6+
cy.visit('/communities/'.concat(Cypress.env('DSPACE_TEST_COMMUNITY')));
87

98
// <ds-community-page> tag must be loaded
109
cy.get('ds-community-page').should('be.visible');

cypress/e2e/community-statistics.cy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { REGEX_MATCH_NON_EMPTY_TEXT, TEST_COMMUNITY } from 'cypress/support/e2e';
1+
import { REGEX_MATCH_NON_EMPTY_TEXT } from 'cypress/support/e2e';
22
import { testA11y } from 'cypress/support/utils';
33

44
describe('Community Statistics Page', () => {
5-
const COMMUNITYSTATISTICSPAGE = '/statistics/communities/'.concat(TEST_COMMUNITY);
5+
const COMMUNITYSTATISTICSPAGE = '/statistics/communities/'.concat(Cypress.env('DSPACE_TEST_COMMUNITY'));
66

77
it('should load if you click on "Statistics" from a Community page', () => {
8-
cy.visit('/communities/'.concat(TEST_COMMUNITY));
8+
cy.visit('/communities/'.concat(Cypress.env('DSPACE_TEST_COMMUNITY')));
99
cy.get('ds-navbar ds-link-menu-item a[title="Statistics"]').click();
1010
cy.location('pathname').should('eq', COMMUNITYSTATISTICSPAGE);
1111
});
@@ -18,7 +18,7 @@ describe('Community Statistics Page', () => {
1818
it('should contain a "Total visits per month" section', () => {
1919
cy.visit(COMMUNITYSTATISTICSPAGE);
2020
// Check just for existence because this table is empty in CI environment as it's historical data
21-
cy.get('.'.concat(TEST_COMMUNITY).concat('_TotalVisitsPerMonth')).should('exist');
21+
cy.get('.'.concat(Cypress.env('DSPACE_TEST_COMMUNITY')).concat('_TotalVisitsPerMonth')).should('exist');
2222
});
2323

2424
it('should pass accessibility tests', () => {

cypress/e2e/homepage-statistics.cy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { REGEX_MATCH_NON_EMPTY_TEXT, TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e';
1+
import { REGEX_MATCH_NON_EMPTY_TEXT } from 'cypress/support/e2e';
22
import { testA11y } from 'cypress/support/utils';
33
import '../support/commands';
44

@@ -11,8 +11,8 @@ describe('Site Statistics Page', () => {
1111

1212
it('should pass accessibility tests', () => {
1313
// generate 2 view events on an Item's page
14-
cy.generateViewEvent(TEST_ENTITY_PUBLICATION, 'item');
15-
cy.generateViewEvent(TEST_ENTITY_PUBLICATION, 'item');
14+
cy.generateViewEvent(Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION'), 'item');
15+
cy.generateViewEvent(Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION'), 'item');
1616

1717
cy.visit('/statistics');
1818

cypress/e2e/item-page.cy.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e';
21
import { testA11y } from 'cypress/support/utils';
32

43
describe('Item Page', () => {
5-
const ITEMPAGE = '/items/'.concat(TEST_ENTITY_PUBLICATION);
6-
const ENTITYPAGE = '/entities/publication/'.concat(TEST_ENTITY_PUBLICATION);
4+
const ITEMPAGE = '/items/'.concat(Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION'));
5+
const ENTITYPAGE = '/entities/publication/'.concat(Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION'));
76

87
// Test that entities will redirect to /entities/[type]/[uuid] when accessed via /items/[uuid]
98
it('should redirect to the entity page when navigating to an item page', () => {

cypress/e2e/item-statistics.cy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { REGEX_MATCH_NON_EMPTY_TEXT, TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e';
1+
import { REGEX_MATCH_NON_EMPTY_TEXT } from 'cypress/support/e2e';
22
import { testA11y } from 'cypress/support/utils';
33

44
describe('Item Statistics Page', () => {
5-
const ITEMSTATISTICSPAGE = '/statistics/items/'.concat(TEST_ENTITY_PUBLICATION);
5+
const ITEMSTATISTICSPAGE = '/statistics/items/'.concat(Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION'));
66

77
it('should load if you click on "Statistics" from an Item/Entity page', () => {
8-
cy.visit('/entities/publication/'.concat(TEST_ENTITY_PUBLICATION));
8+
cy.visit('/entities/publication/'.concat(Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION')));
99
cy.get('ds-navbar ds-link-menu-item a[title="Statistics"]').click();
1010
cy.location('pathname').should('eq', ITEMSTATISTICSPAGE);
1111
});
@@ -24,7 +24,7 @@ describe('Item Statistics Page', () => {
2424
it('should contain a "Total visits per month" section', () => {
2525
cy.visit(ITEMSTATISTICSPAGE);
2626
// Check just for existence because this table is empty in CI environment as it's historical data
27-
cy.get('.'.concat(TEST_ENTITY_PUBLICATION).concat('_TotalVisitsPerMonth')).should('exist');
27+
cy.get('.'.concat(Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION')).concat('_TotalVisitsPerMonth')).should('exist');
2828
});
2929

3030
it('should pass accessibility tests', () => {

cypress/e2e/login-modal.cy.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { TEST_ADMIN_PASSWORD, TEST_ADMIN_USER, TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e';
21
import { testA11y } from 'cypress/support/utils';
32

43
const page = {
@@ -37,7 +36,7 @@ const page = {
3736

3837
describe('Login Modal', () => {
3938
it('should login when clicking button & stay on same page', () => {
40-
const ENTITYPAGE = '/entities/publication/'.concat(TEST_ENTITY_PUBLICATION);
39+
const ENTITYPAGE = '/entities/publication/'.concat(Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION'));
4140
cy.visit(ENTITYPAGE);
4241

4342
// Login menu should exist
@@ -47,7 +46,7 @@ describe('Login Modal', () => {
4746
page.openLoginMenu();
4847
cy.get('.form-login').should('be.visible');
4948

50-
page.submitLoginAndPasswordByPressingButton(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD);
49+
page.submitLoginAndPasswordByPressingButton(Cypress.env('DSPACE_TEST_ADMIN_USER'), Cypress.env('DSPACE_TEST_ADMIN_PASSWORD'));
5150
cy.get('ds-log-in').should('not.exist');
5251

5352
// Verify we are still on the same page
@@ -67,7 +66,7 @@ describe('Login Modal', () => {
6766
cy.get('.form-login').should('be.visible');
6867

6968
// Login, and the <ds-log-in> tag should no longer exist
70-
page.submitLoginAndPasswordByPressingEnter(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD);
69+
page.submitLoginAndPasswordByPressingEnter(Cypress.env('DSPACE_TEST_ADMIN_USER'), Cypress.env('DSPACE_TEST_ADMIN_PASSWORD'));
7170
cy.get('.form-login').should('not.exist');
7271

7372
// Verify we are still on homepage
@@ -81,7 +80,7 @@ describe('Login Modal', () => {
8180

8281
it('should support logout', () => {
8382
// First authenticate & access homepage
84-
cy.login(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD);
83+
cy.login(Cypress.env('DSPACE_TEST_ADMIN_USER'), Cypress.env('DSPACE_TEST_ADMIN_PASSWORD'));
8584
cy.visit('/');
8685

8786
// Verify ds-log-in tag doesn't exist, but ds-log-out tag does exist
@@ -140,7 +139,7 @@ describe('Login Modal', () => {
140139
testA11y('ds-log-in');
141140

142141
// Now login
143-
page.submitLoginAndPasswordByPressingButton(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD);
142+
page.submitLoginAndPasswordByPressingButton(Cypress.env('DSPACE_TEST_ADMIN_USER'), Cypress.env('DSPACE_TEST_ADMIN_PASSWORD'));
144143
cy.get('ds-log-in').should('not.exist');
145144

146145
// Open user menu, verify user menu accesibility

0 commit comments

Comments
 (0)