Spaces:
Sleeping
Sleeping
File size: 4,927 Bytes
7596726 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | const assert = require('node:assert/strict');
const test = require('node:test');
const { createJsonResponse, loadFullApp, withBrowserEnv } = require('./support/load-browser-modules');
const { duplicateNameEmployees, shift } = require('./support/fixtures');
const flush = () => new Promise((resolve) => setTimeout(resolve, 0));
const displayValue = (element) => element.style.display || '';
// This is the broad smoke test for the browser boot path.
test('full app boot renders timeline blocks without runtime render errors', async () => {
const { document, errors } = await loadFullApp({
demoData: {
employees: duplicateNameEmployees(),
shifts: [
shift({ id: 'shift-1', employeeIdx: 0 }),
shift({
id: 'shift-2',
start: '2024-01-01T12:00:00',
end: '2024-01-01T20:00:00',
requiredSkill: 'Nurse',
employeeIdx: null,
}),
],
},
});
assert.deepEqual(errors, []);
assert.ok(document.body.querySelectorAll('.sf-rail-timeline').length >= 1);
assert.ok(document.body.querySelectorAll('.sf-rail-timeline-row').length >= 1);
assert.ok(document.body.querySelectorAll('.sf-rail-timeline-item').length >= 1);
assert.equal(document.body.querySelectorAll('.sf-content').length, 4);
assert.ok(!document.body.textContent.includes('7860'));
});
test('terminal Solve is exposed by the stock header and restarts through cleanup', async () => {
const calls = [];
const eventSources = [];
let createCount = 0;
class TestEventSource {
constructor(url) {
this.url = url;
this.readyState = 1;
eventSources.push(this);
calls.push(['stream', url]);
}
close() {
this.readyState = 2;
calls.push(['close', this.url]);
}
}
TestEventSource.CLOSED = 2;
await withBrowserEnv({
EventSource: TestEventSource,
fetch: async (url, options = {}) => {
const method = options.method || 'GET';
calls.push([method, url]);
if (url === '/sf-config.json') {
return createJsonResponse({
title: 'SolverForge Hospital',
subtitle: 'Test shell',
defaultDemoId: 'LARGE',
});
}
if (url === '/generated/ui-model.json') {
return createJsonResponse({
constraints: [],
entities: [],
facts: [],
views: [{ id: 'schedule', label: 'Schedule', kind: 'timeline-by-location' }],
});
}
if (url === '/demo-data') return createJsonResponse(['LARGE']);
if (url === '/demo-data/LARGE') return createJsonResponse({ employees: [], shifts: [] });
if (url === '/jobs' && method === 'POST') {
createCount += 1;
return createJsonResponse({ id: `job-${createCount}` });
}
if (url.startsWith('/jobs/job-1/snapshot') && method === 'GET') {
return createJsonResponse({
id: 'job-1',
jobId: 'job-1',
snapshotRevision: 3,
lifecycleState: 'COMPLETED',
currentScore: '0hard/0soft',
bestScore: '0hard/0soft',
solution: { employees: [], shifts: [], score: '0hard/0soft' },
});
}
if (url.startsWith('/jobs/job-1/analysis') && method === 'GET') {
return createJsonResponse({
id: 'job-1',
jobId: 'job-1',
snapshotRevision: 3,
lifecycleState: 'COMPLETED',
analysis: { score: '0hard/0soft', constraints: [] },
});
}
if (url === '/jobs/job-1' && method === 'DELETE') {
return createJsonResponse('');
}
throw new Error(`unexpected ${method} ${url}`);
},
}, async ({ importModule, document }) => {
const { bootApp } = await importModule('static/app/main.mjs');
const boot = await bootApp(globalThis);
await flush();
const solveButton = boot.shell.header.sfControls.solveBtn;
assert.equal(solveButton.textContent, 'Solve');
assert.equal(displayValue(solveButton), '');
solveButton.eventListeners.click[0]({ type: 'click' });
await flush();
assert.equal(createCount, 1);
assert.equal(solveButton.style.display, 'none');
eventSources[0].onmessage({
data: JSON.stringify({
eventType: 'completed',
jobId: 'job-1',
lifecycleState: 'COMPLETED',
snapshotRevision: 3,
currentScore: '0hard/0soft',
bestScore: '0hard/0soft',
}),
});
await flush();
await flush();
assert.equal(document.getElementById('sf-app').dataset.lifecycleState, 'COMPLETED');
assert.equal(displayValue(solveButton), '');
solveButton.eventListeners.click[0]({ type: 'click' });
await flush();
await flush();
assert.equal(createCount, 2);
assert.deepEqual(calls.filter(([method]) => method === 'DELETE' || method === 'POST'), [
['POST', '/jobs'],
['DELETE', '/jobs/job-1'],
['POST', '/jobs'],
]);
});
});
|