diff --git a/src/discord/daily.test.ts b/src/discord/daily.test.ts index 7289c2d..b11dd3e 100644 --- a/src/discord/daily.test.ts +++ b/src/discord/daily.test.ts @@ -154,9 +154,13 @@ test('native layouts stay within Discord limits and use existing habit colors', await f.json('/habits', 'POST', { name: 'Routine', method: 'tasks', tasks: Array.from({ length: 20 }, (_, n) => ({ name: `Step ${n}` })) }, 201); const d = await f.run(click(control(t, 'Details'))); expect(components(d.data.components).length).toBeLessThanOrEqual(40); - const list = await f.run({ data: { name: 'today' } }); - const last = await f.run(click(control(await f.run(click(control(list, 'Next'))), 'Next'))); - const checklist = await f.run(click(habitControl(last, 'Routine', 'Open checklist'))); + // Equal creation timestamps are ordered by random IDs, not insertion order. + let list = await f.run({ data: { name: 'today' } }); + while (!messageText(list).includes('**Routine**') && components(list.data.components).some(c => c.label === 'Next')) { + list = await f.run(click(control(list, 'Next'))); + } + expect(messageText(list)).toContain('**Routine**'); + const checklist = await f.run(click(habitControl(list, 'Routine', 'Open checklist'))); expect(components(checklist.data.components).length).toBeLessThanOrEqual(40); expect(messageText(checklist)).toContain('Page 1 of 3'); }); diff --git a/src/discord/test-fixture.ts b/src/discord/test-fixture.ts index cf45d19..518699c 100644 --- a/src/discord/test-fixture.ts +++ b/src/discord/test-fixture.ts @@ -44,5 +44,6 @@ export function messageText(reply: any): string { } export function habitControl(reply: any, name: string, label = 'Details'): string { const item = reply.data.components.find((item: any) => item.type === 17 && messageText({ data: { components: [item] } }).includes(`**${name}**`)); + if (!item) throw new Error(`Missing habit ${name}: ${JSON.stringify(reply)}`); return control({ data: { components: [item] } }, label); }