91 lines
3.2 KiB
TypeScript
91 lines
3.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { FindingRecord } from '../../src/domain/finding';
|
|
import { compactTileBadges, tileBadges } from '../../src/components/TileCard/TileCard';
|
|
|
|
const record: FindingRecord = {
|
|
id: 'tile-1',
|
|
index: 0,
|
|
title: 'Enterprise applications using SAML for SSO',
|
|
fields: [
|
|
{ index: 0, label: 'Score', value: '86' },
|
|
{ index: 1, label: 'Severity', value: 'Low' },
|
|
{ index: 2, label: 'Weight', value: '2' },
|
|
{ index: 3, label: 'Category', value: 'Entra ID' },
|
|
{ index: 4, label: 'Result', value: 'IOE Found' }
|
|
],
|
|
filled: [],
|
|
meta: []
|
|
};
|
|
|
|
describe('tileBadges', () => {
|
|
it('uses the fixed legacy order independently of source-column order', () => {
|
|
expect(tileBadges(record).map(badge => badge.text)).toEqual([
|
|
'IOE Found',
|
|
'Entra ID',
|
|
'Low',
|
|
'Weight: 2',
|
|
'Score: 86'
|
|
]);
|
|
});
|
|
|
|
it('only prefixes weight and score and applies severity styling to severity', () => {
|
|
const badges = tileBadges(record);
|
|
expect(badges.find(badge => badge.label === 'Category')?.text).toBe('Entra ID');
|
|
expect(badges.find(badge => badge.label === 'Severity')?.severity).toBe('low');
|
|
});
|
|
|
|
it('filters out Maester result message from status badge', () => {
|
|
const maesterRecord: FindingRecord = {
|
|
id: 'maester-1',
|
|
index: 0,
|
|
title: 'Ensure all users can complete multifactor authentication',
|
|
fields: [
|
|
{ index: 0, label: 'Severity', value: 'High' },
|
|
{ index: 1, label: 'Status', value: 'Failed' },
|
|
{ index: 2, label: 'Result', value: 'You have 52 of 78 users that aren\'t registered for MFA | --- | --- | Fail | ...' }
|
|
],
|
|
filled: [],
|
|
meta: []
|
|
};
|
|
|
|
const badges = tileBadges(maesterRecord, 'maester');
|
|
expect(badges.find(badge => badge.label === 'Status')?.text).toBe('Failed');
|
|
});
|
|
|
|
it('zeigt bei Purple Knight Status statt des SI-Verweises aus Result', () => {
|
|
const projected: FindingRecord = {
|
|
...record,
|
|
fields: [
|
|
{ index: 0, label: 'Result', value: 'SI000067' },
|
|
{ index: 1, label: 'Status', value: 'Pass' },
|
|
{ index: 2, label: 'ShortName', value: 'SI000067' }
|
|
]
|
|
};
|
|
|
|
expect(tileBadges(projected, 'purple-knight').find(badge => badge.label === 'Status')?.text).toBe('Passed');
|
|
});
|
|
|
|
it('zeigt abgeleitete CIS-Kategorien auch auf Finding-Kacheln', () => {
|
|
const cisRecord: FindingRecord = {
|
|
...record,
|
|
title: '2.2.2 Ensure a synthetic user right',
|
|
fields: [{ index: 0, label: 'Rule ID', value: '2.2.2' }]
|
|
};
|
|
|
|
expect(tileBadges(cisRecord, 'cis-cat').filter(badge => badge.label === 'CIS Category').map(badge => badge.text))
|
|
.toEqual(['CIS 2', 'CIS 2.2']);
|
|
});
|
|
|
|
it('verdichtet ueberzaehlige Graphbadges zu einem sichtbaren Zaehler', () => {
|
|
const badges = [
|
|
{ label: 'Status', value: 'Fail', text: 'Fail' },
|
|
{ label: 'Weight', value: '1.0', text: 'Weight: 1.0' },
|
|
{ label: 'CIS Category', value: 'CIS 18', text: 'CIS 18' },
|
|
{ label: 'CIS Category', value: 'CIS 18.10', text: 'CIS 18.10' },
|
|
{ label: 'CIS Category', value: 'CIS 18.10.18', text: 'CIS 18.10.18' }
|
|
];
|
|
|
|
expect(compactTileBadges(badges, 4).map(badge => badge.text)).toEqual(['Fail', 'Weight: 1.0', 'CIS 18.10.18', '+2']);
|
|
});
|
|
});
|