From 42b080db1ec9f2768871aea848a8ff11bfbb4b3e Mon Sep 17 00:00:00 2001 From: Patrick Segura <95709965+patrickseguraoddball@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:42:44 -0400 Subject: [PATCH] [NOREF] - Fixed task list last updated (#657) * Added filter for null check before comparing time * Added unit test * Reduce requires array with length, added check --- src/views/ModelPlan/TaskList/index.test.tsx | 26 ++++++++++++++++++++- src/views/ModelPlan/TaskList/index.tsx | 25 +++++++++++--------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/views/ModelPlan/TaskList/index.test.tsx b/src/views/ModelPlan/TaskList/index.test.tsx index 485b273313..f7adaae74f 100644 --- a/src/views/ModelPlan/TaskList/index.test.tsx +++ b/src/views/ModelPlan/TaskList/index.test.tsx @@ -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(); @@ -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( diff --git a/src/views/ModelPlan/TaskList/index.tsx b/src/views/ModelPlan/TaskList/index.tsx index b9585efbf3..178c8abba1 100644 --- a/src/views/ModelPlan/TaskList/index.tsx +++ b/src/views/ModelPlan/TaskList/index.tsx @@ -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'); @@ -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)