From 8b2dc42f8174c37a83c638c1d9305908eb501140 Mon Sep 17 00:00:00 2001 From: ofir-eldar-snyk Date: Wed, 28 Jul 2021 14:57:13 +0300 Subject: [PATCH] test: colorTextBySeverity tests --- test/jest/unit/common.spec.ts | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/jest/unit/common.spec.ts diff --git a/test/jest/unit/common.spec.ts b/test/jest/unit/common.spec.ts new file mode 100644 index 0000000000..a27027735c --- /dev/null +++ b/test/jest/unit/common.spec.ts @@ -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'), + ); + }); +});