diff --git a/src/components/pages/__tests__/client.tsx b/src/components/pages/__tests__/client.tsx index c129aa02db..aa9649c13f 100644 --- a/src/components/pages/__tests__/client.tsx +++ b/src/components/pages/__tests__/client.tsx @@ -12,7 +12,8 @@ import { mapDispatchToProps, handleAfterClose, handleOnChange, - handleOnCardClick + handleOnCardClick, + onCardClickParams } from '../client' import { addQuery } from '@/utils/client-url-params' import { AppSummaryModel } from '@reapit/foundations-ts-definitions' @@ -216,10 +217,18 @@ describe('Client', () => { describe('handleOnCardClick', () => { it('should run correctly', () => { - const mockProps = { + const mockProps: onCardClickParams = { setVisible: jest.fn(), appDetail: { - appDetailData: appsDataStub.data, + authentication: { + loading: false, + code: '200' + }, + error: false, + loading: false, + appDetailData: { + data: appsDataStub.data.data![0] + }, isStale: true }, setStateViewBrowse: jest.fn(), diff --git a/src/components/pages/client.tsx b/src/components/pages/client.tsx index 045ccd9212..0a9d1eeba2 100644 --- a/src/components/pages/client.tsx +++ b/src/components/pages/client.tsx @@ -38,14 +38,27 @@ export const handleAfterClose = ({ setVisible }) => () => setVisible(false) export const handleOnChange = history => (page: number) => { history.push(addQuery({ page })) } -export const handleOnCardClick = ({ setVisible, setStateViewBrowse, appDetail, fetchAppDetail, clientId }) => ( - app: AppSummaryModel -) => { + +export interface onCardClickParams { + setVisible: (isVisible: boolean) => void + setStateViewBrowse: () => void + appDetail: AppDetailState + fetchAppDetail: (id: string, client: string) => void + clientId: string +} + +export const handleOnCardClick = ({ + setVisible, + setStateViewBrowse, + appDetail, + fetchAppDetail, + clientId +}: onCardClickParams) => (app: AppSummaryModel) => { setVisible(true) setStateViewBrowse() const isCacheEmpty = !appDetail.appDetailData const isCacheStale = appDetail.isStale - const currentAppIdNotMatchWithCachedAppId = appDetail.appDetailData.data.id !== app.id + const currentAppIdNotMatchWithCachedAppId = appDetail.appDetailData?.data?.id !== app.id if (app.id && (isCacheEmpty || isCacheStale || currentAppIdNotMatchWithCachedAppId)) { fetchAppDetail(app.id, clientId)