78 lines
3.3 KiB
TypeScript
78 lines
3.3 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { act } from 'react';
|
|
import { createRoot } from 'react-dom/client';
|
|
import { afterEach, expect, it, vi } from 'vitest';
|
|
import { useApp } from '../../src/app/AppProvider';
|
|
import { DatasetViewer } from '../../src/features/dataset-viewer/DatasetViewer';
|
|
import { recordResultSheets } from '../../src/features/linked-results/record-results';
|
|
import { useFilteredRecords } from '../../src/features/search-filter/use-filtered-records';
|
|
import { makeSheet } from '../../src/importers/sheet-factory';
|
|
|
|
vi.mock('../../src/app/AppProvider', () => ({ useApp: vi.fn() }));
|
|
vi.mock('../../src/features/search-filter/use-filtered-records', () => ({ useFilteredRecords: vi.fn() }));
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
vi.unstubAllGlobals();
|
|
Reflect.deleteProperty(HTMLElement.prototype, 'scrollIntoView');
|
|
});
|
|
|
|
it('opens a passing CIS-CAT Result with its evaluated source value highlighted as a green match', async () => {
|
|
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true);
|
|
vi.stubGlobal('ResizeObserver', class { observe() {} disconnect() {} });
|
|
Object.defineProperty(HTMLElement.prototype, 'scrollIntoView', { value: vi.fn(), configurable: true });
|
|
|
|
const findings = makeSheet('Assessment Results', [
|
|
['Benchmark Item', 'Result', 'Result File', 'Source: Scan'],
|
|
['Passing registry check', 'Pass', 'evidence.csv', 'CIS-CAT Pro · 2026-09-20T00:00:00Z']
|
|
], '', 'assessment.html', { toolId: 'cis-cat' });
|
|
const evidence = makeSheet('Assessment Evidence · Registry Item', [
|
|
['Field', 'Value'],
|
|
['Criterion:', "Ensure 'ForceGuest' is 'Windows: Registry Value' to '0'"],
|
|
['Type', 'reg_dword'],
|
|
['Value', '0']
|
|
], '', 'evidence.csv', { toolId: 'cis-cat' });
|
|
evidence.analysis.records[1].highlighted = true;
|
|
evidence.analysis.records[2].highlighted = true;
|
|
|
|
const record = findings.analysis.records[0];
|
|
expect(recordResultSheets(record, [findings, evidence], findings.id, 'cis-cat')).toHaveLength(1);
|
|
const state = {
|
|
dataset: { sheets: [findings, evidence], rawText: '', profileId: 'cis-cat' },
|
|
activeSheet: findings,
|
|
view: 'records',
|
|
search: '',
|
|
titleColumn: 'Benchmark Item',
|
|
selectedRecordId: record.id,
|
|
reviews: {},
|
|
facetFilters: {},
|
|
statusFilter: 'passed',
|
|
actionOnly: false,
|
|
setView: vi.fn(),
|
|
setSelectedRecord: vi.fn(),
|
|
updateReview: vi.fn()
|
|
} as unknown as ReturnType<typeof useApp>;
|
|
vi.mocked(useApp).mockReturnValue(state);
|
|
vi.mocked(useFilteredRecords).mockReturnValue(findings.analysis.records);
|
|
|
|
const container = document.createElement('div');
|
|
document.body.append(container);
|
|
const root = createRoot(container);
|
|
try {
|
|
await act(async () => root.render(<DatasetViewer />));
|
|
const resultsButton = [...container.querySelectorAll<HTMLButtonElement>('button')]
|
|
.find(button => button.textContent?.trim() === 'Results');
|
|
expect(resultsButton).toBeDefined();
|
|
await act(async () => resultsButton!.click());
|
|
|
|
expect(container.querySelectorAll('.rich-text-table-row--match')).toHaveLength(2);
|
|
expect(container.querySelector('.rich-text-table-row--violation')).toBeNull();
|
|
expect(container.textContent).toContain('reg_dword');
|
|
expect(container.textContent).toContain('0');
|
|
} finally {
|
|
await act(async () => root.unmount());
|
|
container.remove();
|
|
}
|
|
});
|