Skip to content

Commit d5b7192

Browse files
add test on beforeunload bug
1 parent 9bf7785 commit d5b7192

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

tests/integration/appWindow.spec.ts

+20
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,23 @@ test('App quits when window is closed', async ({ app }) => {
1313
await window.close();
1414
await app.app.waitForEvent('close');
1515
});
16+
17+
test('App can quit when graph has unsaved changes', async ({ graphCanvas, installWizard, installedApp }) => {
18+
await installWizard.stepThroughOnboarding();
19+
await graphCanvas.expectLoaded();
20+
21+
// Create a workflow and add unsaved changes
22+
await installedApp.createBlankWorkflow();
23+
await installedApp.saveWorkflow();
24+
await installedApp.addFirstNodeResult();
25+
26+
// Wait for change tracker
27+
await installedApp.window.waitForTimeout(1024);
28+
29+
// Ensure beforeunload dialog is not raised and app can quit normally
30+
// (https://github.com/Comfy-Org/desktop/issues/688)
31+
await installedApp.window.close({
32+
runBeforeUnload: true,
33+
});
34+
await installedApp.window.waitForEvent('close');
35+
});

tests/integration/testInstallWizard.ts

+17
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ export class TestInstallWizard {
55
readonly nextButton;
66
readonly cpuToggle;
77
readonly installLocationInput;
8+
readonly installButton;
89

910
constructor(readonly window: Page) {
1011
this.nextButton = this.getButton('Next');
1112
this.getStartedButton = this.getButton('Get Started');
1213
this.cpuToggle = this.window.locator('#cpu-mode');
1314
this.installLocationInput = this.getInput('', true);
15+
this.installButton = this.getButton('Install');
1416
}
1517

1618
async clickNext() {
@@ -28,4 +30,19 @@ export class TestInstallWizard {
2830
getInput(name: string, exact?: boolean) {
2931
return this.window.getByRole('textbox', { name, exact });
3032
}
33+
34+
async stepThroughOnboarding() {
35+
await this.clickGetStarted();
36+
await this.cpuToggle.click();
37+
await this.clickNext();
38+
await this.clickNext();
39+
await this.clickNext();
40+
await this.installButton.click();
41+
42+
// Wait for app to be ready
43+
await this.window.waitForFunction(() => {
44+
// @ts-expect-error window is not typed
45+
return window['app'] && window['app'].extensionManager;
46+
});
47+
}
3148
}

tests/integration/testInstalledApp.ts

+26
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,30 @@ export class TestInstalledApp {
1818
await expect(this.blockUi).not.toBeVisible();
1919
}).toPass({ timeout, intervals: [500] });
2020
}
21+
22+
/** Creates a new blank workflow using the button in the tabs */
23+
async createBlankWorkflow() {
24+
const newWorkflowButton = this.window.getByLabel('Create a new blank workflow');
25+
await newWorkflowButton.click();
26+
}
27+
28+
/** Saves the current workflow using keyboard shortcuts. */
29+
async saveWorkflow() {
30+
await this.window.keyboard.press('Control+S');
31+
await this.window.waitForSelector('#global-prompt', { state: 'visible' });
32+
await this.window.keyboard.press('Enter');
33+
await this.window.waitForSelector('#global-prompt', { state: 'hidden' });
34+
}
35+
36+
/** Opens the node searchbox by double clicking on the canvas. */
37+
async openNodeSearchbox() {
38+
await this.window.mouse.dblclick(256, 256, { delay: 128 });
39+
await this.window.waitForSelector('.p-autocomplete');
40+
}
41+
42+
/** Opens the node searchbox and adds the first result to the graph. */
43+
async addFirstNodeResult() {
44+
await this.openNodeSearchbox();
45+
await this.window.keyboard.press('Enter');
46+
}
2147
}

0 commit comments

Comments
 (0)