From a74cd848feeabe380026f504f0e70f6de134fd65 Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Wed, 16 Oct 2024 16:33:20 -0500 Subject: [PATCH] Add basic e2e testing for i18n --- cypress/e2e/header.cy.ts | 25 +++++++++++++++++++ .../lang-switch/lang-switch.component.html | 1 + 2 files changed, 26 insertions(+) diff --git a/cypress/e2e/header.cy.ts b/cypress/e2e/header.cy.ts index 043d67dd2b9..1471e5ae6c5 100644 --- a/cypress/e2e/header.cy.ts +++ b/cypress/e2e/header.cy.ts @@ -10,4 +10,29 @@ describe('Header', () => { // Analyze for accessibility testA11y('ds-header'); }); + + it('should allow for changing language to German (for example)', () => { + cy.visit('/'); + + // Click the language switcher (globe) in header + cy.get('a[data-test="lang-switch"]').click(); + // Click on the "Deusch" language in dropdown + cy.get('#language-menu-list li').contains('Deutsch').click(); + + // HTML "lang" attribute should switch to "de" + cy.get('html').invoke('attr', 'lang').should('eq', 'de'); + + // Login menu should now be in German + cy.get('a[data-test="login-menu"]').contains('Anmelden'); + + // Change back to English from language switcher + cy.get('a[data-test="lang-switch"]').click(); + cy.get('#language-menu-list li').contains('English').click(); + + // HTML "lang" attribute should switch to "en" + cy.get('html').invoke('attr', 'lang').should('eq', 'en'); + + // Login menu should now be in English + cy.get('a[data-test="login-menu"]').contains('Log In'); + }); }); diff --git a/src/app/shared/lang-switch/lang-switch.component.html b/src/app/shared/lang-switch/lang-switch.component.html index 9be622099bb..6d1727cfe76 100644 --- a/src/app/shared/lang-switch/lang-switch.component.html +++ b/src/app/shared/lang-switch/lang-switch.component.html @@ -5,6 +5,7 @@ aria-haspopup="menu" [title]="'nav.language' | translate" (click)="$event.preventDefault()" data-toggle="dropdown" ngbDropdownToggle + data-test="lang-switch" tabindex="0">