Skip to content

Commit

Permalink
chore: create test for undo block movements and editing a field
Browse files Browse the repository at this point in the history
  • Loading branch information
ericblackmonGoogle committed Jul 11, 2023
1 parent 00bcd3e commit 7e7a97d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
28 changes: 11 additions & 17 deletions tests/browser/test/block_undo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ const {Key} = require('webdriverio');
const {
testSetup,
testFileLocations,
getSelectedBlockElement,
getNthBlockOfCategory,
getBlockTypeFromCategory,
connect,
switchRTL,
dragBlockTypeFromFlyout,
screenDirection
} = require('./test_setup');

let browser;
Expand All @@ -31,12 +29,12 @@ suite('Testing undo block movement', function (done) {
});

test('Undoing Block Movement LTR', async function () {
await testUndoBlock(1);
await testUndoBlock(screenDirection.ltr);
});

test('Undoing Block Movement RTL', async function () {
await switchRTL(browser);
await testUndoBlock(-1);
await testUndoBlock(screenDirection.rtl);
});

// Teardown entire suite after test are done running
Expand All @@ -47,25 +45,21 @@ suite('Testing undo block movement', function (done) {

async function testUndoBlock(delta) {
// Drag out first function
const proceduresDefReturn = await getBlockTypeFromCategory(
const defReturnBlock = await dragBlockTypeFromFlyout(
browser,
'Functions',
'procedures_defreturn'
'procedures_defreturn',
50*delta,
20
);

// undo the block drag out
await proceduresDefReturn.dragAndDrop({x: 50 * delta, y: 20});
await browser.keys([Key.Ctrl, 'z']);

const blockOnWorkspace = await browser.execute(() => {
const workspaceBlockCheck =
Blockly.getMainWorkspace().getAllBlocks(false)[0];
if (workspaceBlockCheck) {
return true;
} else {
return false;
}
return !!Blockly.getMainWorkspace().getAllBlocks(false)[0];
});

chai.assert.isFalse(blockOnWorkspace);
}


29 changes: 15 additions & 14 deletions tests/browser/test/field_edits_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const {
testSetup,
testFileLocations,
getSelectedBlockElement,
getNthBlockOfCategory,
getBlockTypeFromCategory,
connect,
switchRTL,
dragBlockTypeFromFlyout,
screenDirection
} = require('./test_setup');
const {Key} = require('webdriverio');

let browser;
suite('Testing Field Edits', function (done) {
Expand Down Expand Up @@ -45,30 +45,31 @@ suite('Testing Field Edits', function (done) {
});

async function testFieldEdits(delta) {
const mathNumber = await getBlockTypeFromCategory(
const mathNumber = await dragBlockTypeFromFlyout(
browser,
'Math',
'math_number'
'math_number',
50 * delta,
20
);
await mathNumber.dragAndDrop({x: 50 * delta, y: 20});
await new Promise((resolve) => setTimeout(resolve, 2000)); // 2 sec
await browser.pause(2000)

// Click on the field to change the value
const numeric = await getSelectedBlockElement(browser);
await numeric.click();
await numeric.click();
await browser.keys(['2']);

// Cick on the workspace
await numeric.doubleClick();
await browser.keys([Key.Delete]);
await numeric.doubleClick();
await browser.keys(['1093'],);
// Click on the workspace
const workspace = await browser.$('#blocklyDiv > div > svg.blocklySvg > g');
await workspace.click();
await new Promise((resolve) => setTimeout(resolve, 2000)); // 2 sec
await browser.pause(2000)
// Get value of the number
const numericText = await browser
.$(
'#blocklyDiv > div > svg.blocklySvg > g > g.blocklyBlockCanvas > g.blocklyDraggable > g > text'
)
.getHTML();

chai.assert.isTrue(numericText.includes('1223'));
chai.assert.isTrue(numericText.includes('1093'));
}
8 changes: 7 additions & 1 deletion tests/browser/test/test_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ const testFileLocations = {
playground: 2,
};

const screenDirection = {
rtl:-1,
ltr: 1
}

async function getSelectedBlockId(browser) {
return await browser.execute(() => {
// Note: selected is an ICopyable and I am assuming that it is a BlockSvg.
Expand Down Expand Up @@ -203,7 +208,6 @@ async function connect(
async function switchRTL(browser) {
// Switch to RTL
const ltrForm = await browser.$('#options > select:nth-child(1)');
console.log(await ltrForm.getValue());
await ltrForm.selectByIndex(1);
}
async function dragNthBlockFromFlyout(browser, categoryName, n, x, y) {
Expand Down Expand Up @@ -247,4 +251,6 @@ module.exports = {
connect,
switchRTL,
contextMenuSelect,
dragBlockTypeFromFlyout,
screenDirection
};

0 comments on commit 7e7a97d

Please sign in to comment.