Merge pull request #17276 from strapi/feature/review-workflow-multiple-initial-colors

Fix: Make stage theme color retrieval more defensive
This commit is contained in:
Gustav Hansen 2023-07-12 09:34:51 +02:00 committed by GitHub
commit 5f5c6ec185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 9 deletions

View File

@ -174,7 +174,7 @@ export function Stage({
dragPreviewRef(getEmptyImage(), { captureDraggingState: false });
}, [dragPreviewRef, index]);
const { themeColorName } = colorField.value ? getStageColorByHex(colorField.value) : {};
const { themeColorName } = getStageColorByHex(colorField.value) ?? {};
return (
<Box ref={composedRef}>

View File

@ -19,18 +19,22 @@ const STAGES_FIXTURE = {
index: 0,
};
const ComponentFixture = (props) => {
const ComponentFixture = ({
// eslint-disable-next-line react/prop-types
stages = [
{
color: STAGE_COLOR_DEFAULT,
name: 'something',
},
],
...props
}) => {
const store = configureStore([], [reducer]);
const formik = useFormik({
enableReinitialize: true,
initialValues: {
stages: [
{
color: STAGE_COLOR_DEFAULT,
name: 'something',
},
],
stages,
},
validateOnChange: false,
});
@ -96,4 +100,19 @@ describe('Admin | Settings | Review Workflow | Stage', () => {
})
).not.toBeInTheDocument();
});
it('should not crash on a custom color code', async () => {
const { getByRole } = setup({
isOpen: true,
canDelete: false,
stages: [
{
color: '#FF4945',
name: 'something',
},
],
});
expect(getByRole('textbox').value).toBe('something');
});
});

View File

@ -9,7 +9,7 @@
},
{
"name": "In progress",
"color": "#FF4945"
"color": "#EE5E52"
},
{
"name": "Reviewed",