Merge pull request #16965 from strapi/chore/fix-styling

This commit is contained in:
Marc 2023-06-09 12:00:33 +02:00 committed by GitHub
commit 6cd60520fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 73 deletions

View File

@ -54,7 +54,6 @@ const useSettingsForm = (endPoint, schema, cbSuccess, fieldsToPick) => {
};
const handleChange = ({ target: { name, value, type: inputType } }) => {
dispatch({
type: 'ON_CHANGE',
inputType,
@ -82,7 +81,6 @@ const useSettingsForm = (endPoint, schema, cbSuccess, fieldsToPick) => {
});
if (!errors) {
try {
lockApp();

View File

@ -12,8 +12,8 @@ jest.mock('@strapi/helper-plugin', () => ({
}));
const mockSchema = {
validate: () => true
}
validate: () => true,
};
const handlers = [
rest.put('*/providers/options', (req, res, ctx) =>
@ -22,9 +22,9 @@ const handlers = [
ctx.json({
data: {
autoRegister: false,
defaultRole: "1",
ssoLockedRoles: ["1","2","3"]
}
defaultRole: '1',
ssoLockedRoles: ['1', '2', '3'],
},
})
)
),
@ -34,18 +34,17 @@ const handlers = [
ctx.json({
data: {
autoRegister: false,
defaultRole: "1",
ssoLockedRoles: ["1","2"]
}
defaultRole: '1',
ssoLockedRoles: ['1', '2'],
},
})
)
)
),
];
const server = setupServer(...handlers);
const setup = (...args) =>
renderHook(() => useSettingsForm(...args));
const setup = (...args) => renderHook(() => useSettingsForm(...args));
describe('useSettingsForm', () => {
beforeAll(() => {
@ -56,7 +55,11 @@ describe('useSettingsForm', () => {
server.close();
});
test('fetches all the providers options', async () => {
const { result } = setup('/admin/providers/options', mockSchema, jest.fn(), ['autoRegister', 'defaultRole', 'ssoLockedRoles'] );
const { result } = setup('/admin/providers/options', mockSchema, jest.fn(), [
'autoRegister',
'defaultRole',
'ssoLockedRoles',
]);
expect(result.current[0].isLoading).toBe(true);
expect(result.current[0].formErrors).toStrictEqual({});
@ -71,16 +74,16 @@ describe('useSettingsForm', () => {
expect(result.current[0].initialData).toStrictEqual(
expect.objectContaining({
autoRegister: false,
defaultRole: "1",
ssoLockedRoles: ["1","2"]
defaultRole: '1',
ssoLockedRoles: ['1', '2'],
})
);
expect(result.current[0].modifiedData).toStrictEqual(
expect.objectContaining({
autoRegister: false,
defaultRole: "1",
ssoLockedRoles: ["1","2"]
defaultRole: '1',
ssoLockedRoles: ['1', '2'],
})
);
@ -89,7 +92,7 @@ describe('useSettingsForm', () => {
});
test('submit new providers options with duplications', async () => {
const ssoLockedRolesWithDuplications = [ '1', '2', '2', '3' ];
const ssoLockedRolesWithDuplications = ['1', '2', '2', '3'];
server.use(
rest.get('*/providers/options', (req, res, ctx) =>
res.once(
@ -97,17 +100,21 @@ describe('useSettingsForm', () => {
ctx.json({
data: {
autoRegister: false,
defaultRole: "1",
ssoLockedRoles: ssoLockedRolesWithDuplications
}
defaultRole: '1',
ssoLockedRoles: ssoLockedRolesWithDuplications,
},
})
)
)
)
);
const cbSucc = jest.fn();
const { result } = setup('/admin/providers/options', mockSchema, cbSucc, ['autoRegister', 'defaultRole', 'ssoLockedRoles'] );
const { result } = setup('/admin/providers/options', mockSchema, cbSucc, [
'autoRegister',
'defaultRole',
'ssoLockedRoles',
]);
await waitFor(() => expect(result.current[0].isLoading).toBe(false));
// call the handleSubmit handler to see if the data provided in modified data are cleaned without duplicates in the ssoLockedRoles list
const e = { preventDefault: jest.fn() };
@ -115,6 +122,8 @@ describe('useSettingsForm', () => {
await result.current[2].handleSubmit(e);
});
expect(result.current[0].modifiedData.ssoLockedRoles.length).not.toBe(ssoLockedRolesWithDuplications.length);
expect(result.current[0].modifiedData.ssoLockedRoles.length).not.toBe(
ssoLockedRolesWithDuplications.length
);
});
});

View File

@ -1,14 +1,6 @@
import React from "react";
import React from 'react';
import PropTypes from 'prop-types';
import {
Typography,
Box,
Grid,
GridItem,
Flex,
Select,
Option
} from '@strapi/design-system';
import { Typography, Box, Grid, GridItem, Flex, Select, Option } from '@strapi/design-system';
import { useIntl } from 'react-intl';
import upperFirst from 'lodash/upperFirst';
@ -75,8 +67,7 @@ const Preferences = ({ onChange, values, localeNames, allApplicationThemes }) =>
})}
hint={formatMessage({
id: 'Settings.profile.form.section.experience.interfaceLanguage.hint',
defaultMessage:
'This will only display your own interface in the chosen language.',
defaultMessage: 'This will only display your own interface in the chosen language.',
})}
onClear={() => {
onChange({
@ -94,13 +85,11 @@ const Preferences = ({ onChange, values, localeNames, allApplicationThemes }) =>
});
}}
>
{
Object.entries(localeNames).map(([ language, langName ]) => (
{Object.entries(localeNames).map(([language, langName]) => (
<Option value={language} key={language}>
{ langName }
{langName}
</Option>
))
}
))}
</Select>
</GridItem>
<GridItem s={12} col={6}>
@ -146,7 +135,7 @@ const Preferences = ({ onChange, values, localeNames, allApplicationThemes }) =>
</Flex>
</Box>
);
}
};
Preferences.propTypes = {
allApplicationThemes: PropTypes.object,

View File

@ -1,20 +1,10 @@
import React from "react";
import React from 'react';
import PropTypes from 'prop-types';
import { GenericInput } from '@strapi/helper-plugin';
import {
Typography,
Box,
Grid,
GridItem,
Flex,
} from '@strapi/design-system';
import { Typography, Box, Grid, GridItem, Flex } from '@strapi/design-system';
import { useIntl } from 'react-intl';
const UserInfo = ({
errors,
onChange,
values
}) => {
const UserInfo = ({ errors, onChange, values }) => {
const { formatMessage } = useIntl();
return (
@ -89,8 +79,8 @@ const UserInfo = ({
</Grid>
</Flex>
</Box>
)
}
);
};
UserInfo.propTypes = {
errors: PropTypes.shape({
@ -115,7 +105,7 @@ UserInfo.defaultProps = {
firstname: '',
lastname: '',
username: '',
email: ''
email: '',
},
};

View File

@ -6,9 +6,11 @@ const schema = yup.object().shape({
defaultRole: yup.mixed().when('autoRegister', (value, initSchema) => {
return value ? initSchema.required(translatedErrors.required) : initSchema.nullable();
}),
ssoLockedRoles: yup.array().of(yup.mixed().when('ssoLockedRoles', (value, initSchema) => {
ssoLockedRoles: yup.array().of(
yup.mixed().when('ssoLockedRoles', (value, initSchema) => {
return value ? initSchema.required(translatedErrors.required) : initSchema.nullable();
})),
})
),
});
export default schema;

View File

@ -10,12 +10,14 @@ const providerOptionsUpdateSchema = yup.object().shape({
.test('is-valid-role', 'You must submit a valid default role', (roleId) => {
return strapi.admin.services.role.exists({ id: roleId });
}),
ssoLockedRoles: yup.array().of(yup
ssoLockedRoles: yup.array().of(
yup
.strapiID()
.required()
.test('is-valid-role', 'You must submit a valid role for the SSO Locked roles', (roleId) => {
return strapi.admin.services.role.exists({ id: roleId });
})),
})
),
});
module.exports = {