Skip to content

Commit

Permalink
test: new schedule generator
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoh86 committed Nov 30, 2024
1 parent 6da2b2c commit f1bf1b0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/lib/schedule.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect, test } from "vitest";
import dayjs from "dayjs";
import { generate } from "./schedule.ts";

const LIMIT_TO_PREVENT_INIFINITE_LOOPS = 1000;

test("generates first date closed to the start", () => {
const today = dayjs();
for (const date of generate({ start: today })) {
expect(today <= date).toBe(true);
expect(
date < today.add(3, "d"),
`expect ${date.format("YYYY-MM-DD")} is less than three days later (${today.add(3, "d").format("YYYY-MM-DD")})`,
).toBe(true);
break;
}
});

test("generates days only on Monday, Wednesday or Friday", () => {
let count = 0; // to prevent infinite loops
for (const date of generate({})) {
expect([1, 3, 5]).contain(date.day());
if (count++ > LIMIT_TO_PREVENT_INIFINITE_LOOPS) {
break;
}
}
});

0 comments on commit f1bf1b0

Please sign in to comment.