Only zero is empty, and the last day is worth reading

This commit is contained in:
2026-08-21 11:57:17 -04:00
parent bbda5cbfe9
commit 74392ccad2
7 changed files with 317 additions and 57 deletions

View File

@@ -108,3 +108,65 @@ describe('what purchasing receives is unchanged', () => {
expect(written[0]).not.toContain('414X Black')
})
})
// --- how long is left ------------------------------------------------------
//
// daysleft used to be int(level / rate), so anything under a full day
// truncated to 0 and the view printed "empty". A cartridge with six hours in it
// still prints, and the row exists to say how long. Only a real zero is empty.
describe('the countdown reads in whatever unit carries meaning', () => {
async function daysCell(daysleft) {
const band = daysleft === null ? 'soon' : daysleft <= 0 ? 'empty' : 'soon'
const base = payload()
base.data.data.cartridges[0].daysleft = daysleft
base.data.data.cartridges[0].band = band
printersApi.supplyForecast.mockResolvedValue(base)
const wrapper = mount(TonerForecast, {
global: { stubs: { 'router-link': { template: '<a><slot /></a>' } } },
})
await flushPromises()
// Only the 'empty' band starts expanded - what is already out is what the
// page opens on. Every band renders a header whether or not it holds
// anything, so the right one has to be picked by its key rather than by
// position; clicking the first would close 'empty' instead.
if (band !== 'empty') {
const head = wrapper.findAll('.band-head')
.find(b => b.find(`.band-count.${band}`).exists())
await head.trigger('click')
await flushPromises()
}
return wrapper.find('tbody .days').text()
}
it('says empty only for an actual zero', async () => {
expect(await daysCell(0)).toBe('empty')
})
it('reads in hours below a day', async () => {
expect(await daysCell(0.25)).toBe('6 hours')
})
it('does not pluralise a single hour', async () => {
expect(await daysCell(1 / 24)).toBe('1 hour')
})
it('reads in minutes below an hour, never as empty', async () => {
const text = await daysCell(0.02)
expect(text).toBe('29 min')
expect(text).not.toBe('empty')
})
it('never rounds a live cartridge down to empty', async () => {
expect(await daysCell(0.0001)).toBe('1 min')
})
it('reads in whole days above a day', async () => {
expect(await daysCell(3.7)).toBe('4 days')
expect(await daysCell(1.2)).toBe('1 day')
})
it('still shows a dash when there is no estimate', async () => {
expect(await daysCell(null)).toBe('-')
})
})