diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-18 18:20:27 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-18 18:20:27 +0200 |
| commit | 37cabe2fea2f86d481516aae6ddaeb14bac2e64f (patch) | |
| tree | 1249429fa55c501f5b6fa74823ce6eba8130ea88 /test/test_data.lua | |
| parent | 46d5607764fb29ae5dbbe001519571f934379917 (diff) | |
| download | conky-theme-udt-37cabe2fea2f86d481516aae6ddaeb14bac2e64f.tar.gz conky-theme-udt-37cabe2fea2f86d481516aae6ddaeb14bac2e64f.zip | |
feat: add a breaktimer card
Replaces the Waybar module that used to show breaktimer.sh with a card
on the dashboard. The card's big value is the phase countdown, coloured
by phase with the same language the Waybar module used, and two rows
name the phase and what the countdown leads to.
Data comes from bin/breaktimer-sample.sh, run by conky at execi 5, which
reads the daemon's runtime files into a cache. The sampler owns the
kill -0 liveness check, because conky's Lua cannot run a process and a
dead daemon must read as 'fermo' rather than a stale 'running'.
Drops outside the work-hours window freeze the countdown while the phase
stays 'working'. The sampler detects this from the remain file's age and
the card reads it as 'outside working hours', which also covers a hung
daemon. The phase words and colour roles live in data.breaktimer_parse
so they are unit-tested; the card only draws the result.
Diffstat (limited to 'test/test_data.lua')
| -rw-r--r-- | test/test_data.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/test_data.lua b/test/test_data.lua index 00616d6..65f92e1 100644 --- a/test/test_data.lua +++ b/test/test_data.lua @@ -383,4 +383,66 @@ assert(ndays == 30 and first == 2, 'september 2026, got ' .. ndays .. '/' .. fir assert((data.month_shape(2024, 2)) == 29, 'leap february has 29 days') assert((data.month_shape(2026, 12)) == 31, 'december rolls over correctly') +-- === breaktimer =========================================================== +-- The phase-to-word and phase-to-colour decisions live in breaktimer_parse so +-- they can be checked here; the card only draws the result. +local bt = data.breaktimer_parse(read('test/fixtures/breaktimer_cache')) +assert(bt, 'breaktimer cache parses') +assert(bt.countdown == '24:31', 'countdown, got ' .. tostring(bt.countdown)) +assert(bt.phase_label == 'working', 'phase label, got ' .. tostring(bt.phase_label)) +assert(bt.next == 'pausa', 'next during work is a break, got ' .. tostring(bt.next)) +assert(bt.role == 'ok', 'working is ok, got ' .. tostring(bt.role)) + +-- Every phase has its own word and colour role. Build caches rather than files: +-- the sampler's output is six plain lines and the parse is the seam that +-- matters. +local function bt_cache(fields) + local out = { 'generated 1', 'running ' .. (fields.running or 'yes'), + 'state ' .. (fields.state or 'running'), + 'phase ' .. (fields.phase or 'working'), + 'remain ' .. (fields.remain or 60), + 'frozen ' .. (fields.frozen or 'no') } + return table.concat(out, '\n') .. '\n' +end + +local b + +b = data.breaktimer_parse(bt_cache({ phase = 'breaking', remain = 125 })) +assert(b.phase_label == 'micro-pausa' and b.role == 'heading' and b.next == 'lavoro', + 'micro-pause: ' .. b.phase_label .. '/' .. b.role .. '/' .. b.next) +assert(b.countdown == '2:05', 'micro-pause countdown, got ' .. b.countdown) + +b = data.breaktimer_parse(bt_cache({ phase = 'longbreak', remain = 600 })) +assert(b.phase_label == 'pausa lunga' and b.role == 'highlight' and b.next == 'lavoro', + 'long pause: ' .. b.phase_label .. '/' .. b.role) + +-- Paused freezes the number, but the phase underneath still decides what the +-- countdown leads to. +b = data.breaktimer_parse(bt_cache({ state = 'paused', phase = 'working' })) +assert(b.phase_label == 'in pausa' and b.role == 'warning' and b.next == 'pausa', + 'paused: ' .. b.phase_label .. '/' .. b.role .. '/' .. b.next) + +-- Frozen: the clock stopped while the phase stayed 'working'. Outside working +-- hours, or a hung daemon; both read the same. +b = data.breaktimer_parse(bt_cache({ frozen = 'yes' })) +assert(b.phase_label == 'outside working hours' and b.role == 'label', + 'frozen: ' .. b.phase_label .. '/' .. b.role) +assert(b.next == 'pausa', 'frozen working still leads to a break') + +-- A dead daemon: the sampler's liveness check sets running no even when the +-- state file was left saying running. +b = data.breaktimer_parse(bt_cache({ running = 'no' })) +assert(b.countdown == '--' and b.phase_label == 'fermo' and b.next == '--' + and b.role == 'label', 'stopped reads as fermo, got ' .. b.phase_label) + +-- A negative remain must clamp, not print '-1:59'. +b = data.breaktimer_parse(bt_cache({ remain = -5 })) +assert(b.countdown == '0:00', 'negative remain clamps, got ' .. b.countdown) + +-- No 'generated' key means the sampler never ran, which is different from a +-- stopped daemon (which still writes a cache). +assert(data.breaktimer_parse('running no\n') == nil, 'no generated key: nil') +assert(data.breaktimer_parse('') == nil, 'empty cache: nil') +assert(data.breaktimer_parse(nil) == nil, 'nil cache: nil') + print('test_data: all assertions passed') |
