mirror of
https://github.com/logto-io/logto.git
synced 2025-01-27 21:39:16 -05:00
test(core): separate the color validation cases from tests of sign-in experience (#577)
* test(core): hexColorRegEx * test(core): sign-in experience branding colors
This commit is contained in:
parent
fe5650e8e2
commit
608f667963
2 changed files with 36 additions and 27 deletions
|
@ -23,35 +23,10 @@ const expectPatchResponseStatus = async (signInExperience: any, status: number)
|
||||||
|
|
||||||
describe('branding', () => {
|
describe('branding', () => {
|
||||||
const colorKeys = ['primaryColor', 'darkPrimaryColor'];
|
const colorKeys = ['primaryColor', 'darkPrimaryColor'];
|
||||||
|
const invalidColors = [undefined, null, '#0'];
|
||||||
const invalidColors = [
|
|
||||||
undefined,
|
|
||||||
null,
|
|
||||||
'',
|
|
||||||
'#',
|
|
||||||
'#1',
|
|
||||||
'#2B',
|
|
||||||
'#3cZ',
|
|
||||||
'#4D9e',
|
|
||||||
'#5f80E',
|
|
||||||
'#6GHiXY',
|
|
||||||
'#78Cb5dA',
|
|
||||||
'rgb(0,13,255)',
|
|
||||||
];
|
|
||||||
|
|
||||||
const validColors = ['#aB3', '#169deF'];
|
|
||||||
|
|
||||||
describe('colors', () => {
|
describe('colors', () => {
|
||||||
test.each(validColors)('%p should succeed', async (validColor) => {
|
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(
|
|
||||||
{ branding: { ...mockBranding, [colorKey]: validColor } },
|
|
||||||
200
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
test.each(invalidColors)('%p should fail', async (invalidColor) => {
|
|
||||||
for (const colorKey of colorKeys) {
|
for (const colorKey of colorKeys) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
await expectPatchResponseStatus(
|
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', () => {
|
describe('style', () => {
|
||||||
|
|
25
packages/core/src/utils/regex.test.ts
Normal file
25
packages/core/src/utils/regex.test.ts
Normal file
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue