Skip to content

Commit 04d18cd

Browse files
authored
Merge pull request #2121 from snyk/test/color-text-by-severity-test
test: colorTextBySeverity tests
2 parents 338f7a9 + 8b2dc42 commit 04d18cd

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/jest/unit/common.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { colorTextBySeverity } from '../../../src/lib/snyk-test/common';
2+
import { color } from '../../../src/lib/theme';
3+
import { SEVERITY } from '../../../src/lib/snyk-test/common';
4+
5+
describe('colorTextBySeverity', () => {
6+
it('Returns a high severity colored text', () => {
7+
const severity = SEVERITY.HIGH;
8+
expect(colorTextBySeverity(severity, 'Pls help me')).toEqual(
9+
color.severity[severity]('Pls help me'),
10+
);
11+
});
12+
13+
it('Pass an empty string as text', () => {
14+
const severity = SEVERITY.HIGH;
15+
expect(colorTextBySeverity(severity, '')).toEqual(
16+
color.severity[severity](''),
17+
);
18+
});
19+
20+
it('Pass an empty string as severity', () => {
21+
const severity = '';
22+
const defaultSeverity = SEVERITY.LOW;
23+
expect(colorTextBySeverity(severity, 'Pls help me')).toEqual(
24+
color.severity[defaultSeverity]('Pls help me'),
25+
);
26+
});
27+
28+
it('Set defaultive low color when given a non existent severity', () => {
29+
const severity = 'nonExistentSeverity';
30+
const defaultSeverity = SEVERITY.LOW;
31+
expect(colorTextBySeverity(severity, 'Pls help me')).toEqual(
32+
color.severity[defaultSeverity]('Pls help me'),
33+
);
34+
});
35+
36+
it('Pass an upper case string as severity', () => {
37+
const severity = 'HIGH';
38+
const lowerCaseSeverity = SEVERITY.HIGH;
39+
expect(colorTextBySeverity(severity, 'Pls help me')).toEqual(
40+
color.severity[lowerCaseSeverity]('Pls help me'),
41+
);
42+
});
43+
});

0 commit comments

Comments
 (0)