From 85945af55e8636410e47adf516d0e6b882b33847 Mon Sep 17 00:00:00 2001 From: Kira Pilot Date: Tue, 6 Dec 2022 16:58:32 -0500 Subject: [PATCH] fixed bug; wrote tests (#5329) --- site/src/components/Timeline/Timeline.test.tsx | 8 ++++++++ site/src/components/Timeline/TimelineDateRow.tsx | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 site/src/components/Timeline/Timeline.test.tsx diff --git a/site/src/components/Timeline/Timeline.test.tsx b/site/src/components/Timeline/Timeline.test.tsx new file mode 100644 index 0000000000..6edf7c8433 --- /dev/null +++ b/site/src/components/Timeline/Timeline.test.tsx @@ -0,0 +1,8 @@ +import { createDisplayDate } from "./TimelineDateRow" + +describe("createDisplayDate", () => { + it("returns correctly for Saturdays", () => { + const date = new Date("Sat Dec 03 2022 00:00:00 GMT-0500") + expect(createDisplayDate(date)).toEqual("last Saturday") + }) +}) diff --git a/site/src/components/Timeline/TimelineDateRow.tsx b/site/src/components/Timeline/TimelineDateRow.tsx index 0ef1c86ce8..abeb1eb5f3 100644 --- a/site/src/components/Timeline/TimelineDateRow.tsx +++ b/site/src/components/Timeline/TimelineDateRow.tsx @@ -8,16 +8,18 @@ export interface TimelineDateRow { date: Date } +// We only want the message related to the date since the time is displayed +// inside of the build row +export const createDisplayDate = (date: Date): string => + formatRelative(date, new Date()).split(" at ")[0] + export const TimelineDateRow: FC = ({ date }) => { const styles = useStyles() - // We only want the message related to the date since the time is displayed - // inside of the build row - const displayDate = formatRelative(date, new Date()).split("at")[0] return ( - {displayDate} + {createDisplayDate(date)} )