platform-deletion-fix.spec.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { test, expect } from '../../utils/test-setup';
  2. test.describe('平台删除功能修复', () => {
  3. const testPlatformName = '测试删除平台-' + Date.now();
  4. test.beforeEach(async ({ adminLoginPage, platformManagementPage }) => {
  5. await adminLoginPage.goto();
  6. await adminLoginPage.login('admin', 'admin123');
  7. await adminLoginPage.expectLoginSuccess();
  8. await platformManagementPage.goto();
  9. });
  10. test.afterEach(async ({ platformManagementPage }) => {
  11. await platformManagementPage.goto();
  12. try {
  13. await platformManagementPage.deletePlatform(testPlatformName);
  14. } catch {
  15. // 平台可能已被删除,忽略错误
  16. }
  17. });
  18. test.describe('物理删除功能', () => {
  19. test('删除平台后可以创建同名平台', async ({ page, platformManagementPage }) => {
  20. await platformManagementPage.createPlatform({
  21. platformName: testPlatformName,
  22. contactPerson: '测试联系人',
  23. contactPhone: '13800138000',
  24. contactEmail: 'test@example.com',
  25. });
  26. await expect(page.getByText(testPlatformName)).toBeVisible();
  27. await platformManagementPage.deletePlatform(testPlatformName);
  28. await expect(page.getByText(testPlatformName)).not.toBeVisible();
  29. await platformManagementPage.createPlatform({
  30. platformName: testPlatformName,
  31. contactPerson: '测试联系人2',
  32. contactPhone: '13800138001',
  33. contactEmail: 'test2@example.com',
  34. });
  35. await expect(page.getByText(testPlatformName)).toBeVisible();
  36. await expect(page.getByText('测试联系人2')).toBeVisible();
  37. await platformManagementPage.deletePlatform(testPlatformName);
  38. });
  39. });
  40. test.describe('启用/禁用功能', () => {
  41. test('禁用平台后状态变为禁用', async ({ page, platformManagementPage }) => {
  42. await platformManagementPage.createPlatform({
  43. platformName: testPlatformName,
  44. contactPerson: '测试联系人',
  45. contactPhone: '13800138000',
  46. contactEmail: 'test@example.com',
  47. });
  48. const selector = '[data-testid="toggle-button-' + testPlatformName + '"]';
  49. await page.click(selector, { timeout: 5000 });
  50. await page.click('button:has-text("禁用")');
  51. await page.reload();
  52. await page.waitForLoadState('networkidle');
  53. const statusCell = page.locator('tr').filter({ hasText: testPlatformName }).locator('td').nth(2);
  54. await expect(statusCell).toContainText('禁用');
  55. await expect(statusCell).toHaveClass(/text-gray-400/);
  56. await platformManagementPage.deletePlatform(testPlatformName);
  57. });
  58. test('禁用的平台可以重新启用', async ({ page, platformManagementPage }) => {
  59. await platformManagementPage.createPlatform({
  60. platformName: testPlatformName,
  61. contactPerson: '测试联系人',
  62. contactPhone: '13800138000',
  63. });
  64. const selector = '[data-testid="toggle-button-' + testPlatformName + '"]';
  65. await page.click(selector, { timeout: 5000 });
  66. await page.click('button:has-text("禁用")');
  67. await page.waitForTimeout(500);
  68. await page.click(selector, { timeout: 5000 });
  69. await page.click('button:has-text("启用")');
  70. await page.reload();
  71. await page.waitForLoadState('networkidle');
  72. const statusCell = page.locator('tr').filter({ hasText: testPlatformName }).locator('td').nth(2);
  73. await expect(statusCell).toContainText('正常');
  74. await expect(statusCell).toHaveClass(/text-green-600/);
  75. await platformManagementPage.deletePlatform(testPlatformName);
  76. });
  77. });
  78. test.describe('删除与禁用功能分离', () => {
  79. test('操作列有三个按钮:编辑、禁用/启用、删除', async ({ platformManagementPage }) => {
  80. await platformManagementPage.createPlatform({
  81. platformName: testPlatformName,
  82. contactPerson: '测试联系人',
  83. contactPhone: '13800138000',
  84. });
  85. const platformRow = platformManagementPage.page.locator('tr').filter({ hasText: testPlatformName });
  86. await expect(platformRow.locator('[data-testid^="edit-button-"]')).toBeVisible();
  87. await expect(platformRow.locator('[data-testid^="toggle-button-"]')).toBeVisible();
  88. await expect(platformRow.locator('[data-testid^="delete-button-"]')).toBeVisible();
  89. await platformManagementPage.deletePlatform(testPlatformName);
  90. });
  91. });
  92. });