Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: colorTextBySeverity tests #2121

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also detect if color is being applied by checking for the ANSII escape code but not a requirement here

);
});

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'),
);
});
});