Skip to content

Commit

Permalink
Merge pull request #11427 from bbc/support-iso-timestamp-most-read
Browse files Browse the repository at this point in the history
WSTEAMA-1136: Add support for ISO string timestamp in Most Read component
  • Loading branch information
karinathomasbbc authored Mar 27, 2024
2 parents 4500ecc + 6462237 commit d7c2080
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface LastUpdatedProps {
prefix: string;
script: TypographyScript;
service: Services;
timestamp: number;
timestamp: number | string;
timezone: string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/components/MostRead/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ export interface MostReadData {
rank: number;
href: string;
title: string;
timestamp: number;
timestamp: number | string;
}[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const isDataStale = formattedTimestamp => {
};

const isMoreThan60Days = unixTimestamp =>
unixTimestamp < Date.now() - SHOULD_RENDER_LAST_UPDATED_TIME;
new Date(unixTimestamp) < Date.now() - SHOULD_RENDER_LAST_UPDATED_TIME;

export const shouldRenderLastUpdated = lastUpdated =>
lastUpdated && isMoreThan60Days(lastUpdated);
25 changes: 16 additions & 9 deletions src/app/lib/utilities/filterPopularStaleData/isDataStale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ describe('mostReadRecordIsFresh', () => {
});

describe('shouldRenderLastUpdated', () => {
it('should return lastUpdated time if older than 60 days', () => {
expect(shouldRenderLastUpdated(calcTimestampDaysAgo(61))).toEqual(true);
expect(shouldRenderLastUpdated(calcTimestampDaysAgo(100))).toEqual(true);
});

it('should return null if less than 60 days old', () => {
expect(shouldRenderLastUpdated(currentTime)).toEqual(false);
expect(shouldRenderLastUpdated(calcTimestampDaysAgo(59))).toEqual(false);
});
it.each`
timestamp | scenario | shouldRender
${calcTimestampDaysAgo(61).getTime()} | ${'date is 61 days ago and timestamp format is unix'} | ${true}
${new Date(calcTimestampDaysAgo(61)).toISOString()} | ${'date is 61 days ago and timestamp format is ISO'} | ${true}
${calcTimestampDaysAgo(100).getTime()} | ${'date is 100 days ago and timestamp format is unix'} | ${true}
${new Date(calcTimestampDaysAgo(100)).toISOString()} | ${'date is 100 days ago and timestamp format is ISO'} | ${true}
${currentTime.getTime()} | ${'date is now and timestamp format is unix'} | ${false}
${currentTime.toISOString()} | ${'date is now and timestamp format is ISO'} | ${false}
${calcTimestampDaysAgo(59).getTime()} | ${'date is 59 days ago and timestamp format is unix'} | ${false}
${new Date(calcTimestampDaysAgo(59)).toISOString()} | ${'date is 59 days ago and timestamp format is ISO'} | ${false}
`(
'should return $shouldRender for $timestamp because $scenario',
({ timestamp, shouldRender }) => {
expect(shouldRenderLastUpdated(timestamp)).toEqual(shouldRender);
},
);
});

0 comments on commit d7c2080

Please sign in to comment.