68 lines
4.8 KiB
TypeScript
68 lines
4.8 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
test('维护多个项目和自定义环境,刷新保留并应用到新资源', async ({ page }) => {
|
|
test.setTimeout(90_000);
|
|
await page.goto('/');
|
|
const session = await (await page.request.get('/api/v1/session')).json();
|
|
const headers = {'X-CSRF-Token': session.csrfToken};
|
|
const original = await (await page.request.get('/api/v1/configuration/scopes')).json();
|
|
let id = '';
|
|
const choose = async (name: string, value: string) => {
|
|
await page.locator('.workspace-scope .el-select').filter({has: page.getByRole('combobox', {name, exact: true})}).click();
|
|
await page.getByRole('option', {name: value, exact: true}).click();
|
|
};
|
|
try {
|
|
await page.getByRole('button', {name: '维护项目与环境', exact: true}).click();
|
|
const dialog = page.getByRole('dialog', {name: '维护项目与环境', exact: true});
|
|
for (const project of ['研发平台', '内部工具']) {
|
|
await dialog.getByRole('textbox', {name: '新增项目名称'}).fill(project);
|
|
await dialog.getByRole('button', {name: '添加项目', exact: true}).click();
|
|
}
|
|
await dialog.getByRole('textbox', {name: '新增环境名称'}).fill('预发布');
|
|
await dialog.getByRole('button', {name: '添加环境', exact: true}).click();
|
|
await dialog.getByRole('button', {name: '保存项目与环境', exact: true}).click();
|
|
await expect(dialog).not.toBeVisible();
|
|
await page.reload();
|
|
await choose('筛选项目', '研发平台'); await choose('筛选环境', '预发布');
|
|
await page.reload();
|
|
await expect(page.locator('.workspace-scope')).toContainText('研发平台');
|
|
await expect(page.locator('.workspace-scope')).toContainText('预发布');
|
|
await page.getByRole('navigation').getByRole('button', {name: /代理管理/}).click();
|
|
await page.getByRole('button', {name: '新建代理', exact: true}).click();
|
|
const drawer = page.getByRole('dialog', {name: '新建代理', exact: true});
|
|
await expect(drawer.getByRole('combobox', {name: '所属项目', exact: true})).toHaveCount(0); await expect(drawer).toContainText('预发布');
|
|
await drawer.getByRole('textbox', {name: '代理名称', exact: true}).fill('自定义归属代理');
|
|
await drawer.getByRole('radio', {name: 'SOCKS5', exact: true}).locator('..').click();
|
|
await drawer.locator('[data-field="outbound.host"] input').fill('127.0.0.1');
|
|
const response = page.waitForResponse(r => r.url().endsWith('/api/v1/outbounds') && r.request().method() === 'POST');
|
|
await drawer.getByRole('button', {name: '保存代理', exact: true}).click();
|
|
const saved = await response; expect(saved.ok()).toBeTruthy();
|
|
const config = (await saved.json()).config; id = config.id;
|
|
expect(config).toMatchObject({environment: '预发布'});
|
|
expect(config.project).toBeUndefined();
|
|
await expect(drawer).not.toBeVisible();
|
|
await page.setViewportSize({width: 390, height: 844});
|
|
await page.getByRole('button', {name: '维护项目与环境', exact: true}).click();
|
|
await expect(dialog).toBeVisible();
|
|
await expect(dialog.locator('.el-tag').filter({hasText: '研发平台'}).locator('.el-tag__close')).toHaveCount(1);
|
|
await expect(dialog.locator('.el-tag').filter({hasText: '预发布'})).toContainText('1 条资源');
|
|
await expect(dialog.locator('.el-tag').filter({hasText: '预发布'}).locator('.el-tag__close')).toHaveCount(0);
|
|
await dialog.locator('.el-tag').filter({hasText: '内部工具'}).locator('.el-tag__close').click();
|
|
await dialog.getByRole('button', {name: '保存项目与环境', exact: true}).click();
|
|
await expect(dialog).not.toBeVisible();
|
|
await page.getByRole('button', {name: '维护项目与环境', exact: true}).click();
|
|
await expect(dialog.getByText('内部工具', {exact: true})).toHaveCount(0);
|
|
await dialog.getByRole('textbox', {name: '新增项目名称'}).fill('不保存的项目');
|
|
await dialog.getByRole('button', {name: '添加项目', exact: true}).click();
|
|
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
|
|
await dialog.getByRole('button', {name: '取消', exact: true}).click();
|
|
const catalog = await (await page.request.get('/api/v1/configuration/scopes')).json();
|
|
expect(catalog.projects).toContain('研发平台'); expect(catalog.projects).not.toContain('内部工具');
|
|
expect(catalog.projects).not.toContain('不保存的项目'); expect(catalog.environments).toContain('预发布');
|
|
} finally {
|
|
if (id) await page.request.delete(`/api/v1/outbounds/${id}`, {headers});
|
|
const current = await (await page.request.get('/api/v1/configuration/scopes')).json();
|
|
await page.request.put('/api/v1/configuration/scopes', {headers, data: {projects: original.projects, environments: original.environments, revision: current.revision}});
|
|
}
|
|
});
|