From a81b2064d455725ea3c61d957a52d11661213062 Mon Sep 17 00:00:00 2001 From: zb3 Date: Sun, 7 Apr 2024 00:23:17 +0200 Subject: [PATCH 1/3] Abort the previous bake when attempting the next autobake --- src/web/App.mjs | 7 ++++++- src/web/waiters/WorkerWaiter.mjs | 22 ++++++++++++++++++++++ tests/browser/01_io.js | 26 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/web/App.mjs b/src/web/App.mjs index 53070e26..f087b168 100755 --- a/src/web/App.mjs +++ b/src/web/App.mjs @@ -160,7 +160,12 @@ class App { // has completed. if (this.autoBakePause) return false; - if (this.autoBake_ && !this.baking) { + if (this.baking) { + this.manager.worker.cancelBakeForAutoBake(); + this.baking = false; + } + + if (this.autoBake_) { log.debug("Auto-baking"); this.manager.worker.bakeInputs({ nums: [this.manager.tabs.getActiveTab("input")], diff --git a/src/web/waiters/WorkerWaiter.mjs b/src/web/waiters/WorkerWaiter.mjs index 3ad9695e..296aa956 100644 --- a/src/web/waiters/WorkerWaiter.mjs +++ b/src/web/waiters/WorkerWaiter.mjs @@ -322,6 +322,28 @@ class WorkerWaiter { }; } + /** + * Cancels the current bake making it possible to autobake again + */ + cancelBakeForAutoBake() { + if (this.totalOutputs > 1) { + this.cancelBake(); + } else { + // In this case the UI changes can be skipped + + for (let i = this.chefWorkers.length - 1; i >= 0; i--) { + if (this.chefWorkers[i].active) { + this.removeChefWorker(this.chefWorkers[i]); + } + } + + this.inputs = []; + this.inputNums = []; + this.totalOutputs = 0; + this.loadingOutputs = 0; + } + } + /** * Cancels the current bake by terminating and removing all ChefWorkers * diff --git a/tests/browser/01_io.js b/tests/browser/01_io.js index 6791c88e..f6132fdb 100644 --- a/tests/browser/01_io.js +++ b/tests/browser/01_io.js @@ -167,6 +167,32 @@ module.exports = { browser.expect.element("#output-text .cm-status-bar .eol-value").text.to.equal("LF"); }, + "Autobaking the latest input": browser => { + // Use the sleep recipe to simulate a long running task + utils.loadRecipe(browser, "Sleep", "input", [2000]); + + browser.waitForElementVisible("#stale-indicator"); + + // Enable previously disabled autobake + browser.click("#auto-bake-label"); + + browser + .sendKeys("#input-text .cm-content", "1"); + + browser.pause(500); + + // Make another change while the previous input is being baked + browser + .sendKeys("#input-text .cm-content", "2"); + + browser + .waitForElementNotVisible("#stale-indicator") + .waitForElementNotVisible("#output-loader"); + + // Ensure we got the latest input baked + utils.expectOutput(browser, "input12"); + }, + "Special content": browser => { /* Special characters are rendered correctly */ utils.setInput(browser, SPECIAL_CHARS, false); From 2e284d38422cae0ff3057c4258e9d4f188b03e24 Mon Sep 17 00:00:00 2001 From: zb3 Date: Sun, 7 Apr 2024 00:37:09 +0200 Subject: [PATCH 2/3] Fix autobake ui test --- tests/browser/01_io.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/browser/01_io.js b/tests/browser/01_io.js index f6132fdb..df0bbe62 100644 --- a/tests/browser/01_io.js +++ b/tests/browser/01_io.js @@ -191,6 +191,9 @@ module.exports = { // Ensure we got the latest input baked utils.expectOutput(browser, "input12"); + + // Turn autobake off again + browser.click("#auto-bake-label"); }, "Special content": browser => { From db331e94ee2dcd8cd022e03f2459761d2bf1bc18 Mon Sep 17 00:00:00 2001 From: zb3 Date: Sun, 7 Apr 2024 01:20:11 +0200 Subject: [PATCH 3/3] fix ui test code style --- tests/browser/01_io.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/browser/01_io.js b/tests/browser/01_io.js index df0bbe62..1ebd3805 100644 --- a/tests/browser/01_io.js +++ b/tests/browser/01_io.js @@ -176,14 +176,12 @@ module.exports = { // Enable previously disabled autobake browser.click("#auto-bake-label"); - browser - .sendKeys("#input-text .cm-content", "1"); + browser.sendKeys("#input-text .cm-content", "1"); browser.pause(500); // Make another change while the previous input is being baked - browser - .sendKeys("#input-text .cm-content", "2"); + browser.sendKeys("#input-text .cm-content", "2"); browser .waitForElementNotVisible("#stale-indicator") @@ -670,6 +668,20 @@ module.exports = { }, "Loading from URL": browser => { + utils.clear(browser); + + /* Side panel displays correct info */ + utils.uploadFile(browser, "files/TowelDay.jpeg"); + + browser + .waitForElementVisible("#input-text .cm-file-details") + .waitForElementVisible("#input-text .cm-file-details .file-details-toggle-shown") + .waitForElementVisible("#input-text .cm-file-details .file-details-thumbnail") + .waitForElementVisible("#input-text .cm-file-details .file-details-name") + .waitForElementVisible("#input-text .cm-file-details .file-details-size") + .waitForElementVisible("#input-text .cm-file-details .file-details-type") + .waitForElementVisible("#input-text .cm-file-details .file-details-loaded"); + /* Complex deep link populates the input correctly (encoding, eol, input) */ browser .urlHash("recipe=To_Base64('A-Za-z0-9%2B/%3D')&input=VGhlIHNoaXBzIGh1bmcgaW4gdGhlIHNreSBpbiBtdWNoIHRoZSBzYW1lIHdheSB0aGF0IGJyaWNrcyBkb24ndC4M&ienc=21866&oenc=1201&ieol=FF&oeol=PS")