None colour from API (#1063)

This commit is contained in:
Alex Christoffer Rasmussen
2024-06-12 21:31:08 +02:00
committed by GitHub
parent b1838a5e9a
commit 9e63261b35
2 changed files with 13 additions and 1 deletions
@@ -18,6 +18,13 @@ describe('parses a colour string that is', () => {
it('not a string', () => {
expect(() => coerceColour(5)).toThrowError(Error('Invalid colour value received'));
});
it('undefinde and null are not valid', () => {
expect(() => coerceColour(null)).toThrowError(Error('Invalid colour value received'));
expect(() => coerceColour(undefined)).toThrowError(Error('Invalid colour value received'));
});
it('empty string is allowed', () => {
expect(coerceColour('')).toBe('');
});
});
describe('match a string to an enum that is', () => {
+6 -1
View File
@@ -90,7 +90,12 @@ export function coerceColour(value: unknown): string {
if (!isColourHex(lowerCaseValue)) {
throw new Error('Invalid hex colour received');
}
} else if (!(lowerCaseValue in cssColours)) {
return lowerCaseValue;
}
if (lowerCaseValue === '') {
return lowerCaseValue; // None colour the same as the UI 'Ø' button
}
if (!(lowerCaseValue in cssColours)) {
throw new Error('Invalid colour name received');
}
return lowerCaseValue;