Skip to content

Commit 51c5c00

Browse files
committed
test: improve automatic locale tests
1 parent 92648b0 commit 51c5c00

File tree

2 files changed

+50
-21
lines changed

2 files changed

+50
-21
lines changed

workspaces/e2e/tests/init.spec.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,11 @@ const run = (packageName: string) => {
4444
body.environment === "prod" &&
4545
body.userProperties.email === "test@flows.sh" &&
4646
body.userProperties.age === 10 &&
47-
body.locale === "en-US"
48-
);
49-
});
50-
const urlParams = new URLSearchParams();
51-
urlParams.set("apiUrl", "https://custom.api.flows.com");
52-
urlParams.set("locale", "en-US");
53-
await page.goto(`/${packageName}.html?${urlParams.toString()}`);
54-
await blocksReq;
55-
});
56-
test(`${packageName} - should call with detected locale`, async ({ page }) => {
57-
await page.route("**/v2/sdk/blocks", (route) => {
58-
route.fulfill({ json: { blocks: [] } });
59-
});
60-
const blocksReq = page.waitForRequest((req) => {
61-
const body = req.postDataJSON();
62-
const headers = req.headers();
63-
return (
64-
req.url() === "https://custom.api.flows.com/v2/sdk/blocks" &&
65-
(headers["x-flows-version"] ?? "").startsWith("@flows/") &&
66-
body.locale === "en-US"
47+
body.locale === undefined
6748
);
6849
});
6950
const urlParams = new URLSearchParams();
7051
urlParams.set("apiUrl", "https://custom.api.flows.com");
71-
urlParams.set("locale", "automatic");
7252
await page.goto(`/${packageName}.html?${urlParams.toString()}`);
7353
await blocksReq;
7454
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)