Skip to content

Commit

Permalink
feat(tests): add right-click tests and helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-fenichel committed Jul 7, 2023
1 parent 34f583f commit 7e9c4ec
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
64 changes: 47 additions & 17 deletions tests/browser/test/basic_playground_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
testSetup,
testFileLocations,
dragNthBlockFromFlyout,
contextMenuSelect,
} = require('./test_setup');

let browser;
Expand Down Expand Up @@ -61,45 +62,74 @@ suite('Right Clicking on Blocks', function (done) {
});

test('Collapse', async function () {
await browser.refresh();
const block = await dragNthBlockFromFlyout(browser, 'Loops', 0, 20, 20);
await block.click({button: 2});
await new Promise((resolve) => setTimeout(resolve, 2000)); // 2 sec

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

const collapse = await browser.$('div=Collapse Block');
await collapse.click();

await new Promise((resolve) => setTimeout(resolve, 2000)); // 2 sec
await contextMenuSelect(browser, block, 'Collapse Block');

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

chai.assert.isTrue(isCollapsed);
// TODO: assert that the text of the block is correct, maybe.
});

test('Expand', async function () {
// Drag out block
// Right click
// Collapse
// Right click
// Expand
// Verify expanded
await browser.refresh();
const block = await dragNthBlockFromFlyout(browser, 'Loops', 0, 20, 20);

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

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

test('Disable', async function () {
await browser.refresh();
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);
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);
chai.assert.isFalse(isEnabled);
});

test('Disable', async function () {});
test('Enable', async function () {
await browser.refresh();
const block = await dragNthBlockFromFlyout(browser, 'Loops', 0, 20, 20);

const blockId = block.id;
await contextMenuSelect(browser, block, 'Disable Block');
await contextMenuSelect(browser, block, 'Enable Block');

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

test('Add Comment', async function () {});
chai.assert.isTrue(isEnabled);
});

test('Remove Comment', async function () {});
// Teardown entire suite after test are done running
suiteTeardown(async function () {
await browser.deleteSession();
Expand Down
9 changes: 9 additions & 0 deletions tests/browser/test/test_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ async function dragNthBlockFromFlyout(browser, categoryName, n, x, y) {
return await getSelectedBlockElement(browser);
}

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

module.exports = {
testSetup,
testFileLocations,
Expand All @@ -219,4 +227,5 @@ module.exports = {
getBlockTypeFromCategory,
dragNthBlockFromFlyout,
connect,
contextMenuSelect,
};

0 comments on commit 7e9c4ec

Please sign in to comment.