|
1 | 1 | import { expect, test } from "bun:test" |
2 | 2 | import { selectTip, type Tip } from "./queue" |
3 | 3 |
|
4 | | -const fresh = { current: "", shownAt: 0, dismissed: [], dismissedAt: 0 } |
| 4 | +const hours = 60 * 60 * 1000 |
| 5 | + |
| 6 | +// Installed an hour before time 0, so the first-tip delay has already passed. |
| 7 | +const fresh = { current: "", shownAt: 0, dismissed: [], dismissedAt: 0, firstSeen: -hours } |
5 | 8 |
|
6 | 9 | const first: Tip = { id: "first", title: "tips.browse.title", description: "tips.browse.description" } |
7 | 10 |
|
8 | 11 | const second: Tip = { ...first, id: "second" } |
9 | 12 |
|
10 | 13 | const tips = [first, second] |
11 | 14 |
|
12 | | -const hours = 60 * 60 * 1000 |
| 15 | +test("the first tip waits an hour after the app first ran", () => { |
| 16 | + const installed = { ...fresh, firstSeen: 10 * hours } |
| 17 | + expect(selectTip(tips, installed, 11 * hours - 1)).toBeUndefined() |
| 18 | + expect(selectTip(tips, installed, 11 * hours)).toBe(first) |
| 19 | + expect(selectTip(tips, { ...fresh, firstSeen: 0 }, 5 * hours)).toBeUndefined() |
| 20 | + expect(selectTip(tips, { ...installed, dismissed: [first.id], dismissedAt: 1 }, 25 * hours)).toBe(second) |
| 21 | +}) |
13 | 22 |
|
14 | 23 | test("first eligible tip wins until it is handled or stops being eligible", () => { |
15 | 24 | expect(selectTip(tips, fresh, 1)).toBe(first) |
|
0 commit comments