diff --git a/tests/browser/test/basic_playground_test.js b/tests/browser/test/basic_playground_test.js index 7f9fb3a70..2805be12c 100644 --- a/tests/browser/test/basic_playground_test.js +++ b/tests/browser/test/basic_playground_test.js @@ -13,6 +13,8 @@ const { testSetup, testFileLocations, dragNthBlockFromFlyout, + dragBlockTypeFromFlyout, + connect, contextMenuSelect, } = require('./test_setup'); @@ -22,9 +24,10 @@ async function getIsCollapsed(browser, blockId) { }, blockId); } -async function getIsEnabled(browser, blockId) { +async function getIsDisabled(browser, blockId) { return await browser.execute((blockId) => { - return Blockly.getMainWorkspace().getBlockById(blockId).isEnabled(); + const block = Blockly.getMainWorkspace().getBlockById(blockId); + return !block.isEnabled() || block.getInheritedDisabled(); }, blockId); } @@ -35,7 +38,7 @@ async function getCommentText(browser, blockId) { } let browser; -suite('Testing Connecting Blocks', function (done) { +suite('Testing Connecting Blocks', function () { // Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test this.timeout(0); @@ -74,7 +77,7 @@ suite('Testing Connecting Blocks', function (done) { * These tests have to run together. Each test acts on the state left by the * previous test, and each test has a single assertion. */ -suite('Right Clicking on Blocks', function (done) { +suite('Right Clicking on Blocks', function () { // Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test this.timeout(0); @@ -87,39 +90,33 @@ suite('Right Clicking on Blocks', function (done) { test('clicking the collapse option collapses the block', async function () { await contextMenuSelect(browser, this.block, 'Collapse Block'); - const isCollapsed = await getIsCollapsed(browser, this.blockId); - chai.assert.isTrue(isCollapsed); + chai.assert.isTrue(await getIsCollapsed(browser, this.blockId)); }); // Assumes that test('clicking the expand option expands the block', async function () { await contextMenuSelect(browser, this.block, 'Expand Block'); - const isCollapsed = await getIsCollapsed(browser, this.blockId); - chai.assert.isFalse(isCollapsed); + chai.assert.isFalse(await getIsCollapsed(browser, this.blockId)); }); test('clicking the disable option disables the block', async function () { await contextMenuSelect(browser, this.block, 'Disable Block'); - const isEnabled = await getIsEnabled(browser, this.blockId); - chai.assert.isFalse(isEnabled); + chai.assert.isTrue(await getIsDisabled(browser, this.blockId)); }); test('clicking the enable option enables the block', async function () { await contextMenuSelect(browser, this.block, 'Enable Block'); - const isEnabled = await getIsEnabled(browser, this.block.id); - chai.assert.isTrue(isEnabled); + chai.assert.isFalse(await getIsDisabled(browser, this.block.id)); }); test('clicking the add comment option adds a comment to the block', async function () { await contextMenuSelect(browser, this.block, 'Add Comment'); - const commentText = await getCommentText(browser, this.block.id); - chai.assert.equal(commentText, ''); + chai.assert.equal(await getCommentText(browser, this.block.id), ''); }); test('clicking the remove comment option removes a comment from the block', async function () { await contextMenuSelect(browser, this.block, 'Remove Comment'); - const commentText = await getCommentText(browser, this.block.id); - chai.assert.isNull(commentText); + chai.assert.isNull(await getCommentText(browser, this.block.id)); }); // Teardown entire suite after test are done running @@ -127,3 +124,99 @@ suite('Right Clicking on Blocks', function (done) { await browser.deleteSession(); }); }); + +suite('Disabling', function () { + // Setting timeout to unlimited as the webdriver takes a longer + // time to run than most mocha tests. + this.timeout(0); + + suiteSetup(async function () { + browser = await testSetup(testFileLocations.PLAYGROUND); + }); + + setup(async function () { + await browser.refresh(); + }); + + test( + 'children connected to value inputs are disabled when the ' + + 'parent is diabled', + async function () { + const parent = await dragBlockTypeFromFlyout( + browser, + 'Logic', + 'controls_if', + 10, + 10 + ); + const child = await dragBlockTypeFromFlyout( + browser, + 'Logic', + 'logic_boolean', + 110, + 110 + ); + await connect(browser, child, 'OUTPUT', parent, 'IF0'); + + await contextMenuSelect(browser, parent, 'Disable Block'); + + chai.assert.isTrue(await getIsDisabled(browser, child.id)); + } + ); + + test( + 'children connected to statement inputs are disabled when the ' + + 'parent is disabled', + async function () { + const parent = await dragBlockTypeFromFlyout( + browser, + 'Logic', + 'controls_if', + 10, + 10 + ); + const child = await dragBlockTypeFromFlyout( + browser, + 'Logic', + 'controls_if', + 110, + 110 + ); + await connect(browser, child, 'PREVIOUS', parent, 'IF0'); + + await contextMenuSelect(browser, parent, 'Disable Block'); + + chai.assert.isTrue(await getIsDisabled(browser, child.id)); + } + ); + + test( + 'children connected to next connections are not disabled when the ' + + 'parent is disabled', + async function () { + const parent = await dragBlockTypeFromFlyout( + browser, + 'Logic', + 'controls_if', + 10, + 10 + ); + const child = await dragBlockTypeFromFlyout( + browser, + 'Logic', + 'controls_if', + 110, + 110 + ); + await connect(browser, child, 'PREVIOUS', parent, 'NEXT'); + + await contextMenuSelect(browser, parent, 'Disable Block'); + + chai.assert.isFalse(await getIsDisabled(browser, child.id)); + } + ); + + suiteTeardown(async function () { + await browser.deleteSession(); + }); +}); diff --git a/tests/browser/test/test_setup.js b/tests/browser/test/test_setup.js index 6797b47ac..c25073cf4 100644 --- a/tests/browser/test/test_setup.js +++ b/tests/browser/test/test_setup.js @@ -338,11 +338,20 @@ async function dragBlockTypeFromFlyout(browser, categoryName, type, x, y) { * @return A Promise that resolves when the actions are completed. */ async function contextMenuSelect(browser, block, itemText) { - await block.click({button: 2}); - await browser.pause(200); + // Clicking will always happen in the middle of the block's bounds + // (including children) by default, which causes problems if it has holes + // (e.g. statement inputs). + // Instead we want to click 20% from the right and 5% from the top. + const xOffset = -Math.round((await block.getSize('width')) * 0.3); + const yOffset = -Math.round((await block.getSize('height')) * 0.45); + + await block.click({button: 2, x: xOffset, y: yOffset}); + await browser.pause(100); + const item = await browser.$(`div=${itemText}`); await item.click(); - await browser.pause(200); + + await browser.pause(100); } /** @@ -375,10 +384,10 @@ module.exports = { getNthBlockOfCategory, getBlockTypeFromCategory, dragNthBlockFromFlyout, + dragBlockTypeFromFlyout, connect, switchRTL, contextMenuSelect, - dragBlockTypeFromFlyout, screenDirection, getBlockTypeFromWorkspace, getAllBlocks,