216 lines
8.6 KiB
TypeScript
216 lines
8.6 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('配置数据库操作测试', () => {
|
|
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=功能配置').locator('..').locator('..');
|
|
const textarea = servicesConfig.locator('textarea').first();
|
|
|
|
await textarea.fill('test_service');
|
|
await servicesConfig.locator('button:has-text("保存")').click();
|
|
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
|
|
|
await page.goto('/');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const serviceCards = page.locator('#services .card');
|
|
const count = await serviceCards.count();
|
|
expect(count).toBeGreaterThan(0);
|
|
|
|
await adminPage.goto('/admin/settings');
|
|
await adminPage.waitForLoadState('networkidle');
|
|
|
|
const configExists = adminPage.locator('textarea').first();
|
|
expect(configExists).toBeVisible();
|
|
});
|
|
|
|
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=功能配置').locator('..').locator('..');
|
|
const displayCountInput = newsConfig.locator('input[type="number"]').nth(1);
|
|
|
|
await displayCountInput.fill('5');
|
|
await newsConfig.locator('button:has-text("保存")').click();
|
|
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
|
|
|
await page.goto('/');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const newsCards = page.locator('#news .card');
|
|
const count = await newsCards.count();
|
|
expect(count).toBe(5);
|
|
|
|
await adminPage.goto('/admin/settings');
|
|
await adminPage.waitForLoadState('networkidle');
|
|
|
|
await displayCountInput.fill('10');
|
|
await newsConfig.locator('button:has-text("保存")').click();
|
|
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
|
|
|
await page.goto('/');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const newCount = await newsCards.count();
|
|
expect(newCount).toBe(10);
|
|
});
|
|
|
|
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=功能配置').locator('..').locator('..');
|
|
const productsCheckbox = productsConfig.locator('input[type="checkbox"]').nth(1);
|
|
|
|
await productsCheckbox.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 adminPage.goto('/admin/settings');
|
|
await adminPage.waitForLoadState('networkidle');
|
|
|
|
await productsCheckbox.uncheck();
|
|
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')).not.toBeVisible();
|
|
});
|
|
|
|
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 featureConfig = adminPage.locator('text=功能配置').locator('..').locator('..');
|
|
const checkboxes = featureConfig.locator('input[type="checkbox"]');
|
|
|
|
const initialServicesState = await checkboxes.nth(0).isChecked();
|
|
const initialProductsState = await checkboxes.nth(1).isChecked();
|
|
const initialNewsState = await checkboxes.nth(2).isChecked();
|
|
|
|
await checkboxes.nth(0).setChecked(!initialServicesState);
|
|
await checkboxes.nth(1).setChecked(!initialProductsState);
|
|
await checkboxes.nth(2).setChecked(!initialNewsState);
|
|
|
|
await featureConfig.locator('button:has-text("保存")').click();
|
|
await adminPage.waitForSelector('text=保存成功', { timeout: 10000 });
|
|
|
|
await page.goto('/');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const finalServicesVisible = await page.locator('#services').isVisible();
|
|
const finalProductsVisible = await page.locator('#products').isVisible();
|
|
const finalNewsVisible = await page.locator('#news').isVisible();
|
|
|
|
expect(finalServicesVisible).toBe(!initialServicesState);
|
|
expect(finalProductsVisible).toBe(!initialProductsState);
|
|
expect(finalNewsVisible).toBe(!initialNewsState);
|
|
});
|
|
|
|
test('配置数据完整性 - updatedAt字段更新', 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 featureConfig = adminPage.locator('text=功能配置').locator('..').locator('..');
|
|
const checkbox = featureConfig.locator('input[type="checkbox"]').first();
|
|
|
|
await checkbox.check();
|
|
await featureConfig.locator('button:has-text("保存")').click();
|
|
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
|
|
|
await adminPage.waitForTimeout(2000);
|
|
|
|
await checkbox.uncheck();
|
|
await featureConfig.locator('button:has-text("保存")').click();
|
|
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
|
|
|
await page.goto('/');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
await expect(page.locator('#services')).not.toBeVisible();
|
|
});
|
|
|
|
test('配置查询 - 按分类过滤', async ({ page }) => {
|
|
await page.goto('/admin/login');
|
|
await page.fill('input[type="email"]', 'admin@novalon.cn');
|
|
await page.fill('input[type="password"]', 'admin123456');
|
|
await page.click('button[type="submit"]');
|
|
await page.waitForURL('/admin');
|
|
|
|
await page.goto('/admin/settings');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const featureConfig = page.locator('text=功能配置').locator('..').locator('..');
|
|
await expect(featureConfig).toBeVisible();
|
|
|
|
const featureCount = await featureConfig.locator('input[type="checkbox"]').count();
|
|
expect(featureCount).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('配置查询 - 按key精确查找', async ({ page }) => {
|
|
await page.goto('/admin/login');
|
|
await page.fill('input[type="email"]', 'admin@novalon.cn');
|
|
await page.fill('input[type="password"]', 'admin123456');
|
|
await page.click('button[type="submit"]');
|
|
await page.waitForURL('/admin');
|
|
|
|
await page.goto('/admin/settings');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const featureConfig = page.locator('text=功能配置').locator('..').locator('..');
|
|
await expect(featureConfig).toBeVisible();
|
|
|
|
const checkboxes = featureConfig.locator('input[type="checkbox"]');
|
|
const count = await checkboxes.count();
|
|
expect(count).toBeGreaterThan(0);
|
|
});
|
|
});
|