mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
Fix procedure tests
This commit is contained in:
@@ -11,10 +11,8 @@
|
|||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import {
|
import {
|
||||||
connect,
|
connect,
|
||||||
getBlockTypeFromCategory,
|
dragBlockTypeFromFlyout,
|
||||||
getDraggableBlockElementByType,
|
dragNthBlockFromFlyout,
|
||||||
getNthBlockOfCategory,
|
|
||||||
getSelectedBlockElement,
|
|
||||||
PAUSE_TIME,
|
PAUSE_TIME,
|
||||||
testFileLocations,
|
testFileLocations,
|
||||||
testSetup,
|
testSetup,
|
||||||
@@ -34,43 +32,41 @@ suite('Testing Connecting Blocks', function (done) {
|
|||||||
|
|
||||||
test('Testing Procedure', async function () {
|
test('Testing Procedure', async function () {
|
||||||
// Drag out first function
|
// Drag out first function
|
||||||
let proceduresDefReturn = await getDraggableBlockElementByType(
|
const doSomething = await dragBlockTypeFromFlyout(
|
||||||
this.browser,
|
this.browser,
|
||||||
'Functions',
|
'Functions',
|
||||||
'procedures_defreturn',
|
'procedures_defreturn',
|
||||||
|
50,
|
||||||
|
20,
|
||||||
);
|
);
|
||||||
await proceduresDefReturn.dragAndDrop({x: 50, y: 20});
|
|
||||||
const doSomething = await getSelectedBlockElement(this.browser);
|
|
||||||
|
|
||||||
// Drag out second function.
|
const doSomething2 = await dragBlockTypeFromFlyout(
|
||||||
proceduresDefReturn = await getDraggableBlockElementByType(
|
|
||||||
this.browser,
|
this.browser,
|
||||||
'Functions',
|
'Functions',
|
||||||
'procedures_defreturn',
|
'procedures_defreturn',
|
||||||
|
50,
|
||||||
|
20,
|
||||||
);
|
);
|
||||||
await proceduresDefReturn.dragAndDrop({x: 50, y: 20});
|
|
||||||
const doSomething2 = await getSelectedBlockElement(this.browser);
|
|
||||||
|
|
||||||
// Drag out numeric
|
const numeric = await dragBlockTypeFromFlyout(
|
||||||
const mathNumeric = await getBlockTypeFromCategory(
|
|
||||||
this.browser,
|
this.browser,
|
||||||
'Math',
|
'Math',
|
||||||
'math_number',
|
'math_number',
|
||||||
|
50,
|
||||||
|
20,
|
||||||
);
|
);
|
||||||
await mathNumeric.dragAndDrop({x: 50, y: 20});
|
|
||||||
const numeric = await getSelectedBlockElement(this.browser);
|
|
||||||
|
|
||||||
// Connect numeric to first procedure
|
// Connect numeric to first procedure
|
||||||
await connect(this.browser, numeric, 'OUTPUT', doSomething, 'RETURN');
|
await connect(this.browser, numeric, 'OUTPUT', doSomething, 'RETURN');
|
||||||
|
|
||||||
// Drag out doSomething caller from flyout.
|
// Drag out doSomething caller from flyout.
|
||||||
const doSomethingFlyout = await getNthBlockOfCategory(
|
const doSomethingCaller = await dragNthBlockFromFlyout(
|
||||||
this.browser,
|
this.browser,
|
||||||
'Functions',
|
'Functions',
|
||||||
3,
|
3,
|
||||||
|
50,
|
||||||
|
20,
|
||||||
);
|
);
|
||||||
await doSomethingFlyout.dragAndDrop({x: 50, y: 20});
|
|
||||||
const doSomethingCaller = await getSelectedBlockElement(this.browser);
|
|
||||||
|
|
||||||
// Connect the doSomething caller to doSomething2
|
// Connect the doSomething caller to doSomething2
|
||||||
await connect(
|
await connect(
|
||||||
@@ -82,22 +78,22 @@ suite('Testing Connecting Blocks', function (done) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Drag out print from flyout.
|
// Drag out print from flyout.
|
||||||
const printFlyout = await getBlockTypeFromCategory(
|
const print = await dragBlockTypeFromFlyout(
|
||||||
this.browser,
|
this.browser,
|
||||||
'Text',
|
'Text',
|
||||||
'text_print',
|
'text_print',
|
||||||
|
50,
|
||||||
|
0,
|
||||||
);
|
);
|
||||||
await printFlyout.dragAndDrop({x: 50, y: 0});
|
|
||||||
const print = await getSelectedBlockElement(this.browser);
|
|
||||||
|
|
||||||
// Drag out doSomething2 caller from flyout.
|
// Drag out doSomething2 caller from flyout.
|
||||||
const doSomething2Flyout = await getNthBlockOfCategory(
|
const doSomething2Caller = await dragNthBlockFromFlyout(
|
||||||
this.browser,
|
this.browser,
|
||||||
'Functions',
|
'Functions',
|
||||||
4,
|
4,
|
||||||
|
50,
|
||||||
|
20,
|
||||||
);
|
);
|
||||||
await doSomething2Flyout.dragAndDrop({x: 50, y: 20});
|
|
||||||
const doSomething2Caller = await getSelectedBlockElement(this.browser);
|
|
||||||
|
|
||||||
// Connect doSomething2 caller with print.
|
// Connect doSomething2 caller with print.
|
||||||
await connect(this.browser, doSomething2Caller, 'OUTPUT', print, 'TEXT');
|
await connect(this.browser, doSomething2Caller, 'OUTPUT', print, 'TEXT');
|
||||||
@@ -107,7 +103,7 @@ suite('Testing Connecting Blocks', function (done) {
|
|||||||
runButton.click();
|
runButton.click();
|
||||||
await this.browser.pause(PAUSE_TIME);
|
await this.browser.pause(PAUSE_TIME);
|
||||||
const alertText = await this.browser.getAlertText(); // get the alert text
|
const alertText = await this.browser.getAlertText(); // get the alert text
|
||||||
chai.assert.equal(alertText, '123');
|
chai.assert.equal(alertText, 'abc');
|
||||||
await this.browser.acceptAlert();
|
await this.browser.acceptAlert();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ export async function clickBlock(browser, blockId, clickOptions) {
|
|||||||
* @return A Promise that resolves when the actions are completed.
|
* @return A Promise that resolves when the actions are completed.
|
||||||
*/
|
*/
|
||||||
export async function clickWorkspace(browser) {
|
export async function clickWorkspace(browser) {
|
||||||
const workspace = await browser.$('#blocklyDiv > div > svg.blocklySvg > g');
|
const workspace = await browser.$('svg.blocklySvg > g');
|
||||||
await workspace.click();
|
await workspace.click();
|
||||||
await browser.pause(PAUSE_TIME);
|
await browser.pause(PAUSE_TIME);
|
||||||
}
|
}
|
||||||
@@ -499,6 +499,9 @@ export async function switchRTL(browser) {
|
|||||||
*/
|
*/
|
||||||
export async function dragNthBlockFromFlyout(browser, categoryName, n, x, y) {
|
export async function dragNthBlockFromFlyout(browser, categoryName, n, x, y) {
|
||||||
const flyoutBlock = await getNthBlockOfCategory(browser, categoryName, n);
|
const flyoutBlock = await getNthBlockOfCategory(browser, categoryName, n);
|
||||||
|
while (!(await elementInBounds(browser, flyoutBlock))) {
|
||||||
|
await scrollFlyout(browser, 0, 50);
|
||||||
|
}
|
||||||
await flyoutBlock.dragAndDrop({x: x, y: y});
|
await flyoutBlock.dragAndDrop({x: x, y: y});
|
||||||
return await getSelectedBlockElement(browser);
|
return await getSelectedBlockElement(browser);
|
||||||
}
|
}
|
||||||
@@ -525,15 +528,44 @@ export async function dragBlockTypeFromFlyout(
|
|||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
) {
|
) {
|
||||||
const flyoutBlock = await getBlockTypeFromCategory(
|
const flyoutBlock = await getDraggableBlockElementByType(
|
||||||
browser,
|
browser,
|
||||||
categoryName,
|
categoryName,
|
||||||
type,
|
type,
|
||||||
);
|
);
|
||||||
|
while (!(await elementInBounds(browser, flyoutBlock))) {
|
||||||
|
await scrollFlyout(browser, 0, 50);
|
||||||
|
}
|
||||||
await flyoutBlock.dragAndDrop({x: x, y: y});
|
await flyoutBlock.dragAndDrop({x: x, y: y});
|
||||||
|
await browser.pause(PAUSE_TIME);
|
||||||
return await getSelectedBlockElement(browser);
|
return await getSelectedBlockElement(browser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether an element is fully inside the bounds of the Blockly div. You can use this
|
||||||
|
* to determine whether a block on the workspace or flyout is inside the Blockly div.
|
||||||
|
* This does not check whether there are other Blockly elements (such as a toolbox or
|
||||||
|
* flyout) on top of the element. A partially visible block is considered out of bounds.
|
||||||
|
* @param browser The active WebdriverIO Browser object.
|
||||||
|
* @param element The element to look for.
|
||||||
|
* @returns A Promise resolving to true if the element is in bounds and false otherwise.
|
||||||
|
*/
|
||||||
|
async function elementInBounds(browser, element) {
|
||||||
|
return await browser.execute((elem) => {
|
||||||
|
const rect = elem.getBoundingClientRect();
|
||||||
|
|
||||||
|
const blocklyDiv = document.getElementsByClassName('blocklySvg')[0];
|
||||||
|
const blocklyRect = blocklyDiv.getBoundingClientRect();
|
||||||
|
|
||||||
|
const vertInView =
|
||||||
|
rect.top >= blocklyRect.top && rect.bottom <= blocklyRect.bottom;
|
||||||
|
const horInView =
|
||||||
|
rect.left >= blocklyRect.left && rect.right <= blocklyRect.right;
|
||||||
|
|
||||||
|
return vertInView && horInView;
|
||||||
|
}, element);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drags the specified block type from the mutator flyout of the given block
|
* Drags the specified block type from the mutator flyout of the given block
|
||||||
* and returns the root element of the block.
|
* and returns the root element of the block.
|
||||||
|
|||||||
@@ -10,11 +10,10 @@
|
|||||||
|
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import {
|
import {
|
||||||
|
dragBlockTypeFromFlyout,
|
||||||
getCategory,
|
getCategory,
|
||||||
getDraggableBlockElementByType,
|
|
||||||
PAUSE_TIME,
|
PAUSE_TIME,
|
||||||
screenDirection,
|
screenDirection,
|
||||||
scrollFlyout,
|
|
||||||
testFileLocations,
|
testFileLocations,
|
||||||
testSetup,
|
testSetup,
|
||||||
} from './test_setup.mjs';
|
} from './test_setup.mjs';
|
||||||
@@ -57,31 +56,6 @@ const testCategories = [
|
|||||||
'Serialization',
|
'Serialization',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether an element is fully inside the bounds of the Blockly div. You can use this
|
|
||||||
* to determine whether a block on the workspace or flyout is inside the Blockly div.
|
|
||||||
* This does not check whether there are other Blockly elements (such as a toolbox or
|
|
||||||
* flyout) on top of the element. A partially visible block is considered out of bounds.
|
|
||||||
* @param browser The active WebdriverIO Browser object.
|
|
||||||
* @param element The element to look for.
|
|
||||||
* @returns A Promise resolving to true if the element is in bounds and false otherwise.
|
|
||||||
*/
|
|
||||||
async function elementInBounds(browser, element) {
|
|
||||||
return await browser.execute((elem) => {
|
|
||||||
const rect = elem.getBoundingClientRect();
|
|
||||||
|
|
||||||
const blocklyDiv = document.getElementById('blocklyDiv');
|
|
||||||
const blocklyRect = blocklyDiv.getBoundingClientRect();
|
|
||||||
|
|
||||||
const vertInView =
|
|
||||||
rect.top >= blocklyRect.top && rect.bottom <= blocklyRect.bottom;
|
|
||||||
const horInView =
|
|
||||||
rect.left >= blocklyRect.left && rect.right <= blocklyRect.right;
|
|
||||||
|
|
||||||
return vertInView && horInView;
|
|
||||||
}, element);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of the nth block in the specified category.
|
* Get the type of the nth block in the specified category.
|
||||||
* @param browser The active WebdriverIO Browser object.
|
* @param browser The active WebdriverIO Browser object.
|
||||||
@@ -173,15 +147,7 @@ async function openCategories(browser, categoryList, directionMultiplier) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const blockType = await getNthBlockType(browser, categoryName, i);
|
const blockType = await getNthBlockType(browser, categoryName, i);
|
||||||
const flyoutBlock = await getDraggableBlockElementByType(
|
dragBlockTypeFromFlyout(browser, categoryName, blockType, 50, 20);
|
||||||
browser,
|
|
||||||
categoryName,
|
|
||||||
blockType,
|
|
||||||
);
|
|
||||||
while (!(await elementInBounds(browser, flyoutBlock))) {
|
|
||||||
await scrollFlyout(browser, 0, 50);
|
|
||||||
}
|
|
||||||
await flyoutBlock.click();
|
|
||||||
await browser.pause(PAUSE_TIME);
|
await browser.pause(PAUSE_TIME);
|
||||||
// Should be one top level block on the workspace.
|
// Should be one top level block on the workspace.
|
||||||
const topBlockCount = await browser.execute(() => {
|
const topBlockCount = await browser.execute(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user