aboutsummaryrefslogtreecommitdiff
path: root/src/lib/shared/routine-metrics.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/shared/routine-metrics.test.ts')
-rw-r--r--src/lib/shared/routine-metrics.test.ts48
1 files changed, 5 insertions, 43 deletions
diff --git a/src/lib/shared/routine-metrics.test.ts b/src/lib/shared/routine-metrics.test.ts
index b3b84a2..64b5da9 100644
--- a/src/lib/shared/routine-metrics.test.ts
+++ b/src/lib/shared/routine-metrics.test.ts
@@ -29,13 +29,13 @@ const routine = {
};
describe('computeRoutineState', () => {
- it('is due when never done, even before the due date', () => {
+ it('is due immediately at creation when never done (created_at = due)', () => {
const now = plusDays(created, 3);
const state = computeRoutineState(routine, [], now);
expect(state.status).toBe('due');
- expect(state.overdueDays).toBe(0);
- expect(state.health).toBe(100);
- expect(state.dueAt).toBe(isoPlusDays(CREATED, 7));
+ expect(state.overdueDays).toBe(3);
+ expect(state.health).toBe(79); // 3/7 of a period overdue
+ expect(state.dueAt).toBe(CREATED);
});
it('uses the last completion as reference once done', () => {
@@ -46,43 +46,6 @@ describe('computeRoutineState', () => {
expect(state.status).toBe('ok');
});
- it('is due at exactly the frequency', () => {
- const now = plusDays(created, 7);
- const state = computeRoutineState(routine, [], now);
- expect(state.status).toBe('due');
- expect(state.health).toBe(100);
- });
-
- it('is very urgent (veryLate) when two full periods overdue', () => {
- const now = plusDays(created, 22);
- const state = computeRoutineState(routine, [], now);
- expect(state.status).toBe('veryLate');
- expect(state.overdueDays).toBe(15);
- expect(state.health).toBe(0);
- });
-
- it('is due (not late) when overdue by half a frequency', () => {
- const now = created
- .toZonedDateTimeISO('UTC')
- .add({ days: 10 })
- .toInstant()
- .add({ hours: 12 });
- const state = computeRoutineState(routine, [], now);
- expect(state.status).toBe('due');
- });
-
- it('is late when a full period overdue', () => {
- const now = plusDays(created, 14);
- const state = computeRoutineState(routine, [], now);
- expect(state.status).toBe('late');
- expect(state.health).toBe(50);
- });
-
- it('health of 50 means a full period overdue', () => {
- const now = plusDays(created, 14);
- const state = computeRoutineState(routine, [], now);
- expect(state.health).toBe(50);
- });
it('is due the calendar day after completion for a daily routine', () => {
const daily = { ...routine, frequencyDays: 1 };
const doneAt = '2026-09-07T20:00:00.000Z'; // yesterday evening
@@ -90,7 +53,6 @@ describe('computeRoutineState', () => {
const state = computeRoutineState(daily, [{ routineId: 1, doneAt }], now);
expect(state.status).toBe('due');
});
-
it('a daily done yesterday is late tomorrow, not today', () => {
const daily = { ...routine, frequencyDays: 1 };
const doneAt = '2026-09-07T20:00:00.000Z'; // yesterday evening
@@ -126,7 +88,7 @@ describe('computeHealthSeries', () => {
const at8d = series.find(
(p) => p.at === plusDays(created, 8).epochMilliseconds,
);
- expect(at8d?.health).toBe(93); // 1/7 of a period overdue
+ expect(at8d?.health).toBe(43); // 8/7 of a period overdue
const last = series[series.length - 1];
expect(last.at).toBe(now.epochMilliseconds);
expect(last.health).toBe(0); // more than two full periods overdue