Skip to content

Commit

Permalink
Support Async Dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed Oct 3, 2024
1 parent 3ab52b8 commit db51ea5
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 45 deletions.
29 changes: 0 additions & 29 deletions .eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion bin/regtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const options = {
interpreter_path: argv.i || argv.interpreter,
//list: argv.l || argv.list,
pdf: argv.pdf,
port: 8080,
port: 8090,
tests: argv._.slice(1),
testfile_path,
timeout: parseInt(argv.t || argv.timeout || '1', 10),
Expand Down
31 changes: 31 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import js from '@eslint/js'
import globals from 'globals'

export default [
js.configs.recommended,
{
languageOptions: {
ecmaVersion: 12,
globals: {
...globals.browser,
...globals.es2020,
...globals.jquery,
...globals.node,
regtest_data: 'readonly',
regtest_event: 'readonly',
regtest_log: 'readonly',
},
sourceType: 'module',
},
rules: {
eqeqeq: ['error', 'always', {'null': 'ignore'}],
indent: ['error', 4],
'linebreak-style': ['error', 'unix'],
'no-empty': ['off'],
'no-var': ['error'],
'prefer-const': ['error', {'destructuring': 'all'}],
quotes: ['error', 'single'],
semi: ['error', 'never'],
},
},
]
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "regtest-html",
"version": "0.1.3",
"version": "0.1.4",
"description": "RegTest compatible test framework for HTML interpreters",
"repository": "curiousdannii/regtest-html",
"keywords": [
Expand All @@ -22,11 +22,11 @@
},
"dependencies": {
"http-server": "^14.1.1",
"minimist": "^1.2.7",
"minimist": "^1.2.8",
"puppeteer": "^23.0.0"
},
"devDependencies": {
"eslint": "^8.28.0"
"eslint": "^9.0.0"
},
"scripts": {
"lint": "eslint .",
Expand Down
73 changes: 63 additions & 10 deletions src/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,41 @@ document.addEventListener('DOMContentLoaded', () => {

glkote_window_obsever.observe(document.getElementById('windowport'), {childList: true})

// Observe the opening of the async dialog
const glkote_async_dialog_observer = new MutationObserver(records => {
for (const record of records) {
if (record.type === 'attributes') {
const dialog = $(record.target)
if (dialog.prop('open')) {
regtest_data({
type: 'input_requested',
data: {
type: 'fileref_prompt',
},
})
}
}
}
})

// Observe the body for the insertion of the async dialog
let async_dialog
const body_observer = new MutationObserver(records => {
for (const record of records) {
if (record.type === 'childList') {
for (const node of record.addedNodes) {
const $node = $(node)
if ($node.hasClass('asyncglk_file_dialog')) {
async_dialog = $node
glkote_async_dialog_observer.observe($node[0], {attributeFilter: ['open']})
body_observer.disconnect()
}
}
}
}
})
body_observer.observe(document.body, {childList: true})

// Submit a Glk event
window.regtest_event = data => {
if (data.type === 'line') {
Expand All @@ -132,21 +167,39 @@ document.addEventListener('DOMContentLoaded', () => {
}
if (data.type === 'fileref_prompt') {
// Now to fill in the dialog form...
const accept = $('#dialog_accept')
if (accept.text() === 'Save') {
$('#dialog_infield').val(data.value)
if (async_dialog) {
const form_button = async_dialog.find('> .inner > .foot button.submit')
if (form_button.text() === 'Save') {
$('#filename_input').val(data.value)
}
else {
const options = async_dialog.find('> .inner > div[role=listbox] button')
for (const option of options) {
const $option = $(option)
if ($option.find('.name').text().startsWith(data.value + '.')) {
$option.click()
}
}
}
form_button.click()
}
else {
const test = new RegExp(`^${data.value}\\s`)
const options = $('#dialog_select option')
for (const option of options) {
const $option = $(option)
if (test.test($option.text())) {
$option.prop('selected', true)
const accept = $('#dialog_accept')
if (accept.text() === 'Save') {
$('#dialog_infield').val(data.value)
}
else {
const test = new RegExp(`^${data.value}\\s`)
const options = $('#dialog_select option')
for (const option of options) {
const $option = $(option)
if (test.test($option.text())) {
$option.prop('selected', true)
}
}
}
accept.click()
}
accept.click()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Runner {
new URL(options.interpreter_path)
options.interpreter_url = options.interpreter_path
}
catch (_) {
catch {
options.interpreter_url = `http://localhost:${options.port}/${path.relative(cwd, options.interpreter_path)}`
}
options.gamefile_url = options.gamefile_path ? `http://localhost:${options.port}/${path.relative(cwd, options.gamefile_path)}` : ''
Expand Down
65 changes: 65 additions & 0 deletions tests/parchment-async-dialog.html

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion tests/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ echo Praxix
echo Advent
./bin/regtest.js -i tests/parchment.html tests/advent.z5.regtest
echo Inputeventtest
./bin/regtest.js -i tests/parchment.html -t 3 tests/inputeventtest.ulx.regtest
./bin/regtest.js -i tests/parchment.html -t 3 tests/inputeventtest.ulx.regtest
echo "Async Dialog (Advent)"
./bin/regtest.js -i tests/parchment-async-dialog.html tests/advent.z5.regtest

0 comments on commit db51ea5

Please sign in to comment.