Fix Discord layout test assumption about habit ordering

This commit is contained in:
syntaxbullet
2026-10-26 20:04:42 +01:00
parent 1a97036112
commit 17b3714861
2 changed files with 8 additions and 3 deletions

View File

@@ -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');
});

View File

@@ -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);
}