Skip to content

Commit bd21871

Browse files
KasinhouMatus Kasak
andauthored
VSB-TUO/e2e tests fix (#1015)
* Highlight actual option in dropdown menu * Removed discojuice from test * Removed forgotten commit * Removed discojuice from tombstone * Updated system wide alert test * Implemented suggested changes from copilot in order to pass e2e --------- Co-authored-by: Matus Kasak <matus.kasak@dataquest.sk>
1 parent e10e2bc commit bd21871

4 files changed

Lines changed: 40 additions & 11 deletions

File tree

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
/// <reference types="cypress" />
12
import { testA11y } from 'cypress/support/utils';
23

34
describe('System Wide Alert', () => {
45
beforeEach(() => {
5-
// Must login as an Admin to see the page
6-
cy.visit('/admin/system-wide-alert');
6+
// Login first to ensure access to admin routes, then visit the target page
7+
cy.visit('/login');
78
cy.loginViaForm(Cypress.env('DSPACE_TEST_ADMIN_USER'), Cypress.env('DSPACE_TEST_ADMIN_PASSWORD'));
9+
cy.visit('/admin/system-wide-alert');
810
});
911

1012
it('should pass accessibility tests', () => {
11-
// Page must first be visible
12-
cy.get('ds-system-wide-alert-form').should('be.visible');
13-
// Analyze <ds-system-wide-alert-form> for accessibility issues
14-
testA11y('ds-system-wide-alert-form');
13+
// Ensure the page component is present and visible
14+
cy.get('ds-system-wide-alert-form').should('be.visible').then(($el) => {
15+
// Analyze <ds-system-wide-alert-form> for accessibility issues
16+
testA11y($el);
17+
});
1518
});
1619
});

cypress/e2e/tombstone.cy.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ const TOMBSTONED_ITEM_MESSAGE = 'This item has been withdrawn';
6161
describe('Admin Tombstone Page', () => {
6262
beforeEach(() => {
6363
cy.visit('/login');
64-
// Cancel discojuice login - only if it is popped up
6564
cy.wait(500);
66-
cy.get('.discojuice_close').should('exist').click();
6765
// Login as admin
6866
cy.loginViaForm(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD);
6967
cy.visit('/');

cypress/support/commands.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ function loginViaForm(
9898
email: string,
9999
password: string
100100
): void {
101-
// Optionally close the DiscoJuice popup if present
102101
cy.wait(500);
103-
cy.get('.discojuice_close').should('exist').click();
104102

105103
// Fill in credentials
106104
cy.get('[data-test="email"]').should('be.visible').type(email);

cypress/support/utils.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,35 @@ export const testA11y = (context?: any, options?: Options) => {
4040
{ id: 'color-contrast', enabled: false },
4141
]
4242
});
43-
cy.checkA11y(context, options, terminalLog);
43+
44+
// If a selector string was provided, ensure it exists and is visible first
45+
if (typeof context === 'string') {
46+
cy.get(context, { timeout: 15000 }).should('be.visible');
47+
cy.checkA11y(context, options, terminalLog);
48+
return;
49+
}
50+
51+
// If a concrete element/JQuery is provided, ensure it exists first
52+
if (context) {
53+
cy.wrap(context).should('exist').then(($el) => {
54+
const node = ($el && ($el as any).get) ? ($el as any).get(0) : $el;
55+
cy.checkA11y(node as any, options, terminalLog);
56+
});
57+
return;
58+
}
59+
60+
// Fallback: run against the whole page after ensuring body is visible
61+
cy.get('body', { timeout: 15000 }).should('be.visible');
62+
cy.checkA11y(undefined, options, terminalLog);
63+
};
64+
65+
// Optional helper: only run a11y if selector exists in the page (useful for empty tabs/pages)
66+
export const testA11yIfExists = (selector: string, options?: Options) => {
67+
cy.get('body').then(($body) => {
68+
if ($body.find(selector).length > 0) {
69+
testA11y(selector, options);
70+
} else {
71+
cy.task('log', `Skipping a11y: no content for selector "${selector}"`);
72+
}
73+
});
4474
};

0 commit comments

Comments
 (0)