Files
LinkPort/web/tests/menu-search.spec.ts
2026-09-27 16:39:38 +08:00

41 lines
2.4 KiB
TypeScript

import { test, expect } from '@playwright/test';
test('菜单可按名称及关键词搜索,清空恢复全部菜单并支持手机搜索', async ({ page }) => {
await page.goto('/');
const nav = page.getByRole('navigation');
const search = page.getByRole('textbox', { name: '搜索菜单', exact: true });
await search.fill('WebDAV');
await expect(nav.getByRole('button')).toHaveCount(1);
await nav.getByRole('button', { name: '多端同步', exact: true }).click();
await expect(page.getByRole('heading', { name: '多端同步', exact: true })).toBeVisible();
await expect(search).toHaveValue('');
await search.fill('不存在的菜单');
await expect(nav.getByRole('status')).toHaveText('没有匹配的菜单');
await expect(nav.getByRole('button')).toHaveCount(0);
await search.press('Escape');
await expect(nav.getByRole('button', { name: '多端同步', exact: true })).toBeVisible();
await search.fill('备份');
await search.press('Enter');
await expect(page.getByRole('heading', { name: '配置管理', exact: true })).toBeVisible();
await page.setViewportSize({ width: 320, height: 568 });
await page.getByRole('button', { name: '搜索菜单', exact: true }).click();
const dialog = page.getByRole('dialog', { name: '搜索菜单', exact: true });
await dialog.getByRole('textbox', { name: '搜索菜单', exact: true }).fill('代理');
await expect(dialog.getByRole('button', { name: '代理管理', exact: true })).toBeInViewport();
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
await dialog.getByRole('button', { name: '代理管理', exact: true }).click();
await expect(dialog).not.toBeVisible();
await expect(page.getByRole('heading', { name: '代理管理', exact: true })).toBeVisible();
await expect(nav.getByRole('button', { name: '多端同步', exact: true })).toHaveCount(1);
});
test('个人菜单搜索不再包含用户管理', async ({ page }) => {
await page.goto('/');
const search = page.getByRole('textbox', { name: '搜索菜单', exact: true });
await search.fill('管理用户');
await expect(page.getByRole('navigation').getByRole('button')).toHaveCount(0);
await expect(page.getByRole('navigation').getByRole('status')).toHaveText('没有匹配的菜单');
await search.fill('WebDAV');
await expect(page.getByRole('navigation').getByRole('button', { name: '多端同步', exact: true })).toBeVisible();
});