fix(history): respect export permission boundary
This commit is contained in:
@@ -13,11 +13,14 @@ const mocks = vi.hoisted(() => ({
|
||||
historyExports: vi.fn(),
|
||||
createHistoryExport: vi.fn()
|
||||
}));
|
||||
const auth = vi.hoisted(() => ({ role: 'admin' }));
|
||||
|
||||
vi.mock('../../api/client', () => ({ api: mocks }));
|
||||
vi.mock('../auth/AuthGate', () => ({ usePlatformSession: () => ({ session: { role: auth.role } }) }));
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
auth.role = 'admin';
|
||||
Object.values(mocks).forEach((mock) => mock.mockReset());
|
||||
});
|
||||
|
||||
@@ -121,3 +124,18 @@ test('opens a working column visibility panel and preserves non-hideable identit
|
||||
fireEvent.click(screen.getByRole('button', { name: '关闭列显示设置' }));
|
||||
expect(screen.queryByRole('dialog', { name: '列显示设置' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('keeps history readable without mounting operator-only export requests for a viewer', async () => {
|
||||
auth.role = 'viewer';
|
||||
mocks.historyMetricCatalog.mockResolvedValue({ categories: [{ key: 'location', label: '位置数据' }], metrics: [metric] });
|
||||
mocks.historyData.mockResolvedValue(historyData('OLDVIN', '旧车牌', 'old-as-of'));
|
||||
mocks.historySeries.mockResolvedValue(historySeries('OLDVIN', '旧车牌', 'old-as-of'));
|
||||
renderPage();
|
||||
|
||||
expect((await screen.findAllByText('旧车牌')).length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('只读 · 导出需操作员权限')).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: /创建导出/ })).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('导出任务')).not.toBeInTheDocument();
|
||||
expect(mocks.historyExports).not.toHaveBeenCalled();
|
||||
expect(mocks.createHistoryExport).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user