|
@@ -0,0 +1,285 @@
|
|
|
|
|
+import { TIMEOUTS } from '../../utils/timeouts';
|
|
|
|
|
+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'));
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 测试区域编码大小写敏感性问题
|
|
|
|
|
+ *
|
|
|
|
|
+ * 测试场景:
|
|
|
|
|
+ * 1. 创建测试省市区数据
|
|
|
|
|
+ * 2. 编辑测试区,尝试使用大写编码 "HPY" 保存
|
|
|
|
|
+ * 3. 捕获控制台错误日志和截图
|
|
|
|
|
+ * 4. 然后尝试使用小写编码 "hpy" 保存
|
|
|
|
|
+ * 5. 对比两种情况的差异
|
|
|
|
|
+ */
|
|
|
|
|
+test.describe('区域编码大小写敏感性测试', () => {
|
|
|
|
|
+ const createdProvinces: string[] = [];
|
|
|
|
|
+
|
|
|
|
|
+ test.beforeEach(async ({ adminLoginPage, regionManagementPage }) => {
|
|
|
|
|
+ // 以管理员身份登录后台
|
|
|
|
|
+ await adminLoginPage.goto();
|
|
|
|
|
+ await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
|
|
|
|
|
+ await adminLoginPage.expectLoginSuccess();
|
|
|
|
|
+ await regionManagementPage.goto();
|
|
|
|
|
+ await regionManagementPage.waitForTreeLoaded();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test.afterEach(async ({ regionManagementPage }) => {
|
|
|
|
|
+ // 清理测试创建的数据
|
|
|
|
|
+ for (const provinceName of createdProvinces) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await regionManagementPage.waitForTreeLoaded();
|
|
|
|
|
+ const exists = await regionManagementPage.regionExists(provinceName);
|
|
|
|
|
+ if (exists) {
|
|
|
|
|
+ await regionManagementPage.deleteRegion(provinceName);
|
|
|
|
|
+ console.debug(`✅ 已清理测试数据: ${provinceName}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.debug(`❌ 清理异常: ${provinceName}`, error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ createdProvinces.length = 0;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('测试区域编码 - 大写 "HPY" vs 小写 "hpy" 编码', async ({
|
|
|
|
|
+ regionManagementPage,
|
|
|
|
|
+ page,
|
|
|
|
|
+ }) => {
|
|
|
|
|
+ console.debug('========== 开始测试区域编码大小写敏感性 ==========');
|
|
|
|
|
+
|
|
|
|
|
+ // 生成唯一的测试数据 - 在省一级测试
|
|
|
|
|
+ const timestamp = Date.now();
|
|
|
|
|
+ const provinceName = `测试省_${timestamp}`;
|
|
|
|
|
+ const uppercaseCode = 'HPY';
|
|
|
|
|
+ const lowercaseCode = 'hpy';
|
|
|
|
|
+
|
|
|
|
|
+ // ============ 步骤 1: 创建测试省 ============
|
|
|
|
|
+ console.debug(`步骤 1: 创建测试省数据`);
|
|
|
|
|
+ console.debug(` 创建省: ${provinceName}`);
|
|
|
|
|
+ await regionManagementPage.createProvince({
|
|
|
|
|
+ name: provinceName,
|
|
|
|
|
+ code: `PROV_${timestamp}`,
|
|
|
|
|
+ level: 1,
|
|
|
|
|
+ });
|
|
|
|
|
+ createdProvinces.push(provinceName);
|
|
|
|
|
+
|
|
|
|
|
+ // 刷新页面以确保新数据可见
|
|
|
|
|
+ await regionManagementPage.refreshTree();
|
|
|
|
|
+
|
|
|
|
|
+ // 验证测试省存在
|
|
|
|
|
+ const provinceExists = await regionManagementPage.regionExists(provinceName);
|
|
|
|
|
+ expect(provinceExists).toBe(true);
|
|
|
|
|
+ console.debug(`✅ 测试数据创建成功: "${provinceName}"`);
|
|
|
|
|
+
|
|
|
|
|
+ // ============ 步骤 2: 测试大写编码 "HPY" ============
|
|
|
|
|
+ console.debug(`\n步骤 2: 测试大写编码 "${uppercaseCode}"`);
|
|
|
|
|
+
|
|
|
|
|
+ // 收集控制台日志(创建新的监听器)
|
|
|
|
|
+ const uppercaseConsoleErrors: string[] = [];
|
|
|
|
|
+ const uppercaseConsoleWarnings: string[] = [];
|
|
|
|
|
+
|
|
|
|
|
+ const uppercaseConsoleHandler = (msg: any) => {
|
|
|
|
|
+ const text = msg.text();
|
|
|
|
|
+ const type = msg.type();
|
|
|
|
|
+
|
|
|
|
|
+ if (type === 'error') {
|
|
|
|
|
+ uppercaseConsoleErrors.push(text);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (type === 'warning') {
|
|
|
|
|
+ uppercaseConsoleWarnings.push(text);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ page.on('console', uppercaseConsoleHandler);
|
|
|
|
|
+
|
|
|
|
|
+ // 打开编辑对话框
|
|
|
|
|
+ await regionManagementPage.openEditDialog(provinceName);
|
|
|
|
|
+
|
|
|
|
|
+ // 填写大写编码
|
|
|
|
|
+ const codeInput = page.getByLabel('行政区划代码');
|
|
|
|
|
+ await codeInput.fill(uppercaseCode);
|
|
|
|
|
+ console.debug(`填写编码: "${uppercaseCode}"`);
|
|
|
|
|
+
|
|
|
|
|
+ // 截图 - 大写编码状态
|
|
|
|
|
+ await page.screenshot({
|
|
|
|
|
+ path: `test-results/region-code-uppercase-${Date.now()}.png`,
|
|
|
|
|
+ fullPage: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ console.debug('📸 已截图: 大写编码状态');
|
|
|
|
|
+
|
|
|
|
|
+ // 提交表单并捕获响应
|
|
|
|
|
+ const uppercaseResult = await regionManagementPage.submitForm();
|
|
|
|
|
+
|
|
|
|
|
+ // 等待对话框关闭
|
|
|
|
|
+ await regionManagementPage.waitForDialogClosed();
|
|
|
|
|
+
|
|
|
|
|
+ // 记录大写编码测试结果
|
|
|
|
|
+ console.debug('\n========== 大写编码 "HPY" 测试结果 ==========');
|
|
|
|
|
+ console.debug(`提交成功: ${uppercaseResult.success}`);
|
|
|
|
|
+ console.debug(`有错误: ${uppercaseResult.hasError}`);
|
|
|
|
|
+ console.debug(`有成功消息: ${uppercaseResult.hasSuccess}`);
|
|
|
|
|
+ console.debug(`错误消息: ${uppercaseResult.errorMessage || '无'}`);
|
|
|
|
|
+ console.debug(`成功消息: ${uppercaseResult.successMessage || '无'}`);
|
|
|
|
|
+
|
|
|
|
|
+ // 记录网络响应
|
|
|
|
|
+ if (uppercaseResult.responses && uppercaseResult.responses.length > 0) {
|
|
|
|
|
+ console.debug('\n网络响应:');
|
|
|
|
|
+ for (const response of uppercaseResult.responses) {
|
|
|
|
|
+ console.debug(` URL: ${response.url}`);
|
|
|
|
|
+ console.debug(` 方法: ${response.method}`);
|
|
|
|
|
+ console.debug(` 状态码: ${response.status}`);
|
|
|
|
|
+ console.debug(` 成功: ${response.ok}`);
|
|
|
|
|
+ if (response.status >= 400) {
|
|
|
|
|
+ console.debug(` 响应体: ${JSON.stringify(response.responseBody)}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 记录控制台日志
|
|
|
|
|
+ console.debug('\n控制台错误日志:');
|
|
|
|
|
+ if (uppercaseConsoleErrors.length > 0) {
|
|
|
|
|
+ for (const error of uppercaseConsoleErrors) {
|
|
|
|
|
+ console.debug(` ❌ ${error}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.debug(' (无错误日志)');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.debug('\n控制台警告日志:');
|
|
|
|
|
+ if (uppercaseConsoleWarnings.length > 0) {
|
|
|
|
|
+ for (const warning of uppercaseConsoleWarnings) {
|
|
|
|
|
+ console.debug(` ⚠️ ${warning}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.debug(' (无警告日志)');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 截图 - 大写编码结果
|
|
|
|
|
+ await page.screenshot({
|
|
|
|
|
+ path: `test-results/region-code-uppercase-result-${Date.now()}.png`,
|
|
|
|
|
+ fullPage: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ console.debug('📸 已截图: 大写编码结果');
|
|
|
|
|
+
|
|
|
|
|
+ // 移除控制台监听器
|
|
|
|
|
+ page.off('console', uppercaseConsoleHandler);
|
|
|
|
|
+
|
|
|
|
|
+ // 等待页面稳定
|
|
|
|
|
+ await page.waitForTimeout(TIMEOUTS.LONG);
|
|
|
|
|
+
|
|
|
|
|
+ // ============ 步骤 3: 测试小写编码 "hpy" ============
|
|
|
|
|
+ console.debug(`\n步骤 3: 测试小写编码 "${lowercaseCode}"`);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建新的控制台监听器
|
|
|
|
|
+ const lowercaseConsoleErrors: string[] = [];
|
|
|
|
|
+ const lowercaseConsoleWarnings: string[] = [];
|
|
|
|
|
+
|
|
|
|
|
+ const lowercaseConsoleHandler = (msg: any) => {
|
|
|
|
|
+ const text = msg.text();
|
|
|
|
|
+ const type = msg.type();
|
|
|
|
|
+
|
|
|
|
|
+ if (type === 'error') {
|
|
|
|
|
+ lowercaseConsoleErrors.push(text);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (type === 'warning') {
|
|
|
|
|
+ lowercaseConsoleWarnings.push(text);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ page.on('console', lowercaseConsoleHandler);
|
|
|
|
|
+
|
|
|
|
|
+ // 打开编辑对话框
|
|
|
|
|
+ await regionManagementPage.openEditDialog(provinceName);
|
|
|
|
|
+
|
|
|
|
|
+ // 填写小写编码
|
|
|
|
|
+ await codeInput.fill(lowercaseCode);
|
|
|
|
|
+ console.debug(`填写编码: "${lowercaseCode}"`);
|
|
|
|
|
+
|
|
|
|
|
+ // 截图 - 小写编码状态
|
|
|
|
|
+ await page.screenshot({
|
|
|
|
|
+ path: `test-results/region-code-lowercase-${Date.now()}.png`,
|
|
|
|
|
+ fullPage: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ console.debug('📸 已截图: 小写编码状态');
|
|
|
|
|
+
|
|
|
|
|
+ // 提交表单
|
|
|
|
|
+ const lowercaseResult = await regionManagementPage.submitForm();
|
|
|
|
|
+
|
|
|
|
|
+ // 等待对话框关闭
|
|
|
|
|
+ await regionManagementPage.waitForDialogClosed();
|
|
|
|
|
+
|
|
|
|
|
+ // 记录小写编码测试结果
|
|
|
|
|
+ console.debug('\n========== 小写编码 "hpy" 测试结果 ==========');
|
|
|
|
|
+ console.debug(`提交成功: ${lowercaseResult.success}`);
|
|
|
|
|
+ console.debug(`有错误: ${lowercaseResult.hasError}`);
|
|
|
|
|
+ console.debug(`有成功消息: ${lowercaseResult.hasSuccess}`);
|
|
|
|
|
+ console.debug(`错误消息: ${lowercaseResult.errorMessage || '无'}`);
|
|
|
|
|
+ console.debug(`成功消息: ${lowercaseResult.successMessage || '无'}`);
|
|
|
|
|
+
|
|
|
|
|
+ // 记录网络响应
|
|
|
|
|
+ if (lowercaseResult.responses && lowercaseResult.responses.length > 0) {
|
|
|
|
|
+ console.debug('\n网络响应:');
|
|
|
|
|
+ for (const response of lowercaseResult.responses) {
|
|
|
|
|
+ console.debug(` URL: ${response.url}`);
|
|
|
|
|
+ console.debug(` 方法: ${response.method}`);
|
|
|
|
|
+ console.debug(` 状态码: ${response.status}`);
|
|
|
|
|
+ console.debug(` 成功: ${response.ok}`);
|
|
|
|
|
+ if (response.status >= 400) {
|
|
|
|
|
+ console.debug(` 响应体: ${JSON.stringify(response.responseBody)}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 记录控制台日志
|
|
|
|
|
+ console.debug('\n控制台错误日志:');
|
|
|
|
|
+ if (lowercaseConsoleErrors.length > 0) {
|
|
|
|
|
+ for (const error of lowercaseConsoleErrors) {
|
|
|
|
|
+ console.debug(` ❌ ${error}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.debug(' (无错误日志)');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.debug('\n控制台警告日志:');
|
|
|
|
|
+ if (lowercaseConsoleWarnings.length > 0) {
|
|
|
|
|
+ for (const warning of lowercaseConsoleWarnings) {
|
|
|
|
|
+ console.debug(` ⚠️ ${warning}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.debug(' (无警告日志)');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 移除控制台监听器
|
|
|
|
|
+ page.off('console', lowercaseConsoleHandler);
|
|
|
|
|
+
|
|
|
|
|
+ // 截图 - 小写编码结果
|
|
|
|
|
+ await page.screenshot({
|
|
|
|
|
+ path: `test-results/region-code-lowercase-result-${Date.now()}.png`,
|
|
|
|
|
+ fullPage: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ console.debug('📸 已截图: 小写编码结果');
|
|
|
|
|
+
|
|
|
|
|
+ // ============ 步骤 4: 对比结果 ============
|
|
|
|
|
+ console.debug('\n========== 对比结果 ==========');
|
|
|
|
|
+ console.debug(`大写编码 "${uppercaseCode}" 成功: ${uppercaseResult.success}, 有错误: ${uppercaseResult.hasError}`);
|
|
|
|
|
+ console.debug(`小写编码 "${lowercaseCode}" 成功: ${lowercaseResult.success}, 有错误: ${lowercaseResult.hasError}`);
|
|
|
|
|
+
|
|
|
|
|
+ // 断言:小写编码应该成功
|
|
|
|
|
+ expect(lowercaseResult.success).toBe(true);
|
|
|
|
|
+ expect(lowercaseResult.hasError).toBe(false);
|
|
|
|
|
+
|
|
|
|
|
+ // 如果大写编码失败,记录差异
|
|
|
|
|
+ if (uppercaseResult.hasError && !lowercaseResult.hasError) {
|
|
|
|
|
+ console.debug('\n⚠️ 发现差异:大写编码失败,小写编码成功!');
|
|
|
|
|
+ console.debug(`大写编码错误消息: ${uppercaseResult.errorMessage}`);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.debug('\n========== 测试完成 ==========');
|
|
|
|
|
+ });
|
|
|
|
|
+});
|