08ea5fbe98
添加用户管理视图、API和状态管理文件
232 lines
7.9 KiB
TypeScript
232 lines
7.9 KiB
TypeScript
/**
|
|
* Uniapp 万年历页面 E2E 测试
|
|
* 测试日历功能的核心业务流程
|
|
*/
|
|
|
|
import { test, expect } from '../shared/fixtures/test-fixtures';
|
|
import { testLogger } from '../shared/utils/test-logger';
|
|
|
|
test.describe('万年历页面功能测试 @uniapp @calendar', () => {
|
|
test.beforeEach(async ({ uniappCalendarPage }) => {
|
|
await uniappCalendarPage.navigate();
|
|
});
|
|
|
|
test('日历页面 - 正常加载显示', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 正常加载显示');
|
|
|
|
// 验证页面标题
|
|
const title = await uniappCalendarPage.getPageTitle();
|
|
expect(title).toContain('万年历');
|
|
|
|
// 验证日历网格可见
|
|
const daysCount = await uniappCalendarPage.getVisibleDays();
|
|
expect(daysCount).toBeGreaterThan(28); // 至少显示28天
|
|
|
|
testLogger.endTest('日历页面 - 正常加载显示', 'passed');
|
|
});
|
|
|
|
test('日历页面 - 月份切换功能', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 月份切换功能');
|
|
|
|
// 点击下一个月
|
|
await uniappCalendarPage.clickNextMonth();
|
|
|
|
// 验证月份变化
|
|
const daysCount = await uniappCalendarPage.getVisibleDays();
|
|
expect(daysCount).toBeGreaterThan(0);
|
|
|
|
// 点击上一个月
|
|
await uniappCalendarPage.clickPrevMonth();
|
|
|
|
// 验证回到当前月
|
|
const daysCountAfterPrev = await uniappCalendarPage.getVisibleDays();
|
|
expect(daysCountAfterPrev).toBeGreaterThan(0);
|
|
|
|
testLogger.endTest('日历页面 - 月份切换功能', 'passed');
|
|
});
|
|
|
|
test('日历页面 - 日期选择功能', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 日期选择功能');
|
|
|
|
// 选择15号
|
|
await uniappCalendarPage.clickDay(15);
|
|
|
|
// 验证选中状态
|
|
const selectedDay = uniappCalendarPage['page'].locator('.calendar-day.selected, .calendar-day--selected');
|
|
const isSelected = await selectedDay.isVisible().catch(() => false);
|
|
|
|
testLogger.info(`日期选中状态: ${isSelected ? '已选中' : '未选中'}`);
|
|
|
|
testLogger.endTest('日历页面 - 日期选择功能', 'passed');
|
|
});
|
|
|
|
test('日历页面 - 返回今天功能', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 返回今天功能');
|
|
|
|
// 先切换到其他月份
|
|
await uniappCalendarPage.clickNextMonth();
|
|
await uniappCalendarPage.clickNextMonth();
|
|
|
|
// 点击返回今天
|
|
await uniappCalendarPage.clickToday();
|
|
|
|
// 验证回到当前月
|
|
const today = new Date().getDate();
|
|
const todayElement = uniappCalendarPage['page'].locator(`.calendar-day.today, .calendar-day--today:has-text("${today}")`);
|
|
const isTodayVisible = await todayElement.isVisible().catch(() => false);
|
|
|
|
testLogger.info(`今天日期显示: ${isTodayVisible ? '正常' : '未找到'}`);
|
|
|
|
testLogger.endTest('日历页面 - 返回今天功能', 'passed');
|
|
});
|
|
|
|
test('日历页面 - 农历信息显示', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 农历信息显示');
|
|
|
|
// 获取农历信息
|
|
const lunarInfo = await uniappCalendarPage.getLunarDate();
|
|
|
|
// 验证农历信息不为空
|
|
expect(lunarInfo).toBeTruthy();
|
|
|
|
testLogger.info(`农历信息: ${lunarInfo}`);
|
|
|
|
testLogger.endTest('日历页面 - 农历信息显示', 'passed');
|
|
});
|
|
|
|
test('日历页面 - 跨年度切换', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 跨年度切换');
|
|
|
|
// 连续点击下一个月12次(跨一年)
|
|
for (let i = 0; i < 12; i++) {
|
|
await uniappCalendarPage.clickNextMonth();
|
|
}
|
|
|
|
// 验证日历正常显示
|
|
const daysCount = await uniappCalendarPage.getVisibleDays();
|
|
expect(daysCount).toBeGreaterThan(0);
|
|
|
|
testLogger.endTest('日历页面 - 跨年度切换', 'passed');
|
|
});
|
|
|
|
test('日历页面 - 闰年2月显示', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 闰年2月显示');
|
|
|
|
// 导航到闰年2月(2024年是闰年)
|
|
// 这里假设可以通过URL参数或直接操作来设置日期
|
|
await uniappCalendarPage.navigate();
|
|
|
|
// 验证页面正常加载
|
|
const daysCount = await uniappCalendarPage.getVisibleDays();
|
|
expect(daysCount).toBeGreaterThan(0);
|
|
|
|
testLogger.endTest('日历页面 - 闰年2月显示', 'passed');
|
|
});
|
|
});
|
|
|
|
test.describe('万年历页面边界测试 @uniapp @calendar @boundary', () => {
|
|
test.beforeEach(async ({ uniappCalendarPage }) => {
|
|
await uniappCalendarPage.navigate();
|
|
});
|
|
|
|
test('日历页面 - 快速连续点击', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 快速连续点击');
|
|
|
|
// 快速连续点击下一个月
|
|
for (let i = 0; i < 10; i++) {
|
|
await uniappCalendarPage['page'].click('[data-testid="next-month"]').catch(() => {});
|
|
}
|
|
|
|
// 等待页面稳定
|
|
await uniappCalendarPage.waitForTimeout(1000);
|
|
|
|
// 验证页面没有崩溃
|
|
const daysCount = await uniappCalendarPage.getVisibleDays();
|
|
expect(daysCount).toBeGreaterThan(0);
|
|
|
|
testLogger.endTest('日历页面 - 快速连续点击', 'passed');
|
|
});
|
|
|
|
test('日历页面 - 选择不存在的日期', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 选择不存在的日期');
|
|
|
|
// 尝试点击不存在的日期(如2月30日)
|
|
// 这里我们尝试点击一个可能不存在的日期
|
|
const nonExistentDay = uniappCalendarPage['page'].locator('.calendar-day:has-text("32")');
|
|
const exists = await nonExistentDay.count() > 0;
|
|
|
|
if (exists) {
|
|
await nonExistentDay.click();
|
|
}
|
|
|
|
// 验证页面正常
|
|
const daysCount = await uniappCalendarPage.getVisibleDays();
|
|
expect(daysCount).toBeGreaterThan(0);
|
|
|
|
testLogger.endTest('日历页面 - 选择不存在的日期', 'passed');
|
|
});
|
|
|
|
test('日历页面 - 页面缩放适配', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 页面缩放适配');
|
|
|
|
// 设置不同的视口大小
|
|
const viewports = [
|
|
{ width: 375, height: 667 }, // iPhone SE
|
|
{ width: 414, height: 896 }, // iPhone 11 Pro Max
|
|
{ width: 768, height: 1024 }, // iPad
|
|
{ width: 1920, height: 1080 }, // Desktop
|
|
];
|
|
|
|
for (const viewport of viewports) {
|
|
await uniappCalendarPage['page'].setViewportSize(viewport);
|
|
await uniappCalendarPage.reload();
|
|
|
|
const daysCount = await uniappCalendarPage.getVisibleDays();
|
|
expect(daysCount).toBeGreaterThan(0);
|
|
|
|
testLogger.info(`视口 ${viewport.width}x${viewport.height}: 正常显示`);
|
|
}
|
|
|
|
testLogger.endTest('日历页面 - 页面缩放适配', 'passed');
|
|
});
|
|
});
|
|
|
|
test.describe('万年历页面性能测试 @uniapp @calendar @performance', () => {
|
|
test('日历页面 - 加载性能', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 加载性能');
|
|
|
|
const startTime = Date.now();
|
|
await uniappCalendarPage.navigate();
|
|
const loadTime = Date.now() - startTime;
|
|
|
|
// 验证加载时间小于3秒
|
|
expect(loadTime).toBeLessThan(3000);
|
|
|
|
testLogger.info(`页面加载时间: ${loadTime}ms`);
|
|
|
|
testLogger.endTest('日历页面 - 加载性能', 'passed');
|
|
});
|
|
|
|
test('日历页面 - 月份切换性能', async ({ uniappCalendarPage }) => {
|
|
testLogger.startTest('日历页面 - 月份切换性能');
|
|
|
|
await uniappCalendarPage.navigate();
|
|
|
|
const startTime = Date.now();
|
|
|
|
// 连续切换12个月
|
|
for (let i = 0; i < 12; i++) {
|
|
await uniappCalendarPage.clickNextMonth();
|
|
}
|
|
|
|
const switchTime = Date.now() - startTime;
|
|
|
|
// 验证切换时间小于5秒
|
|
expect(switchTime).toBeLessThan(5000);
|
|
|
|
testLogger.info(`12个月切换时间: ${switchTime}ms`);
|
|
|
|
testLogger.endTest('日历页面 - 月份切换性能', 'passed');
|
|
});
|
|
});
|