ReportChartV2.test.tsx36 lines · main
| 1 | import { describe, expect, it } from 'vitest' |
| 2 | |
| 3 | import { computePeriodTotal } from './ReportChartV2' |
| 4 | |
| 5 | describe('computePeriodTotal', () => { |
| 6 | const attrs = [ |
| 7 | { attribute: 'SignInAttempts', label: 'Password', enabled: true }, |
| 8 | { attribute: 'SignInAttempts', label: 'PKCE', enabled: true }, |
| 9 | { attribute: 'SignInAttempts', label: 'Refresh Token', enabled: true }, |
| 10 | { attribute: 'SignInAttempts', label: 'ID Token', enabled: true }, |
| 11 | ] |
| 12 | |
| 13 | it('deduplicates attributes that map to same field', () => { |
| 14 | const data = [ |
| 15 | { timestamp: 1, SignInAttempts: 1 }, |
| 16 | { timestamp: 2, SignInAttempts: 0 }, |
| 17 | ] |
| 18 | expect(computePeriodTotal(data as any, attrs as any)).toBe(1) |
| 19 | }) |
| 20 | |
| 21 | it('excludes reference lines, max values, omitted and disabled attributes', () => { |
| 22 | const data = [ |
| 23 | { timestamp: 1, a: 1, b: 2, c: 4, d: 8 }, |
| 24 | { timestamp: 2, a: 1, b: 2, c: 4, d: 8 }, |
| 25 | ] |
| 26 | const attributes = [ |
| 27 | { attribute: 'a', enabled: true }, |
| 28 | { attribute: 'b', provider: 'reference-line', enabled: true }, |
| 29 | { attribute: 'c', isMaxValue: true, enabled: true }, |
| 30 | { attribute: 'd', omitFromTotal: true, enabled: true }, |
| 31 | { attribute: 'e', enabled: false }, |
| 32 | ] |
| 33 | // Only 'a' should count: period total = 1+1 = 2 |
| 34 | expect(computePeriodTotal(data as any, attributes as any)).toBe(2) |
| 35 | }) |
| 36 | }) |