fix: use static base date for timeline tests (#5460)

It was returning "yesterday" since today is Sunday ;p
This commit is contained in:
Kyle Carberry
2022-12-18 15:27:09 -06:00
committed by GitHub
parent 88d3496a99
commit d1f8fec1d3
2 changed files with 4 additions and 4 deletions
@@ -2,13 +2,13 @@ import { createDisplayDate } from "./TimelineDateRow"
describe("createDisplayDate", () => {
it("returns correctly for Saturdays", () => {
const now = new Date()
const now = new Date(2020, 1, 7)
const date = new Date(
now.getFullYear(),
now.getMonth(),
// Previous Saturday, from now.
now.getDate() - now.getDay() - 1,
)
expect(createDisplayDate(date)).toEqual("last Saturday")
expect(createDisplayDate(date, now)).toEqual("last Saturday")
})
})
@@ -10,8 +10,8 @@ export interface TimelineDateRow {
// 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 createDisplayDate = (date: Date, base = new Date()): string =>
formatRelative(date, base).split(" at ")[0]
export const TimelineDateRow: FC<TimelineDateRow> = ({ date }) => {
const styles = useStyles()