Files

43 lines
2.6 KiB
TypeScript

import { test, expect } from '@playwright/test';
test('目标分组保存、筛选与清空', async ({ page }) => {
await page.goto('/');
const session = await (await page.request.get('/api/v1/session')).json();
const created = await page.request.post('/api/v1/targets', { headers: { 'X-CSRF-Token': session.csrfToken }, data: { name: '分组测试目标', type: 'mysql', targetHost: 'localhost', targetPort: 3306, accounts: [{ id: 'test', remark: 'Test', username: 'test', password: 'test-password' }], group: '开发' } });
expect(created.ok()).toBe(true);
await page.getByRole('button', { name: /目标服务/ }).first().click();
const card = page.locator('.target-card').filter({ hasText: '分组测试目标' });
await expect(card).toContainText('开发');
await card.getByRole('button', { name: '配置目标' }).click();
const drawer = page.getByRole('dialog');
await drawer.getByRole('tab', { name: '高级', exact: true }).click();
const group = drawer.getByRole('combobox', { name: '目标所属分组' });
await group.fill('生产');
await page.getByRole('option', { name: '生产', exact: true }).click();
await drawer.getByRole('button', { name: '保存配置' }).click();
await expect(drawer).not.toBeVisible();
await page.reload();
await page.getByRole('button', { name: /目标服务/ }).first().click();
const groupFilter = page.locator('.el-select').filter({ has: page.getByRole('combobox', { name: '目标分组', exact: true }) });
const protocolFilter = page.locator('.el-select').filter({ has: page.getByRole('combobox', { name: '目标协议', exact: true }) });
await groupFilter.click();
await page.getByRole('option', { name: '生产', exact: true }).click();
await expect(card).toBeVisible();
await protocolFilter.click();
await page.getByRole('option', { name: 'SSH', exact: true }).click();
await expect(card).not.toBeVisible();
await protocolFilter.click();
await page.getByRole('option', { name: 'MySQL', exact: true }).click();
await expect(card).toBeVisible();
await groupFilter.click();
await page.getByRole('option', { name: '未分组', exact: true }).click();
await expect(card).not.toBeVisible();
const target = (await created.json()).config;
const cleared = await page.request.put(`/api/v1/targets/${target.id}`, { headers: { 'X-CSRF-Token': session.csrfToken }, data: { group: '' } });
expect(cleared.ok()).toBe(true);
await page.getByRole('button', { name: /目标服务/ }).first().click();
await page.reload();
await page.getByRole('button', { name: /目标服务/ }).first().click();
await expect(card).toContainText('未分组');
});