-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create test for undo block movements and editing a field (#7272)
* chore: create test for undo block movements and editing a field * chore: create test for undo block movements and editing a field * chore: create test for undo block movements and editing a field * chore: create test for undo block movements and editing a field * chore: create test for undo block movements and editing a field * chore: create test for undo block movements and editing a field * chore: create test for undo block movements and editing a field * chore: create test for undo block movements and editing a field * chore: create test for undo block movements and editing a field * chore: create test for undo block movements and editing a field * chore: create test for undo block movements and editing a field
- Loading branch information
1 parent
b1045a2
commit cae721e
Showing
3 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* @fileoverview Node.js script to run Automated tests in Chrome, via webdriver. | ||
*/ | ||
|
||
const chai = require('chai'); | ||
const {Key} = require('webdriverio'); | ||
const { | ||
testSetup, | ||
testFileLocations, | ||
switchRTL, | ||
dragBlockTypeFromFlyout, | ||
screenDirection, | ||
} = require('./test_setup'); | ||
|
||
let browser; | ||
suite('Testing undo block movement', function (done) { | ||
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test | ||
this.timeout(0); | ||
|
||
// Setup Selenium for all of the tests | ||
suiteSetup(async function () { | ||
browser = await testSetup(testFileLocations.playground); | ||
}); | ||
|
||
test('Undoing Block Movement LTR', async function () { | ||
await testUndoBlock(screenDirection.LTR); | ||
}); | ||
|
||
test('Undoing Block Movement RTL', async function () { | ||
await switchRTL(browser); | ||
await testUndoBlock(screenDirection.RTL); | ||
}); | ||
|
||
// Teardown entire suite after test are done running | ||
suiteTeardown(async function () { | ||
await browser.deleteSession(); | ||
}); | ||
}); | ||
|
||
async function testUndoBlock(delta) { | ||
// Drag out first function | ||
const defReturnBlock = await dragBlockTypeFromFlyout( | ||
browser, | ||
'Functions', | ||
'procedures_defreturn', | ||
50 * delta, | ||
20 | ||
); | ||
|
||
await browser.keys([Key.Ctrl, 'z']); | ||
|
||
const blockOnWorkspace = await browser.execute(() => { | ||
return !!Blockly.getMainWorkspace().getAllBlocks(false)[0]; | ||
}); | ||
|
||
chai.assert.isFalse(blockOnWorkspace); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* @fileoverview Node.js script to run Automated tests in Chrome, via webdriver. | ||
*/ | ||
|
||
const chai = require('chai'); | ||
const { | ||
testSetup, | ||
testFileLocations, | ||
getSelectedBlockElement, | ||
switchRTL, | ||
dragBlockTypeFromFlyout, | ||
screenDirection, | ||
} = require('./test_setup'); | ||
const {Key} = require('webdriverio'); | ||
|
||
let browser; | ||
suite('Testing Field Edits', function (done) { | ||
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test | ||
this.timeout(0); | ||
|
||
// Setup Selenium for all of the tests | ||
suiteSetup(async function () { | ||
browser = await testSetup(testFileLocations.playground); | ||
}); | ||
|
||
test('Testing Field Edits LTR', async function () { | ||
await testFieldEdits(screenDirection.LTR); | ||
}); | ||
|
||
test('Testing Field Edits RTL', async function () { | ||
switchRTL(browser); | ||
await testFieldEdits(screenDirection.RTL); | ||
}); | ||
|
||
// Teardown entire suite after test are done running | ||
suiteTeardown(async function () { | ||
await browser.deleteSession(); | ||
}); | ||
}); | ||
|
||
async function testFieldEdits(delta) { | ||
const mathNumber = await dragBlockTypeFromFlyout( | ||
browser, | ||
'Math', | ||
'math_number', | ||
50 * delta, | ||
20 | ||
); | ||
await browser.pause(2000); | ||
|
||
// Click on the field to change the value | ||
const numeric = await getSelectedBlockElement(browser); | ||
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 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('1093')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters