|
| 1 | +import { test } from "@playwright/test"; |
| 2 | + |
| 3 | +test.beforeEach(async ({ page }) => { |
| 4 | + await page.routeWebSocket( |
| 5 | + (url) => url.pathname === "/ws/sdk/block-updates", |
| 6 | + () => {}, |
| 7 | + ); |
| 8 | +}); |
| 9 | + |
| 10 | +const run = (packageName: string, locale: string) => { |
| 11 | + test(`${packageName} (${locale}) - should call custom apiUrl`, async ({ page }) => { |
| 12 | + await page.route("**/v2/sdk/blocks", (route) => { |
| 13 | + route.fulfill({ json: { blocks: [] } }); |
| 14 | + }); |
| 15 | + const blocksReq = page.waitForRequest((req) => { |
| 16 | + const body = req.postDataJSON(); |
| 17 | + return req.url() === "https://api.flows-cloud.com/v2/sdk/blocks" && body.locale === "en-GB"; |
| 18 | + }); |
| 19 | + const urlParams = new URLSearchParams(); |
| 20 | + urlParams.set("locale", "en-GB"); |
| 21 | + await page.goto(`/${packageName}.html?${urlParams.toString()}`); |
| 22 | + await blocksReq; |
| 23 | + }); |
| 24 | + test(`${packageName} (${locale}) - should call with detected locale`, async ({ page }) => { |
| 25 | + await page.route("**/v2/sdk/blocks", (route) => { |
| 26 | + route.fulfill({ json: { blocks: [] } }); |
| 27 | + }); |
| 28 | + const blocksReq = page.waitForRequest((req) => { |
| 29 | + const body = req.postDataJSON(); |
| 30 | + return req.url() === "https://api.flows-cloud.com/v2/sdk/blocks" && body.locale === locale; |
| 31 | + }); |
| 32 | + const urlParams = new URLSearchParams(); |
| 33 | + urlParams.set("locale", "automatic"); |
| 34 | + await page.goto(`/${packageName}.html?${urlParams.toString()}`); |
| 35 | + await blocksReq; |
| 36 | + }); |
| 37 | +}; |
| 38 | + |
| 39 | +test.describe("en-US", () => { |
| 40 | + test.use({ locale: "en-US" }); |
| 41 | + run("js", "en-US"); |
| 42 | + run("react", "en-US"); |
| 43 | +}); |
| 44 | + |
| 45 | +test.describe("fr-FR", () => { |
| 46 | + test.use({ locale: "fr-FR" }); |
| 47 | + run("js", "fr-FR"); |
| 48 | + run("react", "fr-FR"); |
| 49 | +}); |
0 commit comments