42 lines
3.4 KiB
TypeScript
42 lines
3.4 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { describe, expect, it } from 'vitest';
|
|
import type { FindingRecord, PolicySourceEvidence } from '../../src/domain/finding';
|
|
import { VariantComparisonResult } from '../../src/features/linked-results/VariantComparisonResult';
|
|
import { POLICY_CONFLICT_DETAILS, policyEvidenceResultSheets, serializePolicyConflictPresentation } from '../../src/profiles/group-policy/conflict-presentation';
|
|
|
|
/** Synthetic conflict: variant A matches every baseline variant, B differs from every one, C is not proven. */
|
|
function record(): FindingRecord {
|
|
const detail = { version: 1 as const, summary: '3 variants · 4 sources. Values differ.',
|
|
context: 'Setting: SyntheticSetting\nScope: computer\nRegistry path: Software\\Policies\\Synthetic\nValue name: SyntheticSetting',
|
|
tables: [
|
|
{ name: 'Conflicting variants', headers: ['Variant', 'Value', 'Type', 'Sources'],
|
|
rows: [['Variant 1', '1', 'REG_DWORD (4)', '2'], ['Variant 2', '0', 'REG_DWORD (4)', '1'], ['Variant 3', '2', 'REG_DWORD (4)', '1']], emphasis: ['Value'] },
|
|
{ name: 'Source references', headers: ['Source', 'Variant', 'Source path', 'Backup', 'Record'],
|
|
rows: [['Source 1', 'Variant 1', 'a/registry.pol#records=1', 'backup-a', 'record-a'],
|
|
['Source 2', 'Variant 1', 'b/registry.pol#records=1', 'backup-b', 'record-b'],
|
|
['Source 3', 'Variant 2', 'c/registry.pol#records=1', 'backup-c', 'record-c'],
|
|
['Source 4', 'Variant 3', 'd/registry.pol#records=1', 'backup-d', 'record-d']], emphasis: [] }
|
|
] };
|
|
const evidence = (recordId: string, baselineRelation?: PolicySourceEvidence['baselineRelation']): PolicySourceEvidence =>
|
|
({ id: JSON.stringify(['synthetic', 'slot', recordId]), sourceReference: recordId, values: [], ...(baselineRelation ? { baselineRelation } : {}) });
|
|
const fields = [{ label: 'Title', value: 'SyntheticSetting', index: 0 }, { label: POLICY_CONFLICT_DETAILS, value: serializePolicyConflictPresentation(detail), index: 1 }];
|
|
return { id: 'synthetic-conflict', index: 0, title: 'SyntheticSetting', fields, filled: fields, meta: [],
|
|
policySourceEvidence: [evidence('record-a', 'aligned'), evidence('record-b', 'aligned'), evidence('record-c', 'conflicting'), evidence('record-d', 'review')] };
|
|
}
|
|
|
|
describe('GPO conflict variants in Results', () => {
|
|
it('marks a variant green or red only when every one of its sources has that proven baseline relation', () => {
|
|
const comparison = policyEvidenceResultSheets(record())[0].resultVariantComparison!;
|
|
expect(comparison.variants.map(variant => variant.baselineState)).toEqual(['aligned', 'deviating', undefined]);
|
|
const container = document.createElement('div');
|
|
container.innerHTML = renderToStaticMarkup(<VariantComparisonResult comparison={comparison} search=""/>);
|
|
const rows = [...container.querySelectorAll('tbody tr')];
|
|
expect(rows.map(row => row.getAttribute('data-baseline-state'))).toEqual(['aligned', 'deviating', 'unassessed']);
|
|
expect(rows[0].querySelector('.policy-value-mark.is-aligned')?.textContent).toBe('1');
|
|
expect(rows[1].querySelector('.policy-value-mark.is-deviating')?.textContent).toBe('0');
|
|
expect(rows[2].querySelector('.policy-value-mark')).toBeNull();
|
|
expect(rows.map(row => row.querySelector('.variant-comparison__value-note')?.textContent ?? '')).toEqual(['Matches the baseline', 'Differs from the baseline', '']);
|
|
});
|
|
});
|