Skip to content

Commit 3101548

Browse files
committed
♻️(e2e) improve config testcases
Improve config testcases: - let THEME_CUSTOMIZATION_FILE_PATH to be set to check the default value - add helper function overrideConfig
1 parent 2733785 commit 3101548

File tree

4 files changed

+37
-65
lines changed

4 files changed

+37
-65
lines changed

env.d/development/common.e2e.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# For the CI job test-e2e
2-
SUSTAINED_THROTTLE_RATES="200/hour"
32
BURST_THROTTLE_RATES="200/minute"
43
DJANGO_SERVER_TO_SERVER_API_TOKENS=test-e2e
4+
SUSTAINED_THROTTLE_RATES="200/hour"
55
Y_PROVIDER_API_KEY=yprovider-api-key
66
Y_PROVIDER_API_BASE_URL=http://y-provider:4444/api/
7-
THEME_CUSTOMIZATION_FILE_PATH="" #force theme_customization to be empty

src/frontend/apps/e2e/__tests__/app-impress/common.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ export const CONFIG = {
2222
theme_customization: {},
2323
};
2424

25+
export const overrideConfig = async (
26+
page: Page,
27+
newConfig: { [K in keyof typeof CONFIG]?: unknown },
28+
) =>
29+
await page.route('**/api/v1.0/config/', async (route) => {
30+
const request = route.request();
31+
if (request.method().includes('GET')) {
32+
await route.fulfill({
33+
json: {
34+
...CONFIG,
35+
...newConfig,
36+
},
37+
});
38+
} else {
39+
await route.continue();
40+
}
41+
});
42+
2543
export const keyCloakSignIn = async (
2644
page: Page,
2745
browserName: string,

src/frontend/apps/e2e/__tests__/app-impress/config.spec.ts

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path';
22

33
import { expect, test } from '@playwright/test';
44

5-
import { CONFIG, createDoc } from './common';
5+
import { CONFIG, createDoc, overrideConfig } from './common';
66

77
test.describe('Config', () => {
88
test('it checks the config api is called', async ({ page }) => {
@@ -16,24 +16,19 @@ test.describe('Config', () => {
1616
const response = await responsePromise;
1717
expect(response.ok()).toBeTruthy();
1818

19-
expect(await response.json()).toStrictEqual(CONFIG);
19+
const json = (await response.json()) as typeof CONFIG;
20+
const { theme_customization, ...configApi } = json;
21+
expect(theme_customization).toBeDefined();
22+
const { theme_customization: _, ...CONFIG_LEFT } = CONFIG;
23+
24+
expect(configApi).toStrictEqual(CONFIG_LEFT);
2025
});
2126

2227
test('it checks that sentry is trying to init from config endpoint', async ({
2328
page,
2429
}) => {
25-
await page.route('**/api/v1.0/config/', async (route) => {
26-
const request = route.request();
27-
if (request.method().includes('GET')) {
28-
await route.fulfill({
29-
json: {
30-
...CONFIG,
31-
SENTRY_DSN: 'https://sentry.io/123',
32-
},
33-
});
34-
} else {
35-
await route.continue();
36-
}
30+
await overrideConfig(page, {
31+
SENTRY_DSN: 'https://sentry.io/123',
3732
});
3833

3934
const invalidMsg = 'Invalid Sentry Dsn: https://sentry.io/123';
@@ -98,18 +93,8 @@ test.describe('Config', () => {
9893
page,
9994
browserName,
10095
}) => {
101-
await page.route('**/api/v1.0/config/', async (route) => {
102-
const request = route.request();
103-
if (request.method().includes('GET')) {
104-
await route.fulfill({
105-
json: {
106-
...CONFIG,
107-
AI_FEATURE_ENABLED: false,
108-
},
109-
});
110-
} else {
111-
await route.continue();
112-
}
96+
await overrideConfig(page, {
97+
AI_FEATURE_ENABLED: false,
11398
});
11499

115100
await page.goto('/');
@@ -129,18 +114,8 @@ test.describe('Config', () => {
129114
test('it checks that Crisp is trying to init from config endpoint', async ({
130115
page,
131116
}) => {
132-
await page.route('**/api/v1.0/config/', async (route) => {
133-
const request = route.request();
134-
if (request.method().includes('GET')) {
135-
await route.fulfill({
136-
json: {
137-
...CONFIG,
138-
CRISP_WEBSITE_ID: '1234',
139-
},
140-
});
141-
} else {
142-
await route.continue();
143-
}
117+
await overrideConfig(page, {
118+
CRISP_WEBSITE_ID: '1234',
144119
});
145120

146121
await page.goto('/');
@@ -151,18 +126,8 @@ test.describe('Config', () => {
151126
});
152127

153128
test('it checks FRONTEND_CSS_URL config', async ({ page }) => {
154-
await page.route('**/api/v1.0/config/', async (route) => {
155-
const request = route.request();
156-
if (request.method().includes('GET')) {
157-
await route.fulfill({
158-
json: {
159-
...CONFIG,
160-
FRONTEND_CSS_URL: 'http://localhost:123465/css/style.css',
161-
},
162-
});
163-
} else {
164-
await route.continue();
165-
}
129+
await overrideConfig(page, {
130+
FRONTEND_CSS_URL: 'http://localhost:123465/css/style.css',
166131
});
167132

168133
await page.goto('/');

src/frontend/apps/e2e/__tests__/app-impress/home.spec.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from '@playwright/test';
22

3-
import { CONFIG } from './common';
3+
import { overrideConfig } from './common';
44

55
test.beforeEach(async ({ page }) => {
66
await page.goto('/docs/');
@@ -54,18 +54,8 @@ test.describe('Home page', () => {
5454
});
5555

5656
test('it checks the homepage feature flag', async ({ page }) => {
57-
await page.route('**/api/v1.0/config/', async (route) => {
58-
const request = route.request();
59-
if (request.method().includes('GET')) {
60-
await route.fulfill({
61-
json: {
62-
...CONFIG,
63-
FRONTEND_HOMEPAGE_FEATURE_ENABLED: false,
64-
},
65-
});
66-
} else {
67-
await route.continue();
68-
}
57+
await overrideConfig(page, {
58+
FRONTEND_HOMEPAGE_FEATURE_ENABLED: false,
6959
});
7060

7161
await page.goto('/');

0 commit comments

Comments
 (0)