refactor the useSettingsForm unit test

This commit is contained in:
Simone Taeggi 2023-05-30 14:40:05 +02:00
parent 536b2ccd4b
commit b58307c990
2 changed files with 18 additions and 9 deletions

View File

@ -3,7 +3,6 @@ import { setupServer } from 'msw/node';
import { rest } from 'msw';
import { renderHook, act } from '@testing-library/react-hooks';
import { IntlProvider } from 'react-intl';
import omit from 'lodash/omit';
import useSettingsForm from '../index';
const toggleNotification = jest.fn();
@ -19,7 +18,7 @@ jest.mock('../../../utils', () => ({
checkFormValidity: () => (null),
}));
jest.mock('lodash/omit');
// jest.mock('lodash/omit');
const handlers = [
rest.put('*/providers/options', (req, res, ctx) =>
@ -105,13 +104,23 @@ describe('useSettingsForm', () => {
});
test('submit new providers options with duplications', async () => {
const cbSucc = jest.fn();
const ssoLockedRolesWithDuplications = [ '1', '2', '2', '3' ];
omit.mockReturnValueOnce({
autoRegister: false,
defaultRole: '1',
ssoLockedRoles: ssoLockedRolesWithDuplications
});
server.use(
rest.get('*/providers/options', (req, res, ctx) =>
res.once(
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'] );
await waitFor(() => expect(result.current[0].isLoading).toBe(false));