Preserve voice test form during periodic page refresh
This commit is contained in:
1 parent
e504d22961
commit
3e99d0f51f
2 files changed
+38
-2
No files matched your search
@@ -0,0 +1,36 @@
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const assert = require('node:assert/strict');
|
||||
let studio = null, form = null, renders = 0, binds = 0;
|
||||
const tabs = ['test', 'profiles'].map(section => ({dataset: {section}}));
|
||||
const view = {set innerHTML(html) {
|
||||
renders++;
|
||||
studio = {dataset: {page: /data-page="([^"]+)"/.exec(html)[1]}};
|
||||
form = {text: '', file: null, audioTime: 0};
|
||||
}};
|
||||
const context = vm.createContext({document: {
|
||||
querySelector: selector => selector === '#studio' ? studio : view,
|
||||
querySelectorAll: () => tabs,
|
||||
}, VoiceUI: {html: () => '', bind: () => binds++},
|
||||
ProfilesUI: {html: () => '', bind: () => {}},
|
||||
});
|
||||
vm.runInContext(fs.readFileSync('studio.js', 'utf8') + '\nthis.testStudio = Studio;', context);
|
||||
const ui = context.testStudio;
|
||||
ui.openTest('voice');
|
||||
const original = form;
|
||||
form.text = 'Dieser Text darf nicht verschwinden.';
|
||||
form.file = {name: 'reference.wav'};
|
||||
form.audioTime = 12;
|
||||
for (let i = 0; i < 5; i++) ui.openTest('voice');
|
||||
assert.equal(form, original);
|
||||
assert.equal(form.text, 'Dieser Text darf nicht verschwinden.');
|
||||
assert.equal(form.file.name, 'reference.wav');
|
||||
assert.equal(form.audioTime, 12);
|
||||
assert.equal(renders, 1);
|
||||
assert.equal(binds, 1);
|
||||
tabs[1].onclick();
|
||||
assert.equal(renders, 2, 'Profile tab remains clickable from voice test');
|
||||
ui.openTest('voice');
|
||||
assert.equal(renders, 3, 'Explicit return from profiles opens the test');
|
||||
assert.equal(binds, 2);
|
||||
console.log('Voice test polling preserves text, reference and audio; tab navigation works.');
|
||||
Reference in new issue
Block a user