Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: use static base date for timeline tests #5460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions site/src/components/Timeline/Timeline.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
4 changes: 2 additions & 2 deletions site/src/components/Timeline/TimelineDateRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down