const test = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const vm = require('node:vm'); const { JSDOM } = require('jsdom'); const { marked } = require('marked'); const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8'); function workspace(t) { // Real .tab-btn elements: the rail and cards mirror these, so a harness // without them cannot show whether the mirroring works. const tabs = '' + '' + '' + ''; const dom = new JSDOM(tabs + '
' + read('public/components/assistant.html') + '
', { url: 'https://example.test', runScripts: 'outside-only' }); const window = dom.window; window.eval(read('public/js/accountBoundary.js')); assert.equal(window.AccountBoundary.enter({ id: 'synthetic-rendering-owner' }, true), true); window.marked = marked; window.DOMPurify = require('dompurify')(window); window.matchMedia = () => ({ matches: true }); const fetched = []; const activated = []; const events = []; const context = { window, document: window.document, console, URL, Blob, TextDecoder, AbortController, setTimeout() {}, clearTimeout() {}, showToast() {}, EMPTY_PROMPT_SETS: [[]], createAssistantImageStore: () => ({ clear() {}, renderGeneratedImage: () => '' }), fetchAssistantStatus: async () => ({ success: true }), fetchAssistantExamples: async () => ({ success: true, examples: [] }), fetchSavedAssistantChats: async () => ({ success: true, chats: [] }), saveAssistantChat: async () => ({ success: true }), fetch: async url => { fetched.push(url); return new Response(read('public/components/learning.html')); } }; vm.createContext(context); for (const file of ['assistant/citations.js', 'assistant/sources.js', 'assistant/sharing.js', 'generatedImages.js', 'assistant/export.js', 'clinicalAssistant.js']) { vm.runInContext(read('public/js/' + file).replace(/^import[\s\S]*?from ['"][^'"]+['"];\s*/gm, '').replace(/^export /gm, ''), context); } context.bindEvents(); window.activateTab = tab => activated.push(tab); window.document.addEventListener('tabChanged', e => events.push(e.detail.tab)); t.after(() => window.close()); return { context, document: window.document, window, fetched, activated, events }; } test('assistant area is an OWUI-style three-column workspace with a slim go-back top bar', t => { const app = workspace(t); const layout = app.document.querySelector('.assistant-layout'); assert.ok(layout); const columns = [...layout.children].map(el => el.className.split(' ')[0]); assert.ok(columns.includes('assistant-history'), 'left history rail'); assert.ok(columns.includes('assistant-main'), 'center chat column'); assert.ok(columns.includes('assistant-side'), 'right image/sources column'); const left = app.document.querySelector('.assistant-history'); assert.ok(left.querySelector('#assistant-saved-chats'), 'saved chats live in the left rail'); assert.equal(left.querySelector('#btn-assistant-clear') !== null, true, 'New chat sits at the top of the rail'); assert.equal(left.firstElementChild.id, 'btn-assistant-drawer-close', 'the drawer leads with its close control'); const right = app.document.querySelector('.assistant-side'); assert.equal(right.querySelector('#assistant-visual-output'), null, 'no image display in the right column — sources only'); assert.ok(right.querySelector('#assistant-sources'), 'sources panel in the right column'); assert.equal(right.querySelector('#assistant-saved-chats'), null, 'saved chats moved out of the right column'); // No bar above the layout at all: the app page has only the blue header, so a // second bar here made the assistant taller and left dead space on top. assert.equal(app.document.querySelector('.assistant-topbar'), null, 'no assistant-only top bar'); // Go back is gone: the Assistant/Workspace switch is how you leave, so a // second exit control in the topbar was one affordance too many. assert.equal(app.document.querySelector('#btn-assistant-goback'), null, 'no Go back in the topbar'); assert.ok(app.document.querySelector('[data-assistant-mode="workspace"]'), 'the mode switch replaces it'); assert.equal(app.document.querySelector('.assistant-history #btn-assistant-create-image'), null, 'Create image moved into the + menu with the other conversation actions'); // The top bar is gone entirely: everything that acts on the conversation moved // into the composer's + menu, so both views start at the same vertical // position and switching cannot nudge the page up or down. assert.equal(app.document.querySelector('.assistant-toolbar'), null, 'no top bar above the transcript'); const menu = app.document.querySelector('#assistant-plus-menu'); assert.ok(menu, 'the + menu exists'); const items = [...menu.querySelectorAll('button')].map(b => b.id); assert.deepEqual(items, ['btn-assistant-create-image', 'btn-assistant-takehome', 'btn-assistant-export-pdf', 'btn-assistant-download-chat'], 'every action on the conversation lives in the + menu'); assert.ok(menu.querySelector('label[for="assistant-attach-input"]'), 'and attaching images with them'); assert.equal(menu.hidden, true, 'closed until asked for'); const examples = app.document.querySelectorAll('.assistant-empty .assistant-examples button, [data-assistant-example]'); assert.ok(examples.length >= 3, 'the generated example questions stay on the empty chat screen'); }); test('opening the assistant replaces the main menu with the saved chats', async t => { const app = workspace(t); app.document.dispatchEvent(new app.window.CustomEvent('tabChanged', { detail: { tab: 'assistant' } })); assert.ok(app.document.body.classList.contains('assistant-workspace'), 'fullscreen workspace class applied'); app.document.dispatchEvent(new app.window.CustomEvent('tabChanged', { detail: { tab: 'encounter' } })); assert.ok(!app.document.body.classList.contains('assistant-workspace'), 'leaving the assistant restores the app chrome'); }); test('Learning Hub is a top-level main-menu entry, not part of the assistant workspace', () => { const indexHtml = read('public/index.html'); assert.match(indexHtml, /data-tab="learning">[\s\S]*?Learning Hub<\/span>/, 'Learning Hub button in the sidebar'); assert.match(indexHtml, /
<\/section>/, 'learning tab section exists'); assert.match(indexHtml, /
<\/section>/, 'assistant tab is a clean standalone section'); }); test('the assistant tab keeps its clean structure next to the restored learning tab', () => { const indexHtml = read('public/index.html'); assert.match(indexHtml, /