diff --git a/tests/department-single-transparent.spec.ts b/tests/department-single-transparent.spec.ts index bbb54df..5b65661 100644 --- a/tests/department-single-transparent.spec.ts +++ b/tests/department-single-transparent.spec.ts @@ -37,19 +37,25 @@ async function loginAndDismissSelectors(page: any) { for (let i = 0; i < 5; i++) { const path = await page.evaluate(() => window.location.pathname); console.log(`[DeptTest] iteration ${i}: path=${path}`); + console.log(`[DeptTest] has Authorization:`, !!await page.evaluate(() => window.localStorage.getItem('Authorization'))); + console.log(`[DeptTest] has HtySudoerToken:`, !!await page.evaluate(() => window.localStorage.getItem('HtySudoerToken'))); if (path === '/org/select') { await page.locator('.van-cell').first().click(); + console.log('[DeptTest] clicked org cell'); await page.waitForTimeout(3_000); } else if (path === '/') { const rs = page.getByText('请选择您的登录身份'); if (await rs.isVisible().catch(() => false)) { await page.locator('.van-grid-item').first().click(); + console.log('[DeptTest] clicked role'); await page.waitForTimeout(3_000); } else { + console.log('[DeptTest] at / but no role selector, break'); break; } } else { + console.log('[DeptTest] unexpected path, break'); break; } } @@ -71,6 +77,11 @@ test.describe('单部门透明', () => { await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 }); + // 打印当前页面状态 + console.log('[DeptTest] path before', await page.evaluate(() => window.location.pathname)); + console.log('[DeptTest] has HtySudoToken:', await page.evaluate(() => !!window.localStorage.getItem('HtySudoerToken'))); + console.log('[DeptTest] has CurrentOrgId:', await page.evaluate(() => window.localStorage.getItem('CurrentOrgId'))); + // 等待异步的部门加载完成 await page.waitForTimeout(3_000); @@ -78,13 +89,14 @@ test.describe('单部门透明', () => { const deptId = await page.evaluate(() => window.localStorage.getItem('CurrentDepartmentId') ); + const pathnameAfter = await page.evaluate(() => window.location.pathname); + console.log('[DeptTest] path after wait:', pathnameAfter); console.log('[DeptTest] CurrentDepartmentId:', deptId); expect(deptId).toBeTruthy(); expect(deptId).toContain('dept_default_'); // 验证页面路径不包含 department 相关参数 - const pathname = await page.evaluate(() => window.location.pathname); - expect(pathname).not.toContain('department'); + expect(pathnameAfter).not.toContain('department'); // 验证 token 中包含 department_id const authToken = await page.evaluate(() => @@ -104,6 +116,8 @@ test.describe('单部门透明', () => { subjectPayload = JSON.parse(payload.sub); console.log('[JWT Debug] sub keys:', Object.keys(subjectPayload)); console.log('[JWT Debug] sub.current_department_id:', subjectPayload.current_department_id); + console.log('[JWT Debug] sub.current_org_id:', subjectPayload.current_org_id); + console.log('[JWT Debug] sub.current_org_id type:', typeof subjectPayload.current_org_id); } const deptIdInJwt = payload.current_department_id || subjectPayload.current_department_id; expect(deptIdInJwt).toBeTruthy();