import assert from 'node:assert/strict'; import test from 'node:test'; import { chipFor as chipForCore, parseUpdateStatus, type UpdateStatus } from '../../../waybetter/packages/shell/src/updateModel.ts'; /** The titlebar chip as the shell shows it for this app. */ const chipFor = (status: UpdateStatus) => chipForCore(status, 'wayBetter for X'); test('chip appears only when an update is ready, installing or broken', () => { for (const state of ['idle', 'checking', 'upToDate']) assert.equal(chipFor(parseUpdateStatus({ state })), null); assert.equal(chipFor(parseUpdateStatus({ state: 'downloading', version: '0.3.0' })), null); assert.equal(chipFor(parseUpdateStatus({ state: 'error', message: 'offline' })), null); assert.deepEqual(chipFor(parseUpdateStatus({ state: 'ready', version: '0.3.0', notes: '' }))?.label, 'Update ready ยท restart'); assert.equal(chipFor(parseUpdateStatus({ state: 'installing', version: '0.3.0' }))?.kind, 'installing'); }); test('malformed payloads are idle', () => { for (const value of [null, 'ready', 42, {}, { state: 'pwned' }, { state: 1 }]) { assert.deepEqual(parseUpdateStatus(value), { state: 'idle' }); } }); test('problem link must be https', () => { assert.equal(chipFor(parseUpdateStatus({ state: 'problem', downloadUrl: 'javascript:alert(1)' })), null); const chip = chipFor(parseUpdateStatus({ state: 'problem', downloadUrl: 'https://twttr.crt.fyi/v1/download/windows/latest' })); assert.equal(chip?.kind, 'problem'); });