ReportChartV2.test.tsx 1.3 KB

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