company-list.spec.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { test, expect } from '../../utils/test-setup';
  2. test.describe('公司列表管理', () => {
  3. test.beforeEach(async ({ adminLoginPage, companyManagementPage }) => {
  4. // 以管理员身份登录后台
  5. await adminLoginPage.goto();
  6. await adminLoginPage.login('admin', 'admin123');
  7. await companyManagementPage.goto();
  8. });
  9. test.describe('页面加载验证', () => {
  10. test('应该成功导航到公司管理页面', async ({ companyManagementPage, page }) => {
  11. // 验证页面 URL
  12. await expect(page).toHaveURL(/\/admin\/companies/);
  13. });
  14. test('应该显示正确的页面标题', async ({ companyManagementPage }) => {
  15. await expect(companyManagementPage.pageTitle).toBeVisible();
  16. await expect(companyManagementPage.pageTitle).toHaveText('公司管理');
  17. });
  18. test('应该加载公司列表表格', async ({ companyManagementPage }) => {
  19. await expect(companyManagementPage.companyTable).toBeVisible();
  20. });
  21. });
  22. test.describe('公司数据展示验证', () => {
  23. test('应该正确显示公司名称', async ({ companyManagementPage }) => {
  24. // 获取表格中第一行数据(如果有)
  25. const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
  26. const count = await firstRow.count();
  27. if (count > 0) {
  28. // 表格第0列是公司名称
  29. const nameCell = firstRow.locator('td').nth(0);
  30. await expect(nameCell).toBeVisible();
  31. const companyName = await nameCell.textContent();
  32. expect(companyName).toBeTruthy();
  33. expect(companyName!.trim()).not.toBe('');
  34. }
  35. });
  36. test('应该正确显示关联平台', async ({ companyManagementPage }) => {
  37. // 获取表格中第一行数据(如果有)
  38. const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
  39. const count = await firstRow.count();
  40. if (count > 0) {
  41. // 表格第1列是平台
  42. const platformCell = firstRow.locator('td').nth(1);
  43. await expect(platformCell).toBeVisible();
  44. }
  45. });
  46. test('应该正确显示联系人信息', async ({ companyManagementPage }) => {
  47. // 获取表格中第一行数据(如果有)
  48. const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
  49. const count = await firstRow.count();
  50. if (count > 0) {
  51. // 表格第2列是联系人
  52. const contactPersonCell = firstRow.locator('td').nth(2);
  53. await expect(contactPersonCell).toBeVisible();
  54. // 表格第3列是联系电话
  55. const contactPhoneCell = firstRow.locator('td').nth(3);
  56. await expect(contactPhoneCell).toBeVisible();
  57. }
  58. });
  59. test('应该正确显示状态徽章', async ({ companyManagementPage }) => {
  60. // 获取表格中第一行数据(如果有)
  61. const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
  62. const count = await firstRow.count();
  63. if (count > 0) {
  64. // 表格第4列是状态(启用/禁用)
  65. const statusCell = firstRow.locator('td').nth(4);
  66. await expect(statusCell).toBeVisible();
  67. // 验证状态文本是"启用"或"禁用"
  68. const statusText = await statusCell.textContent();
  69. expect(statusText).toBeTruthy();
  70. expect(['启用', '禁用']).toContain(statusText!.trim());
  71. }
  72. });
  73. test('应该正确显示创建时间', async ({ companyManagementPage }) => {
  74. // 获取表格中第一行数据(如果有)
  75. const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
  76. const count = await firstRow.count();
  77. if (count > 0) {
  78. // 表格第5列是创建时间
  79. const createdAtCell = firstRow.locator('td').nth(5);
  80. await expect(createdAtCell).toBeVisible();
  81. }
  82. });
  83. });
  84. test.describe('列表功能验证', () => {
  85. test('应该显示创建公司按钮', async ({ companyManagementPage }) => {
  86. await expect(companyManagementPage.createCompanyButton).toBeVisible();
  87. });
  88. test('应该显示搜索输入框', async ({ companyManagementPage }) => {
  89. await expect(companyManagementPage.searchInput).toBeVisible();
  90. await expect(companyManagementPage.searchButton).toBeVisible();
  91. });
  92. test('应该显示操作按钮', async ({ companyManagementPage }) => {
  93. // 获取表格中第一行数据(如果有)
  94. const firstRow = companyManagementPage.companyTable.locator('tbody tr').first();
  95. const count = await firstRow.count();
  96. if (count > 0) {
  97. // 表格第6列是操作列,包含编辑和删除按钮
  98. const actionCell = firstRow.locator('td').nth(6);
  99. await expect(actionCell).toBeVisible();
  100. // 验证操作列中有按钮(编辑和删除按钮使用图标,没有文本)
  101. // 操作列包含两个 button 元素
  102. const buttons = actionCell.getByRole('button');
  103. const buttonCount = await buttons.count();
  104. expect(buttonCount).toBeGreaterThanOrEqual(1);
  105. }
  106. });
  107. test('无数据时应该显示正确提示', async ({ page, companyManagementPage }) => {
  108. // 这个测试需要数据库中没有公司数据的情况
  109. // 在实际测试环境中,可能已经存在数据
  110. // 这里我们验证表格结构存在
  111. await expect(companyManagementPage.companyTable).toBeVisible();
  112. });
  113. });
  114. });