diff --git a/packages/core/src/routes/sign-in-experience.branding.guard.test.ts b/packages/core/src/routes/sign-in-experience.branding.guard.test.ts index 899a797ba..8903c514c 100644 --- a/packages/core/src/routes/sign-in-experience.branding.guard.test.ts +++ b/packages/core/src/routes/sign-in-experience.branding.guard.test.ts @@ -23,35 +23,10 @@ const expectPatchResponseStatus = async (signInExperience: any, status: number) describe('branding', () => { const colorKeys = ['primaryColor', 'darkPrimaryColor']; - - const invalidColors = [ - undefined, - null, - '', - '#', - '#1', - '#2B', - '#3cZ', - '#4D9e', - '#5f80E', - '#6GHiXY', - '#78Cb5dA', - 'rgb(0,13,255)', - ]; - - const validColors = ['#aB3', '#169deF']; + const invalidColors = [undefined, null, '#0']; describe('colors', () => { - test.each(validColors)('%p should succeed', async (validColor) => { - for (const colorKey of colorKeys) { - // eslint-disable-next-line no-await-in-loop - await expectPatchResponseStatus( - { branding: { ...mockBranding, [colorKey]: validColor } }, - 200 - ); - } - }); - test.each(invalidColors)('%p should fail', async (invalidColor) => { + test.each(invalidColors)('should fail when color is %p', async (invalidColor) => { for (const colorKey of colorKeys) { // eslint-disable-next-line no-await-in-loop await expectPatchResponseStatus( @@ -60,6 +35,15 @@ describe('branding', () => { ); } }); + it('should succeed when color is valid', async () => { + for (const colorKey of colorKeys) { + // eslint-disable-next-line no-await-in-loop + await expectPatchResponseStatus( + { branding: { ...mockBranding, [colorKey]: '#169deF' } }, + 200 + ); + } + }); }); describe('style', () => { diff --git a/packages/core/src/utils/regex.test.ts b/packages/core/src/utils/regex.test.ts new file mode 100644 index 000000000..ac08f868f --- /dev/null +++ b/packages/core/src/utils/regex.test.ts @@ -0,0 +1,25 @@ +import { hexColorRegEx } from '@/utils/regex'; + +const invalidColors = [ + '', + '#', + '#1', + '#2B', + '#3cZ', + '#4D9e', + '#5f80E', + '#6GHiXY', + '#78Cb5dA', + 'rgb(0,13,255)', +]; + +const validColors = ['#aB3', '#169deF']; + +describe('hexColorRegEx', () => { + test.each(validColors)('%p should succeed', async (validColor) => { + expect(hexColorRegEx.test(validColor)).toBeTruthy(); + }); + test.each(invalidColors)('%p should fail', async (invalidColor) => { + expect(hexColorRegEx.test(invalidColor)).toBeFalsy(); + }); +});