diff --git a/source/frontend/src/AppRouter.test.tsx b/source/frontend/src/AppRouter.test.tsx index 0870ac0bf3..762156e637 100644 --- a/source/frontend/src/AppRouter.test.tsx +++ b/source/frontend/src/AppRouter.test.tsx @@ -11,7 +11,7 @@ import { lookupCodesSlice } from './store/slices/lookupCodes'; import { networkSlice } from './store/slices/network/networkSlice'; import { tenantsSlice } from './store/slices/tenants'; import { defaultTenant } from './tenants/config/defaultTenant'; -import { mockKeycloak, render, RenderOptions, screen } from './utils/test-utils'; +import { cleanup, mockKeycloak, render, RenderOptions, screen } from './utils/test-utils'; const history = createMemoryHistory(); const storeState = { @@ -61,11 +61,11 @@ jest.mock('@/store/slices/tenants/useTenants', () => ({ jest.mock('./hooks/pims-api/useApiUsers'); (useApiUsers as jest.MockedFunction).mockReturnValue({ activateUser: jest.fn(), - exportUsers: jest.fn(), getUser: jest.fn().mockResolvedValue(getUserMock()), getUserInfo: jest.fn().mockResolvedValue(getUserMock()), getUsersPaged: jest.fn(), putUser: jest.fn(), + exportUsers: jest.fn(), }); describe('PSP routing', () => { @@ -86,7 +86,7 @@ describe('PSP routing', () => { }; afterEach(() => { - // cleanup(); + cleanup(); jest.clearAllMocks(); }); diff --git a/source/frontend/src/components/common/form/Select.test.tsx b/source/frontend/src/components/common/form/Select.test.tsx index 541042c1af..a336fc011d 100644 --- a/source/frontend/src/components/common/form/Select.test.tsx +++ b/source/frontend/src/components/common/form/Select.test.tsx @@ -1,73 +1,154 @@ -// import React from 'react'; - -// import { PropertyClassificationTypes } from '@/constants/propertyClassificationTypes'; -// import { getIn, useFormikContext } from 'formik'; -// import renderer from 'react-test-renderer'; - -// import { FastSelect } from './FastSelect'; - -// jest.mock('formik'); - -// (useFormikContext as jest.Mock).mockReturnValue({ -// values: { -// classificationId: PropertyClassificationTypes.CoreOperational, -// classification: 'zero', -// }, -// registerField: jest.fn(), -// unregisterField: jest.fn(), -// }); -// (getIn as jest.Mock).mockReturnValue(0); - -// const options = [ -// { -// label: 'zero', -// value: '0', -// selected: true, -// }, -// { -// label: 'one', -// value: '1', -// selected: true, -// }, -// { -// label: 'two', -// value: '2', -// selected: true, -// }, -// ]; - -describe('LimitedSelect - Enzyme Tests - NEEDS REFACTORING', () => { - it('should be implemented', async () => {}); - // it('limited fast select renders correctly', () => { - // const context = useFormikContext(); - // const tree = renderer - // .create( - // , - // ) - // .toJSON(); - // expect(tree).toMatchSnapshot(); - // }); - // - // it('only renders the limited options + the previous value', async () => { - // const context = useFormikContext(); - // const component = mount( - // , - // ); - // expect(component.find('option')).toHaveLength(2); - // }); -}); +import { Formik, FormikProps } from 'formik'; +import React from 'react'; + +import { act, fireEvent, render, RenderOptions, screen, userEvent } from '@/utils/test-utils'; + +import { Select, SelectOption, SelectProps } from './Select'; + +const countries: SelectOption[] = [ + { label: 'Austria', value: 'AT' }, + { label: 'United States', value: 'US' }, + { label: 'Ireland', value: 'IE' }, +]; + +const onSubmit = jest.fn(); + +describe('Select component', () => { + const setup = ( + options: RenderOptions & { props?: Partial } & { + initialValues?: { countryId: string }; + } = {}, + ) => { + const formikRef = React.createRef>(); + const utils = render( + + + + + + + + + +`;