grafana/e2e/various-suite/verify-i18n.spec.ts
Ashley Harrison b662879c98
Internationalisation: Add basic e2e test to ensure languages load correctly (#96556)
* fix pseudo locale and add simple e2e test

* add comment

* update test and add comments

* fix unit test

* try 5 instead of 6?

* clear input

* only check pseudo in dev mode

* don't check pseudo in CI

* don't test pseudo locale

* isolate language changes

* move waits around

* only wait for preferences on first visit

* add proper loading state

* bit of tidy up

* hook up ids correctly

* use disabled/isLoading instead of skeleton

* set props on Field
2024-11-19 15:07:14 +00:00

66 lines
2.1 KiB
TypeScript

import { e2e } from '../utils';
import { fromBaseUrl } from '../utils/support/url';
describe('Verify i18n', () => {
const I18N_USER = 'i18n-test';
const I18N_PASSWORD = 'i18n-test';
// create a new user to isolate the language changes from other tests
before(() => {
e2e.flows.login(Cypress.env('USERNAME'), Cypress.env('PASSWORD'));
cy.request({
method: 'POST',
url: fromBaseUrl('/api/admin/users'),
body: {
email: I18N_USER,
login: I18N_USER,
name: I18N_USER,
password: I18N_PASSWORD,
},
}).then((response) => {
cy.wrap(response.body.uid).as('uid');
});
});
// remove the user created in the before hook
after(() => {
e2e.flows.login(Cypress.env('USERNAME'), Cypress.env('PASSWORD'));
cy.get('@uid').then((uid) => {
cy.request({
method: 'DELETE',
url: fromBaseUrl(`/api/admin/users/${uid}`),
});
});
});
beforeEach(() => {
e2e.flows.login(I18N_USER, I18N_PASSWORD);
});
// map between languages in the language picker and the corresponding translation of the 'Language' label
const languageMap: Record<string, string> = {
Deutsch: 'Sprache',
English: 'Language',
Español: 'Idioma',
Français: 'Langue',
'Português Brasileiro': 'Idioma',
'中文(简体)': '语言',
};
// basic test which loops through the defined languages in the picker
// and verifies that the corresponding label is translated correctly
it('loads all the languages correctly', () => {
cy.visit('/profile');
const LANGUAGE_SELECTOR = '[id="locale-select"]';
cy.wrap(Object.entries(languageMap)).each(([language, label]: [string, string]) => {
cy.get(LANGUAGE_SELECTOR).should('not.be.disabled');
cy.get(LANGUAGE_SELECTOR).click();
cy.get(LANGUAGE_SELECTOR).clear().type(language).type('{downArrow}{enter}');
e2e.components.UserProfile.preferencesSaveButton().click();
cy.contains('label', label).should('be.visible');
cy.get(LANGUAGE_SELECTOR).should('have.value', language);
});
});
});