Skip to content

Commit 5ee26c9

Browse files
feat: use block instead of block ID in getClickableBlockElement
1 parent cad3d4b commit 5ee26c9

3 files changed

Lines changed: 27 additions & 26 deletions

File tree

tests/browser/test/basic_playground_test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,33 +72,33 @@ suite('Right Clicking on Blocks', function () {
7272
});
7373

7474
test('clicking the collapse option collapses the block', async function () {
75-
await contextMenuSelect(this.browser, this.block.id, 'Collapse Block');
75+
await contextMenuSelect(this.browser, this.block, 'Collapse Block');
7676
chai.assert.isTrue(await getIsCollapsed(this.browser, this.block.id));
7777
});
7878

7979
// Assumes that
8080
test('clicking the expand option expands the block', async function () {
81-
await contextMenuSelect(this.browser, this.block.id, 'Expand Block');
81+
await contextMenuSelect(this.browser, this.block, 'Expand Block');
8282
chai.assert.isFalse(await getIsCollapsed(this.browser, this.block.id));
8383
});
8484

8585
test('clicking the disable option disables the block', async function () {
86-
await contextMenuSelect(this.browser, this.block.id, 'Disable Block');
86+
await contextMenuSelect(this.browser, this.block, 'Disable Block');
8787
chai.assert.isTrue(await getIsDisabled(this.browser, this.block.id));
8888
});
8989

9090
test('clicking the enable option enables the block', async function () {
91-
await contextMenuSelect(this.browser, this.block.id, 'Enable Block');
91+
await contextMenuSelect(this.browser, this.block, 'Enable Block');
9292
chai.assert.isFalse(await getIsDisabled(this.browser, this.block.id));
9393
});
9494

9595
test('clicking the add comment option adds a comment to the block', async function () {
96-
await contextMenuSelect(this.browser, this.block.id, 'Add Comment');
96+
await contextMenuSelect(this.browser, this.block, 'Add Comment');
9797
chai.assert.equal(await getCommentText(this.browser, this.block.id), '');
9898
});
9999

100100
test('clicking the remove comment option removes a comment from the block', async function () {
101-
await contextMenuSelect(this.browser, this.block.id, 'Remove Comment');
101+
await contextMenuSelect(this.browser, this.block, 'Remove Comment');
102102
chai.assert.isNull(await getCommentText(this.browser, this.block.id));
103103
});
104104
});
@@ -138,7 +138,7 @@ suite('Disabling', function () {
138138
);
139139
await connect(this.browser, child, 'OUTPUT', parent, 'IF0');
140140

141-
await contextMenuSelect(this.browser, parent.id, 'Disable Block');
141+
await contextMenuSelect(this.browser, parent, 'Disable Block');
142142

143143
chai.assert.isTrue(await getIsDisabled(this.browser, child.id));
144144
},
@@ -164,7 +164,7 @@ suite('Disabling', function () {
164164
);
165165
await connect(this.browser, child, 'PREVIOUS', parent, 'DO0');
166166

167-
await contextMenuSelect(this.browser, parent.id, 'Disable Block');
167+
await contextMenuSelect(this.browser, parent, 'Disable Block');
168168

169169
chai.assert.isTrue(await getIsDisabled(this.browser, child.id));
170170
},
@@ -190,7 +190,7 @@ suite('Disabling', function () {
190190
);
191191
await connect(this.browser, child, 'PREVIOUS', parent, 'NEXT');
192192

193-
await contextMenuSelect(this.browser, parent.id, 'Disable Block');
193+
await contextMenuSelect(this.browser, parent, 'Disable Block');
194194

195195
chai.assert.isFalse(await getIsDisabled(this.browser, child.id));
196196
},

tests/browser/test/delete_blocks_test.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const {
1010
testFileLocations,
1111
getAllBlocks,
1212
getBlockElementById,
13-
getClickableBlockElementById,
13+
getClickableBlockElement,
1414
contextMenuSelect,
1515
PAUSE_TIME,
1616
} = require('./test_setup');
@@ -131,14 +131,15 @@ suite('Delete blocks', function (done) {
131131
(await getBlockElementById(this.browser, firstBlockId)).waitForExist({
132132
timeout: 2000,
133133
});
134+
this.firstBlock = await getBlockElementById(this.browser, firstBlockId);
134135
});
135136

