106 lines
3.2 KiB
JavaScript
106 lines
3.2 KiB
JavaScript
import test from 'brittle'
|
|
import { readFile } from 'node:fs/promises'
|
|
import { dirname, join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
import { attachBareOsTuiSdk } from '../../bare-os-booter/lib/bare-os-tui-sdk.js'
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
|
|
async function load() {
|
|
const parts = await Promise.all([
|
|
readFile(join(__dirname, '../lib/summon-url.js'), 'utf8'),
|
|
readFile(join(__dirname, '../lib/summon-cookie.js'), 'utf8'),
|
|
readFile(join(__dirname, '../lib/summon-http.js'), 'utf8'),
|
|
readFile(join(__dirname, '../lib/summon-html.js'), 'utf8'),
|
|
readFile(join(__dirname, '../lib/summon-css.js'), 'utf8'),
|
|
readFile(join(__dirname, '../lib/summon-layout.js'), 'utf8'),
|
|
readFile(join(__dirname, '../lib/summon-form.js'), 'utf8'),
|
|
readFile(join(__dirname, '../lib/summon-dom.js'), 'utf8'),
|
|
readFile(join(__dirname, '../lib/summon-js.js'), 'utf8'),
|
|
readFile(join(__dirname, '../lib/summon-session.js'), 'utf8'),
|
|
readFile(join(__dirname, '../lib/summon-tui.js'), 'utf8')
|
|
])
|
|
const hook = {}
|
|
new Function(
|
|
'exports',
|
|
parts.join('\n') +
|
|
`
|
|
exports.bareSummonCreateSession = bareSummonCreateSession;
|
|
exports.bareSummonCurrent = bareSummonCurrent;
|
|
exports.bareSummonAboutBody = bareSummonAboutBody;
|
|
exports.bareSummonApplyDocument = bareSummonApplyDocument;
|
|
exports.bareSummonCreateTuiApp = bareSummonCreateTuiApp;
|
|
`
|
|
)(hook)
|
|
return hook
|
|
}
|
|
|
|
function makeStream(isTTY) {
|
|
return {
|
|
isTTY: !!isTTY,
|
|
columns: 80,
|
|
rows: 24,
|
|
write() {},
|
|
setRawMode() {},
|
|
resume() {},
|
|
pause() {},
|
|
on() {},
|
|
removeListener() {}
|
|
}
|
|
}
|
|
|
|
function makeCtx() {
|
|
const ctx = {
|
|
env: { HOME: '/home/guest' },
|
|
console: { error() {}, log() {} },
|
|
replStdin: makeStream(true),
|
|
replStdout: makeStream(true),
|
|
suspendReplForSubprocess() {},
|
|
resumeReplAfterSubprocess() {}
|
|
}
|
|
attachBareOsTuiSdk(ctx)
|
|
return ctx
|
|
}
|
|
|
|
test('summon TUI paints a fixed-height frame', async (t) => {
|
|
const h = await load()
|
|
const ctx = makeCtx()
|
|
const session = h.bareSummonCreateSession(ctx, { url: 'about:summon' })
|
|
h.bareSummonApplyDocument(
|
|
session,
|
|
h.bareSummonCurrent(session),
|
|
h.bareSummonAboutBody('summon', session),
|
|
'about:summon'
|
|
)
|
|
const app = h.bareSummonCreateTuiApp(ctx, session)
|
|
app.width = 80
|
|
app.height = 24
|
|
app._sync()
|
|
const view = ctx.tui.style.stripAnsi(app.view())
|
|
t.is(view.split('\n').length, 24)
|
|
t.ok(view.toLowerCase().includes('summon'))
|
|
t.ok(view.includes('about:summon'))
|
|
})
|
|
|
|
test('summon TUI help overlay', async (t) => {
|
|
const h = await load()
|
|
const ctx = makeCtx()
|
|
const session = h.bareSummonCreateSession(ctx, { url: 'about:summon' })
|
|
const app = h.bareSummonCreateTuiApp(ctx, session)
|
|
app.update(ctx.tui.decode('?')[0])
|
|
t.ok(app.help)
|
|
const ov = app.overlay({ width: 80, height: 24 })
|
|
t.ok(ov && ctx.tui.style.stripAnsi(ov.text).includes('text web browser'))
|
|
})
|
|
|
|
test('kernel summon bin includes TEA factory after build', async (t) => {
|
|
const bin = await readFile(
|
|
join(__dirname, '../../../kernel/bin/summon'),
|
|
'utf8'
|
|
)
|
|
t.ok(bin.includes('bareSummonCreateTuiApp'))
|
|
t.ok(bin.includes('ctx.tui.run'))
|
|
t.ok(bin.includes('about:summon'))
|
|
})
|