Skip to content

Commit

Permalink
Merge branch 'google:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnesky authored Aug 4, 2023
2 parents c52b7e1 + 2ac13b5 commit d6dc413
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 83 deletions.
5 changes: 3 additions & 2 deletions core/flyout_horizontal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {FlyoutButton} from './flyout_button.js';
import type {Options} from './options.js';
import * as registry from './registry.js';
import {Scrollbar} from './scrollbar.js';
import type {Coordinate} from './utils/coordinate.js';
import {Coordinate} from './utils/coordinate.js';
import {Rect} from './utils/rect.js';
import * as toolbox from './utils/toolbox.js';
import * as WidgetDiv from './widgetdiv.js';
Expand Down Expand Up @@ -285,7 +285,8 @@ export class HorizontalFlyout extends Flyout {
} else {
moveX = cursorX - tab;
}
block!.moveBy(moveX, cursorY);
// No 'reason' provided since events are disabled.
block!.moveTo(new Coordinate(moveX, cursorY));

const rect = this.createRect_(block!, moveX, cursorY, blockHW, i);
cursorX += blockHW.width + gaps[i];
Expand Down
8 changes: 5 additions & 3 deletions core/flyout_vertical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {FlyoutButton} from './flyout_button.js';
import type {Options} from './options.js';
import * as registry from './registry.js';
import {Scrollbar} from './scrollbar.js';
import type {Coordinate} from './utils/coordinate.js';
import {Coordinate} from './utils/coordinate.js';
import {Rect} from './utils/rect.js';
import * as toolbox from './utils/toolbox.js';
import * as WidgetDiv from './widgetdiv.js';
Expand Down Expand Up @@ -246,7 +246,8 @@ export class VerticalFlyout extends Flyout {
const moveX = block!.outputConnection
? cursorX - this.tabWidth_
: cursorX;
block!.moveBy(moveX, cursorY);
// No 'reason' provided since events are disabled.
block!.moveTo(new Coordinate(moveX, cursorY));

const rect = this.createRect_(
block!,
Expand Down Expand Up @@ -357,7 +358,8 @@ export class VerticalFlyout extends Flyout {
if (!block.outputConnection) {
newX -= this.tabWidth_;
}
block.moveBy(newX - oldX, 0);
// No 'reason' provided since events are disabled.
block.moveTo(new Coordinate(newX - oldX, 0));
}
if (this.rectMap_.has(block)) {
this.moveRectToBlock_(this.rectMap_.get(block)!, block);
Expand Down
16 changes: 16 additions & 0 deletions core/rendered_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,22 @@ export class RenderedConnection extends Connection {
this.sourceBlock_.bumpNeighbours();
}
}

/**
* Change a connection's compatibility.
* Rerender blocks as needed.
*
* @param check Compatible value type or list of value types. Null if all
* types are compatible.
* @returns The connection being modified (to allow chaining).
*/
override setCheck(check: string | string[] | null): RenderedConnection {
super.setCheck(check);
if (this.sourceBlock_.rendered) {
this.sourceBlock_.queueRender();
}
return this;
}
}

export namespace RenderedConnection {
Expand Down
2 changes: 2 additions & 0 deletions core/trashcan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export class Trashcan
setTimeout(() => {
this.flyout?.show(contents);
blocklyStyle.cursor = '';
this.workspace.scrollbar?.setVisible(false);
}, 10);
this.fireUiEvent(true);
}
Expand All @@ -316,6 +317,7 @@ export class Trashcan
return;
}
this.flyout?.hide();
this.workspace.scrollbar?.setVisible(true);
this.fireUiEvent(false);
this.workspace.recordDragTargets();
}
Expand Down
2 changes: 0 additions & 2 deletions core/utils/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export interface BlockInfo {
disabled?: string | boolean;
enabled?: boolean;
id?: string;
x?: number;
y?: number;
collapsed?: boolean;
inline?: boolean;
data?: string;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
"publish:beta": "npm ci && gulp publishBeta",
"recompile": "gulp recompile",
"release": "gulp gitCreateRC",
"start": "npm run build && concurrently -n tsc,server \"tsc --watch --preserveWatchOutput --outDir 'build/src' --declarationDir 'build/declarations'\" \"http-server ./ -s -o /tests/playground.html -c-1\"",
"start": "npm run build && concurrently -n tsc,server \"tsc --watch --preserveWatchOutput --outDir \"build/src\" --declarationDir \"build/declarations\"\" \"http-server ./ -s -o /tests/playground.html -c-1\"",
"tsc": "gulp tsc",
"test": "gulp test",
"test:browser": "npx mocha ./tests/browser/test --config ./tests/browser/test/.mocharc.js",
"test:browser": "cd tests/browser && npx mocha",
"test:generators": "gulp testGenerators",
"test:mocha:interactive": "http-server ./ -o /tests/mocha/index.html -c-1",
"test:compile:advanced": "gulp buildAdvancedCompilationTest --debug",
Expand Down
17 changes: 14 additions & 3 deletions scripts/gulpfiles/build_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const {posixPath} = require('../helpers');
// Build //
////////////////////////////////////////////////////////////

/**
* Path to the python runtime.
* This will normalize the command across platforms (e.g. python3 on Linux and
* Mac, python on Windows).
*/
const PYTHON = process.platform === 'win32' ? 'python' : 'python3';

/**
* Suffix to add to compiled output files.
*/
Expand Down Expand Up @@ -380,7 +387,7 @@ error message above, try running:
*/
function generateMessages(done) {
// Run js_to_json.py
const jsToJsonCmd = `python3 scripts/i18n/js_to_json.py \
const jsToJsonCmd = `${PYTHON} scripts/i18n/js_to_json.py \
--input_file ${path.join('msg', 'messages.js')} \
--output_dir ${path.join('msg', 'json')} \
--quiet`;
Expand Down Expand Up @@ -418,7 +425,8 @@ function buildLangfiles(done) {
json_files = json_files.filter(file => file.endsWith('json') &&
!(new RegExp(/(keys|synonyms|qqq|constants)\.json$/).test(file)));
json_files = json_files.map(file => path.join('msg', 'json', file));
const createMessagesCmd = `python3 ./scripts/i18n/create_messages.py \

const createMessagesCmd = `${PYTHON} ./scripts/i18n/create_messages.py \
--source_lang_file ${path.join('msg', 'json', 'en.json')} \
--source_synonym_file ${path.join('msg', 'json', 'synonyms.json')} \
--source_constants_file ${path.join('msg', 'json', 'constants.json')} \
Expand Down Expand Up @@ -559,7 +567,10 @@ function getChunkOptions() {
// Figure out which chunk this is by looking for one of the
// known chunk entrypoints in chunkFiles. N.B.: O(n*m). :-(
const chunk = chunks.find(
chunk => chunkFiles.find(f => f.endsWith(path.sep + chunk.entry)));
chunk => chunkFiles.find(f => {
return f.endsWith('/' + chunk.entry.replaceAll('\\', '/'));
}
));
if (!chunk) throw new Error('Unable to identify chunk');

// Replace nicknames with the names we chose.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module.exports = {
ui: 'tdd',
require: 'tests/browser/test/hooks.js',
require: __dirname + '/test/hooks.js',
};
21 changes: 5 additions & 16 deletions tests/browser/test/basic_playground_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,13 @@ suite('Testing Connecting Blocks', function () {
this.browser = await testSetup(testFileLocations.PLAYGROUND);
});

test('Testing Block Flyout', async function () {
const logicButton = await this.browser.$('#blockly-0');
logicButton.click();
const ifDoBlock = await this.browser.$(
'#blocklyDiv > div > svg:nth-child(7) > g > g.blocklyBlockCanvas > g:nth-child(3)',
);
await ifDoBlock.dragAndDrop({x: 20, y: 20});
await this.browser.pause(200);
const blockOnWorkspace = await this.browser.execute(() => {
const newBlock = Blockly.getMainWorkspace().getAllBlocks(false)[0];
if (newBlock.id) {
return true;
} else {
return false;
}
test('dragging a block from the flyout results in a block on the workspace', async function () {
await dragBlockTypeFromFlyout(this.browser, 'Logic', 'controls_if', 20, 20);
const blockCount = await this.browser.execute(() => {
return Blockly.getMainWorkspace().getAllBlocks(false).length;
});

chai.assert.isTrue(blockOnWorkspace);
chai.assert.equal(blockCount, 1);
});
});

Expand Down
23 changes: 8 additions & 15 deletions tests/browser/test/block_undo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,38 @@ const {Key} = require('webdriverio');
const {
testSetup,
testFileLocations,
switchRTL,
dragBlockTypeFromFlyout,
screenDirection,
getAllBlocks,
} = require('./test_setup');

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 () {
this.browser = await testSetup(testFileLocations.PLAYGROUND);
});

test('Undoing Block Movement LTR', async function () {
this.browser = await testSetup(testFileLocations.PLAYGROUND);
await testUndoBlock(this.browser, screenDirection.LTR);
});

test('Undoing Block Movement RTL', async function () {
await switchRTL(this.browser);
this.browser = await testSetup(testFileLocations.PLAYGROUND_RTL);
await testUndoBlock(this.browser, screenDirection.RTL);
});
});

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

await browser.keys([Key.Ctrl, 'z']);

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

chai.assert.isFalse(blockOnWorkspace);
const allBlocks = await getAllBlocks(browser);
chai.assert.equal(allBlocks.length, 0);
}
6 changes: 2 additions & 4 deletions tests/browser/test/delete_blocks_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const startBlocks = {
],
},
};
const pauseLength = 20;
const pauseLength = 200;

suite('Delete blocks', function (done) {
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test
Expand Down Expand Up @@ -167,9 +167,7 @@ suite('Delete blocks', function (done) {
test('Delete block using context menu', async function () {
const before = (await getAllBlocks(this.browser)).length;
// Get first print block, click to select it, and delete it using context menu.
const block = (await getBlockElementById(this.browser, firstBlockId)).$(
'.blocklyPath',
);
const block = await getBlockElementById(this.browser, firstBlockId);
await contextMenuSelect(this.browser, block, 'Delete 2 Blocks');
const after = (await getAllBlocks(this.browser)).length;
chai.assert.equal(
Expand Down
19 changes: 8 additions & 11 deletions tests/browser/test/extensive_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
testSetup,
testFileLocations,
getBlockElementById,
getAllBlocks,
} = require('./test_setup');
const {Key} = require('webdriverio');

Expand All @@ -25,32 +26,28 @@ suite('This tests loading Large Configuration and Deletion', function (done) {
this.browser = await testSetup(testFileLocations.PLAYGROUND);
});

test('This test loading from JSON results in the correct number of blocks', async function () {
test('loading from JSON results in the correct number of blocks', async function () {
const blockNum = await testingJSONLoad(this.browser);
chai.assert.equal(blockNum, 13);
});

test('This test deleting block results in the correct number of blocks', async function () {
test('deleting block results in the correct number of blocks', async function () {
const fourthRepeatDo = await getBlockElementById(
this.browser,
'E8bF[-r:B~cabGLP#QYd',
);
await fourthRepeatDo.click({x: -100, y: -40});
await this.browser.keys([Key.Delete]);
await this.browser.pause(100);
const blockNum = await this.browser.execute(() => {
return Blockly.getMainWorkspace().getAllBlocks(false).length;
});
chai.assert.equal(blockNum, 10);
const allBlocks = await getAllBlocks(this.browser);
chai.assert.equal(allBlocks.length, 10);
});

test('This test undoing delete block results in the correct number of blocks', async function () {
test('undoing delete block results in the correct number of blocks', async function () {
await this.browser.keys([Key.Ctrl, 'z']);
await this.browser.pause(100);
const blockNum = await this.browser.execute(() => {
return Blockly.getMainWorkspace().getAllBlocks(false).length;
});
chai.assert.equal(blockNum, 13);
const allBlocks = await getAllBlocks(this.browser);
chai.assert.equal(allBlocks.length, 13);
});
});

Expand Down
39 changes: 16 additions & 23 deletions tests/browser/test/field_edits_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const chai = require('chai');
const {
testSetup,
testFileLocations,
getSelectedBlockElement,
switchRTL,
dragBlockTypeFromFlyout,
screenDirection,
} = require('./test_setup');
Expand All @@ -23,47 +21,42 @@ 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 () {
this.browser = await testSetup(testFileLocations.PLAYGROUND);
});

test('Testing Field Edits LTR', async function () {
this.browser = await testSetup(testFileLocations.PLAYGROUND);
await testFieldEdits(this.browser, screenDirection.LTR);
});

test('Testing Field Edits RTL', async function () {
await switchRTL(this.browser);
this.browser = await testSetup(testFileLocations.PLAYGROUND_RTL);
await testFieldEdits(this.browser, screenDirection.RTL);
});
});

async function testFieldEdits(browser, delta) {
const mathNumber = await dragBlockTypeFromFlyout(
async function testFieldEdits(browser, direction) {
const numberBlock = await dragBlockTypeFromFlyout(
browser,
'Math',
'math_number',
50 * delta,
50 * direction,
20,
);
await browser.pause(200);

// Click on the field to change the value
const numeric = await getSelectedBlockElement(browser);
await numeric.doubleClick();
await numberBlock.click();
await browser.keys([Key.Delete]);
await numeric.doubleClick();
await numberBlock.click();
await browser.keys(['1093']);
// Click on the workspace
// Click on the workspace to exit the field editor
const workspace = await browser.$('#blocklyDiv > div > svg.blocklySvg > g');
await workspace.click();
await browser.pause(200);
// 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'));
const fieldValue = await browser.execute((id) => {
return Blockly.getMainWorkspace()
.getBlockById(id)
.getField('NUM')
.getValue();
}, numberBlock.id);

chai.assert.equal(fieldValue, '1093');
}
Loading

0 comments on commit d6dc413

Please sign in to comment.