|
@@ -0,0 +1,136 @@
|
|
|
|
|
+import { test, expect } from '../../utils/test-setup';
|
|
|
|
|
+
|
|
|
|
|
+test.describe('公司列表管理', () => {
|
|
|
|
|
+ test.beforeEach(async ({ adminLoginPage, companyManagementPage }) => {
|
|
|
|
|
+ // 以管理员身份登录后台
|
|
|
|
|
+ await adminLoginPage.goto();
|
|
|
|
|
+ await adminLoginPage.login('admin', 'admin123');
|
|
|
|
|
+ await companyManagementPage.goto();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test.describe('页面加载验证', () => {
|
|
|
|
|
+ test('应该成功导航到公司管理页面', async ({ companyManagementPage, page }) => {
|
|
|
|
|
+ // 验证页面 URL
|
|
|
|
|
+ await expect(page).toHaveURL(/\/admin\/companies/);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('应该显示正确的页面标题', async ({ companyManagementPage }) => {
|
|
|
|
|
+ await expect(companyManagementPage.pageTitle).toBeVisible();
|
|
|
|
|
+ await expect(companyManagementPage.pageTitle).toHaveText('公司管理');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('应该加载公司列表表格', async ({ companyManagementPage }) => {
|
|
|
|
|
+ await expect(companyManagementPage.companyTable).toBeVisible();
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test.describe('公司数据展示验证', () => {
|
|
|
|
|
+ test('应该正确显示公司名称', async ({ companyManagementPage }) => {
|
|
|
|
|
+ // 获取表格中第一行数据(如果有)
|
|
|
|
|
+ const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
|
|
|
|
|
+ const count = await firstRow.count();
|
|
|
|
|
+
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ // 表格第0列是公司名称
|
|
|
|
|
+ const nameCell = firstRow.locator('td').nth(0);
|
|
|
|
|
+ await expect(nameCell).toBeVisible();
|
|
|
|
|
+ const companyName = await nameCell.textContent();
|
|
|
|
|
+ expect(companyName).toBeTruthy();
|
|
|
|
|
+ expect(companyName!.trim()).not.toBe('');
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('应该正确显示关联平台', async ({ companyManagementPage }) => {
|
|
|
|
|
+ // 获取表格中第一行数据(如果有)
|
|
|
|
|
+ const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
|
|
|
|
|
+ const count = await firstRow.count();
|
|
|
|
|
+
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ // 表格第1列是平台
|
|
|
|
|
+ const platformCell = firstRow.locator('td').nth(1);
|
|
|
|
|
+ await expect(platformCell).toBeVisible();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('应该正确显示联系人信息', async ({ companyManagementPage }) => {
|
|
|
|
|
+ // 获取表格中第一行数据(如果有)
|
|
|
|
|
+ const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
|
|
|
|
|
+ const count = await firstRow.count();
|
|
|
|
|
+
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ // 表格第2列是联系人
|
|
|
|
|
+ const contactPersonCell = firstRow.locator('td').nth(2);
|
|
|
|
|
+ await expect(contactPersonCell).toBeVisible();
|
|
|
|
|
+
|
|
|
|
|
+ // 表格第3列是联系电话
|
|
|
|
|
+ const contactPhoneCell = firstRow.locator('td').nth(3);
|
|
|
|
|
+ await expect(contactPhoneCell).toBeVisible();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('应该正确显示状态徽章', async ({ companyManagementPage }) => {
|
|
|
|
|
+ // 获取表格中第一行数据(如果有)
|
|
|
|
|
+ const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
|
|
|
|
|
+ const count = await firstRow.count();
|
|
|
|
|
+
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ // 表格第4列是状态(启用/禁用)
|
|
|
|
|
+ const statusCell = firstRow.locator('td').nth(4);
|
|
|
|
|
+ await expect(statusCell).toBeVisible();
|
|
|
|
|
+
|
|
|
|
|
+ // 验证状态文本是"启用"或"禁用"
|
|
|
|
|
+ const statusText = await statusCell.textContent();
|
|
|
|
|
+ expect(statusText).toBeTruthy();
|
|
|
|
|
+ expect(['启用', '禁用']).toContain(statusText!.trim());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('应该正确显示创建时间', async ({ companyManagementPage }) => {
|
|
|
|
|
+ // 获取表格中第一行数据(如果有)
|
|
|
|
|
+ const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
|
|
|
|
|
+ const count = await firstRow.count();
|
|
|
|
|
+
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ // 表格第5列是创建时间
|
|
|
|
|
+ const createdAtCell = firstRow.locator('td').nth(5);
|
|
|
|
|
+ await expect(createdAtCell).toBeVisible();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test.describe('列表功能验证', () => {
|
|
|
|
|
+ test('应该显示创建公司按钮', async ({ companyManagementPage }) => {
|
|
|
|
|
+ await expect(companyManagementPage.createCompanyButton).toBeVisible();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('应该显示搜索输入框', async ({ companyManagementPage }) => {
|
|
|
|
|
+ await expect(companyManagementPage.searchInput).toBeVisible();
|
|
|
|
|
+ await expect(companyManagementPage.searchButton).toBeVisible();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('应该显示操作按钮', async ({ companyManagementPage }) => {
|
|
|
|
|
+ // 获取表格中第一行数据(如果有)
|
|
|
|
|
+ const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
|
|
|
|
|
+ const count = await firstRow.count();
|
|
|
|
|
+
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ // 表格第6列是操作列,包含编辑和删除按钮
|
|
|
|
|
+ const actionCell = firstRow.locator('td').nth(6);
|
|
|
|
|
+ await expect(actionCell).toBeVisible();
|
|
|
|
|
+
|
|
|
|
|
+ // 验证操作列中有按钮(编辑和删除按钮使用图标,没有文本)
|
|
|
|
|
+ // 操作列包含两个 button 元素
|
|
|
|
|
+ const buttons = actionCell.getByRole('button');
|
|
|
|
|
+ const buttonCount = await buttons.count();
|
|
|
|
|
+ expect(buttonCount).toBeGreaterThanOrEqual(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('无数据时应该显示正确提示', async ({ page, companyManagementPage }) => {
|
|
|
|
|
+ // 这个测试需要数据库中没有公司数据的情况
|
|
|
|
|
+ // 在实际测试环境中,可能已经存在数据
|
|
|
|
|
+ // 这里我们验证表格结构存在
|
|
|
|
|
+ await expect(companyManagementPage.companyTable).toBeVisible();
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+});
|