Files
workspace/code/g3soft-erp/web/e2e/smoke.spec.ts
T
2026-10-14 17:25:47 +08:00

43 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { expect, test } from './support/fixtures'
import { loadSession } from './support/session'
/**
* 冒烟用例:证明「免登录」这条基础设施真的通了。
*
* 落点选 `/approval/todo` 而不是首页:
* - `/dashboard` **没有任何权限点**(`sql/20_registration/14_dashboard_menu.sql` 写明
* 「不建权限点」,只有 `g3soft` 提权可见);
* - e2e 默认账号 `demo_zhangwei` 只被授了 `menu.approval%`
* (`sql/90_mock/02_fms_workflow_runtime_mock.sql:186`)。
* 于是非超管进 `/dashboard` 会被守卫送到 `/403`,而 `/approval/todo` 是演示账号有授权的页面,
* 换成 `g3soft`(超管)也照样通过 —— 两边都不挑账号。
*/
test('种了会话就能直接进受保护页面,不跳登录页也不跳 403', async ({ page }) => {
await page.goto('/approval/todo')
// 断言最终 URL 就是目标页,同时覆盖两种失败:跳 /login(会话没种上)、
// 跳 /403(种上了但没授权)。只写 not.toHaveURL('/login') 会漏掉后者,而且
// goto 之后 URL 立刻就是目标值,not 断言会在重定向发生前就通过 —— 断言不到东西。
await expect(page).toHaveURL(/\/approval\/todo$/)
})
test('顶栏显示的是会话里的那个用户', async ({ page }) => {
const user = loadSession().user
const expected = user?.name || user?.account || ''
expect(expected, '会话里没有用户名,登录响应结构可能变了').not.toBe('')
await page.goto('/approval/todo')
await expect(page.locator('.layout-header__user')).toContainText(expected)
})
test('刷新后仍是登录态(会话读自 sessionStorage,不靠内存)', async ({ page }) => {
await page.goto('/approval/todo')
await expect(page).toHaveURL(/\/approval\/todo$/)
await page.reload()
await expect(page).toHaveURL(/\/approval\/todo$/)
})