Skip to content

Commit

Permalink
test: add test suite for fixupColorCode method
Browse files Browse the repository at this point in the history
  • Loading branch information
privateOmega committed Jun 16, 2023
1 parent cb7b95f commit 3445170
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/helpers/xml-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2211,4 +2211,5 @@ export {
buildUnderline,
buildDrawing,
fixupLineHeight,
fixupColorCode,
};
32 changes: 32 additions & 0 deletions tests/color-conversion.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-undef */
import { fixupColorCode } from '../src/helpers/xml-builder';
import {
rgbRegex,
hslRegex,
Expand Down Expand Up @@ -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');
});
});

0 comments on commit 3445170

Please sign in to comment.