Skip to content

Commit

Permalink
Add basic e2e testing for i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
tdonohue committed Oct 16, 2024
1 parent 7e19686 commit a3b4fe8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cypress/e2e/header.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,29 @@ describe('Header', () => {
// Analyze <ds-header> 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();

Check failure on line 20 in cypress/e2e/header.cy.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote

Check failure on line 20 in cypress/e2e/header.cy.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Strings must use singlequote

// 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");

Check failure on line 26 in cypress/e2e/header.cy.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote

Check failure on line 26 in cypress/e2e/header.cy.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Strings must use singlequote

// Change back to English from language switcher
cy.get('a[data-test="lang-switch"]').click();
cy.get('#language-menu-list li').contains("English").click();

Check failure on line 30 in cypress/e2e/header.cy.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote

Check failure on line 30 in cypress/e2e/header.cy.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Strings must use singlequote

// 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");

Check failure on line 36 in cypress/e2e/header.cy.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote

Check failure on line 36 in cypress/e2e/header.cy.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Strings must use singlequote
});
});
1 change: 1 addition & 0 deletions src/app/shared/lang-switch/lang-switch.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
aria-haspopup="menu"
[title]="'nav.language' | translate"
(click)="$event.preventDefault()" data-toggle="dropdown" ngbDropdownToggle
data-test="lang-switch"
tabindex="0">
<i class="fas fa-globe-asia fa-lg fa-fw"></i>
</a>
Expand Down

0 comments on commit a3b4fe8

Please sign in to comment.