Skip to content

Commit

Permalink
Merge pull request #2700 from bcgov/NDT-41-Bug-Can-t-edit-open-intake…
Browse files Browse the repository at this point in the history
…-end-date-time

fix: intake edit and delete with time machine
  • Loading branch information
RRanath authored Dec 11, 2023
2 parents fa22121 + 86a4d23 commit faf1428
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/components/Admin/Intake.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConnectionHandler, graphql, useFragment } from 'react-relay';
import styled from 'styled-components';
import cookie from 'js-cookie';
import { DateTime } from 'luxon';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faClose, faPen } from '@fortawesome/free-solid-svg-icons';
Expand Down Expand Up @@ -135,7 +136,11 @@ const Intake: React.FC<IntakeProps> = ({
DateTime.DATETIME_FULL
);

const currentDateTime = DateTime.now();
const mockedDateCookie = cookie.get('mocks.mocked_date');
const currentDateTime = mockedDateCookie
? DateTime.fromJSDate(new Date(Date.parse(mockedDateCookie)))
: DateTime.now();

const startDateTime = DateTime.fromISO(openTimestamp);
const endDateTime = DateTime.fromISO(closeTimestamp);
const isAllowedDelete = currentDateTime <= startDateTime;
Expand Down
82 changes: 82 additions & 0 deletions app/tests/pages/analyst/admin/application-intakes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ApplicationIntakes from 'pages/analyst/admin/application-intakes';
import compiledApplicationIntakesQuery, {
applicationIntakesQuery,
} from '__generated__/applicationIntakesQuery.graphql';
import cookie from 'js-cookie';
import PageTestingHelper from '../../../utils/pageTestingHelper';
import { checkTabStyles, checkRouteAuthorization } from './shared-admin-tests';

Expand Down Expand Up @@ -105,8 +106,39 @@ const mockEditQueryPayload = {
},
};

const mockTimeMachineQueryPayload = {
Query() {
return {
allIntakes: {
edges: [
{
node: {
ccbcIntakeNumber: 1,
closeTimestamp: '2022-01-15T23:00:00-08:00',
description: 'Intake 3 description',
openTimestamp: '2021-01-15T00:00:00-08:00',
rowId: 1,
},
},
],
},
openIntake: {
ccbcIntakeNumber: 2,
},
session: {
sub: '4e0ac88c-bf05-49ac-948f-7fd53c7a9fd6',
authRole: 'ccbc_admin',
},
};
},
};

jest.mock('@bcgov-cas/sso-express/dist/helpers');

jest.mock('js-cookie', () => ({
get: jest.fn(),
}));

const pageTestingHelper = new PageTestingHelper<applicationIntakesQuery>({
pageComponent: ApplicationIntakes,
compiledQuery: compiledApplicationIntakesQuery,
Expand Down Expand Up @@ -298,6 +330,32 @@ describe('The Application intakes admin page', () => {
});
});

it('should handle delete intake correctly when time machine is set', async () => {
pageTestingHelper.loadQuery(mockTimeMachineQueryPayload);
cookie.get.mockReturnValue('2021-01-01');
pageTestingHelper.renderPage();

const deleteButton = screen.getByRole('button', {
name: 'Delete',
});

await act(async () => {
fireEvent.click(deleteButton);
});

pageTestingHelper.expectMutationToBeCalled('archiveIntakeMutation', {
input: {
intakeNumber: 1,
},
});

await act(async () => {
pageTestingHelper.environment.mock.resolveMostRecentOperation({
data: {},
});
});
});

it('should edit an intake', async () => {
pageTestingHelper.loadQuery(mockEditQueryPayload);
pageTestingHelper.renderPage();
Expand Down Expand Up @@ -367,6 +425,30 @@ describe('The Application intakes admin page', () => {
});
});

it('should handle edit intake correctly when time machine is set', async () => {
pageTestingHelper.loadQuery(mockTimeMachineQueryPayload);
cookie.get.mockReturnValue('2021-03-01');
pageTestingHelper.renderPage();

const editButton = screen.getByTestId('edit-intake');

await act(async () => {
fireEvent.click(editButton);
});

const startDateInput = screen.getAllByPlaceholderText(
'YYYY-MM-DD hh:mm aa'
)[0];
const endDateInput = screen.getAllByPlaceholderText(
'YYYY-MM-DD hh:mm aa'
)[1];
const descriptionInput = screen.getByTestId('root_description');

expect(startDateInput).toBeVisible();
expect(endDateInput).toBeVisible();
expect(descriptionInput).toBeVisible();
});

it('should not overlap the next intake when editing an intake', async () => {
pageTestingHelper.loadQuery(mockEditQueryPayload);
pageTestingHelper.renderPage();
Expand Down

0 comments on commit faf1428

Please sign in to comment.