Skip to content

Commit 9fb24ba

Browse files
author
Andrea Barbasso
committed
[DSC-2580] improve header.cy language switch test
1 parent fcc0694 commit 9fb24ba

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

cypress/e2e/header.cy.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,33 @@ describe('Header', () => {
1414
it('should allow for changing language to German (for example)', () => {
1515
cy.visit('/');
1616

17-
// Click the language switcher (globe) in header
18-
cy.get('button[data-test="lang-switch"]').click();
19-
// Click on the "Deusch" language in dropdown
20-
cy.get('#language-menu-list div[role="option"]').contains('Deutsch').click();
17+
// This test should only run if the language switcher is visible.
18+
// We query for the body first, so the test doesn't fail if the button doesn't exist.
19+
cy.get('body').then($body => {
20+
if ($body.find('button[data-test="lang-switch"]').is(':visible')) {
2121

22-
// HTML "lang" attribute should switch to "de"
23-
cy.get('html').invoke('attr', 'lang').should('eq', 'de');
22+
// Click the language switcher (globe) in header
23+
cy.get('button[data-test="lang-switch"]').click();
24+
// Click on the "Deutsch" language in dropdown
25+
cy.get('#language-menu-list div[role="option"]').contains('Deutsch').click();
2426

25-
// Login menu should now be in German
26-
cy.get('[data-test="login-menu"]').contains('Anmelden');
27+
// HTML "lang" attribute should switch to "de"
28+
cy.get('html').invoke('attr', 'lang').should('eq', 'de');
2729

28-
// Change back to English from language switcher
29-
cy.get('button[data-test="lang-switch"]').click();
30-
cy.get('#language-menu-list div[role="option"]').contains('English').click();
30+
// Login menu should now be in German
31+
cy.get('[data-test="login-menu"]').contains('Anmelden');
3132

32-
// HTML "lang" attribute should switch to "en"
33-
cy.get('html').invoke('attr', 'lang').should('eq', 'en');
33+
// Change back to English from language switcher
34+
cy.get('button[data-test="lang-switch"]').click();
35+
cy.get('#language-menu-list div[role="option"]').contains('English').click();
3436

35-
// Login menu should now be in English
36-
cy.get('[data-test="login-menu"]').contains('Log In');
37+
// HTML "lang" attribute should switch to "en"
38+
cy.get('html').invoke('attr', 'lang').should('eq', 'en');
39+
40+
// Login menu should now be in English
41+
cy.get('[data-test="login-menu"]').contains('Log In');
42+
}
43+
});
3744
});
45+
3846
});

0 commit comments

Comments
 (0)