Skip to content

Commit fe8ec00

Browse files
committed
Add test for finishing a drag on focus lost
1 parent f6dde9d commit fe8ec00

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

test/webdriverio/test/basic_test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import * as chai from 'chai';
88
import * as Blockly from 'blockly';
99
import {
10+
isDragging,
1011
setCurrentCursorNodeById,
1112
setCurrentCursorNodeByIdAndFieldName,
1213
getCurrentFocusNodeId,
@@ -247,6 +248,21 @@ suite('Keyboard navigation on Blocks', function () {
247248
.expect(await getCurrentFocusedBlockId(this.browser))
248249
.equal('controls_repeat_1');
249250
});
251+
252+
test('Losing focus cancels move', async function () {
253+
await tabNavigateToWorkspace(this.browser);
254+
await this.browser.pause(PAUSE_TIME);
255+
await setCurrentCursorNodeById(this.browser, 'text_print_1');
256+
await this.browser.keys("m");
257+
await this.browser.pause(PAUSE_TIME);
258+
259+
chai.assert.isTrue(await isDragging(this.browser));
260+
261+
await this.browser.keys(Key.Tab);
262+
await this.browser.pause(PAUSE_TIME);
263+
264+
chai.assert.isFalse(await isDragging(this.browser));
265+
});
250266
});
251267

252268
// TODO(#499) These tests fail because focusing on a field doesn't update the cursor

test/webdriverio/test/test_setup.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,15 @@ export async function tabNavigateForward(browser: WebdriverIO.Browser) {
356356
await browser.keys(webdriverio.Key.Tab);
357357
await browser.pause(PAUSE_TIME);
358358
}
359+
360+
/**
361+
* Returns whether there's a drag in progress on the main workspace.
362+
*
363+
* @param browser The active WebdriverIO Browser object.
364+
*/
365+
export async function isDragging(browser: WebdriverIO.Browser): Promise<boolean> {
366+
return await browser.execute(() => {
367+
const workspaceSvg = Blockly.getMainWorkspace() as Blockly.WorkspaceSvg;
368+
return workspaceSvg.isDragging();
369+
});
370+
}

0 commit comments

Comments
 (0)