Files
novalon-website/e2e/src/tests/config-linkage/config-toggle.spec.ts
T
张翔 259b790309 fix: update E2E test selectors and improve login stability
- Fix selectors to use config keys instead of Chinese labels
- Add page load waiting and element visibility checks
- Improve global setup with better error handling
- Update all config-linkage tests with correct selectors
2026-03-13 13:35:10 +08:00

115 lines
4.9 KiB
TypeScript

import { test, expect } from '@playwright/test';
test.describe('前后台配置联动测试', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
});
test('配置开关 - 服务模块显示/隐藏', async ({ page, context }) => {
const adminPage = await context.newPage();
await adminPage.goto('/admin/login');
await adminPage.fill('input[type="email"]', 'admin@novalon.cn');
await adminPage.fill('input[type="password"]', 'admin123456');
await adminPage.click('button[type="submit"]');
await adminPage.waitForURL('/admin');
await adminPage.goto('/admin/settings');
await adminPage.waitForLoadState('networkidle');
const servicesConfig = adminPage.locator('text=feature_services').locator('..').locator('..');
await servicesConfig.locator('input[type="checkbox"]').first().check();
await servicesConfig.locator('button:has-text("保存")').click();
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
await page.goto('/');
await page.waitForLoadState('networkidle');
await expect(page.locator('#services')).toBeVisible();
await servicesConfig.locator('input[type="checkbox"]').first().uncheck();
await servicesConfig.locator('button:has-text("保存")').click();
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
await page.reload();
await page.waitForLoadState('networkidle');
await expect(page.locator('#services')).not.toBeVisible();
await servicesConfig.locator('input[type="checkbox"]').first().check();
await servicesConfig.locator('button:has-text("保存")').click();
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
await adminPage.close();
});
test('配置开关 - 产品模块显示/隐藏', async ({ page, context }) => {
const adminPage = await context.newPage();
await adminPage.goto('/admin/login');
await adminPage.fill('input[type="email"]', 'admin@novalon.cn');
await adminPage.fill('input[type="password"]', 'admin123456');
await adminPage.click('button[type="submit"]');
await adminPage.waitForURL('/admin');
await adminPage.goto('/admin/settings');
await adminPage.waitForLoadState('networkidle');
const productsConfig = adminPage.locator('text=feature_products').locator('..').locator('..');
await productsConfig.locator('input[type="checkbox"]').first().check();
await productsConfig.locator('button:has-text("保存")').click();
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
await page.goto('/');
await page.waitForLoadState('networkidle');
await expect(page.locator('#products')).toBeVisible();
await productsConfig.locator('input[type="checkbox"]').first().uncheck();
await productsConfig.locator('button:has-text("保存")').click();
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
await page.reload();
await page.waitForLoadState('networkidle');
await expect(page.locator('#products')).not.toBeVisible();
await productsConfig.locator('input[type="checkbox"]').first().check();
await productsConfig.locator('button:has-text("保存")').click();
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
await adminPage.close();
});
test('配置开关 - 新闻模块显示/隐藏', async ({ page, context }) => {
const adminPage = await context.newPage();
await adminPage.goto('/admin/login');
await adminPage.fill('input[type="email"]', 'admin@novalon.cn');
await adminPage.fill('input[type="password"]', 'admin123456');
await adminPage.click('button[type="submit"]');
await adminPage.waitForURL('/admin');
await adminPage.goto('/admin/settings');
await adminPage.waitForLoadState('networkidle');
const newsConfig = adminPage.locator('text=feature_news').locator('..').locator('..');
await newsConfig.locator('input[type="checkbox"]').first().check();
await newsConfig.locator('button:has-text("保存")').click();
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
await page.goto('/');
await page.waitForLoadState('networkidle');
await expect(page.locator('#news')).toBeVisible();
await newsConfig.locator('input[type="checkbox"]').first().uncheck();
await newsConfig.locator('button:has-text("保存")').click();
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
await page.reload();
await page.waitForLoadState('networkidle');
await expect(page.locator('#news')).not.toBeVisible();
await newsConfig.locator('input[type="checkbox"]').first().check();
await newsConfig.locator('button:has-text("保存")').click();
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
await adminPage.close();
});
});