Skip to content

Commit 42ad9a4

Browse files
authored
Merge pull request #1786 from zb3/fix-overwritten-output
2 parents 7538be6 + db331e9 commit 42ad9a4

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

src/web/App.mjs

+6-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ class App {
160160
// has completed.
161161
if (this.autoBakePause) return false;
162162

163-
if (this.autoBake_ && !this.baking) {
163+
if (this.baking) {
164+
this.manager.worker.cancelBakeForAutoBake();
165+
this.baking = false;
166+
}
167+
168+
if (this.autoBake_) {
164169
log.debug("Auto-baking");
165170
this.manager.worker.bakeInputs({
166171
nums: [this.manager.tabs.getActiveTab("input")],

src/web/waiters/WorkerWaiter.mjs

+22
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,28 @@ class WorkerWaiter {
322322
};
323323
}
324324

325+
/**
326+
* Cancels the current bake making it possible to autobake again
327+
*/
328+
cancelBakeForAutoBake() {
329+
if (this.totalOutputs > 1) {
330+
this.cancelBake();
331+
} else {
332+
// In this case the UI changes can be skipped
333+
334+
for (let i = this.chefWorkers.length - 1; i >= 0; i--) {
335+
if (this.chefWorkers[i].active) {
336+
this.removeChefWorker(this.chefWorkers[i]);
337+
}
338+
}
339+
340+
this.inputs = [];
341+
this.inputNums = [];
342+
this.totalOutputs = 0;
343+
this.loadingOutputs = 0;
344+
}
345+
}
346+
325347
/**
326348
* Cancels the current bake by terminating and removing all ChefWorkers
327349
*

tests/browser/01_io.js

+41
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,33 @@ module.exports = {
167167
browser.expect.element("#output-text .cm-status-bar .eol-value").text.to.equal("LF");
168168
},
169169

170+
"Autobaking the latest input": browser => {
171+
// Use the sleep recipe to simulate a long running task
172+
utils.loadRecipe(browser, "Sleep", "input", [2000]);
173+
174+
browser.waitForElementVisible("#stale-indicator");
175+
176+
// Enable previously disabled autobake
177+
browser.click("#auto-bake-label");
178+
179+
browser.sendKeys("#input-text .cm-content", "1");
180+
181+
browser.pause(500);
182+
183+
// Make another change while the previous input is being baked
184+
browser.sendKeys("#input-text .cm-content", "2");
185+
186+
browser
187+
.waitForElementNotVisible("#stale-indicator")
188+
.waitForElementNotVisible("#output-loader");
189+
190+
// Ensure we got the latest input baked
191+
utils.expectOutput(browser, "input12");
192+
193+
// Turn autobake off again
194+
browser.click("#auto-bake-label");
195+
},
196+
170197
"Special content": browser => {
171198
/* Special characters are rendered correctly */
172199
utils.setInput(browser, SPECIAL_CHARS, false);
@@ -645,6 +672,20 @@ module.exports = {
645672
},
646673

647674
"Loading from URL": browser => {
675+
utils.clear(browser);
676+
677+
/* Side panel displays correct info */
678+
utils.uploadFile(browser, "files/TowelDay.jpeg");
679+
680+
browser
681+
.waitForElementVisible("#input-text .cm-file-details")
682+
.waitForElementVisible("#input-text .cm-file-details .file-details-toggle-shown")
683+
.waitForElementVisible("#input-text .cm-file-details .file-details-thumbnail")
684+
.waitForElementVisible("#input-text .cm-file-details .file-details-name")
685+
.waitForElementVisible("#input-text .cm-file-details .file-details-size")
686+
.waitForElementVisible("#input-text .cm-file-details .file-details-type")
687+
.waitForElementVisible("#input-text .cm-file-details .file-details-loaded");
688+
648689
/* Complex deep link populates the input correctly (encoding, eol, input) */
649690
browser
650691
.urlHash("recipe=To_Base64('A-Za-z0-9%2B/%3D')&input=VGhlIHNoaXBzIGh1bmcgaW4gdGhlIHNreSBpbiBtdWNoIHRoZSBzYW1lIHdheSB0aGF0IGJyaWNrcyBkb24ndC4M&ienc=21866&oenc=1201&ieol=FF&oeol=PS")

0 commit comments

Comments
 (0)