102 lines
6.5 KiB
JavaScript
102 lines
6.5 KiB
JavaScript
import { expect, FACT, label, PROJECT, test, visit, VULNERABILITY } from './fixtures.mjs';
|
||
|
||
test('project archive keeps history accessible and preserves a manual vulnerability archive', async ({ page, mockApi }) => {
|
||
const project = { ...PROJECT };
|
||
const projectPath = `/api/projects/${project.id}`;
|
||
const manual = { ...VULNERABILITY, id: 'manual-finding', title: '单独归档的示例漏洞' };
|
||
const manualPath = `/api/vulnerabilities/${manual.id}/archive`;
|
||
let manuallyArchived = false;
|
||
const records = () => [VULNERABILITY, manual].map(record => ({
|
||
...record,
|
||
archived: project.status === 'archived' || (record.id === manual.id && manuallyArchived),
|
||
project_archived: project.status === 'archived'
|
||
}));
|
||
mockApi.respond('GET', '/api/projects', () => ({ json: { projects: [project], total: 1 } }));
|
||
mockApi.respond('GET', projectPath, () => ({ json: project }));
|
||
mockApi.respond('PUT', projectPath, ({ body }) => {
|
||
project.status = body.status;
|
||
return { json: project };
|
||
});
|
||
mockApi.respond('PUT', manualPath, ({ body }) => {
|
||
manuallyArchived = body.archived;
|
||
return { json: { success: true } };
|
||
});
|
||
mockApi.respond('GET', '/api/vulnerabilities', (_, url) => {
|
||
const filter = url.searchParams.get('archived');
|
||
const vulnerabilities = records().filter(record => filter === 'all' || record.archived === (filter === 'true'));
|
||
return { json: { vulnerabilities, total: vulnerabilities.length, page: 1 } };
|
||
});
|
||
mockApi.respond('GET', `/api/vulnerabilities/${VULNERABILITY.id}/context`, () => ({
|
||
json: { vulnerability: records()[0], history: [], members: [], assets: [] }
|
||
}));
|
||
|
||
const vulnerabilities = await visit(page, 'vulnerabilities');
|
||
const manualRow = vulnerabilities.getByRole('row').filter({ hasText: manual.title });
|
||
const archive = label('projects.archiveProject', '归档');
|
||
const restore = label('projects.restore', '恢复');
|
||
await manualRow.getByRole('button', { name: archive, exact: true }).click();
|
||
await expect(manualRow).toHaveCount(0);
|
||
await expect(vulnerabilities.getByText(VULNERABILITY.title, { exact: true })).toBeVisible();
|
||
|
||
const projects = await visit(page, 'projects');
|
||
const list = projects.locator('.project-list-card');
|
||
const projectRow = list.getByRole('row').filter({ hasText: project.name });
|
||
await projectRow.getByRole('button', { name: archive, exact: true }).click();
|
||
await page.getByRole('dialog').getByRole('button', { name: label('common.confirm', '确认'), exact: true }).click();
|
||
await expect(projectRow).toHaveCount(0);
|
||
await expect(projects.getByText(FACT.summary, { exact: true })).toBeVisible();
|
||
await expect(projects.locator('.project-detail-title-row')).toContainText(label('projects.statusArchived', '已归档'));
|
||
await projects.getByRole('button', { name: label('projects.projectVulnerabilities', '项目漏洞'), exact: true }).click();
|
||
await expect(page).toHaveURL(/archived=true/);
|
||
await expect(vulnerabilities.getByText(VULNERABILITY.title, { exact: true })).toBeVisible();
|
||
await vulnerabilities.getByText(VULNERABILITY.title, { exact: true }).click();
|
||
const detail = page.getByRole('dialog');
|
||
await expect(detail.getByText(label('vulnerabilityPage.archivedWithProject', '随项目归档'), { exact: true })).toBeVisible();
|
||
await expect(detail.getByRole('button', { name: restore, exact: true })).toHaveCount(0);
|
||
|
||
await visit(page, 'projects');
|
||
await list.locator('.project-toolbar .semi-select').click();
|
||
await page.getByRole('option').filter({ hasText: label('projects.statusArchived', '已归档') }).click();
|
||
await projectRow.getByRole('button', { name: restore, exact: true }).click();
|
||
await page.getByRole('dialog').getByRole('button', { name: label('common.confirm', '确认'), exact: true }).click();
|
||
await expect(projectRow).toHaveCount(0);
|
||
|
||
await visit(page, 'vulnerabilities');
|
||
await expect(vulnerabilities.getByText(VULNERABILITY.title, { exact: true })).toBeVisible();
|
||
await expect(manualRow).toHaveCount(0);
|
||
await vulnerabilities.getByRole('combobox', { name: label('vulnerabilityPage.archiveStatus', '归档状态') }).click();
|
||
await page.getByRole('option').filter({ hasText: label('projects.statusArchived', '已归档') }).click();
|
||
await expect(vulnerabilities.getByText(VULNERABILITY.title, { exact: true })).toHaveCount(0);
|
||
await manualRow.getByRole('button', { name: restore, exact: true }).click();
|
||
await expect(manualRow).toHaveCount(0);
|
||
expect(mockApi.calls('PUT', manualPath).map(call => call.body)).toEqual([{ archived: true }, { archived: false }]);
|
||
expect(mockApi.calls('PUT', projectPath).map(call => call.body)).toEqual([{ status: 'archived' }, { status: 'active' }]);
|
||
});
|
||
|
||
test('archived projects are excluded from new workspace and finding selectors while remaining visible in history filters', async ({ page, mockApi }) => {
|
||
const activeProject = { ...PROJECT, id: 'proj-active', name: '进行中示例项目', status: 'active' };
|
||
const archivedProject = { ...PROJECT, id: 'proj-archived', name: '已归档历史项目', status: 'archived' };
|
||
const archivedLabel = `${archivedProject.name}(${label('projects.statusArchived', '已归档')})`;
|
||
|
||
mockApi.respond('GET', '/api/projects', () => ({
|
||
json: { projects: [activeProject, archivedProject], total: 2 }
|
||
}));
|
||
|
||
const chat = await visit(page, 'chat');
|
||
await chat.getByRole('combobox', { name: label('chat.chooseWorkspace', '选择会话工作区') }).click();
|
||
await expect(page.getByRole('option').filter({ hasText: activeProject.name })).toHaveCount(1);
|
||
await expect(page.getByRole('option').filter({ hasText: archivedProject.name })).toHaveCount(0);
|
||
await page.keyboard.press('Escape');
|
||
|
||
await chat.getByRole('combobox', { name: label('chat.filterByProject', '按项目过滤') }).click();
|
||
await expect(page.getByRole('option').filter({ hasText: archivedLabel })).toHaveCount(1);
|
||
await page.keyboard.press('Escape');
|
||
|
||
const vulnerabilities = await visit(page, 'vulnerabilities');
|
||
await vulnerabilities.getByRole('button', { name: label('vulnerability.addVuln', '添加漏洞') }).click();
|
||
const drawer = page.getByRole('dialog');
|
||
await drawer.getByRole('combobox', { name: label('vulnerabilityModal.project', '所属项目') }).click();
|
||
await expect(page.getByRole('option').filter({ hasText: activeProject.name })).toHaveCount(1);
|
||
await expect(page.getByRole('option').filter({ hasText: archivedProject.name })).toHaveCount(0);
|
||
});
|