Skip to content

Commit

Permalink
bookings countdown: fix one failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
ikusteu committed Mar 20, 2024
1 parent 3c093ce commit 1317491
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { updateLocalDocuments } from "@eisbuk/react-redux-firebase-firestore";
import BookingsCountdownContainer from "../BookingsCountdownContainer";

import { getNewStore } from "@/store/createStore";
import { changeCalendarDate, storeSecretKey } from "@/store/actions/appActions";
import {
changeCalendarDate,
setSystemDate,
storeSecretKey,
} from "@/store/actions/appActions";

import { renderWithRedux } from "@/__testUtils__/wrappers";

Expand All @@ -35,8 +39,6 @@ describe("BookingsCountdown", () => {
test("should open a finalize bookings modal on 'Finalize' button click", () => {
// Set up test state so that the second deadline is shown
const testDate = DateTime.fromISO("2022-01-01");
// In order to keep tests consistent we need to also mock the `Date.now`
vi.spyOn(Date, "now").mockReturnValue(testDate.toMillis());
const month = testDate;
const extendedDate = testDate.plus({ days: 2 }).toISODate();
const store = getNewStore();
Expand All @@ -61,6 +63,8 @@ describe("BookingsCountdown", () => {
);
store.dispatch(changeCalendarDate(month));
store.dispatch(storeSecretKey(saul.secretKey));
// Instead of mocking Date.now, we're passing the test date (as system date) directly
store.dispatch(setSystemDate(testDate));
// With test state set up, 'finalize' button should be in the screen for
// provided 'month'
renderWithRedux(<BookingsCountdownContainer />, store);
Expand Down

0 comments on commit 1317491

Please sign in to comment.