mirror of
https://github.com/strapi/strapi.git
synced 2025-08-10 09:47:46 +00:00
refactor the useSettingsForm unit test
This commit is contained in:
parent
536b2ccd4b
commit
b58307c990
@ -90,7 +90,7 @@ const useSettingsForm = (endPoint, schema, cbSuccess, fieldsToPick) => {
|
|||||||
type: 'ON_SUBMIT',
|
type: 'ON_SUBMIT',
|
||||||
});
|
});
|
||||||
const cleanedData = omit(modifiedData, ['confirmPassword', 'registrationToken']);
|
const cleanedData = omit(modifiedData, ['confirmPassword', 'registrationToken']);
|
||||||
|
|
||||||
if (cleanedData.roles) {
|
if (cleanedData.roles) {
|
||||||
cleanedData.roles = cleanedData.roles.map((role) => role.id);
|
cleanedData.roles = cleanedData.roles.map((role) => role.id);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import { setupServer } from 'msw/node';
|
|||||||
import { rest } from 'msw';
|
import { rest } from 'msw';
|
||||||
import { renderHook, act } from '@testing-library/react-hooks';
|
import { renderHook, act } from '@testing-library/react-hooks';
|
||||||
import { IntlProvider } from 'react-intl';
|
import { IntlProvider } from 'react-intl';
|
||||||
import omit from 'lodash/omit';
|
|
||||||
import useSettingsForm from '../index';
|
import useSettingsForm from '../index';
|
||||||
|
|
||||||
const toggleNotification = jest.fn();
|
const toggleNotification = jest.fn();
|
||||||
@ -19,7 +18,7 @@ jest.mock('../../../utils', () => ({
|
|||||||
checkFormValidity: () => (null),
|
checkFormValidity: () => (null),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('lodash/omit');
|
// jest.mock('lodash/omit');
|
||||||
|
|
||||||
const handlers = [
|
const handlers = [
|
||||||
rest.put('*/providers/options', (req, res, ctx) =>
|
rest.put('*/providers/options', (req, res, ctx) =>
|
||||||
@ -105,13 +104,23 @@ describe('useSettingsForm', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('submit new providers options with duplications', async () => {
|
test('submit new providers options with duplications', async () => {
|
||||||
const cbSucc = jest.fn();
|
|
||||||
const ssoLockedRolesWithDuplications = [ '1', '2', '2', '3' ];
|
const ssoLockedRolesWithDuplications = [ '1', '2', '2', '3' ];
|
||||||
omit.mockReturnValueOnce({
|
server.use(
|
||||||
autoRegister: false,
|
rest.get('*/providers/options', (req, res, ctx) =>
|
||||||
defaultRole: '1',
|
res.once(
|
||||||
ssoLockedRoles: ssoLockedRolesWithDuplications
|
ctx.status(200),
|
||||||
});
|
ctx.json({
|
||||||
|
data: {
|
||||||
|
autoRegister: false,
|
||||||
|
defaultRole: "1",
|
||||||
|
ssoLockedRoles: ssoLockedRolesWithDuplications
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const cbSucc = jest.fn();
|
||||||
|
|
||||||
const { result, waitFor } = setup('/admin/providers/options', {}, cbSucc, ['autoRegister', 'defaultRole', 'ssoLockedRoles'] );
|
const { result, waitFor } = setup('/admin/providers/options', {}, cbSucc, ['autoRegister', 'defaultRole', 'ssoLockedRoles'] );
|
||||||
await waitFor(() => expect(result.current[0].isLoading).toBe(false));
|
await waitFor(() => expect(result.current[0].isLoading).toBe(false));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user