🤡(e2e) mock PATCH language switch
We add some flaky tests because the aria label selectors were not everytime in english language. It was because the language switch was not mocked in the e2e tests, impacting the consistency of other concurrent tests. We mock the language switch in the e2e tests to ensure that the other tests are not impacted by the language switch.
This commit is contained in:
@@ -484,8 +484,6 @@ test.describe('Doc Export', () => {
|
||||
const pdfString = pdfBuffer.toString('latin1');
|
||||
|
||||
expect(pdfString).toContain('/Lang (fr)');
|
||||
|
||||
await waitForLanguageSwitch(page, TestLanguage.English);
|
||||
});
|
||||
|
||||
test('it exports the doc with interlinking', async ({
|
||||
|
||||
@@ -1,26 +1,10 @@
|
||||
import { Page, expect, test } from '@playwright/test';
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
import { TestLanguage, createDoc, waitForLanguageSwitch } from './utils-common';
|
||||
|
||||
test.describe.serial('Language', () => {
|
||||
let page: Page;
|
||||
|
||||
test.beforeAll(async ({ browser }) => {
|
||||
page = await browser.newPage();
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await page.close();
|
||||
});
|
||||
|
||||
test.describe('Language', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await waitForLanguageSwitch(page, TestLanguage.English);
|
||||
});
|
||||
|
||||
test.afterEach(async ({ page }) => {
|
||||
// Switch back to English - important for other tests to run as expected
|
||||
await waitForLanguageSwitch(page, TestLanguage.English);
|
||||
});
|
||||
|
||||
test('checks language switching', async ({ page }) => {
|
||||
|
||||
@@ -296,6 +296,18 @@ export async function waitForLanguageSwitch(
|
||||
page: Page,
|
||||
lang: TestLanguageValue,
|
||||
) {
|
||||
await page.route('**/api/v1.0/users/**', async (route, request) => {
|
||||
if (request.method().includes('PATCH')) {
|
||||
await route.fulfill({
|
||||
json: {
|
||||
language: lang.expectedLocale[0],
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
const header = page.locator('header').first();
|
||||
const languagePicker = header.locator('.--docs--language-picker-text');
|
||||
const isAlreadyTargetLanguage = await languagePicker
|
||||
@@ -307,15 +319,6 @@ export async function waitForLanguageSwitch(
|
||||
}
|
||||
|
||||
await languagePicker.click();
|
||||
const responsePromise = page.waitForResponse(
|
||||
(resp) =>
|
||||
resp.url().includes('/user') && resp.request().method() === 'PATCH',
|
||||
);
|
||||
await page.getByLabel(lang.label).click();
|
||||
const resolvedResponsePromise = await responsePromise;
|
||||
const responseData = (await resolvedResponsePromise.json()) as {
|
||||
language: string;
|
||||
};
|
||||
|
||||
expect(lang.expectedLocale).toContain(responseData.language);
|
||||
await page.getByLabel(lang.label).click();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user