-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathlogin-plugin.spec.ts
More file actions
62 lines (54 loc) · 1.99 KB
/
login-plugin.spec.ts
File metadata and controls
62 lines (54 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// E2E tests for the login-screen plugin slot (`config.plugin.login`).
//
// Login plugins follow the same runtime-fetch model as page plugins:
// `LoginView.tsx` imports `/dist/plugins/<name>.js` (or
// `${apiEndpoint}/dist/plugins/<name>.js` in Electron) at runtime, so
// `page.route` can fulfill the request with fixture content — the same
// pattern as the existing page-plugin tests in this directory.
import { webuiEndpoint, modifyConfigToml } from '../utils/test-util';
import { test, expect } from '@playwright/test';
import fs from 'fs';
import path from 'path';
const PLUGIN_NAME = 'backend-ai-homepage-link';
const HOMEPAGE_LINK_PLUGIN_JS = fs.readFileSync(
path.join(__dirname, `${PLUGIN_NAME}.js`),
'utf-8',
);
test.describe(
'Login Plugin',
{ tag: ['@plugin', '@functional', '@regression'] },
() => {
test('homepage-link plugin injects an external link into the login form', async ({
page,
request,
}) => {
await modifyConfigToml(page, request, {
plugin: { login: PLUGIN_NAME },
});
await page.route(`**/dist/plugins/${PLUGIN_NAME}.js`, async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/javascript',
body: HOMEPAGE_LINK_PLUGIN_JS,
});
});
await page.goto(webuiEndpoint);
const link = page.locator('.bai-homepage-link a');
await expect(link).toBeVisible();
await expect(link).toHaveAttribute('href', 'https://www.backend.ai/');
await expect(link).toHaveAttribute('target', '_blank');
await expect(link).toHaveText(/Visit backend\.ai/i);
});
test('no link appears when the plugin slot is unset', async ({
page,
request,
}) => {
await modifyConfigToml(page, request, {
plugin: { login: '' },
});
await page.goto(webuiEndpoint);
await page.locator('form').first().waitFor({ state: 'visible' });
await expect(page.locator('.bai-homepage-link')).toHaveCount(0);
});
},
);