Skip to content

Commit

Permalink
Test corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
asanchezr committed Nov 18, 2023
1 parent ea08b85 commit c7888b8
Showing 1 changed file with 11 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { mockLookups } from '@/mocks/lookups.mock';
import { Api_FinancialCode } from '@/models/api/FinancialCode';
import { lookupCodesSlice } from '@/store/slices/lookupCodes';
import { systemConstantsSlice } from '@/store/slices/systemConstants/systemConstantsSlice';
import { act, render, RenderOptions, waitFor } from '@/utils/test-utils';
import { act, render, RenderOptions, waitFor, waitForEffects } from '@/utils/test-utils';

import { CompensationRequisitionFormModel } from './models';
import UpdateCompensationRequisitionContainer, {
Expand All @@ -38,28 +38,7 @@ jest.mock('@/hooks/repositories/useAcquisitionProvider', () => ({
getAcquisitionOwners: {
error: undefined,
response: mockAcquisitionFileOwnersResponse(1),
execute: jest.fn().mockReturnValue(mockAcquisitionFileOwnersResponse(1)),
loading: false,
},
getAcquisitionFileSolicitors: {
execute: jest.fn(),
loading: false,
},
getAcquisitionFileRepresentatives: {
execute: jest.fn(),
loading: false,
},
};
},
}));

jest.mock('@/hooks/repositories/useAcquisitionProvider', () => ({
useAcquisitionProvider: () => {
return {
getAcquisitionOwners: {
error: undefined,
response: mockAcquisitionFileOwnersResponse(1),
execute: jest.fn().mockReturnValue(mockAcquisitionFileOwnersResponse(1)),
execute: jest.fn().mockResolvedValue(mockAcquisitionFileOwnersResponse(1)),
loading: false,
},
getAcquisitionFileSolicitors: {
Expand All @@ -85,29 +64,6 @@ jest.mock('@/hooks/repositories/useInterestHolderRepository', () => ({
},
}));

jest.mock('@/hooks/repositories/useFinancialCodeRepository', () => ({
useInterestHolderRepository: () => {
return {
getFinancialActivityCodeTypes: {
execute: jest.fn(),
loading: false,
},
getChartOfAccountsCodeTypes: {
execute: jest.fn(),
loading: false,
},
getYearlyFinancialsCodeTypes: {
execute: jest.fn(),
loading: false,
},
getResponsibilityCodeTypes: {
execute: jest.fn(),
loading: false,
},
};
},
}));

const mockGetApi = {
error: undefined,
response: [],
Expand Down Expand Up @@ -174,12 +130,12 @@ describe('UpdateCompensationRequisition Container component', () => {
jest.clearAllMocks();
});

it('Renders the underlying form', async () => {
it('renders the underlying form', async () => {
const { getByText } = await setup();
expect(getByText(/Content Rendered/)).toBeVisible();
});

it('Calls onSuccess when the compensation is saved successfully', async () => {
it('calls onSuccess when the compensation is saved successfully', async () => {
const mockCompensationUpdate = getMockApiDefaultCompensation();
await setup({
props: { compensation: mockCompensationUpdate },
Expand All @@ -198,7 +154,7 @@ describe('UpdateCompensationRequisition Container component', () => {
expect(onSuccess).toHaveBeenCalled();
});

it('does not call onSucess if the returned value is invalid', async () => {
it('does not call onSuccess if the returned value is invalid', async () => {
const mockCompensationUpdate = getMockApiDefaultCompensation();
mockUpdateCompensation.mockResolvedValue(undefined);

Expand All @@ -222,6 +178,8 @@ describe('UpdateCompensationRequisition Container component', () => {
props: { compensation: mockCompensationUpdate },
});

await waitForEffects();

mockCompensationUpdate.detailedRemarks = 'my update';
mockUpdateCompensation.mockResolvedValue(mockCompensationUpdate);

Expand All @@ -238,15 +196,11 @@ describe('UpdateCompensationRequisition Container component', () => {

updatedCompensationModel.payee.payeeKey = testPayeeOption.value;

setTimeout(async () => {
await act(async () => {
await viewProps?.onSave(updatedCompensationModel);
});
await act(async () => viewProps?.onSave(updatedCompensationModel));

expect(mockUpdateCompensation).toHaveBeenCalledWith(
updatedCompensationModel.toApi([testPayeeOption]),
);
}, 500);
expect(mockUpdateCompensation).toHaveBeenCalledWith(
updatedCompensationModel.toApi([testPayeeOption]),
);
});

it('filters expired financial codes when updating', async () => {
Expand Down

0 comments on commit c7888b8

Please sign in to comment.