Skip to content

Commit

Permalink
test: new schedule generator
Browse files Browse the repository at this point in the history
kyoh86 committed Nov 30, 2024

Verified

This commit was signed with the committer’s verified signature.
bkioshn bkioshn
1 parent 8ebe797 commit 9e4f05a
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 9e4f05a

Please sign in to comment.