From 3445170c3277c5049000aa9dea0820610ae086c8 Mon Sep 17 00:00:00 2001 From: privateOmega Date: Thu, 17 Mar 2022 01:06:20 +0530 Subject: [PATCH] test: add test suite for fixupColorCode method --- src/helpers/xml-builder.js | 1 + tests/color-conversion.test.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/helpers/xml-builder.js b/src/helpers/xml-builder.js index d05cfba8..a0223ebd 100644 --- a/src/helpers/xml-builder.js +++ b/src/helpers/xml-builder.js @@ -2211,4 +2211,5 @@ export { buildUnderline, buildDrawing, fixupLineHeight, + fixupColorCode, }; diff --git a/tests/color-conversion.test.js b/tests/color-conversion.test.js index d3107b93..c50f58e6 100644 --- a/tests/color-conversion.test.js +++ b/tests/color-conversion.test.js @@ -1,4 +1,5 @@ /* eslint-disable no-undef */ +import { fixupColorCode } from '../src/helpers/xml-builder'; import { rgbRegex, hslRegex, @@ -112,3 +113,34 @@ describe('Color Conversion Methods', () => { }); }); }); + +describe('fixupColorCode', () => { + it('should get hex value from color name', () => { + expect(fixupColorCode('antiquewhite')).toEqualCaseInsensitive('faebd7'); + }); + + it('should get 000000 hex value only from random color names', () => { + expect(fixupColorCode('randomcolor')).toEqualCaseInsensitive('000000'); + }); + + it.skip('should get 000000 hex value only for invalid input', () => { + expect(fixupColorCode(null)).toEqualCaseInsensitive('000000'); + expect(fixupColorCode(undefined)).toEqualCaseInsensitive('000000'); + }); + + it('should get hex value from rgb value', () => { + expect(fixupColorCode('rgb(128, 0, 128)')).toEqual('800080'); + }); + + it('should get hex value from hsl value', () => { + expect(fixupColorCode('hsl(3, 100%, 50%)')).toEqual('ff0d00'); + }); + + it('should get hex value from hex value', () => { + expect(fixupColorCode('#ff0d00')).toEqual('ff0d00'); + }); + + it('should get hex value from hex3 value', () => { + expect(fixupColorCode('#fd0')).toEqual('ffdd00'); + }); +});