136137
test('Delete block using backspace key', async function () {
137138
const before = (await getAllBlocks(this.browser)).length;
138139
// Get first print block, click to select it, and delete it using backspace key.
139-
const clickEl = await getClickableBlockElementById(
140+
const clickEl = await getClickableBlockElement(
140141
this.browser,
141-
firstBlockId,
142+
this.firstBlock,
142143
);
143144
await clickEl.click();
144145
await this.browser.keys([Key.Backspace]);
@@ -153,9 +154,9 @@ suite('Delete blocks', function (done) {
153154
test('Delete block using delete key', async function () {
154155
const before = (await getAllBlocks(this.browser)).length;
155156
// Get first print block, click to select it, and delete it using delete key.
156-
const clickEl = await getClickableBlockElementById(
157+
const clickEl = await getClickableBlockElement(
157158
this.browser,
158-
firstBlockId,
159+
this.firstBlock,
159160
);
160161
await clickEl.click();
161162
await this.browser.keys([Key.Delete]);
@@ -170,7 +171,7 @@ suite('Delete blocks', function (done) {
170171
test('Delete block using context menu', async function () {
171172
const before = (await getAllBlocks(this.browser)).length;
172173
// Get first print block, click to select it, and delete it using context menu.
173-
await contextMenuSelect(this.browser, firstBlockId, 'Delete 2 Blocks');
174+
await contextMenuSelect(this.browser, this.firstBlock, 'Delete 2 Blocks');
174175
const after = (await getAllBlocks(this.browser)).length;
175176
chai.assert.equal(
176177
before - 2,
@@ -182,9 +183,9 @@ suite('Delete blocks', function (done) {
182183
test('Undo block deletion', async function () {
183184
const before = (await getAllBlocks(this.browser)).length;
184185
// Get first print block, click to select it, and delete it using backspace key.
185-
const clickEl = await getClickableBlockElementById(
186+
const clickEl = await getClickableBlockElement(
186187
this.browser,
187-
firstBlockId,
188+
this.firstBlock,
188189
);
189190
await clickEl.click();
190191
await this.browser.keys([Key.Backspace]);
@@ -202,9 +203,9 @@ suite('Delete blocks', function (done) {
202203
test('Redo block deletion', async function () {
203204
const before = (await getAllBlocks(this.browser)).length;
204205
// Get first print block, click to select it, and delete it using backspace key.
205-
const clickEl = await getClickableBlockElementById(
206+
const clickEl = await getClickableBlockElement(
206207
this.browser,
207-
firstBlockId,
208+
this.firstBlock,
208209
);
209210
await clickEl.click();
210211
await this.browser.keys([Key.Backspace]);

tests/browser/test/test_setup.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ async function getBlockElementById(browser, id) {
162162
* (e.g. statement inputs). Instead, this tries to get the first text field on the
163163
* block. It falls back on the block's SVG root.
164164
* @param browser The active WebdriverIO Browser object.
165-
* @param id The ID of the Blockly block to search for.
165+
* @param block The block to click, as an interactable element.
166166
* @return A Promise that resolves to the text element of the first label
167167
* field on the block, or the block's SVG root if no label field was found.
168168
*/
169-
async function getClickableBlockElementById(browser, id) {
169+
async function getClickableBlockElement(browser, block) {
170170
// In the browser context, find the element that we want and give it a findable ID.
171171
await browser.execute((blockId) => {
172172
const block = Blockly.getMainWorkspace().getBlockById(blockId);
@@ -180,7 +180,7 @@ async function getClickableBlockElementById(browser, id) {
180180
}
181181
// No label field found. Fall back to the block's SVG root.
182182
block.getSvgRoot().id = 'clickTargetElement';
183-
}, id);
183+
}, block.id);
184184

185185
// In the test context, get the Webdriverio Element that we've identified.
186186
const elem = await browser.$('#clickTargetElement');
@@ -460,13 +460,13 @@ async function dragBlockFromMutatorFlyout(browser, mutatorBlock, type, x, y) {
460460
* context menu item.
461461
*
462462
* @param browser The active WebdriverIO Browser object.
463-
* @param blockId The ID of the block to click. This block should
463+
* @param block The block to click, as an interactable element. This block should
464464
* have text on it, because we use the text element as the click target.
465465
* @param itemText The display text of the context menu item to click.
466466
* @return A Promise that resolves when the actions are completed.
467467
*/
468-
async function contextMenuSelect(browser, blockId, itemText) {
469-
const clickEl = await getClickableBlockElementById(browser, blockId);
468+
async function contextMenuSelect(browser, block, itemText) {
469+
const clickEl = await getClickableBlockElement(browser, block);
470470
// Even though the element should definitely already exist,
471471
// one specific test breaks if you remove this...
472472
await clickEl.waitForExist();
@@ -542,7 +542,7 @@ module.exports = {
542542
getSelectedBlockElement,
543543
getSelectedBlockId,
544544
getBlockElementById,
545-
getClickableBlockElementById,
545+
getClickableBlockElement,
546546
getCategory,
547547
getNthBlockOfCategory,
548548
getBlockTypeFromCategory,

0 commit comments

Comments
 (0)