forked from
npmx.dev/npmx.dev
[READ-ONLY]
a fast, modern browser for the npm registry
1import { describe, expect, it } from 'vitest'
2import {
3 SEVERITY_COLORS,
4 SEVERITY_TEXT_COLORS,
5 SEVERITY_BADGE_COLORS,
6 getHighestSeverity,
7} from '../../../../shared/utils/severity'
8
9describe('severity utils', () => {
10 describe('SEVERITY_COLORS', () => {
11 it('has colors for all severity levels', () => {
12 expect(SEVERITY_COLORS.critical).toBeDefined()
13 expect(SEVERITY_COLORS.high).toBeDefined()
14 expect(SEVERITY_COLORS.moderate).toBeDefined()
15 expect(SEVERITY_COLORS.low).toBeDefined()
16 expect(SEVERITY_COLORS.unknown).toBeDefined()
17 })
18
19 it('critical has red colors', () => {
20 expect(SEVERITY_COLORS.critical).toContain('red')
21 })
22
23 it('high has red colors', () => {
24 expect(SEVERITY_COLORS.high).toContain('red')
25 })
26
27 it('moderate has orange colors', () => {
28 expect(SEVERITY_COLORS.moderate).toContain('orange')
29 })
30
31 it('low has yellow colors', () => {
32 expect(SEVERITY_COLORS.low).toContain('yellow')
33 })
34 })
35
36 describe('SEVERITY_TEXT_COLORS', () => {
37 it('has text colors for all severity levels', () => {
38 expect(SEVERITY_TEXT_COLORS.critical).toContain('text-')
39 expect(SEVERITY_TEXT_COLORS.high).toContain('text-')
40 expect(SEVERITY_TEXT_COLORS.moderate).toContain('text-')
41 expect(SEVERITY_TEXT_COLORS.low).toContain('text-')
42 expect(SEVERITY_TEXT_COLORS.unknown).toContain('text-')
43 })
44 })
45
46 describe('SEVERITY_BADGE_COLORS', () => {
47 it('has badge colors for all severity levels', () => {
48 expect(SEVERITY_BADGE_COLORS.critical).toBeDefined()
49 expect(SEVERITY_BADGE_COLORS.high).toBeDefined()
50 expect(SEVERITY_BADGE_COLORS.moderate).toBeDefined()
51 expect(SEVERITY_BADGE_COLORS.low).toBeDefined()
52 expect(SEVERITY_BADGE_COLORS.unknown).toBeDefined()
53 })
54 })
55
56 describe('getHighestSeverity', () => {
57 it('returns critical when critical count > 0', () => {
58 expect(getHighestSeverity({ critical: 1, high: 0, moderate: 0, low: 0 })).toBe('critical')
59 })
60
61 it('returns high when high is highest', () => {
62 expect(getHighestSeverity({ critical: 0, high: 2, moderate: 1, low: 0 })).toBe('high')
63 })
64
65 it('returns moderate when moderate is highest', () => {
66 expect(getHighestSeverity({ critical: 0, high: 0, moderate: 3, low: 1 })).toBe('moderate')
67 })
68
69 it('returns low when only low', () => {
70 expect(getHighestSeverity({ critical: 0, high: 0, moderate: 0, low: 5 })).toBe('low')
71 })
72
73 it('returns unknown when all counts are 0', () => {
74 expect(getHighestSeverity({ critical: 0, high: 0, moderate: 0, low: 0 })).toBe('unknown')
75 })
76
77 it('returns unknown for empty object', () => {
78 expect(getHighestSeverity({})).toBe('unknown')
79 })
80
81 it('prioritizes critical over all others', () => {
82 expect(getHighestSeverity({ critical: 1, high: 10, moderate: 20, low: 30 })).toBe('critical')
83 })
84
85 it('handles missing keys gracefully', () => {
86 expect(getHighestSeverity({ high: 1 })).toBe('high')
87 expect(getHighestSeverity({ moderate: 1 })).toBe('moderate')
88 expect(getHighestSeverity({ low: 1 })).toBe('low')
89 })
90 })
91})