diff --git a/src/pages/ExamsPage/components/AllowanceListActions.test.jsx b/src/pages/ExamsPage/components/AllowanceListActions.test.jsx index a3e3577..13df4c4 100644 --- a/src/pages/ExamsPage/components/AllowanceListActions.test.jsx +++ b/src/pages/ExamsPage/components/AllowanceListActions.test.jsx @@ -1,10 +1,9 @@ -import { render, screen } from '@testing-library/react'; +import { fireEvent, render, screen } from '@testing-library/react'; import { useDeleteAllowance, useEditAllowance } from '../hooks'; import AllowanceListActions from './AllowanceListActions'; import * as reduxHooks from '../../../data/redux/hooks'; -// const mockEditAllowance = jest.fn(); const mockClearRequest = jest.fn(); const mockRequestError = jest.fn(); @@ -16,6 +15,7 @@ const mockAllowance = { allowanceType: 'Minutes', extraTimeMins: 45, }; +const newExtraTimeMins = 60; jest.mock('../hooks', () => ({ useDeleteAllowance: jest.fn(), @@ -33,7 +33,6 @@ jest.unmock('react'); describe('AllowanceListActions', () => { beforeEach(() => { jest.resetAllMocks(); - // hooks.useEditAllowance().mockReturnValue(mockEditAllowance); reduxHooks.useRequestError.mockReturnValue(mockRequestError); reduxHooks.useClearRequest.mockReturnValue(mockClearRequest); }); @@ -50,7 +49,6 @@ describe('AllowanceListActions', () => { expect(screen.getByText('Are you sure you want to delete this allowance?')).toBeInTheDocument(); }); - // todo: figure out why this isn't working it('should open the edit modal when the edit icon is clicked', () => { render(); screen.getByTestId('edit-allowance-icon').click(); @@ -87,17 +85,17 @@ describe('AllowanceListActions', () => { }); describe('edit modal', () => { - // todo: figure out why this fails it('should edit the allowance when the save button is clicked', () => { const mockEditAllowance = jest.fn(); useEditAllowance.mockReturnValue(mockEditAllowance); render(); screen.getByTestId('edit-allowance-icon').click(); + fireEvent.change(screen.getByTestId('extra-time-mins'), { target: { value: newExtraTimeMins } }); screen.getByText('Save').click(); const expectedData = { username: mockAllowance.username, exam_id: mockAllowance.examId, - extra_time_mins: mockAllowance.extraTimeMins, + extra_time_mins: newExtraTimeMins, }; expect(mockEditAllowance).toHaveBeenCalledWith(mockAllowance.id, expectedData, expect.any(Function)); }); @@ -118,14 +116,14 @@ describe('AllowanceListActions', () => { expect(screen.queryByTestId('edit-allowance-header')).not.toBeInTheDocument(); }); - // todo: figure out why this fails it('should close the modal when the edit is successful', () => { const mockEditAllowance = jest.fn(); useEditAllowance.mockReturnValue(mockEditAllowance); render(); screen.getByTestId('edit-allowance-icon').click(); + fireEvent.change(screen.getByTestId('extra-time-mins'), { target: { value: newExtraTimeMins } }); screen.getByText('Save').click(); - // expect(mockEditAllowance.mock.calls).toBe(1); + mockEditAllowance.mock.calls[0][2](); expect(screen.queryByTestId('edit-allowance-header')).not.toBeInTheDocument(); }); });