Skip to content

Commit

Permalink
Merge pull request #2121 from snyk/test/color-text-by-severity-test
Browse files Browse the repository at this point in the history
test: colorTextBySeverity tests
  • Loading branch information
JackuB committed Aug 11, 2021
2 parents 338f7a9 + 8b2dc42 commit 04d18cd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/jest/unit/common.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { colorTextBySeverity } from '../../../src/lib/snyk-test/common';
import { color } from '../../../src/lib/theme';
import { SEVERITY } from '../../../src/lib/snyk-test/common';

describe('colorTextBySeverity', () => {
it('Returns a high severity colored text', () => {
const severity = SEVERITY.HIGH;
expect(colorTextBySeverity(severity, 'Pls help me')).toEqual(
color.severity[severity]('Pls help me'),
);
});

it('Pass an empty string as text', () => {
const severity = SEVERITY.HIGH;
expect(colorTextBySeverity(severity, '')).toEqual(
color.severity[severity](''),
);
});

it('Pass an empty string as severity', () => {
const severity = '';
const defaultSeverity = SEVERITY.LOW;
expect(colorTextBySeverity(severity, 'Pls help me')).toEqual(
color.severity[defaultSeverity]('Pls help me'),
);
});

it('Set defaultive low color when given a non existent severity', () => {
const severity = 'nonExistentSeverity';
const defaultSeverity = SEVERITY.LOW;
expect(colorTextBySeverity(severity, 'Pls help me')).toEqual(
color.severity[defaultSeverity]('Pls help me'),
);
});

it('Pass an upper case string as severity', () => {
const severity = 'HIGH';
const lowerCaseSeverity = SEVERITY.HIGH;
expect(colorTextBySeverity(severity, 'Pls help me')).toEqual(
color.severity[lowerCaseSeverity]('Pls help me'),
);
});
});

0 comments on commit 04d18cd

Please sign in to comment.