89ccb4e52f
- 创建 PermissionHelper 类 - 支持验证页面访问权限 - 支持验证CRUD操作权限 - 支持验证角色权限边界 - 添加基础单元测试(5个测试用例全部通过)
70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { PermissionHelper } from '../permission-helper';
|
|
import type { RoleDefinition } from '../../roles/base.role';
|
|
|
|
// Mock Playwright
|
|
vi.mock('@playwright/test', () => ({
|
|
expect: Object.assign(vi.fn(), {
|
|
extend: vi.fn().mockReturnValue(expect),
|
|
}),
|
|
}));
|
|
|
|
describe('PermissionHelper', () => {
|
|
it('should create PermissionHelper instance', () => {
|
|
const mockPage = {
|
|
goto: vi.fn(),
|
|
url: vi.fn().mockReturnValue('http://localhost:3000/dashboard'),
|
|
locator: vi.fn().mockReturnValue({
|
|
count: vi.fn().mockResolvedValue(0),
|
|
}),
|
|
} as any;
|
|
|
|
const helper = new PermissionHelper(mockPage);
|
|
expect(helper).toBeDefined();
|
|
});
|
|
|
|
it('should have verifyCanAccess method', () => {
|
|
const mockPage = {
|
|
goto: vi.fn(),
|
|
url: vi.fn().mockReturnValue('http://localhost:3000/dashboard'),
|
|
locator: vi.fn(),
|
|
} as any;
|
|
|
|
const helper = new PermissionHelper(mockPage);
|
|
expect(typeof helper.verifyCanAccess).toBe('function');
|
|
});
|
|
|
|
it('should have verifyCannotAccess method', () => {
|
|
const mockPage = {
|
|
goto: vi.fn(),
|
|
url: vi.fn(),
|
|
locator: vi.fn(),
|
|
} as any;
|
|
|
|
const helper = new PermissionHelper(mockPage);
|
|
expect(typeof helper.verifyCannotAccess).toBe('function');
|
|
});
|
|
|
|
it('should have verifyRolePermissions method', () => {
|
|
const mockPage = {
|
|
goto: vi.fn(),
|
|
url: vi.fn(),
|
|
locator: vi.fn(),
|
|
} as any;
|
|
|
|
const helper = new PermissionHelper(mockPage);
|
|
expect(typeof helper.verifyRolePermissions).toBe('function');
|
|
});
|
|
|
|
it('should have verifyPermissionBoundary method', () => {
|
|
const mockPage = {
|
|
goto: vi.fn(),
|
|
url: vi.fn(),
|
|
locator: vi.fn(),
|
|
} as any;
|
|
|
|
const helper = new PermissionHelper(mockPage);
|
|
expect(typeof helper.verifyPermissionBoundary).toBe('function');
|
|
});
|
|
});
|