45 lines
3.0 KiB
TypeScript
45 lines
3.0 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
const source = readFileSync(new URL('../../src/features/project-import/DataHub.tsx', import.meta.url), 'utf8');
|
|
const disabledExpression = source.match(/const openDisabled = ([\s\S]*?);/)![1];
|
|
const openBody = source.match(/const openSelectedTimeslots = \(\) => \{([\s\S]*?)\n \};/)![1];
|
|
|
|
describe('GPO-only timeslot navigation', () => {
|
|
it('keeps Open disabled until displayable results have been confirmed', () => {
|
|
const disabled = new Function('selectedTimeslots', 'singleTimeslotRunIds', 'selectedSources', 'form', 'projectOpenReadiness', `return ${disabledExpression}`);
|
|
const form = { project: { id: 'synthetic-project' } };
|
|
const slots = [{ id: 'slot', gpoBackups: [{ state: 'succeeded' }] }];
|
|
expect(disabled(slots, [], { runIds: [] }, form, {})).toBe(true);
|
|
expect(disabled(slots, [], { runIds: [] }, form, { 'synthetic-project': { slot: { canOpen: false, hasPolicyResults: false } } })).toBe(true);
|
|
expect(disabled(slots, [], { runIds: [] }, form, { 'synthetic-project': { slot: { canOpen: true, hasPolicyResults: true } } })).toBe(false);
|
|
expect(disabled([], [], { runIds: [] }, form, {})).toBe(true);
|
|
expect(disabled([slots[0], slots[0]], [], { runIds: [] }, form, {})).toBe(true);
|
|
});
|
|
|
|
it('opens the client with an explicit GPO assessment scope instead of GPO analysis', () => {
|
|
const detail = vi.fn();
|
|
const open = vi.fn();
|
|
const error = vi.fn();
|
|
const handler = new Function('form', 'selectedTimeslots', 'excludedScanRunIds', 'selectedSources',
|
|
'scanReadiness', 'isDatahubScanViewable', 'setDetailSection', 'setError', 'onProjectSelected', 'projectOpenReadiness', openBody);
|
|
handler({ project: { id: 'synthetic-project' } }, [{ id: 'slot', scanRunIds: [], assessmentIds: ['synthetic-assessment'], gpoBackups: [{}] }], [],
|
|
{ runIds: [] }, {}, () => false, detail, error, open, { 'synthetic-project': { slot: { canOpen: true, hasPolicyResults: true } } });
|
|
expect(detail).not.toHaveBeenCalled();
|
|
expect(open).toHaveBeenCalledWith({ id: 'synthetic-project' }, [], ['synthetic-assessment']);
|
|
expect(error).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('keeps the GPO assessment scope when a normal timeslot also contains scanner runs', () => {
|
|
const open = vi.fn();
|
|
const handler = new Function('form', 'selectedTimeslots', 'excludedScanRunIds', 'selectedSources',
|
|
'scanReadiness', 'isDatahubScanViewable', 'setDetailSection', 'setError', 'onProjectSelected', 'projectOpenReadiness', openBody);
|
|
handler({ project: { id: 'synthetic-project' } }, [{
|
|
id: 'slot', scanRunIds: ['scanner-run'], assessmentIds: ['scanner-assessment', 'gpo-assessment'], gpoBackups: [{}]
|
|
}], [], { runIds: ['scanner-run'] }, { 'scanner-run': 'ready' }, () => true, vi.fn(), vi.fn(), open, {});
|
|
expect(open).toHaveBeenCalledWith(
|
|
{ id: 'synthetic-project' }, ['scanner-run'], ['scanner-assessment', 'gpo-assessment']
|
|
);
|
|
});
|
|
});
|