Skip to content

Commit

Permalink
test(date picker): fix date manipulation in date picker tests (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispymm authored Dec 2, 2024
1 parent 29aa618 commit e382d89
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/moj/components/date-picker/date-picker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,13 @@ describe("Date picker with defaults", () => {
});

test("can navigate back in time", async () => {
const today = new Date();
const currentMonthName = today.toLocaleString("default", { month: "long" });
const currentYear = today.getFullYear();
const currentMonth = today.getMonth();
const previousMonthName = new Date(
today.setMonth(currentMonth - 1),
).toLocaleString("default", { month: "long" });
const previousYear = currentYear - 1;
const today = dayjs();
const previousMonth = dayjs().subtract(1, 'month')
const previousYear = previousMonth.subtract(1, 'year')

const currentTitle = `${currentMonthName} ${currentYear}`;
const previousMonthTitle = `${previousMonthName} ${currentYear}`;
const previousYearTitle = `${previousMonthName} ${previousYear}`;
const currentTitle = `${today.format('MMMM YYYY')}`;
const previousMonthTitle = `${previousMonth.format('MMMM YYYY')}`;
const previousYearTitle = `${previousYear.format('MMMM YYYY')}`;

await user.click(calendarButton);
let prevMonthButton = getByText(dialog, "Previous month");
Expand All @@ -224,18 +219,13 @@ describe("Date picker with defaults", () => {
});

test("can navigate forward in time", async () => {
const today = new Date();
const currentMonthName = today.toLocaleString("default", { month: "long" });
const currentYear = today.getFullYear();
const currentMonth = today.getMonth();
const nextMonthName = new Date(
today.setMonth(currentMonth + 1),
).toLocaleString("default", { month: "long" });
const nextYear = currentYear + 1;

const currentTitle = `${currentMonthName} ${currentYear}`;
const nextMonthTitle = `${nextMonthName} ${currentYear}`;
const nextYearTitle = `${nextMonthName} ${nextYear}`;
const today = dayjs();
const nextMonth = dayjs().add(1, 'month')
const nextYear = nextMonth.add(1, 'year')

const currentTitle = `${today.format('MMMM YYYY')}`;
const nextMonthTitle = `${nextMonth.format('MMMM YYYY')}`;
const nextYearTitle = `${nextYear.format('MMMM YYYY')}`;

await user.click(calendarButton);
let nextMonthButton = getByText(dialog, "Next month");
Expand Down

0 comments on commit e382d89

Please sign in to comment.