Skip to content

Commit

Permalink
chore(tests): respond to review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-fenichel committed Jul 10, 2023
1 parent 7e9c4ec commit d873fad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
37 changes: 18 additions & 19 deletions tests/browser/test/basic_playground_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ const {
contextMenuSelect,
} = require('./test_setup');

async function getIsCollapsed(browser, blockId) {
return await browser.execute((blockId) => {
return Blockly.getMainWorkspace().getBlockById(blockId).isCollapsed();
}, blockId);
}

async function getIsEnabled(browser, blockId) {
return await browser.execute((blockId) => {
return Blockly.getMainWorkspace().getBlockById(blockId).isEnabled();
}, blockId);
}

let browser;
suite('Testing Connecting Blocks', function (done) {
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test
Expand Down Expand Up @@ -66,16 +78,12 @@ suite('Right Clicking on Blocks', function (done) {
const block = await dragNthBlockFromFlyout(browser, 'Loops', 0, 20, 20);

const blockId = block.id;
let isCollapsed = await browser.execute((blockId) => {
return Blockly.getMainWorkspace().getBlockById(blockId).isCollapsed();
}, blockId);
let isCollapsed = await getIsCollapsed(browser, blockId);
chai.assert.isFalse(isCollapsed);

await contextMenuSelect(browser, block, 'Collapse Block');

isCollapsed = await browser.execute((blockId) => {
return Blockly.getMainWorkspace().getBlockById(blockId).isCollapsed();
}, blockId);
isCollapsed = await getIsCollapsed(browser, blockId);

chai.assert.isTrue(isCollapsed);
});
Expand All @@ -89,9 +97,7 @@ suite('Right Clicking on Blocks', function (done) {

// Verify.
const blockId = block.id;
const isCollapsed = await browser.execute((blockId) => {
return Blockly.getMainWorkspace().getBlockById(blockId).isCollapsed();
}, blockId);
const isCollapsed = await getIsCollapsed(browser, blockId);
chai.assert.isFalse(isCollapsed);
});

Expand All @@ -100,18 +106,14 @@ suite('Right Clicking on Blocks', function (done) {
const block = await dragNthBlockFromFlyout(browser, 'Loops', 0, 20, 20);

const blockId = block.id;
let isEnabled = await browser.execute((blockId) => {
return Blockly.getMainWorkspace().getBlockById(blockId).isEnabled();
}, blockId);
let isEnabled = await getIsEnabled(browser, blockId);
chai.assert.isTrue(isEnabled);

await contextMenuSelect(browser, block, 'Disable Block');

await new Promise((resolve) => setTimeout(resolve, 2000)); // 2 sec

isEnabled = await browser.execute((blockId) => {
return Blockly.getMainWorkspace().getBlockById(blockId).isEnabled();
}, blockId);
isEnabled = await getIsEnabled(browser, blockId);
chai.assert.isFalse(isEnabled);
});

Expand All @@ -123,10 +125,7 @@ suite('Right Clicking on Blocks', function (done) {
await contextMenuSelect(browser, block, 'Disable Block');
await contextMenuSelect(browser, block, 'Enable Block');

const isEnabled = await browser.execute((blockId) => {
return Blockly.getMainWorkspace().getBlockById(blockId).isEnabled();
}, blockId);

const isEnabled = await getIsEnabled(browser, blockId);
chai.assert.isTrue(isEnabled);
});

Expand Down
20 changes: 16 additions & 4 deletions tests/browser/test/test_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,30 @@ async function connect(

async function dragNthBlockFromFlyout(browser, categoryName, n, x, y) {
const flyoutBlock = await getNthBlockOfCategory(browser, categoryName, n);
await new Promise((resolve) => setTimeout(resolve, 2000)); // 2 sec
await browser.pause(2000);
await flyoutBlock.dragAndDrop({x: x, y: y});
await new Promise((resolve) => setTimeout(resolve, 2000)); // 2 sec
await browser.pause(2000);
return await getSelectedBlockElement(browser);
}

async function dragBlockTypeFromFlyout(browser, categoryName, type, x, y) {
const flyoutBlock = await getBlockTypeFromCategory(
browser,
categoryName,
type
);
await browser.pause(2000);
await flyoutBlock.dragAndDrop({x: x, y: y});
await browser.pause(2000);
return await getSelectedBlockElement(browser);
}

async function contextMenuSelect(browser, block, itemText) {
await block.click({button: 2});
await new Promise((resolve) => setTimeout(resolve, 2000)); // 2 sec
await browser.pause(2000);
const item = await browser.$(`div=${itemText}`);
await item.click();
await new Promise((resolve) => setTimeout(resolve, 2000)); // 2 sec
await browser.pause(2000);
}

module.exports = {
Expand Down

0 comments on commit d873fad

Please sign in to comment.