okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-0213-qafix into f-0213-int64b48c0d0

main
2.5 KiB34 linesraw
1/**
2 * QAGUI 0213 #2: in the first seconds after a start the engine is there but Control's installed list has not arrived, so a downloaded
3 * model must not be offered as "Download & load". The per-model buttons wait (existing "Checking…" label, disabled) until the list is in.
4 */
5import test from 'node:test';
6import assert from 'node:assert/strict';
7import { build } from 'esbuild';
8import { readFileSync } from 'node:fs';
9import { fileURLToPath } from 'node:url';
10
11const here = (p) => fileURLToPath(new URL(p, import.meta.url));
12const result = await build({
13  entryPoints: [here('../src/lib/native.ts')], bundle: true, format: 'esm', platform: 'node', write: false, logLevel: 'silent',
14  alias: { react: here('./helpers/react-stub.mjs') }, loader: { '.json': 'json' },
15});
16const { installedListPending } = await import(`data:text/javascript;base64,${Buffer.from(result.outputFiles[0].text).toString('base64')}`);
17
18test('the list is pending only while the engine answered and the installed list is still missing', () => {
19  assert.equal(installedListPending(null), false, 'nothing read yet: the buttons are already off (engine not available)');
20  assert.equal(installedListPending({ available: false, installed: null, error: null }), false);
21  assert.equal(installedListPending({ available: true, installed: null, error: null }), true, 'the flash: engine up, list not here');
22  assert.equal(installedListPending({ available: true, installed: { models: [] }, error: null }), false, 'an empty list is an answer: Download & load is right');
23  assert.equal(installedListPending({ available: true, installed: { models: [{ model: 'a', ready: true }] }, error: null }), false);
24  assert.equal(installedListPending({ available: true, installed: null, error: 'boom' }), false, 'a failed read does not hold the buttons for ever');
25});
26
27test('the Models page waits on it for the download size, Tune model and the primary button, and uses the existing Checking label', () => {
28  const src = readFileSync(here('../src/components/NativeModels.tsx'), 'utf8');
29  assert.match(src, /listPending = installedListPending\(native\)/);
30  assert.match(src, /!loadedSelected && !listPending && !installed\?\.ready && selectedSize\?\.download_gb/);
31  assert.match(src, /<Btn icon="gauge" disabled=\{listPending \|\|/);
32  assert.match(src, /<Btn variant="primary" icon="models" disabled=\{pending \|\| listPending \|\|/);
33  assert.match(src, /tr\(pending \|\| listPending \? 'Checking…' : installed\?\.ready \? 'Load model' : 'Download & load'\)/);
34});