test: create-image dialog coverage (describe or pick a chat)

This commit is contained in:
Daniel 2026-09-08 23:44:26 +02:00
parent bb218750d9
commit 77375c7461

View file

@ -158,6 +158,8 @@ function client(t, options = {}) {
fetchAssistantStatus: async () => ({ success: true, translateProvider: 'libretranslate' }),
translateAssistantMessage: (message, target, provider) => apiFetch('/api/clinical-assistant/translate', { method: 'POST', headers: {}, body: JSON.stringify({ message, target, provider }) }).then(r => r.json()),
getAuthHeaders: () => ({ 'X-Synthetic': '1' }),
fetchSavedAssistantChat: async id => ({ success: true, chat: { id, payload: { version: 2, messages: [{ role: 'user', content: 'Old question' }] } } }),
startAssistantImageJob: async (prompt, history) => { calls.push({ url: 'image-job', prompt, history }); return { success: true, jobId: 'job-1' }; },
fetch: apiFetch };
vm.createContext(context);
for (const file of ['assistant/citations.js', 'assistant/sources.js', 'assistant/sharing.js', 'generatedImages.js', 'assistant/export.js', 'clinicalAssistant.js']) {
@ -211,6 +213,34 @@ test('email send succeeds and clears the field; failure shows the server message
assert.ok(app.toasts.some(t => /sent to parent@example\.com/.test(t[0])));
});
test('Create image dialog: describe it or pick a chat; the latest chat is one tap away', async t => {
const app = client(t);
const c = app.context;
c.fetchSavedAssistantChats = async () => ({ success: true, chats: [{ id: 2, title: 'Older chat', updated_at: new Date().toISOString() }, { id: 9, title: 'Newest chat', updated_at: new Date().toISOString() }] });
await c.loadSavedChats();
app.document.getElementById('btn-assistant-create-image').click();
const modal = app.document.getElementById('assistant-create-image-modal');
assert.ok(modal, 'dialog opens');
assert.ok(modal.querySelector('#create-image-description'));
const options = [...modal.querySelectorAll('#create-image-chat option')].map(o => o.textContent);
assert.deepEqual(options, ['This chat', 'Older chat', 'Newest chat'], 'current chat default, saved chats newest first');
modal.querySelector('#btn-create-image-generate').click();
await new Promise(r => setImmediate(r)); await new Promise(r => setImmediate(r));
const job = app.calls.find(c => c.url === 'image-job');
assert.ok(job, 'generation requested');
assert.equal(job.prompt, 'Create a pediatric teaching visual from this conversation.');
// picking an older chat loads its messages
app.document.getElementById('btn-assistant-create-image').click();
app.document.getElementById('create-image-chat').value = '2';
app.document.getElementById('btn-create-image-generate').click();
await new Promise(r => setImmediate(r)); await new Promise(r => setImmediate(r));
const jobs = app.calls.filter(c => c.url === 'image-job');
assert.equal(jobs.length, 2);
assert.equal(jobs[1].history.length, 1);
assert.equal(jobs[1].history[0].role, 'user');
assert.equal(jobs[1].history[0].content, 'Old question', 'generates from the selected chat');
});
test('translate picker filters languages by the local provider availability', async t => {
const app = client(t);
const c = app.context;