| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { test, expect } from '@playwright/test';
- // BUG-11 修复:原版用 .example-chip 选择器,可能因 hash 路由或 CSS hash 失效
- // 改用 data-testid 属性(更稳定)+ 兼容 class 选择器(兜底)
- const CHIP_LOCATOR = '[data-testid="example-chip"], .example-chip';
- const CHIP_TEXT_LOCATOR = '[data-testid="example-chip-text"], .example-chip-text';
- const TEXTAREA_LOCATOR = '[data-testid="form-textarea"], .form-textarea, textarea';
- test.describe('示例提示词轮播', () => {
- test('每隔几秒自动切换', async ({ page }) => {
- await page.goto('http://localhost:5173/#/pages/book-generator/create', { waitUntil: 'networkidle' });
- await page.waitForSelector(CHIP_LOCATOR, { timeout: 15000 });
- const initial = (await page.locator(CHIP_LOCATOR).first().textContent())?.trim() || '';
- console.log('[T=0] 示例:', initial);
- expect(initial.length).toBeGreaterThan(0);
- await page.waitForTimeout(5500);
- const after5s = (await page.locator(CHIP_LOCATOR).first().textContent())?.trim() || '';
- console.log('[T=5s] 示例:', after5s);
- expect(after5s).not.toBe(initial);
- await page.waitForTimeout(5000);
- const after10s = (await page.locator(CHIP_LOCATOR).first().textContent())?.trim() || '';
- console.log('[T=10s]示例:', after10s);
- expect(after10s).not.toBe(after5s);
- await page.screenshot({ path: 'tests/example-rotation.png', fullPage: false });
- });
- test('点击示例填充到文本框', async ({ page }) => {
- await page.goto('http://localhost:5173/#/pages/book-generator/create', { waitUntil: 'networkidle' });
- await page.waitForSelector(CHIP_LOCATOR, { timeout: 15000 });
- const text = (await page.locator(CHIP_TEXT_LOCATOR).first().textContent())?.trim() || '';
- await page.locator(CHIP_LOCATOR).first().click();
- await page.waitForTimeout(500);
- const value = await page.locator(TEXTAREA_LOCATOR).first().evaluate((el: any) => el.value);
- console.log('点击后文本框内容:', value);
- expect(value).toBe(text);
- });
- test('页面只展示一个示例 chip(不重复铺开)', async ({ page }) => {
- await page.goto('http://localhost:5173/#/pages/book-generator/create', { waitUntil: 'networkidle' });
- await page.waitForSelector(CHIP_LOCATOR, { timeout: 15000 });
- const count = await page.locator(CHIP_LOCATOR).count();
- console.log('chip 数量:', count);
- expect(count).toBe(1);
- });
- });
|