| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- import { test, expect } from '../../utils/test-setup';
- import { readFileSync } from 'fs';
- import { join, dirname } from 'path';
- import { fileURLToPath } from 'url';
- const __filename = fileURLToPath(import.meta.url);
- const __dirname = dirname(__filename);
- const testUsers = JSON.parse(readFileSync(join(__dirname, '../../fixtures/test-users.json'), 'utf-8'));
- test.describe.serial('订单列表查看测试', () => {
- test.beforeEach(async ({ adminLoginPage, orderManagementPage }) => {
- // 以管理员身份登录后台
- await adminLoginPage.goto();
- await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
- await adminLoginPage.expectLoginSuccess();
- await orderManagementPage.goto();
- });
- test.describe('页面加载验证', () => {
- test('应该显示订单列表页面标题', async ({ orderManagementPage }) => {
- await expect(orderManagementPage.pageTitle).toBeVisible();
- await expect(orderManagementPage.pageTitle).toContainText('订单管理');
- });
- test('应该显示新增订单按钮', async ({ orderManagementPage }) => {
- await expect(orderManagementPage.addOrderButton).toBeVisible();
- await expect(orderManagementPage.addOrderButton).toContainText('创建订单');
- });
- test('应该显示订单列表表格', async ({ orderManagementPage }) => {
- await expect(orderManagementPage.orderTable).toBeVisible();
- });
- test('应该显示搜索框和搜索按钮', async ({ orderManagementPage }) => {
- await expect(orderManagementPage.searchInput).toBeVisible();
- await expect(orderManagementPage.searchButton).toBeVisible();
- await expect(orderManagementPage.searchButton).toContainText('搜索');
- });
- });
- test.describe('订单数据展示验证', () => {
- test('应该显示订单列表表格', async ({ orderManagementPage }) => {
- // 验证表格存在
- await expect(orderManagementPage.orderTable).toBeVisible();
- // 验证表格有表头
- const thead = orderManagementPage.orderTable.locator('thead');
- await expect(thead).toBeVisible();
- // 验证表格有数据行(至少尝试等待)
- const tbody = orderManagementPage.orderTable.locator('tbody');
- await expect(tbody).toBeVisible();
- });
- test('应该显示订单名称列', async ({ orderManagementPage }) => {
- // 获取表头中的所有列
- const headers = orderManagementPage.orderTable.locator('thead th');
- const headerTexts = await headers.allTextContents();
- // 验证订单名称列存在
- const hasOrderName = headerTexts.some((text) => text.includes('订单名称') || text.includes('名称'));
- expect(hasOrderName).toBe(true);
- });
- test('应该显示平台列', async ({ orderManagementPage }) => {
- const headers = orderManagementPage.orderTable.locator('thead th');
- const headerTexts = await headers.allTextContents();
- // 验证平台列存在
- const hasPlatform = headerTexts.some((text) => text.includes('平台'));
- expect(hasPlatform).toBe(true);
- });
- test('应该显示公司列', async ({ orderManagementPage }) => {
- const headers = orderManagementPage.orderTable.locator('thead th');
- const headerTexts = await headers.allTextContents();
- // 验证公司列存在
- const hasCompany = headerTexts.some((text) => text.includes('公司'));
- expect(hasCompany).toBe(true);
- });
- test('应该显示渠道列', async ({ orderManagementPage }) => {
- const headers = orderManagementPage.orderTable.locator('thead th');
- const headerTexts = await headers.allTextContents();
- // 验证渠道列存在
- const hasChannel = headerTexts.some((text) => text.includes('渠道'));
- expect(hasChannel).toBe(true);
- });
- test('应该显示预计开始日期列', async ({ orderManagementPage }) => {
- const headers = orderManagementPage.orderTable.locator('thead th');
- const headerTexts = await headers.allTextContents();
- // 验证预计开始日期列存在
- const hasStartDate = headerTexts.some((text) =>
- text.includes('预计开始日期') || text.includes('开始日期') || text.includes('日期')
- );
- expect(hasStartDate).toBe(true);
- });
- });
- test.describe('订单状态徽章验证', () => {
- test('应该显示订单状态列', async ({ orderManagementPage }) => {
- const headers = orderManagementPage.orderTable.locator('thead th');
- const headerTexts = await headers.allTextContents();
- // 验证订单状态列存在
- const hasOrderStatus = headerTexts.some((text) =>
- text.includes('订单状态') || text.includes('订单状态')
- );
- expect(hasOrderStatus).toBe(true);
- });
- test('订单状态应该包含草稿、已确认、进行中、已完成等状态', async ({ page }) => {
- // 这个测试验证页面中可能显示的订单状态徽章
- // 不假设数据库中有特定状态的订单,只验证状态标签存在
- const tbody = page.locator('table tbody');
- const rows = tbody.locator('tr');
- const rowCount = await rows.count();
- if (rowCount > 0) {
- // 获取所有可能的状态文本
- const allText = await tbody.allTextContents();
- const allTextString = allText.join(' ');
- // 验证可能存在至少一个订单状态标签
- const statusLabels = ['草稿', '已确认', '进行中', '已完成'];
- const hasAnyStatus = statusLabels.some((label) => allTextString.includes(label));
- if (hasAnyStatus) {
- console.debug('发现订单状态徽章');
- // 如果有订单,验证状态标签是已知的
- statusLabels.forEach((label) => {
- if (allTextString.includes(label)) {
- console.debug(` - 发现状态: ${label}`);
- }
- });
- }
- } else {
- console.debug('订单列表为空,跳过状态徽章验证');
- }
- });
- });
- test.describe('工作状态徽章验证', () => {
- test('应该显示工作状态列', async ({ orderManagementPage }) => {
- const headers = orderManagementPage.orderTable.locator('thead th');
- const headerTexts = await headers.allTextContents();
- // 验证工作状态列存在
- const hasWorkStatus = headerTexts.some((text) =>
- text.includes('工作状态') || text.includes('就业状态')
- );
- expect(hasWorkStatus).toBe(true);
- });
- test('工作状态应该包含未就业、待就业、已就业、已离职等状态', async ({ page }) => {
- const tbody = page.locator('table tbody');
- const rows = tbody.locator('tr');
- const rowCount = await rows.count();
- if (rowCount > 0) {
- const allText = await tbody.allTextContents();
- const allTextString = allText.join(' ');
- // 验证可能存在至少一个工作状态标签
- const workStatusLabels = ['未就业', '待就业', '已就业', '已离职'];
- const hasAnyStatus = workStatusLabels.some((label) => allTextString.includes(label));
- if (hasAnyStatus) {
- console.debug('发现工作状态徽章');
- workStatusLabels.forEach((label) => {
- if (allTextString.includes(label)) {
- console.debug(` - 发现状态: ${label}`);
- }
- });
- }
- } else {
- console.debug('订单列表为空,跳过工作状态徽章验证');
- }
- });
- });
- test.describe('分页功能验证', () => {
- test('应该显示分页控件或记录信息', async ({ page }) => {
- // 查找分页相关的元素
- // 可能的分页元素:分页按钮、页码选择器、记录数量显示
- // 检查是否有分页控件(常见的选择器模式)
- const paginationSelectors = [
- 'pagination',
- '[role="navigation"]',
- '.pagination',
- '[data-testid="pagination"]',
- ];
- let hasPagination = false;
- for (const selector of paginationSelectors) {
- const element = page.locator(selector).first();
- if (await element.count() > 0) {
- hasPagination = true;
- console.debug(`发现分页控件: ${selector}`);
- break;
- }
- }
- // 检查是否有记录数量显示
- const recordInfoSelectors = [
- 'text=/共.*条/',
- 'text=/total.*/i',
- '[data-testid="record-count"]',
- ];
- let hasRecordInfo = false;
- for (const selector of recordInfoSelectors) {
- const element = page.locator(selector).first();
- if (await element.count() > 0) {
- hasRecordInfo = true;
- console.debug(`发现记录信息: ${selector}`);
- break;
- }
- }
- // 至少应该有分页控件或记录信息之一(如果订单数量较多)
- if (hasPagination || hasRecordInfo) {
- console.debug('页面包含分页功能');
- } else {
- console.debug('未发现明显的分页控件(可能是订单数量较少,未显示分页)');
- }
- // 此测试不会失败,只是记录分页控件的存在性
- expect(true).toBe(true);
- });
- test('应该能获取订单列表中的数据行数', async ({ page }) => {
- const tbody = page.locator('table tbody');
- const rows = tbody.locator('tr');
- const rowCount = await rows.count();
- console.debug(`订单列表当前显示 ${rowCount} 行数据`);
- // 至少应该能获取到行数(可以是0)
- expect(typeof rowCount).toBe('number');
- expect(rowCount).toBeGreaterThanOrEqual(0);
- });
- });
- test.describe('订单数据交互', () => {
- test('应该能检查订单是否存在', async ({ orderManagementPage }) => {
- // 测试检查不存在的订单
- const notExists = await orderManagementPage.orderExists('不存在的测试订单XYZ123');
- expect(notExists).toBe(false);
- console.debug('验证不存在的订单: 通过');
- });
- test('应该能搜索订单', async ({ orderManagementPage, page }) => {
- // 测试搜索功能
- await orderManagementPage.searchByName('测试');
- await page.waitForTimeout(1000);
- // 验证搜索后表格仍然可见
- await expect(orderManagementPage.orderTable).toBeVisible();
- console.debug('搜索功能执行成功');
- });
- });
- test.describe('导航功能', () => {
- test('应该能从其他页面导航到订单管理', async ({ adminLoginPage, orderManagementPage, page }) => {
- // 先访问其他页面
- await page.goto('/admin/dashboard');
- await page.waitForLoadState('domcontentloaded');
- // 然后导航到订单管理页面
- await orderManagementPage.goto();
- // 验证页面正常加载
- await expect(orderManagementPage.pageTitle).toBeVisible();
- await expect(orderManagementPage.orderTable).toBeVisible();
- });
- test('页面刷新后订单列表应该正常显示', async ({ orderManagementPage, page }) => {
- // 刷新页面
- await page.reload();
- await page.waitForLoadState('domcontentloaded');
- // 重新导航到订单管理页面
- await orderManagementPage.goto();
- // 验证页面正常加载
- await expect(orderManagementPage.pageTitle).toBeVisible();
- await expect(orderManagementPage.orderTable).toBeVisible();
- });
- });
- test.describe('操作按钮验证', () => {
- test('订单列表应该包含操作按钮', async ({ page }) => {
- const tbody = page.locator('table tbody');
- const rows = tbody.locator('tr');
- const rowCount = await rows.count();
- if (rowCount > 0) {
- // 获取第一行数据
- const firstRow = rows.first();
- // 检查可能存在的操作按钮
- const possibleButtons = ['编辑', '删除', '详情', '人员'];
- const foundButtons: string[] = [];
- for (const buttonText of possibleButtons) {
- const button = firstRow.getByRole('button', { name: buttonText });
- if (await button.count() > 0) {
- foundButtons.push(buttonText);
- }
- }
- if (foundButtons.length > 0) {
- console.debug(`发现操作按钮: ${foundButtons.join(', ')}`);
- }
- // 至少应该有一个操作按钮(不强制要求,取决于UI设计)
- expect(true).toBe(true);
- } else {
- console.debug('订单列表为空,跳过操作按钮验证');
- expect(true).toBe(true);
- }
- });
- });
- });
|