0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -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:
IceHe.xyz 2022-04-20 12:08:55 +08:00 committed by GitHub
parent fe5650e8e2
commit 608f667963
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 27 deletions

View file

@ -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', () => {

View 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();
});
});