garage44.eu/jeroen/midas

logclone: git clone https://garage44.eu/jeroen/midas.git

.. /web/src/lib/sentence.test.ts

raw

import {expect, test} from 'bun:test'

import {sentence, text} from '@/lib/sentence'
import {$s} from '@/lib/store'

const say = (e: Parameters<typeof sentence>[0]) => {
    const parts = sentence(e)
    return parts && text(parts)
}

test('frequent kinds read as sentences, with names', () => {
    $s.names = {s1: {label: 'tile loading', branch: null, link: null}}
    const ts = '2026-10-21T10:00:00Z'
    expect(say({kind: 'claim', ts, actor: 's1', node: 'mac-1', purpose: 'build'})).toBe('tile loading took mac-1 for build')
    expect(say({kind: 'release', ts, actor: 's1', node: 'mac-1', held_s: 600})).toBe('tile loading gave mac-1 back after 10m')
    expect(say({kind: 'session_label', ts, actor: 's1', label: 'tile loading'})).toBe('a session is called “tile loading”')
    expect(say({kind: 'note', ts, actor: 'hub', to: 's1', text: 'hi'})).toBe('midas → tile loading: hi')
    expect(say({kind: 'deploy_step', ts, deploy: '20261021-181924-atlas-ce02e61e', ok: true, step: 'check: d=x'})).toBe('atlas deploy: check')
    expect(say({kind: 'something_new', ts})).toBeNull()
})

test('names stay parts of their own, to be set apart', () => {
    $s.names = {s1: {label: 'tile loading', branch: null, link: null}}
    expect(sentence({kind: 'claim', ts: '', actor: 's1', node: 'mac-1'})).toEqual([{name: 'tile loading', full: 'tile loading'}, ' took mac-1'])
})