Skip to content

Commit

Permalink
[NOREF] - Fixed task list last updated (#657)
Browse files Browse the repository at this point in the history
* Added filter for null check before comparing time

* Added unit test

* Reduce requires array with length, added check
  • Loading branch information
patrickseguraoddball authored Aug 2, 2023
1 parent 75cc488 commit 42b080d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
26 changes: 25 additions & 1 deletion src/views/ModelPlan/TaskList/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import GetModelPlanQuery from 'queries/GetModelPlan';
import { GetModelPlan_modelPlan as GetModelPlanTypes } from 'queries/types/GetModelPlan';
import { ModelStatus } from 'types/graphql-global-types';

import TaskList from './index';
import TaskList, { getLatestModifiedDate } from './index';

describe('The Model Plan Task List', () => {
const mockStore = configureMockStore();
Expand Down Expand Up @@ -117,6 +117,30 @@ describe('The Model Plan Task List', () => {
).toBeInTheDocument();
});

it('gets the last modified date of it solutions', async () => {
const expectedDate: string = '2023-05-21T13:38:11.998962Z';

const lastUpdated = getLatestModifiedDate([
{
__typename: 'OperationalNeed',
id: '724c19ce-0309-4f04-a4fe-d9ed345dbec',
modifiedDts: null
},
{
__typename: 'OperationalNeed',
id: '864c19ce-0309-4f04-a4fe-d9ed844edbec',
modifiedDts: '2023-04-01T13:38:11.998962Z'
},
{
__typename: 'OperationalNeed',
id: '134c19ce-0309-4f04-a4fe-d9ed844edbec',
modifiedDts: '2023-05-21T13:38:11.998962Z'
}
]);

expect(lastUpdated).toEqual(expectedDate);
});

it('displays the model plan task list steps', async () => {
modelPlan.modelName = '';
render(
Expand Down
25 changes: 14 additions & 11 deletions src/views/ModelPlan/TaskList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ const taskListSectionMap: TaskListSectionMapType = {
prepareForClearance: TaskListSection.PREPARE_FOR_CLEARANCE
};

export const getLatestModifiedDate = (
operationalNeedsArray: OperationalNeedsType[]
) => {
const updatedNeeds = operationalNeedsArray.filter(need => need.modifiedDts);

if (updatedNeeds.length !== 0) {
return updatedNeeds.reduce((a, b) =>
a.modifiedDts! > b.modifiedDts! ? a : b
).modifiedDts;
}

return null;
};

const TaskList = () => {
const { t } = useTranslation('modelPlanTaskList');
const { t: h } = useTranslation('draftModelPlan');
Expand Down Expand Up @@ -152,17 +166,6 @@ const TaskList = () => {
return inProgress ? TaskStatus.IN_PROGRESS : TaskStatus.READY;
};

const getLatestModifiedDate = (
operationalNeedsArray: OperationalNeedsType[]
) => {
if (operationalNeedsArray.length !== 0) {
return operationalNeedsArray.reduce((a, b) =>
a.modifiedDts! > b.modifiedDts! ? a : b
).modifiedDts;
}
return null;
};

const itSolutions: ITSolutionsType = {
modifiedDts: getLatestModifiedDate(operationalNeeds),
status: getITSolutionsStatus(operationalNeeds)
Expand Down

0 comments on commit 42b080d

Please sign in to comment.