mirror of
https://github.com/google/blockly.git
synced 2026-01-09 18:10:08 +01:00
release: Merge branch 'develop' into rc/v12.0.0
This commit is contained in:
@@ -295,8 +295,8 @@ export class CodeGenerator {
|
||||
* @param name The name of the input.
|
||||
* @param outerOrder The maximum binding strength (minimum order value) of any
|
||||
* operators adjacent to "block".
|
||||
* @returns Generated code or '' if no blocks are connected or the specified
|
||||
* input does not exist.
|
||||
* @returns Generated code or '' if no blocks are connected.
|
||||
* @throws ReferenceError if the specified input does not exist.
|
||||
*/
|
||||
valueToCode(block: Block, name: string, outerOrder: number): string {
|
||||
if (isNaN(outerOrder)) {
|
||||
@@ -381,6 +381,7 @@ export class CodeGenerator {
|
||||
* @param block The block containing the input.
|
||||
* @param name The name of the input.
|
||||
* @returns Generated code or '' if no blocks are connected.
|
||||
* @throws ReferenceError if the specified input does not exist.
|
||||
*/
|
||||
statementToCode(block: Block, name: string): string {
|
||||
const targetBlock = block.getInputTargetBlock(name);
|
||||
|
||||
@@ -77,6 +77,8 @@ export function inject(
|
||||
common.setMainWorkspace(workspace);
|
||||
});
|
||||
|
||||
browserEvents.conditionalBind(subContainer, 'keydown', null, onKeyDown);
|
||||
|
||||
return workspace;
|
||||
}
|
||||
|
||||
@@ -320,8 +322,6 @@ let documentEventsBound = false;
|
||||
* Most of these events should be bound to the SVG's surface.
|
||||
* However, 'mouseup' has to be on the whole document so that a block dragged
|
||||
* out of bounds and released will know that it has been released.
|
||||
* Also, 'keydown' has to be on the whole document since the browser doesn't
|
||||
* understand a concept of focus on the SVG image.
|
||||
*/
|
||||
function bindDocumentEvents() {
|
||||
if (!documentEventsBound) {
|
||||
@@ -333,7 +333,6 @@ function bindDocumentEvents() {
|
||||
}
|
||||
}
|
||||
});
|
||||
browserEvents.conditionalBind(document, 'keydown', null, onKeyDown);
|
||||
// longStop needs to run to stop the context menu from showing up. It
|
||||
// should run regardless of what other touch event handlers have run.
|
||||
browserEvents.bind(document, 'touchend', null, Touch.longStop);
|
||||
|
||||
@@ -85,8 +85,8 @@ Blockly.Blocks['factory_base'] = {
|
||||
var type = this.workspace.newBlock('type_null');
|
||||
type.setShadow(true);
|
||||
type.outputConnection.connect(this.getInput(outputType).connection);
|
||||
type.initSvg();
|
||||
if (this.rendered) {
|
||||
type.initSvg();
|
||||
type.render();
|
||||
}
|
||||
},
|
||||
|
||||
1956
package-lock.json
generated
1956
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -22,17 +22,12 @@
|
||||
"build-debug-log": "npm run build:debug > build-debug.log 2>&1 && tail -3 build-debug.log",
|
||||
"build-strict": "gulp build --verbose --strict",
|
||||
"build-strict-log": "npm run build:strict > build-debug.log 2>&1 && tail -3 build-debug.log",
|
||||
"build:compiled": "exit 1 # Deprecated; use \"npm run minify\" instead.",
|
||||
"build:compressed": "exit 1 # Deprecated; use \"npm run minify\" instead.",
|
||||
"build:js": "exit 1 # Deprecated; use \"npm run tsc\" instead.",
|
||||
"build:langfiles": "exit 1 # Deprecated; use \"npm run langfiles\" instead.",
|
||||
"clean": "gulp clean",
|
||||
"deployDemos": "npm ci && gulp deployDemos",
|
||||
"deployDemos:beta": "npm ci && gulp deployDemosBeta",
|
||||
"docs": "gulp docs",
|
||||
"format": "prettier --write .",
|
||||
"format:check": "prettier --check .",
|
||||
"generate:langfiles": "exit 1 # Deprecated; use \"npm run messages\" instead.",
|
||||
"messages": "gulp messages",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
@@ -113,7 +108,7 @@
|
||||
"@microsoft/api-extractor": "^7.29.5",
|
||||
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
||||
"async-done": "^2.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"chai": "^5.1.1",
|
||||
"concurrently": "^8.0.1",
|
||||
"eslint": "^8.4.1",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
|
||||
162
scripts/migration/cjs2esm
Executable file
162
scripts/migration/cjs2esm
Executable file
@@ -0,0 +1,162 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const filenames = process.argv.slice(2); // Trim off node and script name.
|
||||
|
||||
/** Absolute path of repository root. */
|
||||
const repoPath = path.resolve(__dirname, '..', '..');
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Process files mentioned on the command line.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** RegExp matching require statements. */
|
||||
const requireRE =
|
||||
/(?:const\s+(?:([$\w]+)|(\{[^}]*\}))\s*=\s*)?require\('([^']+)'\);/g;
|
||||
|
||||
/** RegExp matching key: value pairs in destructuring assignments. */
|
||||
const keyValueRE = /([$\w]+)\s*:\s*([$\w]+)\s*(?=,|})/g;
|
||||
|
||||
/** Prefix for RegExp matching a top-level declaration. */
|
||||
const declPrefix = '(?:const|let|var|(?:async\\s+)?function(?:\\s*\\*)?|class)';
|
||||
|
||||
for (const filename of filenames) {
|
||||
let contents = null;
|
||||
try {
|
||||
contents = String(fs.readFileSync(filename));
|
||||
} catch (e) {
|
||||
console.error(`error while reading ${filename}: ${e.message}`);
|
||||
continue;
|
||||
}
|
||||
console.log(`Converting ${filename} from CJS to ESM...`);
|
||||
|
||||
// Remove "use strict".
|
||||
contents = contents.replace(/^\s*["']use strict["']\s*; *\n/m, '');
|
||||
|
||||
// Migrate from require to import.
|
||||
contents = contents.replace(
|
||||
requireRE,
|
||||
function (
|
||||
orig, // Whole statement to be replaced.
|
||||
name, // Name of named import of whole module (if applicable).
|
||||
names, // {}-enclosed list of destructured imports.
|
||||
moduleName, // Imported module name or path.
|
||||
) {
|
||||
if (moduleName[0] === '.') {
|
||||
// Relative path. Could check and add '.mjs' suffix if desired.
|
||||
}
|
||||
if (name) {
|
||||
return `import * as ${name} from '${moduleName}';`;
|
||||
} else if (names) {
|
||||
names = names.replace(keyValueRE, '$1 as $2');
|
||||
return `import ${names} from '${moduleName}';`;
|
||||
} else {
|
||||
// Side-effect only require.
|
||||
return `import '${moduleName}';`;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Find and update or remove old-style single-export assignments
|
||||
// like:
|
||||
//
|
||||
// exports.bar = foo; // becomes export {foo as bar};
|
||||
// exports.foo = foo; // remove the export and export at declaration
|
||||
// // instead, if possible.
|
||||
/** @type {!Array<{name: string, re: RegExp>}>} */
|
||||
const easyExports = [];
|
||||
contents = contents.replace(
|
||||
/^\s*exports\.([$\w]+)\s*=\s*([$\w]+)\s*;\n/gm,
|
||||
function (
|
||||
orig, // Whole statement to be replaced.
|
||||
exportName, // Name to export item as.
|
||||
declName, // Already-declared name for item being exported.
|
||||
) {
|
||||
// Renamed exports have to be translated as-is.
|
||||
if (exportName !== declName) {
|
||||
return `export {${declName} as ${exportName}};\n`;
|
||||
}
|
||||
// OK, we're doing "export.foo = foo;". Can we update the
|
||||
// declaration? We can't actualy modify it yet as we're in
|
||||
// the middle of a search-and-replace on contents already, but
|
||||
// we can delete the old export and later update the
|
||||
// declaration into an export.
|
||||
const declRE = new RegExp(
|
||||
`^(\\s*)(${declPrefix}\\s+${declName})\\b`,
|
||||
'gm',
|
||||
);
|
||||
if (contents.match(declRE)) {
|
||||
easyExports.push({exportName, declRE});
|
||||
return ''; // Delete existing export assignment.
|
||||
} else {
|
||||
return `export ${exportName};\n`; // Safe fallback.
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Find and update or remove old-style module.exports assignment
|
||||
// like:
|
||||
//
|
||||
// module.exports = {foo, bar: baz, quux};
|
||||
//
|
||||
// which becomes export {baz as bar}, with foo and quux exported at
|
||||
// declaration instead, if possible.
|
||||
contents = contents.replace(
|
||||
/^module\.exports\s*=\s*\{([^\}]+)\};?(\n?)/m,
|
||||
function (
|
||||
orig, // Whole statement to be replaced.
|
||||
items, // List of items to be exported.
|
||||
) {
|
||||
items = items.replace(
|
||||
/( *)([$\w]+)\s*(?::\s*([$\w]+)\s*)?,?(\s*?\n?)/gm,
|
||||
function (
|
||||
origItem, // Whole item being replaced.
|
||||
indent, // Optional leading whitespace.
|
||||
exportName, // Name to export item as.
|
||||
declName, // Already-declared name being exported, if different.
|
||||
newline, // Optional trailing whitespace.
|
||||
) {
|
||||
if (!declName) declName = exportName;
|
||||
|
||||
// Renamed exports have to be translated as-is.
|
||||
if (exportName !== declName) {
|
||||
return `${indent}${declName} as ${exportName},${newline}`;
|
||||
}
|
||||
// OK, this item has no rename. Can we update the
|
||||
// declaration? We can't actualy modify it yet as we're in
|
||||
// the middle of a search-and-replace on contents already,
|
||||
// but we can delete the item and later update the
|
||||
// declaration into an export.
|
||||
const declRE = new RegExp(
|
||||
`^(\\s*)(${declPrefix}\\s+${declName})\\b`,
|
||||
'gm',
|
||||
);
|
||||
if (contents.match(declRE)) {
|
||||
easyExports.push({exportName, declRE});
|
||||
return ''; // Delete existing item.
|
||||
} else {
|
||||
return `${indent}${exportName},${newline}`; // Safe fallback.
|
||||
}
|
||||
},
|
||||
);
|
||||
if (/^\s*$/s.test(items)) {
|
||||
// No items left?
|
||||
return ''; // Delete entire module.export assignment.
|
||||
} else {
|
||||
return `export {${items}};\n`;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Add 'export' to existing declarations where appropriate.
|
||||
for (const {exportName, declRE} of easyExports) {
|
||||
contents = contents.replace(declRE, '$1export $2');
|
||||
}
|
||||
|
||||
// Write converted file with new extension.
|
||||
const newFilename = filename.replace(/.c?js$/, '.mjs');
|
||||
fs.writeFileSync(newFilename, contents);
|
||||
console.log(`Wrote ${newFilename}.`);
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
module.exports = {
|
||||
ui: 'tdd',
|
||||
require: __dirname + '/test/hooks.js',
|
||||
require: __dirname + '/test/hooks.mjs',
|
||||
};
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* @fileoverview Node.js script to run Automated tests in Chrome, via webdriver.
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const {testSetup, testFileLocations} = require('./test_setup');
|
||||
import * as chai from 'chai';
|
||||
import {testSetup, testFileLocations} from './test_setup.mjs';
|
||||
|
||||
suite('Testing Connecting Blocks', function (done) {
|
||||
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test
|
||||
@@ -9,14 +9,14 @@
|
||||
* webdriver, of basic Blockly block functionality.
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const {
|
||||
import * as chai from 'chai';
|
||||
import {
|
||||
testSetup,
|
||||
testFileLocations,
|
||||
getAllBlocks,
|
||||
dragNthBlockFromFlyout,
|
||||
} = require('./test_setup');
|
||||
const {Key} = require('webdriverio');
|
||||
} from './test_setup.mjs';
|
||||
import {Key} from 'webdriverio';
|
||||
|
||||
suite('Basic block tests', function (done) {
|
||||
// Setting timeout to unlimited as the webdriver takes a longer time
|
||||
@@ -8,8 +8,8 @@
|
||||
* @fileoverview Node.js script to run Automated tests in Chrome, via webdriver.
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const {
|
||||
import * as chai from 'chai';
|
||||
import {
|
||||
testSetup,
|
||||
testFileLocations,
|
||||
dragNthBlockFromFlyout,
|
||||
@@ -17,7 +17,7 @@ const {
|
||||
connect,
|
||||
contextMenuSelect,
|
||||
PAUSE_TIME,
|
||||
} = require('./test_setup');
|
||||
} from './test_setup.mjs';
|
||||
|
||||
async function getIsCollapsed(browser, blockId) {
|
||||
return await browser.execute((blockId) => {
|
||||
@@ -8,15 +8,15 @@
|
||||
* @fileoverview Node.js script to run Automated tests in Chrome, via webdriver.
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const {Key} = require('webdriverio');
|
||||
const {
|
||||
import * as chai from 'chai';
|
||||
import {Key} from 'webdriverio';
|
||||
import {
|
||||
testSetup,
|
||||
testFileLocations,
|
||||
dragBlockTypeFromFlyout,
|
||||
screenDirection,
|
||||
getAllBlocks,
|
||||
} = require('./test_setup');
|
||||
} from './test_setup.mjs';
|
||||
|
||||
suite('Testing undo block movement', function (done) {
|
||||
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test
|
||||
@@ -4,8 +4,8 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const {
|
||||
import * as chai from 'chai';
|
||||
import {
|
||||
testSetup,
|
||||
testFileLocations,
|
||||
getAllBlocks,
|
||||
@@ -13,8 +13,8 @@ const {
|
||||
clickBlock,
|
||||
contextMenuSelect,
|
||||
PAUSE_TIME,
|
||||
} = require('./test_setup');
|
||||
const {Key} = require('webdriverio');
|
||||
} from './test_setup.mjs';
|
||||
import {Key} from 'webdriverio';
|
||||
|
||||
const firstBlockId = 'root_block';
|
||||
const startBlocks = {
|
||||
@@ -8,15 +8,15 @@
|
||||
* @fileoverview Node.js script to run Automated tests in Chrome, via webdriver.
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const {
|
||||
import * as chai from 'chai';
|
||||
import {
|
||||
testSetup,
|
||||
testFileLocations,
|
||||
getBlockElementById,
|
||||
getAllBlocks,
|
||||
PAUSE_TIME,
|
||||
} = require('./test_setup');
|
||||
const {Key} = require('webdriverio');
|
||||
} from './test_setup.mjs';
|
||||
import {Key} from 'webdriverio';
|
||||
|
||||
suite('This tests loading Large Configuration and Deletion', function (done) {
|
||||
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test
|
||||
@@ -8,15 +8,15 @@
|
||||
* @fileoverview Node.js script to run Automated tests in Chrome, via webdriver.
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const {
|
||||
import * as chai from 'chai';
|
||||
import {
|
||||
testSetup,
|
||||
testFileLocations,
|
||||
dragBlockTypeFromFlyout,
|
||||
screenDirection,
|
||||
clickWorkspace,
|
||||
} = require('./test_setup');
|
||||
const {Key} = require('webdriverio');
|
||||
} from './test_setup.mjs';
|
||||
import {Key} from 'webdriverio';
|
||||
|
||||
suite('Testing Field Edits', function (done) {
|
||||
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test
|
||||
@@ -9,9 +9,9 @@
|
||||
* These create a shared chromedriver instance, so we don't have to fire up
|
||||
* a new one for every suite.
|
||||
*/
|
||||
const {driverSetup, driverTeardown} = require('./test_setup');
|
||||
import {driverSetup, driverTeardown} from './test_setup.mjs';
|
||||
|
||||
const mochaHooks = {
|
||||
export const mochaHooks = {
|
||||
async beforeAll() {
|
||||
// Set a long timeout for startup.
|
||||
this.timeout(10000);
|
||||
@@ -21,5 +21,3 @@ const mochaHooks = {
|
||||
return await driverTeardown();
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {mochaHooks};
|
||||
@@ -4,8 +4,8 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const {
|
||||
import * as chai from 'chai';
|
||||
import {
|
||||
testSetup,
|
||||
testFileLocations,
|
||||
connect,
|
||||
@@ -15,7 +15,7 @@ const {
|
||||
getBlockElementById,
|
||||
dragBlockFromMutatorFlyout,
|
||||
openMutatorForBlock,
|
||||
} = require('./test_setup');
|
||||
} from './test_setup.mjs';
|
||||
|
||||
suite('Mutating a block', function (done) {
|
||||
this.timeout(0);
|
||||
@@ -8,8 +8,8 @@
|
||||
* @fileoverview Node.js script to run Automated tests in Chrome, via webdriver.
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const {
|
||||
import * as chai from 'chai';
|
||||
import {
|
||||
testSetup,
|
||||
testFileLocations,
|
||||
getSelectedBlockElement,
|
||||
@@ -17,7 +17,7 @@ const {
|
||||
getBlockTypeFromCategory,
|
||||
connect,
|
||||
PAUSE_TIME,
|
||||
} = require('./test_setup');
|
||||
} from './test_setup.mjs';
|
||||
|
||||
suite('Testing Connecting Blocks', function (done) {
|
||||
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test
|
||||
@@ -16,9 +16,10 @@
|
||||
* identifiers that Selenium can use to find those elements.
|
||||
*/
|
||||
|
||||
const webdriverio = require('webdriverio');
|
||||
const path = require('path');
|
||||
const {posixPath} = require('../../../scripts/helpers');
|
||||
import * as webdriverio from 'webdriverio';
|
||||
import * as path from 'path';
|
||||
import {fileURLToPath} from 'url';
|
||||
import {posixPath} from '../../../scripts/helpers.js';
|
||||
|
||||
let driver = null;
|
||||
|
||||
@@ -26,14 +27,14 @@ let driver = null;
|
||||
* The default amount of time to wait during a test. Increase this to make
|
||||
* tests easier to watch; decrease it to make tests run faster.
|
||||
*/
|
||||
const PAUSE_TIME = 50;
|
||||
export const PAUSE_TIME = 50;
|
||||
|
||||
/**
|
||||
* Start up the test page. This should only be done once, to avoid
|
||||
* constantly popping browser windows open and closed.
|
||||
* @return A Promsie that resolves to a webdriverIO browser that tests can manipulate.
|
||||
*/
|
||||
async function driverSetup() {
|
||||
export async function driverSetup() {
|
||||
const options = {
|
||||
capabilities: {
|
||||
'browserName': 'chrome',
|
||||
@@ -67,7 +68,7 @@ async function driverSetup() {
|
||||
* End the webdriverIO session.
|
||||
* @return A Promise that resolves after the actions have been completed.
|
||||
*/
|
||||
async function driverTeardown() {
|
||||
export async function driverTeardown() {
|
||||
await driver.deleteSession();
|
||||
driver = null;
|
||||
return;
|
||||
@@ -79,7 +80,7 @@ async function driverTeardown() {
|
||||
* a Blockly playground with a workspace.
|
||||
* @return A Promsie that resolves to a webdriverIO browser that tests can manipulate.
|
||||
*/
|
||||
async function testSetup(playgroundUrl) {
|
||||
export async function testSetup(playgroundUrl) {
|
||||
if (!driver) {
|
||||
await driverSetup();
|
||||
}
|
||||
@@ -91,7 +92,9 @@ async function testSetup(playgroundUrl) {
|
||||
return driver;
|
||||
}
|
||||
|
||||
const testFileLocations = {
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export const testFileLocations = {
|
||||
BLOCK_FACTORY:
|
||||
'file://' +
|
||||
posixPath(path.join(__dirname, '..', '..', '..', 'demos', 'blockfactory')) +
|
||||
@@ -116,7 +119,7 @@ const testFileLocations = {
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
*/
|
||||
const screenDirection = {
|
||||
export const screenDirection = {
|
||||
RTL: -1,
|
||||
LTR: 1,
|
||||
};
|
||||
@@ -125,7 +128,7 @@ const screenDirection = {
|
||||
* @param browser The active WebdriverIO Browser object.
|
||||
* @return A Promise that resolves to the ID of the currently selected block.
|
||||
*/
|
||||
async function getSelectedBlockId(browser) {
|
||||
export async function getSelectedBlockId(browser) {
|
||||
return await browser.execute(() => {
|
||||
// Note: selected is an ICopyable and I am assuming that it is a BlockSvg.
|
||||
return Blockly.common.getSelected()?.id;
|
||||
@@ -137,7 +140,7 @@ async function getSelectedBlockId(browser) {
|
||||
* @return A Promise that resolves to the selected block's root SVG element,
|
||||
* as an interactable browser element.
|
||||
*/
|
||||
async function getSelectedBlockElement(browser) {
|
||||
export async function getSelectedBlockElement(browser) {
|
||||
const id = await getSelectedBlockId(browser);
|
||||
return getBlockElementById(browser, id);
|
||||
}
|
||||
@@ -148,7 +151,7 @@ async function getSelectedBlockElement(browser) {
|
||||
* @return A Promise that resolves to the root SVG element of the block with
|
||||
* the given ID, as an interactable browser element.
|
||||
*/
|
||||
async function getBlockElementById(browser, id) {
|
||||
export async function getBlockElementById(browser, id) {
|
||||
const elem = await browser.$(`[data-id="${id}"]`);
|
||||
elem['id'] = id;
|
||||
return elem;
|
||||
@@ -165,7 +168,7 @@ async function getBlockElementById(browser, id) {
|
||||
* @param clickOptions The options to pass to webdriverio's element.click function.
|
||||
* @return A Promise that resolves when the actions are completed.
|
||||
*/
|
||||
async function clickBlock(browser, block, clickOptions) {
|
||||
export async function clickBlock(browser, block, clickOptions) {
|
||||
const findableId = 'clickTargetElement';
|
||||
// In the browser context, find the element that we want and give it a findable ID.
|
||||
await browser.execute(
|
||||
@@ -203,7 +206,7 @@ async function clickBlock(browser, block, clickOptions) {
|
||||
* @param browser The active WebdriverIO Browser object.
|
||||
* @return A Promise that resolves when the actions are completed.
|
||||
*/
|
||||
async function clickWorkspace(browser) {
|
||||
export async function clickWorkspace(browser) {
|
||||
const workspace = await browser.$('#blocklyDiv > div > svg.blocklySvg > g');
|
||||
await workspace.click();
|
||||
await browser.pause(PAUSE_TIME);
|
||||
@@ -215,7 +218,7 @@ async function clickWorkspace(browser) {
|
||||
* @return A Promise that resolves when the actions are completed.
|
||||
* @throws If the mutator workspace cannot be found.
|
||||
*/
|
||||
async function clickMutatorWorkspace(browser) {
|
||||
export async function clickMutatorWorkspace(browser) {
|
||||
const hasMutator = await browser.$('.blocklyMutatorBackground');
|
||||
if (!hasMutator) {
|
||||
throw new Error('No mutator workspace found');
|
||||
@@ -234,7 +237,7 @@ async function clickMutatorWorkspace(browser) {
|
||||
* category with the given name, as an interactable browser element.
|
||||
* @throws If the category cannot be found.
|
||||
*/
|
||||
async function getCategory(browser, categoryName) {
|
||||
export async function getCategory(browser, categoryName) {
|
||||
const category = browser.$(`.blocklyToolboxCategory*=${categoryName}`);
|
||||
category.waitForExist();
|
||||
|
||||
@@ -248,7 +251,7 @@ async function getCategory(browser, categoryName) {
|
||||
* @return A Promise that resolves to the root element of the nth
|
||||
* block in the given category.
|
||||
*/
|
||||
async function getNthBlockOfCategory(browser, categoryName, n) {
|
||||
export async function getNthBlockOfCategory(browser, categoryName, n) {
|
||||
const category = await getCategory(browser, categoryName);
|
||||
await category.click();
|
||||
const block = await browser.$(
|
||||
@@ -265,7 +268,11 @@ async function getNthBlockOfCategory(browser, categoryName, n) {
|
||||
* @return A Promise that resolves to the root element of the first
|
||||
* block with the given type in the given category.
|
||||
*/
|
||||
async function getBlockTypeFromCategory(browser, categoryName, blockType) {
|
||||
export async function getBlockTypeFromCategory(
|
||||
browser,
|
||||
categoryName,
|
||||
blockType,
|
||||
) {
|
||||
if (categoryName) {
|
||||
const category = await getCategory(browser, categoryName);
|
||||
await category.click();
|
||||
@@ -287,7 +294,7 @@ async function getBlockTypeFromCategory(browser, categoryName, blockType) {
|
||||
* @return A Promise that resolves to the root element of the block with the
|
||||
* given position and type on the workspace.
|
||||
*/
|
||||
async function getBlockTypeFromWorkspace(browser, blockType, position) {
|
||||
export async function getBlockTypeFromWorkspace(browser, blockType, position) {
|
||||
const id = await browser.execute(
|
||||
(blockType, position) => {
|
||||
return Blockly.getMainWorkspace().getBlocksByType(blockType, true)[
|
||||
@@ -372,7 +379,7 @@ async function getLocationOfBlockConnection(
|
||||
* @param dragBlockSelector The selector of the block to drag
|
||||
* @return A Promise that resolves when the actions are completed.
|
||||
*/
|
||||
async function connect(
|
||||
export async function connect(
|
||||
browser,
|
||||
draggedBlock,
|
||||
draggedConnection,
|
||||
@@ -411,7 +418,7 @@ async function connect(
|
||||
* @param browser The active WebdriverIO Browser object.
|
||||
* @return A Promise that resolves when the actions are completed.
|
||||
*/
|
||||
async function switchRTL(browser) {
|
||||
export async function switchRTL(browser) {
|
||||
const ltrForm = await browser.$('#options > select:nth-child(1)');
|
||||
await ltrForm.selectByIndex(1);
|
||||
await browser.pause(PAUSE_TIME + 450);
|
||||
@@ -431,7 +438,7 @@ async function switchRTL(browser) {
|
||||
* @return A Promise that resolves to the root element of the newly
|
||||
* created block.
|
||||
*/
|
||||
async function dragNthBlockFromFlyout(browser, categoryName, n, x, y) {
|
||||
export async function dragNthBlockFromFlyout(browser, categoryName, n, x, y) {
|
||||
const flyoutBlock = await getNthBlockOfCategory(browser, categoryName, n);
|
||||
await flyoutBlock.dragAndDrop({x: x, y: y});
|
||||
return await getSelectedBlockElement(browser);
|
||||
@@ -452,7 +459,13 @@ async function dragNthBlockFromFlyout(browser, categoryName, n, x, y) {
|
||||
* @return A Promise that resolves to the root element of the newly
|
||||
* created block.
|
||||
*/
|
||||
async function dragBlockTypeFromFlyout(browser, categoryName, type, x, y) {
|
||||
export async function dragBlockTypeFromFlyout(
|
||||
browser,
|
||||
categoryName,
|
||||
type,
|
||||
x,
|
||||
y,
|
||||
) {
|
||||
const flyoutBlock = await getBlockTypeFromCategory(
|
||||
browser,
|
||||
categoryName,
|
||||
@@ -477,7 +490,13 @@ async function dragBlockTypeFromFlyout(browser, categoryName, type, x, y) {
|
||||
* @return A Promise that resolves to the root element of the newly
|
||||
* created block.
|
||||
*/
|
||||
async function dragBlockFromMutatorFlyout(browser, mutatorBlock, type, x, y) {
|
||||
export async function dragBlockFromMutatorFlyout(
|
||||
browser,
|
||||
mutatorBlock,
|
||||
type,
|
||||
x,
|
||||
y,
|
||||
) {
|
||||
const id = await browser.execute(
|
||||
(mutatorBlockId, blockType) => {
|
||||
return Blockly.getMainWorkspace()
|
||||
@@ -505,7 +524,7 @@ async function dragBlockFromMutatorFlyout(browser, mutatorBlock, type, x, y) {
|
||||
* @param itemText The display text of the context menu item to click.
|
||||
* @return A Promise that resolves when the actions are completed.
|
||||
*/
|
||||
async function contextMenuSelect(browser, block, itemText) {
|
||||
export async function contextMenuSelect(browser, block, itemText) {
|
||||
await clickBlock(browser, block, {button: 2});
|
||||
|
||||
const item = await browser.$(`div=${itemText}`);
|
||||
@@ -522,7 +541,7 @@ async function contextMenuSelect(browser, block, itemText) {
|
||||
* @param block The block to click, as an interactable element.
|
||||
* @return A Promise that resolves when the actions are complete.
|
||||
*/
|
||||
async function openMutatorForBlock(browser, block) {
|
||||
export async function openMutatorForBlock(browser, block) {
|
||||
const icon = await browser.$(`[data-id="${block.id}"] > g.blocklyIconGroup`);
|
||||
await icon.click();
|
||||
}
|
||||
@@ -535,7 +554,7 @@ async function openMutatorForBlock(browser, block) {
|
||||
* @param browser The active WebdriverIO Browser object.
|
||||
* @return A Promise that resolves to an array of blocks on the main workspace.
|
||||
*/
|
||||
async function getAllBlocks(browser) {
|
||||
export async function getAllBlocks(browser) {
|
||||
return browser.execute(() => {
|
||||
return Blockly.getMainWorkspace()
|
||||
.getAllBlocks(false)
|
||||
@@ -556,7 +575,7 @@ async function getAllBlocks(browser) {
|
||||
* @param yDelta How far to drag the flyout in the y direction. Positive is down.
|
||||
* @return A Promise that resolves when the actions are completed.
|
||||
*/
|
||||
async function scrollFlyout(browser, xDelta, yDelta) {
|
||||
export async function scrollFlyout(browser, xDelta, yDelta) {
|
||||
// There are two flyouts on the playground workspace: one for the trash can
|
||||
// and one for the toolbox. We want the second one.
|
||||
// This assumes there is only one scrollbar handle in the flyout, but it could
|
||||
@@ -568,31 +587,3 @@ async function scrollFlyout(browser, xDelta, yDelta) {
|
||||
await scrollbarHandle.dragAndDrop({x: xDelta, y: yDelta});
|
||||
await browser.pause(PAUSE_TIME);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
testSetup,
|
||||
testFileLocations,
|
||||
driverSetup,
|
||||
driverTeardown,
|
||||
getSelectedBlockElement,
|
||||
getSelectedBlockId,
|
||||
getBlockElementById,
|
||||
clickBlock,
|
||||
clickWorkspace,
|
||||
clickMutatorWorkspace,
|
||||
getCategory,
|
||||
getNthBlockOfCategory,
|
||||
getBlockTypeFromCategory,
|
||||
dragNthBlockFromFlyout,
|
||||
dragBlockTypeFromFlyout,
|
||||
dragBlockFromMutatorFlyout,
|
||||
connect,
|
||||
switchRTL,
|
||||
contextMenuSelect,
|
||||
openMutatorForBlock,
|
||||
screenDirection,
|
||||
getBlockTypeFromWorkspace,
|
||||
getAllBlocks,
|
||||
scrollFlyout,
|
||||
PAUSE_TIME,
|
||||
};
|
||||
@@ -8,15 +8,15 @@
|
||||
* @fileoverview Tests for the dragging out of the toolbox and flyout.
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const {
|
||||
import * as chai from 'chai';
|
||||
import {
|
||||
testSetup,
|
||||
testFileLocations,
|
||||
getCategory,
|
||||
scrollFlyout,
|
||||
screenDirection,
|
||||
PAUSE_TIME,
|
||||
} = require('./test_setup');
|
||||
} from './test_setup.mjs';
|
||||
|
||||
// Categories in the basic toolbox.
|
||||
const basicCategories = [
|
||||
@@ -4,10 +4,10 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
const chai = require('chai');
|
||||
const sinon = require('sinon');
|
||||
const {Key} = require('webdriverio');
|
||||
const {testSetup, testFileLocations} = require('./test_setup');
|
||||
import * as chai from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import {Key} from 'webdriverio';
|
||||
import {testSetup, testFileLocations} from './test_setup.mjs';
|
||||
|
||||
suite('Workspace comments', function () {
|
||||
// Setting timeout to unlimited as the webdriver takes a longer time
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {ASTNode} from '../../build/src/core/keyboard_nav/ast_node.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -110,7 +111,7 @@ suite('ASTNode', function () {
|
||||
const connection = input.connection;
|
||||
const node = ASTNode.createConnectionNode(connection);
|
||||
const newASTNode = node.findNextForInput(input);
|
||||
chai.assert.equal(newASTNode.getLocation(), input2.connection);
|
||||
assert.equal(newASTNode.getLocation(), input2.connection);
|
||||
});
|
||||
|
||||
test('findPrevForInput', function () {
|
||||
@@ -119,7 +120,7 @@ suite('ASTNode', function () {
|
||||
const connection = input2.connection;
|
||||
const node = ASTNode.createConnectionNode(connection);
|
||||
const newASTNode = node.findPrevForInput(input2);
|
||||
chai.assert.equal(newASTNode.getLocation(), input.connection);
|
||||
assert.equal(newASTNode.getLocation(), input.connection);
|
||||
});
|
||||
|
||||
test('findNextForField', function () {
|
||||
@@ -127,7 +128,7 @@ suite('ASTNode', function () {
|
||||
const field2 = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
||||
const node = ASTNode.createFieldNode(field);
|
||||
const newASTNode = node.findNextForField(field);
|
||||
chai.assert.equal(newASTNode.getLocation(), field2);
|
||||
assert.equal(newASTNode.getLocation(), field2);
|
||||
});
|
||||
|
||||
test('findPrevForField', function () {
|
||||
@@ -135,7 +136,7 @@ suite('ASTNode', function () {
|
||||
const field2 = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
||||
const node = ASTNode.createFieldNode(field2);
|
||||
const newASTNode = node.findPrevForField(field2);
|
||||
chai.assert.equal(newASTNode.getLocation(), field);
|
||||
assert.equal(newASTNode.getLocation(), field);
|
||||
});
|
||||
|
||||
test('navigateBetweenStacks_Forward', function () {
|
||||
@@ -144,7 +145,7 @@ suite('ASTNode', function () {
|
||||
this.blocks.statementInput1.nextConnection,
|
||||
);
|
||||
const newASTNode = node.navigateBetweenStacks(true);
|
||||
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput4);
|
||||
assert.equal(newASTNode.getLocation(), this.blocks.statementInput4);
|
||||
});
|
||||
|
||||
test('navigateBetweenStacks_Backward', function () {
|
||||
@@ -153,7 +154,7 @@ suite('ASTNode', function () {
|
||||
this.blocks.statementInput4,
|
||||
);
|
||||
const newASTNode = node.navigateBetweenStacks(false);
|
||||
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(newASTNode.getLocation(), this.blocks.statementInput1);
|
||||
});
|
||||
test('getOutAstNodeForBlock', function () {
|
||||
const node = new ASTNode(
|
||||
@@ -163,7 +164,7 @@ suite('ASTNode', function () {
|
||||
const newASTNode = node.getOutAstNodeForBlock(
|
||||
this.blocks.statementInput2,
|
||||
);
|
||||
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(newASTNode.getLocation(), this.blocks.statementInput1);
|
||||
});
|
||||
test('getOutAstNodeForBlock_OneBlock', function () {
|
||||
const node = new ASTNode(
|
||||
@@ -173,7 +174,7 @@ suite('ASTNode', function () {
|
||||
const newASTNode = node.getOutAstNodeForBlock(
|
||||
this.blocks.statementInput4,
|
||||
);
|
||||
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput4);
|
||||
assert.equal(newASTNode.getLocation(), this.blocks.statementInput4);
|
||||
});
|
||||
test('findFirstFieldOrInput_', function () {
|
||||
const node = new ASTNode(
|
||||
@@ -184,7 +185,7 @@ suite('ASTNode', function () {
|
||||
const newASTNode = node.findFirstFieldOrInput(
|
||||
this.blocks.statementInput4,
|
||||
);
|
||||
chai.assert.equal(newASTNode.getLocation(), field);
|
||||
assert.equal(newASTNode.getLocation(), field);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -345,31 +346,31 @@ suite('ASTNode', function () {
|
||||
const prevConnection = this.blocks.statementInput1.previousConnection;
|
||||
const node = ASTNode.createConnectionNode(prevConnection);
|
||||
const nextNode = node.next();
|
||||
chai.assert.equal(nextNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(nextNode.getLocation(), this.blocks.statementInput1);
|
||||
});
|
||||
test('fromBlockToNext', function () {
|
||||
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||
const node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
||||
const nextNode = node.next();
|
||||
chai.assert.equal(nextNode.getLocation(), nextConnection);
|
||||
assert.equal(nextNode.getLocation(), nextConnection);
|
||||
});
|
||||
test('fromBlockToNull', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.noNextConnection);
|
||||
const nextNode = node.next();
|
||||
chai.assert.isNull(nextNode);
|
||||
assert.isNull(nextNode);
|
||||
});
|
||||
test('fromNextToPrevious', function () {
|
||||
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||
const prevConnection = this.blocks.statementInput2.previousConnection;
|
||||
const node = ASTNode.createConnectionNode(nextConnection);
|
||||
const nextNode = node.next();
|
||||
chai.assert.equal(nextNode.getLocation(), prevConnection);
|
||||
assert.equal(nextNode.getLocation(), prevConnection);
|
||||
});
|
||||
test('fromNextToNull', function () {
|
||||
const nextConnection = this.blocks.statementInput2.nextConnection;
|
||||
const node = ASTNode.createConnectionNode(nextConnection);
|
||||
const nextNode = node.next();
|
||||
chai.assert.isNull(nextNode);
|
||||
assert.isNull(nextNode);
|
||||
});
|
||||
test('fromInputToInput', function () {
|
||||
const input = this.blocks.statementInput1.inputList[0];
|
||||
@@ -377,7 +378,7 @@ suite('ASTNode', function () {
|
||||
this.blocks.statementInput1.inputList[1].connection;
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const nextNode = node.next();
|
||||
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
||||
assert.equal(nextNode.getLocation(), inputConnection);
|
||||
});
|
||||
test('fromInputToStatementInput', function () {
|
||||
const input = this.blocks.fieldAndInputs2.inputList[1];
|
||||
@@ -385,26 +386,26 @@ suite('ASTNode', function () {
|
||||
this.blocks.fieldAndInputs2.inputList[2].connection;
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const nextNode = node.next();
|
||||
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
||||
assert.equal(nextNode.getLocation(), inputConnection);
|
||||
});
|
||||
test('fromInputToField', function () {
|
||||
const input = this.blocks.fieldAndInputs2.inputList[0];
|
||||
const field = this.blocks.fieldAndInputs2.inputList[1].fieldRow[0];
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const nextNode = node.next();
|
||||
chai.assert.equal(nextNode.getLocation(), field);
|
||||
assert.equal(nextNode.getLocation(), field);
|
||||
});
|
||||
test('fromInputToNull', function () {
|
||||
const input = this.blocks.fieldAndInputs2.inputList[2];
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const nextNode = node.next();
|
||||
chai.assert.isNull(nextNode);
|
||||
assert.isNull(nextNode);
|
||||
});
|
||||
test('fromOutputToBlock', function () {
|
||||
const output = this.blocks.fieldWithOutput.outputConnection;
|
||||
const node = ASTNode.createConnectionNode(output);
|
||||
const nextNode = node.next();
|
||||
chai.assert.equal(nextNode.getLocation(), this.blocks.fieldWithOutput);
|
||||
assert.equal(nextNode.getLocation(), this.blocks.fieldWithOutput);
|
||||
});
|
||||
test('fromFieldToInput', function () {
|
||||
const field = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
||||
@@ -412,31 +413,31 @@ suite('ASTNode', function () {
|
||||
this.blocks.statementInput1.inputList[0].connection;
|
||||
const node = ASTNode.createFieldNode(field);
|
||||
const nextNode = node.next();
|
||||
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
||||
assert.equal(nextNode.getLocation(), inputConnection);
|
||||
});
|
||||
test('fromFieldToField', function () {
|
||||
const field = this.blocks.fieldAndInputs.inputList[0].fieldRow[0];
|
||||
const node = ASTNode.createFieldNode(field);
|
||||
const field2 = this.blocks.fieldAndInputs.inputList[1].fieldRow[0];
|
||||
const nextNode = node.next();
|
||||
chai.assert.equal(nextNode.getLocation(), field2);
|
||||
assert.equal(nextNode.getLocation(), field2);
|
||||
});
|
||||
test('fromFieldToNull', function () {
|
||||
const field = this.blocks.twoFields.inputList[0].fieldRow[0];
|
||||
const node = ASTNode.createFieldNode(field);
|
||||
const nextNode = node.next();
|
||||
chai.assert.isNull(nextNode);
|
||||
assert.isNull(nextNode);
|
||||
});
|
||||
test('fromStackToStack', function () {
|
||||
const node = ASTNode.createStackNode(this.blocks.statementInput1);
|
||||
const nextNode = node.next();
|
||||
chai.assert.equal(nextNode.getLocation(), this.blocks.statementInput4);
|
||||
chai.assert.equal(nextNode.getType(), ASTNode.types.STACK);
|
||||
assert.equal(nextNode.getLocation(), this.blocks.statementInput4);
|
||||
assert.equal(nextNode.getType(), ASTNode.types.STACK);
|
||||
});
|
||||
test('fromStackToNull', function () {
|
||||
const node = ASTNode.createStackNode(this.blocks.singleBlock);
|
||||
const nextNode = node.next();
|
||||
chai.assert.isNull(nextNode);
|
||||
assert.isNull(nextNode);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -445,55 +446,55 @@ suite('ASTNode', function () {
|
||||
const prevConnection = this.blocks.statementInput1.previousConnection;
|
||||
const node = ASTNode.createConnectionNode(prevConnection);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.isNull(prevNode);
|
||||
assert.isNull(prevNode);
|
||||
});
|
||||
test('fromPreviousToNext', function () {
|
||||
const prevConnection = this.blocks.statementInput2.previousConnection;
|
||||
const node = ASTNode.createConnectionNode(prevConnection);
|
||||
const prevNode = node.prev();
|
||||
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||
chai.assert.equal(prevNode.getLocation(), nextConnection);
|
||||
assert.equal(prevNode.getLocation(), nextConnection);
|
||||
});
|
||||
test('fromPreviousToInput', function () {
|
||||
const prevConnection = this.blocks.statementInput3.previousConnection;
|
||||
const node = ASTNode.createConnectionNode(prevConnection);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.isNull(prevNode);
|
||||
assert.isNull(prevNode);
|
||||
});
|
||||
test('fromBlockToPrevious', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
||||
const prevNode = node.prev();
|
||||
const prevConnection = this.blocks.statementInput1.previousConnection;
|
||||
chai.assert.equal(prevNode.getLocation(), prevConnection);
|
||||
assert.equal(prevNode.getLocation(), prevConnection);
|
||||
});
|
||||
test('fromBlockToNull', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.noPrevConnection);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.isNull(prevNode);
|
||||
assert.isNull(prevNode);
|
||||
});
|
||||
test('fromBlockToOutput', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.fieldWithOutput);
|
||||
const prevNode = node.prev();
|
||||
const outputConnection = this.blocks.fieldWithOutput.outputConnection;
|
||||
chai.assert.equal(prevNode.getLocation(), outputConnection);
|
||||
assert.equal(prevNode.getLocation(), outputConnection);
|
||||
});
|
||||
test('fromNextToBlock', function () {
|
||||
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||
const node = ASTNode.createConnectionNode(nextConnection);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.equal(prevNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(prevNode.getLocation(), this.blocks.statementInput1);
|
||||
});
|
||||
test('fromInputToField', function () {
|
||||
const input = this.blocks.statementInput1.inputList[0];
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.equal(prevNode.getLocation(), input.fieldRow[1]);
|
||||
assert.equal(prevNode.getLocation(), input.fieldRow[1]);
|
||||
});
|
||||
test('fromInputToNull', function () {
|
||||
const input = this.blocks.fieldAndInputs2.inputList[0];
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.isNull(prevNode);
|
||||
assert.isNull(prevNode);
|
||||
});
|
||||
test('fromInputToInput', function () {
|
||||
const input = this.blocks.fieldAndInputs2.inputList[2];
|
||||
@@ -501,19 +502,19 @@ suite('ASTNode', function () {
|
||||
this.blocks.fieldAndInputs2.inputList[1].connection;
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.equal(prevNode.getLocation(), inputConnection);
|
||||
assert.equal(prevNode.getLocation(), inputConnection);
|
||||
});
|
||||
test('fromOutputToNull', function () {
|
||||
const output = this.blocks.fieldWithOutput.outputConnection;
|
||||
const node = ASTNode.createConnectionNode(output);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.isNull(prevNode);
|
||||
assert.isNull(prevNode);
|
||||
});
|
||||
test('fromFieldToNull', function () {
|
||||
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||
const node = ASTNode.createFieldNode(field);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.isNull(prevNode);
|
||||
assert.isNull(prevNode);
|
||||
});
|
||||
test('fromFieldToInput', function () {
|
||||
const field = this.blocks.fieldAndInputs2.inputList[1].fieldRow[0];
|
||||
@@ -521,20 +522,20 @@ suite('ASTNode', function () {
|
||||
this.blocks.fieldAndInputs2.inputList[0].connection;
|
||||
const node = ASTNode.createFieldNode(field);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.equal(prevNode.getLocation(), inputConnection);
|
||||
assert.equal(prevNode.getLocation(), inputConnection);
|
||||
});
|
||||
test('fromFieldToField', function () {
|
||||
const field = this.blocks.fieldAndInputs.inputList[1].fieldRow[0];
|
||||
const field2 = this.blocks.fieldAndInputs.inputList[0].fieldRow[0];
|
||||
const node = ASTNode.createFieldNode(field);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.equal(prevNode.getLocation(), field2);
|
||||
assert.equal(prevNode.getLocation(), field2);
|
||||
});
|
||||
test('fromStackToStack', function () {
|
||||
const node = ASTNode.createStackNode(this.blocks.statementInput4);
|
||||
const prevNode = node.prev();
|
||||
chai.assert.equal(prevNode.getLocation(), this.blocks.statementInput1);
|
||||
chai.assert.equal(prevNode.getType(), ASTNode.types.STACK);
|
||||
assert.equal(prevNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(prevNode.getType(), ASTNode.types.STACK);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -551,13 +552,13 @@ suite('ASTNode', function () {
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const inNode = node.in();
|
||||
const outputConnection = this.blocks.fieldWithOutput.outputConnection;
|
||||
chai.assert.equal(inNode.getLocation(), outputConnection);
|
||||
assert.equal(inNode.getLocation(), outputConnection);
|
||||
});
|
||||
test('fromInputToNull', function () {
|
||||
const input = this.blocks.statementInput2.inputList[0];
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const inNode = node.in();
|
||||
chai.assert.isNull(inNode);
|
||||
assert.isNull(inNode);
|
||||
});
|
||||
test('fromInputToPrevious', function () {
|
||||
const input = this.blocks.statementInput2.inputList[1];
|
||||
@@ -565,60 +566,57 @@ suite('ASTNode', function () {
|
||||
this.blocks.statementInput3.previousConnection;
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const inNode = node.in();
|
||||
chai.assert.equal(inNode.getLocation(), previousConnection);
|
||||
assert.equal(inNode.getLocation(), previousConnection);
|
||||
});
|
||||
test('fromBlockToInput', function () {
|
||||
const input = this.blocks.valueInput.inputList[0];
|
||||
const node = ASTNode.createBlockNode(this.blocks.valueInput);
|
||||
const inNode = node.in();
|
||||
chai.assert.equal(inNode.getLocation(), input.connection);
|
||||
assert.equal(inNode.getLocation(), input.connection);
|
||||
});
|
||||
test('fromBlockToField', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
||||
const inNode = node.in();
|
||||
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||
chai.assert.equal(inNode.getLocation(), field);
|
||||
assert.equal(inNode.getLocation(), field);
|
||||
});
|
||||
test('fromBlockToPrevious', function () {
|
||||
const prevConnection = this.blocks.statementInput4.previousConnection;
|
||||
const node = ASTNode.createStackNode(this.blocks.statementInput4);
|
||||
const inNode = node.in();
|
||||
chai.assert.equal(inNode.getLocation(), prevConnection);
|
||||
chai.assert.equal(inNode.getType(), ASTNode.types.PREVIOUS);
|
||||
assert.equal(inNode.getLocation(), prevConnection);
|
||||
assert.equal(inNode.getType(), ASTNode.types.PREVIOUS);
|
||||
});
|
||||
test('fromBlockToNull_DummyInput', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.dummyInput);
|
||||
const inNode = node.in();
|
||||
chai.assert.isNull(inNode);
|
||||
assert.isNull(inNode);
|
||||
});
|
||||
test('fromBlockToInput_DummyInputValue', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.dummyInputValue);
|
||||
const inputConnection =
|
||||
this.blocks.dummyInputValue.inputList[1].connection;
|
||||
const inNode = node.in();
|
||||
chai.assert.equal(inNode.getLocation(), inputConnection);
|
||||
assert.equal(inNode.getLocation(), inputConnection);
|
||||
});
|
||||
test('fromOuputToNull', function () {
|
||||
const output = this.blocks.fieldWithOutput.outputConnection;
|
||||
const node = ASTNode.createConnectionNode(output);
|
||||
const inNode = node.in();
|
||||
chai.assert.isNull(inNode);
|
||||
assert.isNull(inNode);
|
||||
});
|
||||
test('fromFieldToNull', function () {
|
||||
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||
const node = ASTNode.createFieldNode(field);
|
||||
const inNode = node.in();
|
||||
chai.assert.isNull(inNode);
|
||||
assert.isNull(inNode);
|
||||
});
|
||||
test('fromWorkspaceToStack', function () {
|
||||
const coordinate = new Blockly.utils.Coordinate(100, 100);
|
||||
const node = ASTNode.createWorkspaceNode(this.workspace, coordinate);
|
||||
const inNode = node.in();
|
||||
chai.assert.equal(
|
||||
inNode.getLocation(),
|
||||
this.workspace.getTopBlocks()[0],
|
||||
);
|
||||
chai.assert.equal(inNode.getType(), ASTNode.types.STACK);
|
||||
assert.equal(inNode.getLocation(), this.workspace.getTopBlocks()[0]);
|
||||
assert.equal(inNode.getType(), ASTNode.types.STACK);
|
||||
});
|
||||
test('fromWorkspaceToNull', function () {
|
||||
const coordinate = new Blockly.utils.Coordinate(100, 100);
|
||||
@@ -627,27 +625,27 @@ suite('ASTNode', function () {
|
||||
coordinate,
|
||||
);
|
||||
const inNode = node.in();
|
||||
chai.assert.isNull(inNode);
|
||||
assert.isNull(inNode);
|
||||
});
|
||||
test('fromStackToPrevious', function () {
|
||||
const node = ASTNode.createStackNode(this.blocks.statementInput1);
|
||||
const previous = this.blocks.statementInput1.previousConnection;
|
||||
const inNode = node.in();
|
||||
chai.assert.equal(inNode.getLocation(), previous);
|
||||
chai.assert.equal(inNode.getType(), ASTNode.types.PREVIOUS);
|
||||
assert.equal(inNode.getLocation(), previous);
|
||||
assert.equal(inNode.getType(), ASTNode.types.PREVIOUS);
|
||||
});
|
||||
test('fromStackToOutput', function () {
|
||||
const node = ASTNode.createStackNode(this.blocks.fieldWithOutput2);
|
||||
const output = this.blocks.fieldWithOutput2.outputConnection;
|
||||
const inNode = node.in();
|
||||
chai.assert.equal(inNode.getLocation(), output);
|
||||
chai.assert.equal(inNode.getType(), ASTNode.types.OUTPUT);
|
||||
assert.equal(inNode.getLocation(), output);
|
||||
assert.equal(inNode.getType(), ASTNode.types.OUTPUT);
|
||||
});
|
||||
test('fromStackToBlock', function () {
|
||||
const node = ASTNode.createStackNode(this.blocks.dummyInput);
|
||||
const inNode = node.in();
|
||||
chai.assert.equal(inNode.getLocation(), this.blocks.dummyInput);
|
||||
chai.assert.equal(inNode.getType(), ASTNode.types.BLOCK);
|
||||
assert.equal(inNode.getLocation(), this.blocks.dummyInput);
|
||||
assert.equal(inNode.getType(), ASTNode.types.BLOCK);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -667,15 +665,15 @@ suite('ASTNode', function () {
|
||||
const input = this.blocks.statementInput1.inputList[0];
|
||||
const node = ASTNode.createInputNode(input);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.BLOCK);
|
||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(outNode.getType(), ASTNode.types.BLOCK);
|
||||
assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
});
|
||||
test('fromOutputToInput', function () {
|
||||
const output = this.blocks.fieldWithOutput.outputConnection;
|
||||
const node = ASTNode.createConnectionNode(output);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
chai.assert.equal(
|
||||
assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
assert.equal(
|
||||
outNode.getLocation(),
|
||||
this.blocks.statementInput1.inputList[0].connection,
|
||||
);
|
||||
@@ -684,15 +682,15 @@ suite('ASTNode', function () {
|
||||
const output = this.blocks.fieldWithOutput2.outputConnection;
|
||||
const node = ASTNode.createConnectionNode(output);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
chai.assert.equal(outNode.getLocation(), this.blocks.fieldWithOutput2);
|
||||
assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
assert.equal(outNode.getLocation(), this.blocks.fieldWithOutput2);
|
||||
});
|
||||
test('fromFieldToBlock', function () {
|
||||
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||
const node = ASTNode.createFieldNode(field);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.BLOCK);
|
||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(outNode.getType(), ASTNode.types.BLOCK);
|
||||
assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
});
|
||||
test('fromStackToWorkspace', function () {
|
||||
const stub = sinon
|
||||
@@ -700,9 +698,9 @@ suite('ASTNode', function () {
|
||||
.returns({x: 10, y: 10});
|
||||
const node = ASTNode.createStackNode(this.blocks.statementInput4);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.WORKSPACE);
|
||||
chai.assert.equal(outNode.wsCoordinate.x, 10);
|
||||
chai.assert.equal(outNode.wsCoordinate.y, -10);
|
||||
assert.equal(outNode.getType(), ASTNode.types.WORKSPACE);
|
||||
assert.equal(outNode.wsCoordinate.x, 10);
|
||||
assert.equal(outNode.wsCoordinate.y, -10);
|
||||
stub.restore();
|
||||
});
|
||||
test('fromPreviousToInput', function () {
|
||||
@@ -711,15 +709,15 @@ suite('ASTNode', function () {
|
||||
this.blocks.statementInput2.inputList[1].connection;
|
||||
const node = ASTNode.createConnectionNode(previous);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
chai.assert.equal(outNode.getLocation(), inputConnection);
|
||||
assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
assert.equal(outNode.getLocation(), inputConnection);
|
||||
});
|
||||
test('fromPreviousToStack', function () {
|
||||
const previous = this.blocks.statementInput2.previousConnection;
|
||||
const node = ASTNode.createConnectionNode(previous);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
});
|
||||
test('fromNextToInput', function () {
|
||||
const next = this.blocks.statementInput3.nextConnection;
|
||||
@@ -727,22 +725,22 @@ suite('ASTNode', function () {
|
||||
this.blocks.statementInput2.inputList[1].connection;
|
||||
const node = ASTNode.createConnectionNode(next);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
chai.assert.equal(outNode.getLocation(), inputConnection);
|
||||
assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
assert.equal(outNode.getLocation(), inputConnection);
|
||||
});
|
||||
test('fromNextToStack', function () {
|
||||
const next = this.blocks.statementInput2.nextConnection;
|
||||
const node = ASTNode.createConnectionNode(next);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
});
|
||||
test('fromNextToStack_NoPreviousConnection', function () {
|
||||
const next = this.blocks.secondBlock.nextConnection;
|
||||
const node = ASTNode.createConnectionNode(next);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
chai.assert.equal(outNode.getLocation(), this.blocks.noPrevConnection);
|
||||
assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
assert.equal(outNode.getLocation(), this.blocks.noPrevConnection);
|
||||
});
|
||||
/**
|
||||
* This is where there is a block with both an output connection and a
|
||||
@@ -752,8 +750,8 @@ suite('ASTNode', function () {
|
||||
const next = this.blocks.outputNextBlock.nextConnection;
|
||||
const node = ASTNode.createConnectionNode(next);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
chai.assert.equal(
|
||||
assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
assert.equal(
|
||||
outNode.getLocation(),
|
||||
this.blocks.secondBlock.inputList[0].connection,
|
||||
);
|
||||
@@ -761,34 +759,34 @@ suite('ASTNode', function () {
|
||||
test('fromBlockToStack', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.statementInput2);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
});
|
||||
test('fromBlockToInput', function () {
|
||||
const input = this.blocks.statementInput2.inputList[1].connection;
|
||||
const node = ASTNode.createBlockNode(this.blocks.statementInput3);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
chai.assert.equal(outNode.getLocation(), input);
|
||||
assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
assert.equal(outNode.getLocation(), input);
|
||||
});
|
||||
test('fromTopBlockToStack', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||
});
|
||||
test('fromBlockToStack_OutputConnection', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.fieldWithOutput2);
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
chai.assert.equal(outNode.getLocation(), this.blocks.fieldWithOutput2);
|
||||
assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||
assert.equal(outNode.getLocation(), this.blocks.fieldWithOutput2);
|
||||
});
|
||||
test('fromBlockToInput_OutputConnection', function () {
|
||||
const node = ASTNode.createBlockNode(this.blocks.outputNextBlock);
|
||||
const inputConnection = this.blocks.secondBlock.inputList[0].connection;
|
||||
const outNode = node.out();
|
||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
chai.assert.equal(outNode.getLocation(), inputConnection);
|
||||
assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||
assert.equal(outNode.getLocation(), inputConnection);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -796,31 +794,31 @@ suite('ASTNode', function () {
|
||||
test('createFieldNode', function () {
|
||||
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||
const node = ASTNode.createFieldNode(field);
|
||||
chai.assert.equal(node.getLocation(), field);
|
||||
chai.assert.equal(node.getType(), ASTNode.types.FIELD);
|
||||
chai.assert.isFalse(node.isConnection());
|
||||
assert.equal(node.getLocation(), field);
|
||||
assert.equal(node.getType(), ASTNode.types.FIELD);
|
||||
assert.isFalse(node.isConnection());
|
||||
});
|
||||
test('createConnectionNode', function () {
|
||||
const prevConnection = this.blocks.statementInput4.previousConnection;
|
||||
const node = ASTNode.createConnectionNode(prevConnection);
|
||||
chai.assert.equal(node.getLocation(), prevConnection);
|
||||
chai.assert.equal(node.getType(), ASTNode.types.PREVIOUS);
|
||||
chai.assert.isTrue(node.isConnection());
|
||||
assert.equal(node.getLocation(), prevConnection);
|
||||
assert.equal(node.getType(), ASTNode.types.PREVIOUS);
|
||||
assert.isTrue(node.isConnection());
|
||||
});
|
||||
test('createInputNode', function () {
|
||||
const input = this.blocks.statementInput1.inputList[0];
|
||||
const node = ASTNode.createInputNode(input);
|
||||
chai.assert.equal(node.getLocation(), input.connection);
|
||||
chai.assert.equal(node.getType(), ASTNode.types.INPUT);
|
||||
chai.assert.isTrue(node.isConnection());
|
||||
assert.equal(node.getLocation(), input.connection);
|
||||
assert.equal(node.getType(), ASTNode.types.INPUT);
|
||||
assert.isTrue(node.isConnection());
|
||||
});
|
||||
test('createWorkspaceNode', function () {
|
||||
const coordinate = new Blockly.utils.Coordinate(100, 100);
|
||||
const node = ASTNode.createWorkspaceNode(this.workspace, coordinate);
|
||||
chai.assert.equal(node.getLocation(), this.workspace);
|
||||
chai.assert.equal(node.getType(), ASTNode.types.WORKSPACE);
|
||||
chai.assert.equal(node.getWsCoordinate(), coordinate);
|
||||
chai.assert.isFalse(node.isConnection());
|
||||
assert.equal(node.getLocation(), this.workspace);
|
||||
assert.equal(node.getType(), ASTNode.types.WORKSPACE);
|
||||
assert.equal(node.getWsCoordinate(), coordinate);
|
||||
assert.isFalse(node.isConnection());
|
||||
});
|
||||
test('createStatementConnectionNode', function () {
|
||||
const nextConnection =
|
||||
@@ -828,24 +826,24 @@ suite('ASTNode', function () {
|
||||
const inputConnection =
|
||||
this.blocks.statementInput1.inputList[1].connection;
|
||||
const node = ASTNode.createConnectionNode(nextConnection);
|
||||
chai.assert.equal(node.getLocation(), inputConnection);
|
||||
chai.assert.equal(node.getType(), ASTNode.types.INPUT);
|
||||
chai.assert.isTrue(node.isConnection());
|
||||
assert.equal(node.getLocation(), inputConnection);
|
||||
assert.equal(node.getType(), ASTNode.types.INPUT);
|
||||
assert.isTrue(node.isConnection());
|
||||
});
|
||||
test('createTopNode-previous', function () {
|
||||
const block = this.blocks.statementInput1;
|
||||
const topNode = ASTNode.createTopNode(block);
|
||||
chai.assert.equal(topNode.getLocation(), block.previousConnection);
|
||||
assert.equal(topNode.getLocation(), block.previousConnection);
|
||||
});
|
||||
test('createTopNode-block', function () {
|
||||
const block = this.blocks.noPrevConnection;
|
||||
const topNode = ASTNode.createTopNode(block);
|
||||
chai.assert.equal(topNode.getLocation(), block);
|
||||
assert.equal(topNode.getLocation(), block);
|
||||
});
|
||||
test('createTopNode-output', function () {
|
||||
const block = this.blocks.outputNextBlock;
|
||||
const topNode = ASTNode.createTopNode(block);
|
||||
chai.assert.equal(topNode.getLocation(), block.outputConnection);
|
||||
assert.equal(topNode.getLocation(), block.outputConnection);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {Align} from '../../build/src/core/inputs/align.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -27,7 +28,7 @@ suite('Block JSON initialization', function () {
|
||||
type: 'test',
|
||||
validateTokens_: Blockly.Block.prototype.validateTokens_,
|
||||
};
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
block.validateTokens_(tokens, count);
|
||||
}, error);
|
||||
};
|
||||
@@ -37,7 +38,7 @@ suite('Block JSON initialization', function () {
|
||||
type: 'test',
|
||||
validateTokens_: Blockly.Block.prototype.validateTokens_,
|
||||
};
|
||||
chai.assert.doesNotThrow(function () {
|
||||
assert.doesNotThrow(function () {
|
||||
block.validateTokens_(tokens, count);
|
||||
});
|
||||
};
|
||||
@@ -105,7 +106,7 @@ suite('Block JSON initialization', function () {
|
||||
stringToFieldJson_: Blockly.Block.prototype.stringToFieldJson_,
|
||||
isInputKeyword_: Blockly.Block.prototype.isInputKeyword_,
|
||||
};
|
||||
chai.assert.deepEqual(
|
||||
assert.deepEqual(
|
||||
block.interpolateArguments_(tokens, args, lastAlign),
|
||||
elements,
|
||||
);
|
||||
@@ -405,7 +406,7 @@ suite('Block JSON initialization', function () {
|
||||
fieldFromJson_: Blockly.Block.prototype.fieldFromJson_,
|
||||
stringToFieldJson_: Blockly.Block.prototype.stringToFieldJson_,
|
||||
};
|
||||
chai.assert.strictEqual(block.fieldFromJson_(json), expectedType);
|
||||
assert.strictEqual(block.fieldFromJson_(json), expectedType);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -573,34 +574,34 @@ suite('Block JSON initialization', function () {
|
||||
const input = block.inputFromJson_(json);
|
||||
switch (type) {
|
||||
case 'input_dummy':
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
block.appendDummyInput.calledOnce,
|
||||
'Expected a dummy input to be created.',
|
||||
);
|
||||
break;
|
||||
case 'input_value':
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
block.appendValueInput.calledOnce,
|
||||
'Expected a value input to be created.',
|
||||
);
|
||||
break;
|
||||
case 'input_statement':
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
block.appendStatementInput.calledOnce,
|
||||
'Expected a statement input to be created.',
|
||||
);
|
||||
break;
|
||||
default:
|
||||
chai.assert.isNull(input, 'Expected input to be null');
|
||||
chai.assert.isTrue(
|
||||
assert.isNull(input, 'Expected input to be null');
|
||||
assert.isTrue(
|
||||
block.appendDummyInput.notCalled,
|
||||
'Expected no input to be created',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
block.appendValueInput.notCalled,
|
||||
'Expected no input to be created',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
block.appendStatementInput.notCalled,
|
||||
'Expected no input to be created',
|
||||
);
|
||||
@@ -608,13 +609,13 @@ suite('Block JSON initialization', function () {
|
||||
}
|
||||
if (check) {
|
||||
if (Array.isArray(check)) {
|
||||
chai.assert.deepEqual(check, input.connection.getCheck());
|
||||
assert.deepEqual(check, input.connection.getCheck());
|
||||
} else {
|
||||
chai.assert.deepEqual([check], input.connection.getCheck());
|
||||
assert.deepEqual([check], input.connection.getCheck());
|
||||
}
|
||||
}
|
||||
if (align !== undefined) {
|
||||
chai.assert.equal(align, input.align);
|
||||
assert.equal(align, input.align);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -667,7 +668,7 @@ suite('Block JSON initialization', function () {
|
||||
);
|
||||
const block = this.workspace.newBlock('test_basic_empty');
|
||||
block.inputFromJson_({'type': 'custom'});
|
||||
chai.assert.instanceOf(
|
||||
assert.instanceOf(
|
||||
block.inputList[0],
|
||||
CustomInput,
|
||||
'Expected the registered input to be constructed',
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../../node_modules/chai/chai.js';
|
||||
import {runSerializationTestSuite} from '../test_helpers/serialization.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -37,8 +38,8 @@ suite('Lists', function () {
|
||||
fields: {MODE: 'GET', WHERE: 'FIRST'},
|
||||
},
|
||||
assertBlockStructure: (block) => {
|
||||
chai.assert.equal(block.type, 'lists_getIndex');
|
||||
chai.assert.exists(block.outputConnection);
|
||||
assert.equal(block.type, 'lists_getIndex');
|
||||
assert.exists(block.outputConnection);
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -50,9 +51,9 @@ suite('Lists', function () {
|
||||
fields: {MODE: 'REMOVE', WHERE: 'FROM_START'},
|
||||
},
|
||||
assertBlockStructure: (block) => {
|
||||
chai.assert.equal(block.type, 'lists_getIndex');
|
||||
chai.assert.isNotTrue(block.outputConnection);
|
||||
chai.assert.isTrue(
|
||||
assert.equal(block.type, 'lists_getIndex');
|
||||
assert.isNotTrue(block.outputConnection);
|
||||
assert.isTrue(
|
||||
block.getInput('AT').type === ConnectionType.INPUT_VALUE,
|
||||
);
|
||||
},
|
||||
@@ -122,7 +123,7 @@ suite('Lists', function () {
|
||||
title: 'JSON not requiring mutations',
|
||||
json: serializedJson,
|
||||
assertBlockStructure: (block) => {
|
||||
chai.assert.equal(block.type, serializedJson.type);
|
||||
assert.equal(block.type, serializedJson.type);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../../node_modules/chai/chai.js';
|
||||
import * as eventUtils from '../../../build/src/core/events/utils.js';
|
||||
import {runSerializationTestSuite} from '../test_helpers/serialization.js';
|
||||
import {
|
||||
@@ -28,21 +29,21 @@ suite('Logic ternary', function () {
|
||||
* inline.
|
||||
*/
|
||||
function assertBlockStructure(block, inputsInline = false) {
|
||||
chai.assert.equal(block.type, 'logic_ternary');
|
||||
assert.equal(block.type, 'logic_ternary');
|
||||
const inputs = block.inputList;
|
||||
chai.assert.exists(inputs, 'Has inputList');
|
||||
chai.assert.lengthOf(inputs, 3);
|
||||
assert.exists(inputs, 'Has inputList');
|
||||
assert.lengthOf(inputs, 3);
|
||||
const ifInput = block.getInput('IF');
|
||||
chai.assert.exists(ifInput, 'Has "IF" input');
|
||||
assert.exists(ifInput, 'Has "IF" input');
|
||||
const checkList = ifInput.connection.getCheck();
|
||||
chai.assert.equal(checkList.length, 1);
|
||||
chai.assert.equal(checkList[0], 'Boolean');
|
||||
chai.assert.exists(block.onchangeWrapper_, 'Has onchange handler');
|
||||
assert.equal(checkList.length, 1);
|
||||
assert.equal(checkList[0], 'Boolean');
|
||||
assert.exists(block.onchangeWrapper_, 'Has onchange handler');
|
||||
if (inputsInline) {
|
||||
chai.assert.isTrue(block.inputsInline);
|
||||
assert.isTrue(block.inputsInline);
|
||||
} else {
|
||||
// inputsInline can be undefined
|
||||
chai.assert.isNotTrue(block.inputsInline);
|
||||
assert.isNotTrue(block.inputsInline);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,20 +91,20 @@ suite('Logic ternary', function () {
|
||||
.getInput(parentInputName)
|
||||
.connection.connect(block.outputConnection);
|
||||
eventUtils.TEST_ONLY.fireNow(); // Force synchronous onchange() call.
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
block.getParent(),
|
||||
parent,
|
||||
'Successful connection to parent',
|
||||
);
|
||||
if (opt_thenInput) {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
opt_thenInput.getParent(),
|
||||
block,
|
||||
'Input THEN still connected after connecting parent',
|
||||
);
|
||||
}
|
||||
if (opt_elseInput) {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
opt_elseInput.getParent(),
|
||||
block,
|
||||
'Input ELSE still connected after connecting parent',
|
||||
@@ -118,16 +119,16 @@ suite('Logic ternary', function () {
|
||||
) {
|
||||
block.getInput('THEN').connection.connect(thenInput.outputConnection);
|
||||
eventUtils.TEST_ONLY.fireNow(); // Force synchronous onchange() call.
|
||||
chai.assert.equal(thenInput.getParent(), block, 'THEN is connected');
|
||||
assert.equal(thenInput.getParent(), block, 'THEN is connected');
|
||||
if (opt_parent) {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
block.getParent(),
|
||||
opt_parent,
|
||||
'Still connected to parent after connecting THEN',
|
||||
);
|
||||
}
|
||||
if (opt_elseInput) {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
opt_elseInput.getParent(),
|
||||
block,
|
||||
'Input ELSE still connected after connecting THEN',
|
||||
@@ -142,16 +143,16 @@ suite('Logic ternary', function () {
|
||||
) {
|
||||
block.getInput('ELSE').connection.connect(elseInput.outputConnection);
|
||||
eventUtils.TEST_ONLY.fireNow(); // Force synchronous onchange() call.
|
||||
chai.assert.equal(elseInput.getParent(), block, 'ELSE is connected');
|
||||
assert.equal(elseInput.getParent(), block, 'ELSE is connected');
|
||||
if (opt_parent) {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
block.getParent(),
|
||||
opt_parent,
|
||||
'Still connected to parent after connecting ELSE',
|
||||
);
|
||||
}
|
||||
if (opt_thenInput) {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
opt_thenInput.getParent(),
|
||||
block,
|
||||
'Input THEN still connected after connecting ELSE',
|
||||
@@ -232,7 +233,7 @@ suite('Logic ternary', function () {
|
||||
|
||||
// Adding mismatching number.
|
||||
connectThenInputAndCheckConnections(this.block, number, string);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.block.getRootBlock(),
|
||||
this.block,
|
||||
'Disconnected from parent',
|
||||
@@ -250,7 +251,7 @@ suite('Logic ternary', function () {
|
||||
|
||||
// Adding mismatching number.
|
||||
connectElseInputAndCheckConnections(this.block, number, string);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.block.getRootBlock(),
|
||||
this.block,
|
||||
'Disconnected from parent',
|
||||
@@ -302,11 +303,7 @@ suite('Logic ternary', function () {
|
||||
null,
|
||||
string,
|
||||
);
|
||||
chai.assert.equal(
|
||||
number.getRootBlock(),
|
||||
number,
|
||||
'Input THEN disconnected',
|
||||
);
|
||||
assert.equal(number.getRootBlock(), number, 'Input THEN disconnected');
|
||||
});
|
||||
test('Mismatch with else causes break with else', function () {
|
||||
const string = this.workspace.newBlock('text');
|
||||
@@ -316,11 +313,7 @@ suite('Logic ternary', function () {
|
||||
|
||||
const parent = this.workspace.newBlock('text_trim');
|
||||
connectParentAndCheckConnections(this.block, parent, 'TEXT', string);
|
||||
chai.assert.equal(
|
||||
number.getRootBlock(),
|
||||
number,
|
||||
'Input ELSE disconnected',
|
||||
);
|
||||
assert.equal(number.getRootBlock(), number, 'Input ELSE disconnected');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../../build/src/core/blockly.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -27,7 +28,7 @@ suite('Loops', function () {
|
||||
this.workspace,
|
||||
);
|
||||
this.clock.runAll();
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
breakBlock.isEnabled(),
|
||||
'Expected the break block to be disabled',
|
||||
);
|
||||
@@ -46,7 +47,7 @@ suite('Loops', function () {
|
||||
.getInput('DO')
|
||||
.connection.connect(breakBlock.previousConnection);
|
||||
this.clock.runAll();
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
breakBlock.isEnabled(),
|
||||
'Expected the break block to be enabled',
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../../build/src/core/blockly.js';
|
||||
import {
|
||||
assertCallBlockStructure,
|
||||
@@ -45,7 +46,7 @@ suite('Procedures', function () {
|
||||
|
||||
defBlock.setFieldValue('new name', 'NAME');
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
callBlock.getFieldValue('NAME'),
|
||||
'new name',
|
||||
'Expected the procedure block to be renamed',
|
||||
@@ -71,12 +72,12 @@ suite('Procedures', function () {
|
||||
|
||||
defBlockB.setFieldValue('procA', 'NAME');
|
||||
|
||||
chai.assert.notEqual(
|
||||
assert.notEqual(
|
||||
defBlockB.getFieldValue('NAME'),
|
||||
'procA',
|
||||
'Expected the procedure def block to have a legal name',
|
||||
);
|
||||
chai.assert.notEqual(
|
||||
assert.notEqual(
|
||||
callBlockB.getFieldValue('NAME'),
|
||||
'procA',
|
||||
'Expected the procedure call block to have a legal name',
|
||||
@@ -112,7 +113,7 @@ suite('Procedures', function () {
|
||||
.getWorkspace()
|
||||
.getTopBlocks(true)[0]
|
||||
.getFieldValue('NAME');
|
||||
chai.assert.notEqual(
|
||||
assert.notEqual(
|
||||
newFlyoutParamName,
|
||||
origFlyoutParamName,
|
||||
'Expected the flyout param to have updated to not conflict',
|
||||
@@ -133,11 +134,11 @@ suite('Procedures', function () {
|
||||
.connection.connect(paramBlock.previousConnection);
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
defBlock.getField('PARAMS'),
|
||||
'Expected the params field to exist',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
defBlock.getFieldValue('PARAMS').includes('param1'),
|
||||
'Expected the params field to contain the name of the new param',
|
||||
);
|
||||
@@ -158,11 +159,11 @@ suite('Procedures', function () {
|
||||
.connection.connect(paramBlock.previousConnection);
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
callBlock.getInput('ARG0'),
|
||||
'Expected the param input to exist',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
callBlock.getFieldValue('ARGNAME0'),
|
||||
'param1',
|
||||
'Expected the params field to match the name of the new param',
|
||||
@@ -185,7 +186,7 @@ suite('Procedures', function () {
|
||||
|
||||
this.workspace.undo();
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
defBlock.getFieldValue('PARAMS').includes('param1'),
|
||||
'Expected the params field to not contain the name of the new param',
|
||||
);
|
||||
@@ -211,11 +212,11 @@ suite('Procedures', function () {
|
||||
this.workspace.undo();
|
||||
this.workspace.undo(/* redo= */ true);
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
defBlock.getField('PARAMS'),
|
||||
'Expected the params field to exist',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
defBlock.getFieldValue('PARAMS').includes('param1'),
|
||||
'Expected the params field to contain the name of the new param',
|
||||
);
|
||||
@@ -241,7 +242,7 @@ suite('Procedures', function () {
|
||||
paramBlock.checkAndDelete();
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
defBlock.getFieldValue('PARAMS').includes('param1'),
|
||||
'Expected the params field to not contain the name of the new param',
|
||||
);
|
||||
@@ -265,7 +266,7 @@ suite('Procedures', function () {
|
||||
paramBlock.checkAndDelete();
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isNull(
|
||||
assert.isNull(
|
||||
callBlock.getInput('ARG0'),
|
||||
'Expected the param input to not exist',
|
||||
);
|
||||
@@ -289,7 +290,7 @@ suite('Procedures', function () {
|
||||
|
||||
this.workspace.undo();
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
defBlock.getFieldValue('PARAMS').includes('param1'),
|
||||
'Expected the params field to contain the name of the new param',
|
||||
);
|
||||
@@ -317,7 +318,7 @@ suite('Procedures', function () {
|
||||
this.workspace.undo();
|
||||
this.workspace.undo(/* redo= */ true);
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
defBlock.getFieldValue('PARAMS').includes('param1'),
|
||||
'Expected the params field to not contain the name of the new param',
|
||||
);
|
||||
@@ -343,11 +344,11 @@ suite('Procedures', function () {
|
||||
paramBlock.setFieldValue('new name', 'NAME');
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
defBlock.getField('PARAMS'),
|
||||
'Expected the params field to exist',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
defBlock.getFieldValue('PARAMS').includes('new name'),
|
||||
'Expected the params field to contain the new name of the param',
|
||||
);
|
||||
@@ -373,11 +374,11 @@ suite('Procedures', function () {
|
||||
paramBlock1.setFieldValue('new name', 'NAME');
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
defBlock.getField('PARAMS'),
|
||||
'Expected the params field to exist',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
defBlock.getFieldValue('PARAMS').includes('new name'),
|
||||
'Expected the params field to contain the new name of the param',
|
||||
);
|
||||
@@ -401,11 +402,11 @@ suite('Procedures', function () {
|
||||
paramBlock.setFieldValue('new name', 'NAME');
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
callBlock.getInput('ARG0'),
|
||||
'Expected the param input to exist',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
callBlock.getFieldValue('ARGNAME0'),
|
||||
'new name',
|
||||
'Expected the params field to match the name of the new param',
|
||||
@@ -430,7 +431,7 @@ suite('Procedures', function () {
|
||||
paramBlock.setFieldValue('param2', 'NAME');
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
this.workspace.getVariable('param1', ''),
|
||||
'Expected the old variable to continue to exist',
|
||||
);
|
||||
@@ -454,11 +455,11 @@ suite('Procedures', function () {
|
||||
const variable = this.workspace.getVariable('param1', '');
|
||||
this.workspace.renameVariableById(variable.getId(), 'new name');
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
defBlock.getField('PARAMS'),
|
||||
'Expected the params field to exist',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
defBlock.getFieldValue('PARAMS').includes('new name'),
|
||||
'Expected the params field to contain the new name of the param',
|
||||
);
|
||||
@@ -481,7 +482,7 @@ suite('Procedures', function () {
|
||||
const variable = this.workspace.getVariable('param1', '');
|
||||
this.workspace.renameVariableById(variable.getId(), 'new name');
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
paramBlock.getFieldValue('NAME'),
|
||||
'new name',
|
||||
'Expected the params field to contain the new name of the param',
|
||||
@@ -507,11 +508,11 @@ suite('Procedures', function () {
|
||||
const variable = this.workspace.getVariable('param1', '');
|
||||
this.workspace.renameVariableById(variable.getId(), 'new name');
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
callBlock.getInput('ARG0'),
|
||||
'Expected the param input to exist',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
callBlock.getFieldValue('ARGNAME0'),
|
||||
'new name',
|
||||
'Expected the params field to match the name of the new param',
|
||||
@@ -536,11 +537,11 @@ suite('Procedures', function () {
|
||||
const variable = this.workspace.getVariable('param1', '');
|
||||
this.workspace.renameVariableById(variable.getId(), 'preCreatedVar');
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
defBlock.getField('PARAMS'),
|
||||
'Expected the params field to exist',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
defBlock.getFieldValue('PARAMS').includes('preCreatedVar'),
|
||||
'Expected the params field to contain the new name of the param',
|
||||
);
|
||||
@@ -563,7 +564,7 @@ suite('Procedures', function () {
|
||||
const variable = this.workspace.getVariable('param1', '');
|
||||
this.workspace.renameVariableById(variable.getId(), 'preCreatedVar');
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
paramBlock.getFieldValue('NAME'),
|
||||
'preCreatedVar',
|
||||
'Expected the params field to contain the new name of the param',
|
||||
@@ -589,11 +590,11 @@ suite('Procedures', function () {
|
||||
const variable = this.workspace.getVariable('param1', '');
|
||||
this.workspace.renameVariableById(variable.getId(), 'preCreatedVar');
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
callBlock.getInput('ARG0'),
|
||||
'Expected the param input to exist',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
callBlock.getFieldValue('ARGNAME0'),
|
||||
'preCreatedVar',
|
||||
'Expected the params field to match the name of the new param',
|
||||
@@ -631,7 +632,7 @@ suite('Procedures', function () {
|
||||
this.workspace.undo();
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
defBlock.getFieldValue('PARAMS').includes('param1'),
|
||||
'Expected the params field to contain the old name of the param',
|
||||
);
|
||||
@@ -662,7 +663,7 @@ suite('Procedures', function () {
|
||||
this.workspace.undo();
|
||||
this.workspace.undo(/* redo= */ true);
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
defBlock.getFieldValue('PARAMS').includes('new'),
|
||||
'Expected the params field to contain the new name of the param',
|
||||
);
|
||||
@@ -696,11 +697,11 @@ suite('Procedures', function () {
|
||||
paramBlock2.nextConnection.connect(paramBlock1.previousConnection);
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
defBlock.getField('PARAMS'),
|
||||
'Expected the params field to exist',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
defBlock.getFieldValue('PARAMS').includes('param2, param1'),
|
||||
'Expected the params field order to match the parameter order',
|
||||
);
|
||||
@@ -733,20 +734,20 @@ suite('Procedures', function () {
|
||||
paramBlock2.nextConnection.connect(paramBlock1.previousConnection);
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
callBlock.getInput('ARG0'),
|
||||
'Expected the param input to exist',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
callBlock.getFieldValue('ARGNAME0'),
|
||||
'param2',
|
||||
'Expected the params field to match the name of the second param',
|
||||
);
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
callBlock.getInput('ARG1'),
|
||||
'Expected the param input to exist',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
callBlock.getFieldValue('ARGNAME1'),
|
||||
'param1',
|
||||
'Expected the params field to match the name of the first param',
|
||||
@@ -789,12 +790,12 @@ suite('Procedures', function () {
|
||||
paramBlock2.nextConnection.connect(paramBlock1.previousConnection);
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
callBlock.getInputTargetBlock('ARG0'),
|
||||
block2,
|
||||
'Expected the second block to be in the first slot',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
callBlock.getInputTargetBlock('ARG1'),
|
||||
block1,
|
||||
'Expected the first block to be in the second slot',
|
||||
@@ -814,7 +815,7 @@ suite('Procedures', function () {
|
||||
defBlock.setDisabledReason(true, 'MANUALLY_DISABLED');
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
callBlock.isEnabled(),
|
||||
'Expected the caller block to be disabled',
|
||||
);
|
||||
@@ -831,7 +832,7 @@ suite('Procedures', function () {
|
||||
defBlock.setDisabledReason(true, 'test reason');
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
callBlock.isEnabled(),
|
||||
'Expected the caller block to be invalid',
|
||||
);
|
||||
@@ -850,7 +851,7 @@ suite('Procedures', function () {
|
||||
defBlock.setDisabledReason(false, 'MANUALLY_DISABLED');
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
callBlock.isEnabled(),
|
||||
'Expected the caller block to be enabled',
|
||||
);
|
||||
@@ -872,7 +873,7 @@ suite('Procedures', function () {
|
||||
defBlock.setDisabledReason(false, 'MANUALLY_DISABLED');
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
callBlock.isEnabled(),
|
||||
'Expected the caller block to continue to be disabled',
|
||||
);
|
||||
@@ -887,7 +888,7 @@ suite('Procedures', function () {
|
||||
this.workspace,
|
||||
);
|
||||
this.clock.runAll();
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
ifreturnBlock.isEnabled(),
|
||||
'Expected the ifreturn block to be invalid',
|
||||
);
|
||||
@@ -903,7 +904,7 @@ suite('Procedures', function () {
|
||||
.getInput('STACK')
|
||||
.connection.connect(ifreturnBlock.previousConnection);
|
||||
this.clock.runAll();
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
ifreturnBlock.isEnabled(),
|
||||
'Expected the ifreturn block to be valid',
|
||||
);
|
||||
@@ -923,11 +924,11 @@ suite('Procedures', function () {
|
||||
defBlock.dispose();
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
callBlock1.disposed,
|
||||
'Expected the first caller to be disposed',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
callBlock2.disposed,
|
||||
'Expected the second caller to be disposed',
|
||||
);
|
||||
@@ -1233,7 +1234,7 @@ suite('Procedures', function () {
|
||||
const options = [];
|
||||
def.customContextMenu(options);
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
options[0].text.includes('test name'),
|
||||
'Expected the context menu to have an option to create the caller',
|
||||
);
|
||||
@@ -1267,11 +1268,11 @@ suite('Procedures', function () {
|
||||
const options = [];
|
||||
def.customContextMenu(options);
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
options[1].text.includes('testParam1'),
|
||||
'Expected the context menu to have an option to create the first param',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
options[2].text.includes('testParam2'),
|
||||
'Expected the context menu to have an option to create the second param',
|
||||
);
|
||||
@@ -1286,13 +1287,13 @@ suite('Procedures', function () {
|
||||
returnBlock.setFieldValue('return', 'NAME');
|
||||
|
||||
const allProcedures = Blockly.Procedures.allProcedures(this.workspace);
|
||||
chai.assert.lengthOf(allProcedures, 2);
|
||||
assert.lengthOf(allProcedures, 2);
|
||||
|
||||
chai.assert.lengthOf(allProcedures[0], 1);
|
||||
chai.assert.equal(allProcedures[0][0][0], 'no return');
|
||||
assert.lengthOf(allProcedures[0], 1);
|
||||
assert.equal(allProcedures[0][0][0], 'no return');
|
||||
|
||||
chai.assert.lengthOf(allProcedures[1], 1);
|
||||
chai.assert.equal(allProcedures[1][0][0], 'return');
|
||||
assert.lengthOf(allProcedures[1], 1);
|
||||
assert.equal(allProcedures[1][0][0], 'return');
|
||||
});
|
||||
|
||||
test('Multiple Blocks', function () {
|
||||
@@ -1305,26 +1306,26 @@ suite('Procedures', function () {
|
||||
const _ = this.workspace.newBlock('controls_if');
|
||||
|
||||
const allProcedures = Blockly.Procedures.allProcedures(this.workspace);
|
||||
chai.assert.lengthOf(allProcedures, 2);
|
||||
assert.lengthOf(allProcedures, 2);
|
||||
|
||||
chai.assert.lengthOf(allProcedures[0], 1);
|
||||
chai.assert.equal(allProcedures[0][0][0], 'no return');
|
||||
assert.lengthOf(allProcedures[0], 1);
|
||||
assert.equal(allProcedures[0][0][0], 'no return');
|
||||
|
||||
chai.assert.lengthOf(allProcedures[1], 2);
|
||||
chai.assert.equal(allProcedures[1][0][0], 'return');
|
||||
chai.assert.equal(allProcedures[1][1][0], 'return2');
|
||||
assert.lengthOf(allProcedures[1], 2);
|
||||
assert.equal(allProcedures[1][0][0], 'return');
|
||||
assert.equal(allProcedures[1][1][0], 'return2');
|
||||
});
|
||||
|
||||
test('No Procedures', function () {
|
||||
const _ = this.workspace.newBlock('controls_if');
|
||||
const allProcedures = Blockly.Procedures.allProcedures(this.workspace);
|
||||
chai.assert.lengthOf(allProcedures, 2);
|
||||
chai.assert.lengthOf(
|
||||
assert.lengthOf(allProcedures, 2);
|
||||
assert.lengthOf(
|
||||
allProcedures[0],
|
||||
0,
|
||||
'No procedures_defnoreturn blocks expected',
|
||||
);
|
||||
chai.assert.lengthOf(
|
||||
assert.lengthOf(
|
||||
allProcedures[1],
|
||||
0,
|
||||
'No procedures_defreturn blocks expected',
|
||||
@@ -1334,21 +1335,19 @@ suite('Procedures', function () {
|
||||
|
||||
suite('isNameUsed', function () {
|
||||
test('returns false if no blocks or models exists', function () {
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
Blockly.Procedures.isNameUsed('proc name', this.workspace),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns true if an associated block exists', function () {
|
||||
createProcDefBlock(this.workspace, false, [], 'proc name');
|
||||
chai.assert.isTrue(
|
||||
Blockly.Procedures.isNameUsed('proc name', this.workspace),
|
||||
);
|
||||
assert.isTrue(Blockly.Procedures.isNameUsed('proc name', this.workspace));
|
||||
});
|
||||
|
||||
test('return false if an associated block does not exist', function () {
|
||||
createProcDefBlock(this.workspace, false, [], 'proc name');
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
Blockly.Procedures.isNameUsed('other proc name', this.workspace),
|
||||
);
|
||||
});
|
||||
@@ -1357,16 +1356,14 @@ suite('Procedures', function () {
|
||||
this.workspace
|
||||
.getProcedureMap()
|
||||
.add(new MockProcedureModel().setName('proc name'));
|
||||
chai.assert.isTrue(
|
||||
Blockly.Procedures.isNameUsed('proc name', this.workspace),
|
||||
);
|
||||
assert.isTrue(Blockly.Procedures.isNameUsed('proc name', this.workspace));
|
||||
});
|
||||
|
||||
test('returns false if an associated procedure model exists', function () {
|
||||
this.workspace
|
||||
.getProcedureMap()
|
||||
.add(new MockProcedureModel().setName('proc name'));
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
Blockly.Procedures.isNameUsed('other proc name', this.workspace),
|
||||
);
|
||||
});
|
||||
@@ -1381,20 +1378,20 @@ suite('Procedures', function () {
|
||||
) {
|
||||
const allProcedures = Blockly.Procedures.allProcedures(workspace);
|
||||
const defNoReturnBlocks = allProcedures[0];
|
||||
chai.assert.lengthOf(
|
||||
assert.lengthOf(
|
||||
defNoReturnBlocks,
|
||||
noReturnNames.length,
|
||||
`Expected the number of no return blocks to be ${noReturnNames.length}`,
|
||||
);
|
||||
for (let i = 0; i < noReturnNames.length; i++) {
|
||||
const expectedName = noReturnNames[i];
|
||||
chai.assert.equal(defNoReturnBlocks[i][0], expectedName);
|
||||
assert.equal(defNoReturnBlocks[i][0], expectedName);
|
||||
if (hasCallers) {
|
||||
const callers = Blockly.Procedures.getCallers(
|
||||
expectedName,
|
||||
workspace,
|
||||
);
|
||||
chai.assert.lengthOf(
|
||||
assert.lengthOf(
|
||||
callers,
|
||||
1,
|
||||
`Expected there to be one caller of the ${expectedName} block`,
|
||||
@@ -1402,20 +1399,20 @@ suite('Procedures', function () {
|
||||
}
|
||||
}
|
||||
const defReturnBlocks = allProcedures[1];
|
||||
chai.assert.lengthOf(
|
||||
assert.lengthOf(
|
||||
defReturnBlocks,
|
||||
returnNames.length,
|
||||
`Expected the number of return blocks to be ${returnNames.length}`,
|
||||
);
|
||||
for (let i = 0; i < returnNames.length; i++) {
|
||||
const expectedName = returnNames[i];
|
||||
chai.assert.equal(defReturnBlocks[i][0], expectedName);
|
||||
assert.equal(defReturnBlocks[i][0], expectedName);
|
||||
if (hasCallers) {
|
||||
const callers = Blockly.Procedures.getCallers(
|
||||
expectedName,
|
||||
workspace,
|
||||
);
|
||||
chai.assert.lengthOf(
|
||||
assert.lengthOf(
|
||||
callers,
|
||||
1,
|
||||
`Expected there to be one caller of the ${expectedName} block`,
|
||||
@@ -1429,7 +1426,7 @@ suite('Procedures', function () {
|
||||
expectedCount *= 2;
|
||||
}
|
||||
const blocks = workspace.getAllBlocks(false);
|
||||
chai.assert.lengthOf(blocks, expectedCount);
|
||||
assert.lengthOf(blocks, expectedCount);
|
||||
}
|
||||
|
||||
suite('no name renamed to unnamed', function () {
|
||||
@@ -1532,7 +1529,7 @@ suite('Procedures', function () {
|
||||
// Do not require procedures to be the built-in procedures.
|
||||
const defBlock = this.workspace.newBlock('new_proc');
|
||||
const def = Blockly.Procedures.getDefinition('test', this.workspace);
|
||||
chai.assert.equal(def, defBlock);
|
||||
assert.equal(def, defBlock);
|
||||
});
|
||||
|
||||
test('Stacked procedures', function () {
|
||||
@@ -1542,7 +1539,7 @@ suite('Procedures', function () {
|
||||
blockB.name = 'b';
|
||||
blockA.nextConnection.connect(blockB.previousConnection);
|
||||
const def = Blockly.Procedures.getDefinition('b', this.workspace);
|
||||
chai.assert.equal(def, blockB);
|
||||
assert.equal(def, blockB);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1612,8 +1609,8 @@ suite('Procedures', function () {
|
||||
this.defBlock.getFieldValue('NAME') + '2',
|
||||
'NAME',
|
||||
);
|
||||
chai.assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name2');
|
||||
chai.assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name2');
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name2');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name2');
|
||||
});
|
||||
test('Simple, Input', function () {
|
||||
const defInput = this.defBlock.getField('NAME');
|
||||
@@ -1625,8 +1622,8 @@ suite('Procedures', function () {
|
||||
|
||||
defInput.htmlInput_.value = 'proc name2';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
chai.assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name2');
|
||||
chai.assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name2');
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name2');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name2');
|
||||
});
|
||||
test('lower -> CAPS', function () {
|
||||
const defInput = this.defBlock.getField('NAME');
|
||||
@@ -1638,8 +1635,8 @@ suite('Procedures', function () {
|
||||
|
||||
defInput.htmlInput_.value = 'PROC NAME';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
chai.assert.equal(this.defBlock.getFieldValue('NAME'), 'PROC NAME');
|
||||
chai.assert.equal(this.callBlock.getFieldValue('NAME'), 'PROC NAME');
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'PROC NAME');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'PROC NAME');
|
||||
});
|
||||
test('CAPS -> lower', function () {
|
||||
this.defBlock.setFieldValue('PROC NAME', 'NAME');
|
||||
@@ -1653,8 +1650,8 @@ suite('Procedures', function () {
|
||||
|
||||
defInput.htmlInput_.value = 'proc name';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
chai.assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name');
|
||||
chai.assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name');
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name');
|
||||
});
|
||||
test('Whitespace', function () {
|
||||
const defInput = this.defBlock.getField('NAME');
|
||||
@@ -1666,8 +1663,8 @@ suite('Procedures', function () {
|
||||
|
||||
defInput.htmlInput_.value = 'proc name ';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
chai.assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name');
|
||||
chai.assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name');
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name');
|
||||
});
|
||||
test('Whitespace then Text', function () {
|
||||
const defInput = this.defBlock.getField('NAME');
|
||||
@@ -1681,11 +1678,8 @@ suite('Procedures', function () {
|
||||
defInput.onHtmlInputChange_(null);
|
||||
defInput.htmlInput_.value = 'proc name 2';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
chai.assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name 2');
|
||||
chai.assert.equal(
|
||||
this.callBlock.getFieldValue('NAME'),
|
||||
'proc name 2',
|
||||
);
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name 2');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name 2');
|
||||
});
|
||||
test('Set Empty', function () {
|
||||
const defInput = this.defBlock.getField('NAME');
|
||||
@@ -1697,11 +1691,11 @@ suite('Procedures', function () {
|
||||
|
||||
defInput.htmlInput_.value = '';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.defBlock.getFieldValue('NAME'),
|
||||
Blockly.Msg['UNNAMED_KEY'],
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.callBlock.getFieldValue('NAME'),
|
||||
Blockly.Msg['UNNAMED_KEY'],
|
||||
);
|
||||
@@ -1718,11 +1712,11 @@ suite('Procedures', function () {
|
||||
defInput.onHtmlInputChange_(null);
|
||||
const newDefBlock = this.workspace.newBlock(testSuite.defType);
|
||||
newDefBlock.setFieldValue('new name', 'NAME');
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.defBlock.getFieldValue('NAME'),
|
||||
Blockly.Msg['UNNAMED_KEY'],
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.callBlock.getFieldValue('NAME'),
|
||||
Blockly.Msg['UNNAMED_KEY'],
|
||||
);
|
||||
@@ -1754,8 +1748,8 @@ suite('Procedures', function () {
|
||||
'proc name',
|
||||
this.workspace,
|
||||
);
|
||||
chai.assert.equal(callers.length, 1);
|
||||
chai.assert.equal(callers[0], this.callBlock);
|
||||
assert.equal(callers.length, 1);
|
||||
assert.equal(callers[0], this.callBlock);
|
||||
});
|
||||
test('Multiple Callers', function () {
|
||||
const caller2 = this.workspace.newBlock(testSuite.callType);
|
||||
@@ -1767,10 +1761,10 @@ suite('Procedures', function () {
|
||||
'proc name',
|
||||
this.workspace,
|
||||
);
|
||||
chai.assert.equal(callers.length, 3);
|
||||
chai.assert.equal(callers[0], this.callBlock);
|
||||
chai.assert.equal(callers[1], caller2);
|
||||
chai.assert.equal(callers[2], caller3);
|
||||
assert.equal(callers.length, 3);
|
||||
assert.equal(callers[0], this.callBlock);
|
||||
assert.equal(callers[1], caller2);
|
||||
assert.equal(callers[2], caller3);
|
||||
});
|
||||
test('Multiple Procedures', function () {
|
||||
const def2 = this.workspace.newBlock(testSuite.defType);
|
||||
@@ -1782,8 +1776,8 @@ suite('Procedures', function () {
|
||||
'proc name',
|
||||
this.workspace,
|
||||
);
|
||||
chai.assert.equal(callers.length, 1);
|
||||
chai.assert.equal(callers[0], this.callBlock);
|
||||
assert.equal(callers.length, 1);
|
||||
assert.equal(callers[0], this.callBlock);
|
||||
});
|
||||
// This can occur if you:
|
||||
// 1) Create an uppercase definition and call block.
|
||||
@@ -1799,8 +1793,8 @@ suite('Procedures', function () {
|
||||
'proc name',
|
||||
this.workspace,
|
||||
);
|
||||
chai.assert.equal(callers.length, 1);
|
||||
chai.assert.equal(callers[0], this.callBlock);
|
||||
assert.equal(callers.length, 1);
|
||||
assert.equal(callers[0], this.callBlock);
|
||||
});
|
||||
test('Multiple Workspaces', function () {
|
||||
const workspace = new Blockly.Workspace();
|
||||
@@ -1814,12 +1808,12 @@ suite('Procedures', function () {
|
||||
'proc name',
|
||||
this.workspace,
|
||||
);
|
||||
chai.assert.equal(callers.length, 1);
|
||||
chai.assert.equal(callers[0], this.callBlock);
|
||||
assert.equal(callers.length, 1);
|
||||
assert.equal(callers[0], this.callBlock);
|
||||
|
||||
callers = Blockly.Procedures.getCallers('proc name', workspace);
|
||||
chai.assert.equal(callers.length, 1);
|
||||
chai.assert.equal(callers[0], caller2);
|
||||
assert.equal(callers.length, 1);
|
||||
assert.equal(callers[0], caller2);
|
||||
} finally {
|
||||
workspaceTeardown.call(this, workspace);
|
||||
}
|
||||
@@ -1851,7 +1845,7 @@ suite('Procedures', function () {
|
||||
'proc name',
|
||||
this.workspace,
|
||||
);
|
||||
chai.assert.equal(def, this.defBlock);
|
||||
assert.equal(def, this.defBlock);
|
||||
});
|
||||
test('Multiple Procedures', function () {
|
||||
const def2 = this.workspace.newBlock(testSuite.defType);
|
||||
@@ -1863,7 +1857,7 @@ suite('Procedures', function () {
|
||||
'proc name',
|
||||
this.workspace,
|
||||
);
|
||||
chai.assert.equal(def, this.defBlock);
|
||||
assert.equal(def, this.defBlock);
|
||||
});
|
||||
test('Multiple Workspaces', function () {
|
||||
const workspace = new Blockly.Workspace();
|
||||
@@ -1877,10 +1871,10 @@ suite('Procedures', function () {
|
||||
'proc name',
|
||||
this.workspace,
|
||||
);
|
||||
chai.assert.equal(def, this.defBlock);
|
||||
assert.equal(def, this.defBlock);
|
||||
|
||||
def = Blockly.Procedures.getDefinition('proc name', workspace);
|
||||
chai.assert.equal(def, def2);
|
||||
assert.equal(def, def2);
|
||||
} finally {
|
||||
workspaceTeardown.call(this, workspace);
|
||||
}
|
||||
@@ -1925,11 +1919,11 @@ suite('Procedures', function () {
|
||||
if (testSuite.defType === 'procedures_defreturn') {
|
||||
test('Has Statements', function () {
|
||||
setStatementValue(this.workspace, this.defBlock, true);
|
||||
chai.assert.isTrue(this.defBlock.hasStatements_);
|
||||
assert.isTrue(this.defBlock.hasStatements_);
|
||||
});
|
||||
test('Has No Statements', function () {
|
||||
setStatementValue(this.workspace, this.defBlock, false);
|
||||
chai.assert.isFalse(this.defBlock.hasStatements_);
|
||||
assert.isFalse(this.defBlock.hasStatements_);
|
||||
});
|
||||
test('Saving Statements', function () {
|
||||
const blockXml = Blockly.utils.xml.textToDom(
|
||||
@@ -1944,14 +1938,14 @@ suite('Procedures', function () {
|
||||
this.workspace,
|
||||
);
|
||||
setStatementValue(this.workspace, defBlock, false);
|
||||
chai.assert.isNull(defBlock.getInput('STACK'));
|
||||
assert.isNull(defBlock.getInput('STACK'));
|
||||
setStatementValue(this.workspace, defBlock, true);
|
||||
chai.assert.isNotNull(defBlock.getInput('STACK'));
|
||||
assert.isNotNull(defBlock.getInput('STACK'));
|
||||
const statementBlocks = defBlock.getChildren();
|
||||
chai.assert.equal(statementBlocks.length, 1);
|
||||
assert.equal(statementBlocks.length, 1);
|
||||
const block = statementBlocks[0];
|
||||
chai.assert.equal(block.type, 'procedures_ifreturn');
|
||||
chai.assert.equal(block.id, 'test');
|
||||
assert.equal(block.type, 'procedures_ifreturn');
|
||||
assert.equal(block.id, 'test');
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1976,21 +1970,21 @@ suite('Procedures', function () {
|
||||
this.clock.runAll();
|
||||
}
|
||||
function assertArgs(argArray) {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.defBlock.getVars().length,
|
||||
argArray.length,
|
||||
'Expected the def to have the right number of arguments',
|
||||
);
|
||||
for (let i = 0; i < argArray.length; i++) {
|
||||
chai.assert.equal(this.defBlock.getVars()[i], argArray[i]);
|
||||
assert.equal(this.defBlock.getVars()[i], argArray[i]);
|
||||
}
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.callBlock.getVars().length,
|
||||
argArray.length,
|
||||
'Expected the call to have the right number of arguments',
|
||||
);
|
||||
for (let i = 0; i < argArray.length; i++) {
|
||||
chai.assert.equal(this.callBlock.getVars()[i], argArray[i]);
|
||||
assert.equal(this.callBlock.getVars()[i], argArray[i]);
|
||||
}
|
||||
}
|
||||
test('Simple Add Arg', async function () {
|
||||
@@ -2062,7 +2056,7 @@ suite('Procedures', function () {
|
||||
const statementInput = mutatorWorkspace
|
||||
.getTopBlocks()[0]
|
||||
.getInput('STATEMENT_INPUT');
|
||||
chai.assert.isNotNull(statementInput);
|
||||
assert.isNotNull(statementInput);
|
||||
});
|
||||
test('Has Statements', function () {
|
||||
this.defBlock.hasStatements_ = true;
|
||||
@@ -2076,7 +2070,7 @@ suite('Procedures', function () {
|
||||
.getTopBlocks()[0]
|
||||
.getField('STATEMENTS')
|
||||
.getValueBoolean();
|
||||
chai.assert.isTrue(statementValue);
|
||||
assert.isTrue(statementValue);
|
||||
});
|
||||
test('No Has Statements', function () {
|
||||
this.defBlock.hasStatements_ = false;
|
||||
@@ -2090,7 +2084,7 @@ suite('Procedures', function () {
|
||||
.getTopBlocks()[0]
|
||||
.getField('STATEMENTS')
|
||||
.getValueBoolean();
|
||||
chai.assert.isFalse(statementValue);
|
||||
assert.isFalse(statementValue);
|
||||
});
|
||||
} else {
|
||||
test('Has no Statement Input', function () {
|
||||
@@ -2103,7 +2097,7 @@ suite('Procedures', function () {
|
||||
const statementInput = mutatorWorkspace
|
||||
.getTopBlocks()[0]
|
||||
.getInput('STATEMENT_INPUT');
|
||||
chai.assert.isNull(statementInput);
|
||||
assert.isNull(statementInput);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -64,7 +65,7 @@ suite('Variables', function () {
|
||||
createTestVarBlock(this.workspace, '3');
|
||||
|
||||
const result = Blockly.Variables.allUsedVarModels(this.workspace);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
result.length,
|
||||
3,
|
||||
'Expected three variables in the list of used variables',
|
||||
@@ -75,12 +76,12 @@ suite('Variables', function () {
|
||||
createTestVarBlock(this.workspace, '2');
|
||||
|
||||
const result = Blockly.Variables.allUsedVarModels(this.workspace);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
result.length,
|
||||
1,
|
||||
'Expected one variable in the list of used variables',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
result[0].getId(),
|
||||
'2',
|
||||
'Expected variable with ID 2 in the list of used variables',
|
||||
@@ -94,12 +95,12 @@ suite('Variables', function () {
|
||||
const result = Blockly.Variables.allUsedVarModels(this.workspace);
|
||||
// Using the same variable multiple times should not change the number of
|
||||
// elements in the list.
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
result.length,
|
||||
1,
|
||||
'Expected one variable in the list of used variables',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
result[0].getId(),
|
||||
'2',
|
||||
'Expected variable with ID 2 in the list of used variables',
|
||||
@@ -108,7 +109,7 @@ suite('Variables', function () {
|
||||
|
||||
test('All unused', function () {
|
||||
const result = Blockly.Variables.allUsedVarModels(this.workspace);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
result.length,
|
||||
0,
|
||||
'Expected no variables in the list of used variables',
|
||||
@@ -125,9 +126,9 @@ suite('Variables', function () {
|
||||
const result2 = Blockly.Variables.getVariable(this.workspace, 'id2');
|
||||
const result3 = Blockly.Variables.getVariable(this.workspace, 'id3');
|
||||
|
||||
chai.assert.equal(var1, result1);
|
||||
chai.assert.equal(var2, result2);
|
||||
chai.assert.equal(var3, result3);
|
||||
assert.equal(var1, result1);
|
||||
assert.equal(var2, result2);
|
||||
assert.equal(var3, result3);
|
||||
});
|
||||
|
||||
test('By name and type', function () {
|
||||
@@ -154,9 +155,9 @@ suite('Variables', function () {
|
||||
);
|
||||
|
||||
// Searching by name + type is correct.
|
||||
chai.assert.equal(var1, result1);
|
||||
chai.assert.equal(var2, result2);
|
||||
chai.assert.equal(var3, result3);
|
||||
assert.equal(var1, result1);
|
||||
assert.equal(var2, result2);
|
||||
assert.equal(var3, result3);
|
||||
});
|
||||
|
||||
test('Bad ID with name and type fallback', function () {
|
||||
@@ -183,9 +184,9 @@ suite('Variables', function () {
|
||||
);
|
||||
|
||||
// Searching by ID failed, but falling back onto name + type is correct.
|
||||
chai.assert.equal(var1, result1);
|
||||
chai.assert.equal(var2, result2);
|
||||
chai.assert.equal(var3, result3);
|
||||
assert.equal(var1, result1);
|
||||
assert.equal(var2, result2);
|
||||
assert.equal(var3, result3);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -214,7 +215,7 @@ suite('Variables', function () {
|
||||
this.workspace,
|
||||
);
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
'test name',
|
||||
nameUsedWithConflictingParam('x', 'y', this.workspace),
|
||||
'Expected the name of the procedure with the conflicting ' +
|
||||
@@ -248,7 +249,7 @@ suite('Variables', function () {
|
||||
this.workspace,
|
||||
);
|
||||
|
||||
chai.assert.isNull(
|
||||
assert.isNull(
|
||||
nameUsedWithConflictingParam('x', 'y', this.workspace),
|
||||
'Expected there to be no conflict',
|
||||
);
|
||||
@@ -270,7 +271,7 @@ suite('Variables', function () {
|
||||
),
|
||||
);
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
'test name',
|
||||
nameUsedWithConflictingParam('x', 'y', this.workspace),
|
||||
'Expected the name of the procedure with the conflicting ' +
|
||||
@@ -299,7 +300,7 @@ suite('Variables', function () {
|
||||
),
|
||||
);
|
||||
|
||||
chai.assert.isNull(
|
||||
assert.isNull(
|
||||
nameUsedWithConflictingParam('x', 'y', this.workspace),
|
||||
'Expected there to be no conflict',
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -30,7 +31,7 @@ suite('Clipboard', function () {
|
||||
Blockly.clipboard.registry.register('test-paster', paster);
|
||||
|
||||
Blockly.clipboard.paste({paster: 'test-paster'}, this.workspace);
|
||||
chai.assert.isTrue(paster.paste.calledOnce);
|
||||
assert.isTrue(paster.paste.calledOnce);
|
||||
|
||||
Blockly.clipboard.registry.unregister('test-paster');
|
||||
});
|
||||
@@ -73,7 +74,7 @@ suite('Clipboard', function () {
|
||||
const data = block.toCopyData();
|
||||
|
||||
const newBlock = Blockly.clipboard.paste(data, this.workspace);
|
||||
chai.assert.deepEqual(
|
||||
assert.deepEqual(
|
||||
newBlock.getRelativeToSurfaceXY(),
|
||||
new Blockly.utils.Coordinate(66, 69),
|
||||
);
|
||||
@@ -105,7 +106,7 @@ suite('Clipboard', function () {
|
||||
const data = this.workspace.getBlockById('sourceBlockId').toCopyData();
|
||||
|
||||
const newBlock = Blockly.clipboard.paste(data, this.workspace);
|
||||
chai.assert.deepEqual(
|
||||
assert.deepEqual(
|
||||
newBlock.getRelativeToSurfaceXY(),
|
||||
new Blockly.utils.Coordinate(94, 125),
|
||||
);
|
||||
@@ -126,7 +127,7 @@ suite('Clipboard', function () {
|
||||
const data = comment.toCopyData();
|
||||
|
||||
const newComment = Blockly.clipboard.paste(data, this.workspace);
|
||||
chai.assert.deepEqual(
|
||||
assert.deepEqual(
|
||||
newComment.getRelativeToSurfaceXY(),
|
||||
new Blockly.utils.Coordinate(60, 60),
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -60,23 +61,23 @@ suite('Comment Deserialization', function () {
|
||||
icon.setBubbleVisible(true);
|
||||
// Check comment bubble size.
|
||||
const bubbleSize = icon.getBubbleSize();
|
||||
chai.assert.isNotNaN(bubbleSize.width);
|
||||
chai.assert.isNotNaN(bubbleSize.height);
|
||||
chai.assert.equal(icon.getText(), text);
|
||||
assert.isNotNaN(bubbleSize.width);
|
||||
assert.isNotNaN(bubbleSize.height);
|
||||
assert.equal(icon.getText(), text);
|
||||
}
|
||||
test('Trashcan', function () {
|
||||
// Create block.
|
||||
this.block = createBlock(this.workspace);
|
||||
// Delete block.
|
||||
this.block.checkAndDelete();
|
||||
chai.assert.equal(this.workspace.getAllBlocks().length, 0);
|
||||
assert.equal(this.workspace.getAllBlocks().length, 0);
|
||||
// Open trashcan.
|
||||
simulateClick(this.workspace.trashcan.svgGroup);
|
||||
// Place from trashcan.
|
||||
simulateClick(
|
||||
this.workspace.trashcan.flyout.svgGroup_.querySelector('.blocklyPath'),
|
||||
);
|
||||
chai.assert.equal(this.workspace.getAllBlocks().length, 1);
|
||||
assert.equal(this.workspace.getAllBlocks().length, 1);
|
||||
// Check comment.
|
||||
assertComment(this.workspace, 'test text');
|
||||
});
|
||||
@@ -85,10 +86,10 @@ suite('Comment Deserialization', function () {
|
||||
this.block = createBlock(this.workspace);
|
||||
// Delete block.
|
||||
this.block.checkAndDelete();
|
||||
chai.assert.equal(this.workspace.getAllBlocks().length, 0);
|
||||
assert.equal(this.workspace.getAllBlocks().length, 0);
|
||||
// Undo.
|
||||
this.workspace.undo(false);
|
||||
chai.assert.equal(this.workspace.getAllBlocks().length, 1);
|
||||
assert.equal(this.workspace.getAllBlocks().length, 1);
|
||||
// Check comment.
|
||||
assertComment(this.workspace, 'test text');
|
||||
});
|
||||
@@ -98,11 +99,11 @@ suite('Comment Deserialization', function () {
|
||||
// Undo & undo.
|
||||
this.workspace.undo(false);
|
||||
this.workspace.undo(false);
|
||||
chai.assert.equal(this.workspace.getAllBlocks().length, 0);
|
||||
assert.equal(this.workspace.getAllBlocks().length, 0);
|
||||
// Redo & redo.
|
||||
this.workspace.undo(true);
|
||||
this.workspace.undo(true);
|
||||
chai.assert.equal(this.workspace.getAllBlocks().length, 1);
|
||||
assert.equal(this.workspace.getAllBlocks().length, 1);
|
||||
// Check comment.
|
||||
assertComment(this.workspace, 'test text');
|
||||
});
|
||||
@@ -113,7 +114,7 @@ suite('Comment Deserialization', function () {
|
||||
simulateClick(
|
||||
toolbox.getFlyout().svgGroup_.querySelector('.blocklyPath'),
|
||||
);
|
||||
chai.assert.equal(this.workspace.getAllBlocks().length, 1);
|
||||
assert.equal(this.workspace.getAllBlocks().length, 1);
|
||||
// Check comment.
|
||||
assertComment(this.workspace, 'test toolbox text');
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {assertEventFired} from './test_helpers/events.js';
|
||||
import * as eventUtils from '../../build/src/core/events/utils.js';
|
||||
import {
|
||||
@@ -40,16 +41,16 @@ suite('Comments', function () {
|
||||
});
|
||||
|
||||
function assertEditable(comment) {
|
||||
chai.assert.isNotOk(comment.textBubble);
|
||||
chai.assert.isOk(comment.textInputBubble);
|
||||
assert.isNotOk(comment.textBubble);
|
||||
assert.isOk(comment.textInputBubble);
|
||||
}
|
||||
function assertNotEditable(comment) {
|
||||
chai.assert.isNotOk(comment.textInputBubble);
|
||||
chai.assert.isOk(comment.textBubble);
|
||||
assert.isNotOk(comment.textInputBubble);
|
||||
assert.isOk(comment.textBubble);
|
||||
}
|
||||
test('Editable', async function () {
|
||||
await this.comment.setBubbleVisible(true);
|
||||
chai.assert.isTrue(this.comment.bubbleIsVisible());
|
||||
assert.isTrue(this.comment.bubbleIsVisible());
|
||||
assertEditable(this.comment);
|
||||
assertEventFired(
|
||||
this.eventsFireStub,
|
||||
@@ -64,7 +65,7 @@ suite('Comments', function () {
|
||||
|
||||
await this.comment.setBubbleVisible(true);
|
||||
|
||||
chai.assert.isTrue(this.comment.bubbleIsVisible());
|
||||
assert.isTrue(this.comment.bubbleIsVisible());
|
||||
assertNotEditable(this.comment);
|
||||
assertEventFired(
|
||||
this.eventsFireStub,
|
||||
@@ -80,7 +81,7 @@ suite('Comments', function () {
|
||||
|
||||
await this.comment.updateEditable();
|
||||
|
||||
chai.assert.isTrue(this.comment.bubbleIsVisible());
|
||||
assert.isTrue(this.comment.bubbleIsVisible());
|
||||
assertNotEditable(this.comment);
|
||||
assertEventFired(
|
||||
this.eventsFireStub,
|
||||
@@ -98,7 +99,7 @@ suite('Comments', function () {
|
||||
editableStub.returns(true);
|
||||
|
||||
await this.comment.updateEditable();
|
||||
chai.assert.isTrue(this.comment.bubbleIsVisible());
|
||||
assert.isTrue(this.comment.bubbleIsVisible());
|
||||
assertEditable(this.comment);
|
||||
assertEventFired(
|
||||
this.eventsFireStub,
|
||||
@@ -115,8 +116,8 @@ suite('Comments', function () {
|
||||
});
|
||||
function assertBubbleSize(comment, height, width) {
|
||||
const size = comment.getBubbleSize();
|
||||
chai.assert.equal(size.height, height);
|
||||
chai.assert.equal(size.width, width);
|
||||
assert.equal(size.height, height);
|
||||
assert.equal(size.width, width);
|
||||
}
|
||||
function assertBubbleSizeDefault(comment) {
|
||||
assertBubbleSize(comment, 80, 160);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -28,11 +29,8 @@ suite('Workspace comment', function () {
|
||||
|
||||
this.commentView.setText('test');
|
||||
|
||||
chai.assert.isTrue(
|
||||
spy.calledOnce,
|
||||
'Expected the spy to be called once',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(spy.calledOnce, 'Expected the spy to be called once');
|
||||
assert.isTrue(
|
||||
spy.calledWith('', 'test'),
|
||||
'Expected the spy to be called with the given args',
|
||||
);
|
||||
@@ -50,15 +48,15 @@ suite('Workspace comment', function () {
|
||||
|
||||
this.commentView.setText('test');
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake1.calledOnce,
|
||||
'Expected the first listener to be called',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake2.calledOnce,
|
||||
'Expected the second listener to be called',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake3.calledOnce,
|
||||
'Expected the third listener to be called',
|
||||
);
|
||||
@@ -74,11 +72,8 @@ suite('Workspace comment', function () {
|
||||
|
||||
this.commentView.setSize(newSize);
|
||||
|
||||
chai.assert.isTrue(
|
||||
spy.calledOnce,
|
||||
'Expected the spy to be called once',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(spy.calledOnce, 'Expected the spy to be called once');
|
||||
assert.isTrue(
|
||||
spy.calledWith(originalSize, newSize),
|
||||
'Expected the spy to be called with the given args',
|
||||
);
|
||||
@@ -97,15 +92,15 @@ suite('Workspace comment', function () {
|
||||
|
||||
this.commentView.setSize(newSize);
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake1.calledOnce,
|
||||
'Expected the first listener to be called',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake2.calledOnce,
|
||||
'Expected the second listener to be called',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake3.calledOnce,
|
||||
'Expected the third listener to be called',
|
||||
);
|
||||
@@ -119,11 +114,8 @@ suite('Workspace comment', function () {
|
||||
|
||||
this.commentView.setCollapsed(true);
|
||||
|
||||
chai.assert.isTrue(
|
||||
spy.calledOnce,
|
||||
'Expected the spy to be called once',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(spy.calledOnce, 'Expected the spy to be called once');
|
||||
assert.isTrue(
|
||||
spy.calledWith(true),
|
||||
'Expected the spy to be called with the given args',
|
||||
);
|
||||
@@ -141,15 +133,15 @@ suite('Workspace comment', function () {
|
||||
|
||||
this.commentView.setCollapsed(true);
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake1.calledOnce,
|
||||
'Expected the first listener to be called',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake2.calledOnce,
|
||||
'Expected the second listener to be called',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake3.calledOnce,
|
||||
'Expected the third listener to be called',
|
||||
);
|
||||
@@ -163,10 +155,7 @@ suite('Workspace comment', function () {
|
||||
|
||||
this.commentView.dispose();
|
||||
|
||||
chai.assert.isTrue(
|
||||
spy.calledOnce,
|
||||
'Expected the spy to be called once',
|
||||
);
|
||||
assert.isTrue(spy.calledOnce, 'Expected the spy to be called once');
|
||||
});
|
||||
|
||||
test('dispose listeners can remove themselves without skipping others', function () {
|
||||
@@ -181,15 +170,15 @@ suite('Workspace comment', function () {
|
||||
|
||||
this.commentView.dispose();
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake1.calledOnce,
|
||||
'Expected the first listener to be called',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake2.calledOnce,
|
||||
'Expected the second listener to be called',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
fake3.calledOnce,
|
||||
'Expected the third listener to be called',
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {ConnectionType} from '../../build/src/core/connection_type.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -22,9 +23,9 @@ suite('Connection checker', function () {
|
||||
});
|
||||
suite('Safety checks', function () {
|
||||
function assertReasonHelper(checker, one, two, reason) {
|
||||
chai.assert.equal(checker.canConnectWithReason(one, two), reason);
|
||||
assert.equal(checker.canConnectWithReason(one, two), reason);
|
||||
// Order should not matter.
|
||||
chai.assert.equal(checker.canConnectWithReason(two, one), reason);
|
||||
assert.equal(checker.canConnectWithReason(two, one), reason);
|
||||
}
|
||||
|
||||
test('Target Null', function () {
|
||||
@@ -452,9 +453,9 @@ suite('Connection checker', function () {
|
||||
this.con2 = new Blockly.Connection({}, ConnectionType.NEXT_STATEMENT);
|
||||
});
|
||||
function assertCheckTypes(checker, one, two) {
|
||||
chai.assert.isTrue(checker.doTypeChecks(one, two));
|
||||
assert.isTrue(checker.doTypeChecks(one, two));
|
||||
// Order should not matter.
|
||||
chai.assert.isTrue(checker.doTypeChecks(one, two));
|
||||
assert.isTrue(checker.doTypeChecks(one, two));
|
||||
}
|
||||
test('No Types', function () {
|
||||
assertCheckTypes(this.checker, this.con1, this.con2);
|
||||
@@ -481,7 +482,7 @@ suite('Connection checker', function () {
|
||||
test('No Compatible Types', function () {
|
||||
this.con1.setCheck('type1');
|
||||
this.con2.setCheck('type2');
|
||||
chai.assert.isFalse(this.checker.doTypeChecks(this.con1, this.con2));
|
||||
assert.isFalse(this.checker.doTypeChecks(this.con1, this.con2));
|
||||
});
|
||||
});
|
||||
suite('Dragging Checks', function () {
|
||||
@@ -509,7 +510,7 @@ suite('Connection checker', function () {
|
||||
|
||||
test('Connect a stack', function () {
|
||||
// block C is not connected to block A; both are movable.
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
this.checker.doDragChecks(
|
||||
this.blockC.nextConnection,
|
||||
this.blockA.previousConnection,
|
||||
@@ -543,7 +544,7 @@ suite('Connection checker', function () {
|
||||
// Try to connect blockC into the input connection of blockA, replacing blockB.
|
||||
// This is allowed because shadow blocks can always be replaced, even though
|
||||
// they are unmovable.
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
this.checker.doDragChecks(
|
||||
this.blockC.previousConnection,
|
||||
this.blockA.nextConnection,
|
||||
@@ -556,7 +557,7 @@ suite('Connection checker', function () {
|
||||
test('Do not splice into unmovable stack', function () {
|
||||
// Try to connect blockC above blockB. It shouldn't work because B is not movable
|
||||
// and is already connected to A's nextConnection.
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
this.checker.doDragChecks(
|
||||
this.blockC.previousConnection,
|
||||
this.blockA.nextConnection,
|
||||
@@ -569,7 +570,7 @@ suite('Connection checker', function () {
|
||||
test('Connect to bottom of unmovable stack', function () {
|
||||
// Try to connect blockC below blockB.
|
||||
// This is allowed even though B is not movable because it is on B's nextConnection.
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
this.checker.doDragChecks(
|
||||
this.blockC.previousConnection,
|
||||
this.blockB.nextConnection,
|
||||
@@ -585,7 +586,7 @@ suite('Connection checker', function () {
|
||||
|
||||
// Try to connect blockC above blockB.
|
||||
// This is allowed because we're not splicing into a stack.
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
this.checker.doDragChecks(
|
||||
this.blockC.nextConnection,
|
||||
this.blockB.previousConnection,
|
||||
@@ -620,7 +621,7 @@ suite('Connection checker', function () {
|
||||
// Try to connect C's output to A's input. Should fail because
|
||||
// A is already connected to B, which is unmovable.
|
||||
const inputConnection = this.blockA.inputList[0].connection;
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
this.checker.doDragChecks(
|
||||
this.blockC.outputConnection,
|
||||
inputConnection,
|
||||
@@ -635,7 +636,7 @@ suite('Connection checker', function () {
|
||||
this.blockC.setMovable(false);
|
||||
// Try to connect A's output to C's input. This is allowed.
|
||||
const inputConnection = this.blockC.inputList[0].connection;
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
this.checker.doDragChecks(
|
||||
this.blockA.outputConnection,
|
||||
inputConnection,
|
||||
@@ -651,7 +652,7 @@ suite('Connection checker', function () {
|
||||
|
||||
// Try to connect C's input to B's output. Allowed because B is now unconnected.
|
||||
const inputConnection = this.blockC.inputList[0].connection;
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
this.checker.doDragChecks(
|
||||
inputConnection,
|
||||
this.blockB.outputConnection,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {ConnectionType} from '../../build/src/core/connection_type.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -18,7 +19,7 @@ suite('Connection Database', function () {
|
||||
this.assertOrder = function () {
|
||||
const length = this.database.connections.length;
|
||||
for (let i = 1; i < length; i++) {
|
||||
chai.assert.isAtMost(
|
||||
assert.isAtMost(
|
||||
this.database.connections[i - 1].y,
|
||||
this.database.connections[i].y,
|
||||
);
|
||||
@@ -59,24 +60,19 @@ suite('Connection Database', function () {
|
||||
const y3b = {y: 3};
|
||||
|
||||
this.database.addConnection(y2, 2);
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [y2]);
|
||||
assert.sameOrderedMembers(this.database.connections, [y2]);
|
||||
|
||||
this.database.addConnection(y4, 4);
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [y2, y4]);
|
||||
assert.sameOrderedMembers(this.database.connections, [y2, y4]);
|
||||
|
||||
this.database.addConnection(y1, 1);
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [y1, y2, y4]);
|
||||
assert.sameOrderedMembers(this.database.connections, [y1, y2, y4]);
|
||||
|
||||
this.database.addConnection(y3a, 3);
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [
|
||||
y1,
|
||||
y2,
|
||||
y3a,
|
||||
y4,
|
||||
]);
|
||||
assert.sameOrderedMembers(this.database.connections, [y1, y2, y3a, y4]);
|
||||
|
||||
this.database.addConnection(y3b, 3);
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [
|
||||
assert.sameOrderedMembers(this.database.connections, [
|
||||
y1,
|
||||
y2,
|
||||
y3b,
|
||||
@@ -99,7 +95,7 @@ suite('Connection Database', function () {
|
||||
this.database.addConnection(y3b, 3);
|
||||
this.database.addConnection(y3a, 3);
|
||||
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [
|
||||
assert.sameOrderedMembers(this.database.connections, [
|
||||
y1,
|
||||
y2,
|
||||
y3a,
|
||||
@@ -109,7 +105,7 @@ suite('Connection Database', function () {
|
||||
]);
|
||||
|
||||
this.database.removeConnection(y2, 2);
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [
|
||||
assert.sameOrderedMembers(this.database.connections, [
|
||||
y1,
|
||||
y3a,
|
||||
y3b,
|
||||
@@ -118,24 +114,19 @@ suite('Connection Database', function () {
|
||||
]);
|
||||
|
||||
this.database.removeConnection(y4, 4);
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [
|
||||
y1,
|
||||
y3a,
|
||||
y3b,
|
||||
y3c,
|
||||
]);
|
||||
assert.sameOrderedMembers(this.database.connections, [y1, y3a, y3b, y3c]);
|
||||
|
||||
this.database.removeConnection(y1, 1);
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [y3a, y3b, y3c]);
|
||||
assert.sameOrderedMembers(this.database.connections, [y3a, y3b, y3c]);
|
||||
|
||||
this.database.removeConnection(y3a, 3);
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [y3b, y3c]);
|
||||
assert.sameOrderedMembers(this.database.connections, [y3b, y3c]);
|
||||
|
||||
this.database.removeConnection(y3c, 3);
|
||||
chai.assert.sameOrderedMembers(this.database.connections, [y3b]);
|
||||
assert.sameOrderedMembers(this.database.connections, [y3b]);
|
||||
|
||||
this.database.removeConnection(y3b, 3);
|
||||
chai.assert.isEmpty(this.database.connections);
|
||||
assert.isEmpty(this.database.connections);
|
||||
});
|
||||
suite('Get Neighbors', function () {
|
||||
test('Empty Database', function () {
|
||||
@@ -145,7 +136,7 @@ suite('Connection Database', function () {
|
||||
ConnectionType.NEXT_STATEMENT,
|
||||
new Blockly.ConnectionDB(),
|
||||
);
|
||||
chai.assert.isEmpty(this.database.getNeighbours(connection), 100);
|
||||
assert.isEmpty(this.database.getNeighbours(connection), 100);
|
||||
});
|
||||
test('Block At Top', function () {
|
||||
this.createSimpleTestConnections();
|
||||
@@ -157,7 +148,7 @@ suite('Connection Database', function () {
|
||||
new Blockly.ConnectionDB(),
|
||||
);
|
||||
const neighbors = this.database.getNeighbours(checkConnection, 4);
|
||||
chai.assert.sameMembers(neighbors, this.database.connections.slice(0, 5));
|
||||
assert.sameMembers(neighbors, this.database.connections.slice(0, 5));
|
||||
});
|
||||
test('Block In Middle', function () {
|
||||
this.createSimpleTestConnections();
|
||||
@@ -169,7 +160,7 @@ suite('Connection Database', function () {
|
||||
new Blockly.ConnectionDB(),
|
||||
);
|
||||
const neighbors = this.database.getNeighbours(checkConnection, 2);
|
||||
chai.assert.sameMembers(neighbors, this.database.connections.slice(2, 7));
|
||||
assert.sameMembers(neighbors, this.database.connections.slice(2, 7));
|
||||
});
|
||||
test('Block At End', function () {
|
||||
this.createSimpleTestConnections();
|
||||
@@ -181,10 +172,7 @@ suite('Connection Database', function () {
|
||||
new Blockly.ConnectionDB(),
|
||||
);
|
||||
const neighbors = this.database.getNeighbours(checkConnection, 4);
|
||||
chai.assert.sameMembers(
|
||||
neighbors,
|
||||
this.database.connections.slice(5, 10),
|
||||
);
|
||||
assert.sameMembers(neighbors, this.database.connections.slice(5, 10));
|
||||
});
|
||||
test('Out of Range X', function () {
|
||||
this.createSimpleTestConnections();
|
||||
@@ -196,7 +184,7 @@ suite('Connection Database', function () {
|
||||
new Blockly.ConnectionDB(),
|
||||
);
|
||||
const neighbors = this.database.getNeighbours(checkConnection, 4);
|
||||
chai.assert.isEmpty(neighbors);
|
||||
assert.isEmpty(neighbors);
|
||||
});
|
||||
test('Out of Range Y', function () {
|
||||
this.createSimpleTestConnections();
|
||||
@@ -208,7 +196,7 @@ suite('Connection Database', function () {
|
||||
new Blockly.ConnectionDB(),
|
||||
);
|
||||
const neighbors = this.database.getNeighbours(checkConnection, 4);
|
||||
chai.assert.isEmpty(neighbors);
|
||||
assert.isEmpty(neighbors);
|
||||
});
|
||||
test('Out of Range Diagonal', function () {
|
||||
this.createSimpleTestConnections();
|
||||
@@ -220,7 +208,7 @@ suite('Connection Database', function () {
|
||||
new Blockly.ConnectionDB(),
|
||||
);
|
||||
const neighbors = this.database.getNeighbours(checkConnection, 2);
|
||||
chai.assert.isEmpty(neighbors);
|
||||
assert.isEmpty(neighbors);
|
||||
});
|
||||
});
|
||||
suite('Ordering', function () {
|
||||
@@ -300,7 +288,7 @@ suite('Connection Database', function () {
|
||||
ConnectionType.NEXT_STATEMENT,
|
||||
new Blockly.ConnectionDB(),
|
||||
);
|
||||
chai.assert.isNull(
|
||||
assert.isNull(
|
||||
this.database.searchForClosest(checkConnection, 100, {x: 0, y: 0})
|
||||
.connection,
|
||||
);
|
||||
@@ -319,7 +307,7 @@ suite('Connection Database', function () {
|
||||
ConnectionType.NEXT_STATEMENT,
|
||||
new Blockly.ConnectionDB(),
|
||||
);
|
||||
chai.assert.isNull(
|
||||
assert.isNull(
|
||||
this.database.searchForClosest(checkConnection, 50, {x: 0, y: 0})
|
||||
.connection,
|
||||
);
|
||||
@@ -334,7 +322,7 @@ suite('Connection Database', function () {
|
||||
x: 0,
|
||||
y: 0,
|
||||
}).connection;
|
||||
chai.assert.equal(last, closest);
|
||||
assert.equal(last, closest);
|
||||
});
|
||||
test('Many in Range', function () {
|
||||
this.createSimpleTestConnections();
|
||||
@@ -346,7 +334,7 @@ suite('Connection Database', function () {
|
||||
x: 0,
|
||||
y: 0,
|
||||
}).connection;
|
||||
chai.assert.equal(last, closest);
|
||||
assert.equal(last, closest);
|
||||
});
|
||||
test('No Y-Coord Priority', function () {
|
||||
const connection1 = this.createConnection(
|
||||
@@ -368,7 +356,7 @@ suite('Connection Database', function () {
|
||||
x: 0,
|
||||
y: 0,
|
||||
}).connection;
|
||||
chai.assert.equal(connection2, closest);
|
||||
assert.equal(connection2, closest);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
createGenUidStubWithReturns,
|
||||
sharedTestSetup,
|
||||
@@ -39,19 +40,19 @@ suite('Connection', function () {
|
||||
|
||||
suite('Set Shadow', function () {
|
||||
function assertBlockMatches(block, isShadow, opt_id) {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
block.isShadow(),
|
||||
isShadow,
|
||||
`expected block ${block.id} to ${isShadow ? '' : 'not'} be a shadow`,
|
||||
);
|
||||
if (opt_id) {
|
||||
chai.assert.equal(block.id, opt_id);
|
||||
assert.equal(block.id, opt_id);
|
||||
}
|
||||
}
|
||||
|
||||
function assertInputHasBlock(parent, inputName, isShadow, opt_name) {
|
||||
const block = parent.getInputTargetBlock(inputName);
|
||||
chai.assert.exists(
|
||||
assert.exists(
|
||||
block,
|
||||
`expected block ${opt_name || ''} to be attached to ${inputName}`,
|
||||
);
|
||||
@@ -60,7 +61,7 @@ suite('Connection', function () {
|
||||
|
||||
function assertNextHasBlock(parent, isShadow, opt_name) {
|
||||
const block = parent.getNextBlock();
|
||||
chai.assert.exists(
|
||||
assert.exists(
|
||||
block,
|
||||
`expected block ${opt_name || ''} to be attached to next connection`,
|
||||
);
|
||||
@@ -69,7 +70,7 @@ suite('Connection', function () {
|
||||
|
||||
function assertInputNotHasBlock(parent, inputName) {
|
||||
const block = parent.getInputTargetBlock(inputName);
|
||||
chai.assert.notExists(
|
||||
assert.notExists(
|
||||
block,
|
||||
`expected block ${
|
||||
block && block.id
|
||||
@@ -79,7 +80,7 @@ suite('Connection', function () {
|
||||
|
||||
function assertNextNotHasBlock(parent) {
|
||||
const block = parent.getNextBlock();
|
||||
chai.assert.notExists(
|
||||
assert.notExists(
|
||||
block,
|
||||
`expected block ${
|
||||
block && block.id
|
||||
@@ -92,8 +93,8 @@ suite('Connection', function () {
|
||||
addNextBlocks: true,
|
||||
});
|
||||
const actualXml = Blockly.Xml.domToText(Blockly.Xml.blockToDom(block));
|
||||
chai.assert.deepEqual(actualJso, jso);
|
||||
chai.assert.equal(actualXml, xmlText);
|
||||
assert.deepEqual(actualJso, jso);
|
||||
assert.equal(actualXml, xmlText);
|
||||
}
|
||||
|
||||
const testSuites = [
|
||||
@@ -1382,7 +1383,7 @@ suite('Connection', function () {
|
||||
suite('Invalid', function () {
|
||||
test('Attach to output', function () {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block.outputConnection.setShadowDom(
|
||||
Blockly.utils.xml.textToDom('<block type="row_block">'),
|
||||
),
|
||||
@@ -1391,7 +1392,7 @@ suite('Connection', function () {
|
||||
|
||||
test('Attach to previous', function () {
|
||||
const block = this.workspace.newBlock('stack_block');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block.previousConnection.setShadowDom(
|
||||
Blockly.utils.xml.textToDom('<block type="stack_block">'),
|
||||
),
|
||||
@@ -1400,7 +1401,7 @@ suite('Connection', function () {
|
||||
|
||||
test('Missing output', function () {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block.outputConnection.setShadowDom(
|
||||
Blockly.utils.xml.textToDom('<block type="stack_block">'),
|
||||
),
|
||||
@@ -1409,7 +1410,7 @@ suite('Connection', function () {
|
||||
|
||||
test('Missing previous', function () {
|
||||
const block = this.workspace.newBlock('stack_block');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block.previousConnection.setShadowDom(
|
||||
Blockly.utils.xml.textToDom('<block type="row_block">'),
|
||||
),
|
||||
@@ -1418,7 +1419,7 @@ suite('Connection', function () {
|
||||
|
||||
test('Invalid connection checks, output', function () {
|
||||
const block = this.workspace.newBlock('logic_operation');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block
|
||||
.getInput('A')
|
||||
.connection.setShadowDom(
|
||||
@@ -1437,7 +1438,7 @@ suite('Connection', function () {
|
||||
},
|
||||
]);
|
||||
const block = this.workspace.newBlock('stack_checks_block');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block.nextConnection.setShadowDom(
|
||||
Blockly.utils.xml.textToDom(
|
||||
'<block type="stack_checks_block">',
|
||||
@@ -2751,14 +2752,14 @@ suite('Connection', function () {
|
||||
suite('Invalid', function () {
|
||||
test('Attach to output', function () {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block.outputConnection.setShadowState({'type': 'row_block'}),
|
||||
);
|
||||
});
|
||||
|
||||
test('Attach to previous', function () {
|
||||
const block = this.workspace.newBlock('stack_block');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block.previousConnection.setShadowState({
|
||||
'type': 'stack_block',
|
||||
}),
|
||||
@@ -2767,21 +2768,21 @@ suite('Connection', function () {
|
||||
|
||||
test('Missing output', function () {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block.outputConnection.setShadowState({'type': 'stack_block'}),
|
||||
);
|
||||
});
|
||||
|
||||
test('Missing previous', function () {
|
||||
const block = this.workspace.newBlock('stack_block');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block.previousConnection.setShadowState({'type': 'row_block'}),
|
||||
);
|
||||
});
|
||||
|
||||
test('Invalid connection checks, output', function () {
|
||||
const block = this.workspace.newBlock('logic_operation');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block
|
||||
.getInput('A')
|
||||
.connection.setShadowState({'type': 'math_number'}),
|
||||
@@ -2798,7 +2799,7 @@ suite('Connection', function () {
|
||||
},
|
||||
]);
|
||||
const block = this.workspace.newBlock('stack_checks_block');
|
||||
chai.assert.throws(() =>
|
||||
assert.throws(() =>
|
||||
block.nextConnection.setShadowState({
|
||||
'type': 'stack_checks_block',
|
||||
}),
|
||||
@@ -2984,7 +2985,7 @@ suite('Connection', function () {
|
||||
|
||||
// Used to make sure we don't get stray shadow blocks or anything.
|
||||
this.assertBlockCount = function (count) {
|
||||
chai.assert.equal(this.workspace.getAllBlocks().length, count);
|
||||
assert.equal(this.workspace.getAllBlocks().length, count);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -2997,9 +2998,7 @@ suite('Connection', function () {
|
||||
oldParent.getInput('INPUT').connection.connect(child.outputConnection);
|
||||
newParent.getInput('INPUT').connection.connect(child.outputConnection);
|
||||
|
||||
chai.assert.isFalse(
|
||||
oldParent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
assert.isFalse(oldParent.getInput('INPUT').connection.isConnected());
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
|
||||
@@ -3011,9 +3010,7 @@ suite('Connection', function () {
|
||||
oldParent.getInput('NAME').connection.connect(child.previousConnection);
|
||||
newParent.getInput('NAME').connection.connect(child.previousConnection);
|
||||
|
||||
chai.assert.isFalse(
|
||||
oldParent.getInput('NAME').connection.isConnected(),
|
||||
);
|
||||
assert.isFalse(oldParent.getInput('NAME').connection.isConnected());
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
|
||||
@@ -3025,7 +3022,7 @@ suite('Connection', function () {
|
||||
oldParent.nextConnection.connect(child.previousConnection);
|
||||
newParent.nextConnection.connect(child.previousConnection);
|
||||
|
||||
chai.assert.isFalse(oldParent.nextConnection.isConnected());
|
||||
assert.isFalse(oldParent.nextConnection.isConnected());
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
});
|
||||
@@ -3036,11 +3033,11 @@ suite('Connection', function () {
|
||||
const child = this.workspace.newBlock('row_block');
|
||||
const xml = Blockly.utils.xml.textToDom('<shadow type="row_block"/>');
|
||||
newParent.getInput('INPUT').connection.setShadowDom(xml);
|
||||
chai.assert.isTrue(newParent.getInputTargetBlock('INPUT').isShadow());
|
||||
assert.isTrue(newParent.getInputTargetBlock('INPUT').isShadow());
|
||||
|
||||
newParent.getInput('INPUT').connection.connect(child.outputConnection);
|
||||
|
||||
chai.assert.isFalse(newParent.getInputTargetBlock('INPUT').isShadow());
|
||||
assert.isFalse(newParent.getInputTargetBlock('INPUT').isShadow());
|
||||
this.assertBlockCount(2);
|
||||
});
|
||||
|
||||
@@ -3049,11 +3046,11 @@ suite('Connection', function () {
|
||||
const child = this.workspace.newBlock('stack_block');
|
||||
const xml = Blockly.utils.xml.textToDom('<shadow type="stack_block"/>');
|
||||
newParent.getInput('NAME').connection.setShadowDom(xml);
|
||||
chai.assert.isTrue(newParent.getInputTargetBlock('NAME').isShadow());
|
||||
assert.isTrue(newParent.getInputTargetBlock('NAME').isShadow());
|
||||
|
||||
newParent.getInput('NAME').connection.connect(child.previousConnection);
|
||||
|
||||
chai.assert.isFalse(newParent.getInputTargetBlock('NAME').isShadow());
|
||||
assert.isFalse(newParent.getInputTargetBlock('NAME').isShadow());
|
||||
this.assertBlockCount(2);
|
||||
});
|
||||
|
||||
@@ -3062,11 +3059,11 @@ suite('Connection', function () {
|
||||
const child = this.workspace.newBlock('stack_block');
|
||||
const xml = Blockly.utils.xml.textToDom('<shadow type="stack_block"/>');
|
||||
newParent.nextConnection.setShadowDom(xml);
|
||||
chai.assert.isTrue(newParent.getNextBlock().isShadow());
|
||||
assert.isTrue(newParent.getNextBlock().isShadow());
|
||||
|
||||
newParent.nextConnection.connect(child.previousConnection);
|
||||
|
||||
chai.assert.isFalse(newParent.getNextBlock().isShadow());
|
||||
assert.isFalse(newParent.getNextBlock().isShadow());
|
||||
this.assertBlockCount(2);
|
||||
});
|
||||
});
|
||||
@@ -3083,8 +3080,8 @@ suite('Connection', function () {
|
||||
newParent.getInput('INPUT').connection.disconnect();
|
||||
|
||||
const target = newParent.getInputTargetBlock('INPUT');
|
||||
chai.assert.isTrue(target.isShadow());
|
||||
chai.assert.equal(target.getFieldValue('FIELD'), 'new');
|
||||
assert.isTrue(target.isShadow());
|
||||
assert.equal(target.getFieldValue('FIELD'), 'new');
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
|
||||
@@ -3099,8 +3096,8 @@ suite('Connection', function () {
|
||||
newParent.getInput('NAME').connection.disconnect();
|
||||
|
||||
const target = newParent.getInputTargetBlock('NAME');
|
||||
chai.assert.isTrue(target.isShadow());
|
||||
chai.assert.equal(target.getFieldValue('FIELD'), 'new');
|
||||
assert.isTrue(target.isShadow());
|
||||
assert.equal(target.getFieldValue('FIELD'), 'new');
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
|
||||
@@ -3115,8 +3112,8 @@ suite('Connection', function () {
|
||||
newParent.nextConnection.disconnect();
|
||||
|
||||
const target = newParent.getNextBlock();
|
||||
chai.assert.isTrue(target.isShadow());
|
||||
chai.assert.equal(target.getFieldValue('FIELD'), 'new');
|
||||
assert.isTrue(target.isShadow());
|
||||
assert.equal(target.getFieldValue('FIELD'), 'new');
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
});
|
||||
@@ -3136,11 +3133,9 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
});
|
||||
|
||||
test('All statements', function () {
|
||||
@@ -3155,11 +3150,9 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
});
|
||||
|
||||
test('Bad checks', function () {
|
||||
@@ -3174,11 +3167,9 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
});
|
||||
|
||||
test('Through different types', function () {
|
||||
@@ -3198,11 +3189,9 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3223,11 +3212,9 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
});
|
||||
|
||||
test('Child blocks', function () {
|
||||
@@ -3253,11 +3240,9 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
});
|
||||
|
||||
test('Spots filled', function () {
|
||||
@@ -3279,11 +3264,9 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3317,11 +3300,9 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
});
|
||||
|
||||
test('Child blocks', function () {
|
||||
@@ -3361,11 +3342,9 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
});
|
||||
|
||||
test('Spots filled', function () {
|
||||
@@ -3394,11 +3373,9 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isFalse(oldChild.outputConnection.isConnected());
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -3417,14 +3394,10 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isTrue(
|
||||
newChild.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(newChild.getInputTargetBlock('INPUT'), oldChild);
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isTrue(newChild.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(newChild.getInputTargetBlock('INPUT'), oldChild);
|
||||
});
|
||||
|
||||
test('Shadows', function () {
|
||||
@@ -3447,14 +3420,10 @@ suite('Connection', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(newChild.outputConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
chai.assert.isTrue(
|
||||
newChild.getInput('INPUT').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(newChild.getInputTargetBlock('INPUT'), oldChild);
|
||||
assert.isTrue(parent.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('INPUT'), newChild);
|
||||
assert.isTrue(newChild.getInput('INPUT').connection.isConnected());
|
||||
assert.equal(newChild.getInputTargetBlock('INPUT'), oldChild);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -3473,12 +3442,10 @@ suite('Connection', function () {
|
||||
.getInput('NAME')
|
||||
.connection.connect(newChild.previousConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('NAME').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('NAME'), newChild);
|
||||
chai.assert.isTrue(newChild.nextConnection.isConnected());
|
||||
chai.assert.equal(newChild.getNextBlock(), oldChild);
|
||||
assert.isTrue(parent.getInput('NAME').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('NAME'), newChild);
|
||||
assert.isTrue(newChild.nextConnection.isConnected());
|
||||
assert.equal(newChild.getNextBlock(), oldChild);
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
|
||||
@@ -3496,12 +3463,10 @@ suite('Connection', function () {
|
||||
.getInput('NAME')
|
||||
.connection.connect(newChild1.previousConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('NAME').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('NAME'), newChild1);
|
||||
chai.assert.isTrue(newChild2.nextConnection.isConnected());
|
||||
chai.assert.equal(newChild2.getNextBlock(), oldChild);
|
||||
assert.isTrue(parent.getInput('NAME').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('NAME'), newChild1);
|
||||
assert.isTrue(newChild2.nextConnection.isConnected());
|
||||
assert.equal(newChild2.getNextBlock(), oldChild);
|
||||
this.assertBlockCount(4);
|
||||
});
|
||||
|
||||
@@ -3521,12 +3486,10 @@ suite('Connection', function () {
|
||||
.getInput('NAME')
|
||||
.connection.connect(newChild.previousConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('NAME').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('NAME'), newChild);
|
||||
chai.assert.isFalse(newChild.nextConnection.isConnected());
|
||||
chai.assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(parent.getInput('NAME').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('NAME'), newChild);
|
||||
assert.isFalse(newChild.nextConnection.isConnected());
|
||||
assert.isTrue(spy.calledOnce);
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
|
||||
@@ -3546,11 +3509,9 @@ suite('Connection', function () {
|
||||
.getInput('NAME')
|
||||
.connection.connect(newChild.previousConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('NAME').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('NAME'), newChild);
|
||||
chai.assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(parent.getInput('NAME').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('NAME'), newChild);
|
||||
assert.isTrue(spy.calledOnce);
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
});
|
||||
@@ -3572,12 +3533,10 @@ suite('Connection', function () {
|
||||
.getInput('NAME')
|
||||
.connection.connect(newChild.previousConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('NAME').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('NAME'), newChild);
|
||||
chai.assert.isTrue(newChild.nextConnection.isConnected());
|
||||
chai.assert.equal(newChild.getNextBlock(), oldChild);
|
||||
assert.isTrue(parent.getInput('NAME').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('NAME'), newChild);
|
||||
assert.isTrue(newChild.nextConnection.isConnected());
|
||||
assert.equal(newChild.getNextBlock(), oldChild);
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
|
||||
@@ -3599,12 +3558,10 @@ suite('Connection', function () {
|
||||
.getInput('NAME')
|
||||
.connection.connect(newChild1.previousConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('NAME').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('NAME'), newChild1);
|
||||
chai.assert.isTrue(newChild2.nextConnection.isConnected());
|
||||
chai.assert.equal(newChild2.getNextBlock(), oldChild);
|
||||
assert.isTrue(parent.getInput('NAME').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('NAME'), newChild1);
|
||||
assert.isTrue(newChild2.nextConnection.isConnected());
|
||||
assert.equal(newChild2.getNextBlock(), oldChild);
|
||||
this.assertBlockCount(4);
|
||||
});
|
||||
|
||||
@@ -3628,13 +3585,11 @@ suite('Connection', function () {
|
||||
.getInput('NAME')
|
||||
.connection.connect(newChild.previousConnection);
|
||||
|
||||
chai.assert.isTrue(
|
||||
parent.getInput('NAME').connection.isConnected(),
|
||||
);
|
||||
chai.assert.equal(parent.getInputTargetBlock('NAME'), newChild);
|
||||
chai.assert.isTrue(newChild.nextConnection.isConnected());
|
||||
chai.assert.isTrue(newChild.getNextBlock().isShadow());
|
||||
chai.assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(parent.getInput('NAME').connection.isConnected());
|
||||
assert.equal(parent.getInputTargetBlock('NAME'), newChild);
|
||||
assert.isTrue(newChild.nextConnection.isConnected());
|
||||
assert.isTrue(newChild.getNextBlock().isShadow());
|
||||
assert.isTrue(spy.calledOnce);
|
||||
this.assertBlockCount(4);
|
||||
});
|
||||
});
|
||||
@@ -3650,10 +3605,10 @@ suite('Connection', function () {
|
||||
|
||||
parent.nextConnection.connect(newChild.previousConnection);
|
||||
|
||||
chai.assert.isTrue(parent.nextConnection.isConnected());
|
||||
chai.assert.equal(parent.getNextBlock(), newChild);
|
||||
chai.assert.isTrue(newChild.nextConnection.isConnected());
|
||||
chai.assert.equal(newChild.getNextBlock(), oldChild);
|
||||
assert.isTrue(parent.nextConnection.isConnected());
|
||||
assert.equal(parent.getNextBlock(), newChild);
|
||||
assert.isTrue(newChild.nextConnection.isConnected());
|
||||
assert.equal(newChild.getNextBlock(), oldChild);
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
|
||||
@@ -3667,10 +3622,10 @@ suite('Connection', function () {
|
||||
|
||||
parent.nextConnection.connect(newChild1.previousConnection);
|
||||
|
||||
chai.assert.isTrue(parent.nextConnection.isConnected());
|
||||
chai.assert.equal(parent.getNextBlock(), newChild1);
|
||||
chai.assert.isTrue(newChild2.nextConnection.isConnected());
|
||||
chai.assert.equal(newChild2.getNextBlock(), oldChild);
|
||||
assert.isTrue(parent.nextConnection.isConnected());
|
||||
assert.equal(parent.getNextBlock(), newChild1);
|
||||
assert.isTrue(newChild2.nextConnection.isConnected());
|
||||
assert.equal(newChild2.getNextBlock(), oldChild);
|
||||
this.assertBlockCount(4);
|
||||
});
|
||||
|
||||
@@ -3686,10 +3641,10 @@ suite('Connection', function () {
|
||||
|
||||
parent.nextConnection.connect(newChild.previousConnection);
|
||||
|
||||
chai.assert.isTrue(parent.nextConnection.isConnected());
|
||||
chai.assert.equal(parent.getNextBlock(), newChild);
|
||||
chai.assert.isFalse(newChild.nextConnection.isConnected());
|
||||
chai.assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(parent.nextConnection.isConnected());
|
||||
assert.equal(parent.getNextBlock(), newChild);
|
||||
assert.isFalse(newChild.nextConnection.isConnected());
|
||||
assert.isTrue(spy.calledOnce);
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
|
||||
@@ -3705,9 +3660,9 @@ suite('Connection', function () {
|
||||
|
||||
parent.nextConnection.connect(newChild.previousConnection);
|
||||
|
||||
chai.assert.isTrue(parent.nextConnection.isConnected());
|
||||
chai.assert.equal(parent.getNextBlock(), newChild);
|
||||
chai.assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(parent.nextConnection.isConnected());
|
||||
assert.equal(parent.getNextBlock(), newChild);
|
||||
assert.isTrue(spy.calledOnce);
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
});
|
||||
@@ -3725,10 +3680,10 @@ suite('Connection', function () {
|
||||
|
||||
parent.nextConnection.connect(newChild.previousConnection);
|
||||
|
||||
chai.assert.isTrue(parent.nextConnection.isConnected());
|
||||
chai.assert.equal(parent.getNextBlock(), newChild);
|
||||
chai.assert.isTrue(newChild.nextConnection.isConnected());
|
||||
chai.assert.equal(newChild.getNextBlock(), oldChild);
|
||||
assert.isTrue(parent.nextConnection.isConnected());
|
||||
assert.equal(parent.getNextBlock(), newChild);
|
||||
assert.isTrue(newChild.nextConnection.isConnected());
|
||||
assert.equal(newChild.getNextBlock(), oldChild);
|
||||
this.assertBlockCount(3);
|
||||
});
|
||||
|
||||
@@ -3746,10 +3701,10 @@ suite('Connection', function () {
|
||||
|
||||
parent.nextConnection.connect(newChild1.previousConnection);
|
||||
|
||||
chai.assert.isTrue(parent.nextConnection.isConnected());
|
||||
chai.assert.equal(parent.getNextBlock(), newChild1);
|
||||
chai.assert.isTrue(newChild2.nextConnection.isConnected());
|
||||
chai.assert.equal(newChild2.getNextBlock(), oldChild);
|
||||
assert.isTrue(parent.nextConnection.isConnected());
|
||||
assert.equal(parent.getNextBlock(), newChild1);
|
||||
assert.isTrue(newChild2.nextConnection.isConnected());
|
||||
assert.equal(newChild2.getNextBlock(), oldChild);
|
||||
this.assertBlockCount(4);
|
||||
});
|
||||
|
||||
@@ -3769,11 +3724,11 @@ suite('Connection', function () {
|
||||
|
||||
parent.nextConnection.connect(newChild.previousConnection);
|
||||
|
||||
chai.assert.isTrue(parent.nextConnection.isConnected());
|
||||
chai.assert.equal(parent.getNextBlock(), newChild);
|
||||
chai.assert.isTrue(newChild.nextConnection.isConnected());
|
||||
chai.assert.isTrue(newChild.getNextBlock().isShadow());
|
||||
chai.assert.isTrue(spy.calledOnce);
|
||||
assert.isTrue(parent.nextConnection.isConnected());
|
||||
assert.equal(parent.getNextBlock(), newChild);
|
||||
assert.isTrue(newChild.nextConnection.isConnected());
|
||||
assert.isTrue(newChild.getNextBlock().isShadow());
|
||||
assert.isTrue(spy.calledOnce);
|
||||
this.assertBlockCount(4);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -39,7 +40,7 @@ suite('Context Menu Items', function () {
|
||||
|
||||
test('Disabled when nothing to undo', function () {
|
||||
const precondition = this.undoOption.preconditionFn(this.scope);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
precondition,
|
||||
'disabled',
|
||||
'Should be disabled when there is nothing to undo',
|
||||
@@ -50,7 +51,7 @@ suite('Context Menu Items', function () {
|
||||
// Create a new block, which should be undoable.
|
||||
this.workspace.newBlock('text');
|
||||
const precondition = this.undoOption.preconditionFn(this.scope);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
precondition,
|
||||
'enabled',
|
||||
'Should be enabled when there are actions to undo',
|
||||
@@ -59,9 +60,9 @@ suite('Context Menu Items', function () {
|
||||
|
||||
test('Undoes adding a new block', function () {
|
||||
this.workspace.newBlock('text');
|
||||
chai.assert.equal(this.workspace.getTopBlocks(false).length, 1);
|
||||
assert.equal(this.workspace.getTopBlocks(false).length, 1);
|
||||
this.undoOption.callback(this.scope);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.workspace.getTopBlocks(false).length,
|
||||
0,
|
||||
'Should be no blocks after undo',
|
||||
@@ -69,7 +70,7 @@ suite('Context Menu Items', function () {
|
||||
});
|
||||
|
||||
test('Has correct label', function () {
|
||||
chai.assert.equal(this.undoOption.displayText(), 'Undo');
|
||||
assert.equal(this.undoOption.displayText(), 'Undo');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -82,7 +83,7 @@ suite('Context Menu Items', function () {
|
||||
// Create a new block. There should be something to undo, but not redo.
|
||||
this.workspace.newBlock('text');
|
||||
const precondition = this.redoOption.preconditionFn(this.scope);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
precondition,
|
||||
'disabled',
|
||||
'Should be disabled when there is nothing to redo',
|
||||
@@ -94,7 +95,7 @@ suite('Context Menu Items', function () {
|
||||
this.workspace.newBlock('text');
|
||||
this.workspace.undo(false);
|
||||
const precondition = this.redoOption.preconditionFn(this.scope);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
precondition,
|
||||
'enabled',
|
||||
'Should be enabled when there are actions to redo',
|
||||
@@ -105,9 +106,9 @@ suite('Context Menu Items', function () {
|
||||
// Add a new block, then undo it, then redo it.
|
||||
this.workspace.newBlock('text');
|
||||
this.workspace.undo(false);
|
||||
chai.assert.equal(this.workspace.getTopBlocks(false).length, 0);
|
||||
assert.equal(this.workspace.getTopBlocks(false).length, 0);
|
||||
this.redoOption.callback(this.scope);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.workspace.getTopBlocks(false).length,
|
||||
1,
|
||||
'Should be 1 block after redo',
|
||||
@@ -115,7 +116,7 @@ suite('Context Menu Items', function () {
|
||||
});
|
||||
|
||||
test('Has correct label', function () {
|
||||
chai.assert.equal(this.redoOption.displayText(), 'Redo');
|
||||
assert.equal(this.redoOption.displayText(), 'Redo');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -128,7 +129,7 @@ suite('Context Menu Items', function () {
|
||||
test('Enabled when multiple blocks', function () {
|
||||
this.workspace.newBlock('text');
|
||||
this.workspace.newBlock('text');
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.cleanupOption.preconditionFn(this.scope),
|
||||
'enabled',
|
||||
'Should be enabled if there are multiple blocks',
|
||||
@@ -136,7 +137,7 @@ suite('Context Menu Items', function () {
|
||||
});
|
||||
|
||||
test('Disabled when no blocks', function () {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.cleanupOption.preconditionFn(this.scope),
|
||||
'disabled',
|
||||
'Should be disabled if there are no blocks',
|
||||
@@ -145,7 +146,7 @@ suite('Context Menu Items', function () {
|
||||
|
||||
test('Hidden when not movable', function () {
|
||||
sinon.stub(this.workspace, 'isMovable').returns(false);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.cleanupOption.preconditionFn(this.scope),
|
||||
'hidden',
|
||||
'Should be hidden if the workspace is not movable',
|
||||
@@ -158,7 +159,7 @@ suite('Context Menu Items', function () {
|
||||
});
|
||||
|
||||
test('Has correct label', function () {
|
||||
chai.assert.equal(this.cleanupOption.displayText(), 'Clean up Blocks');
|
||||
assert.equal(this.cleanupOption.displayText(), 'Clean up Blocks');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -171,7 +172,7 @@ suite('Context Menu Items', function () {
|
||||
this.workspace.newBlock('text');
|
||||
const block2 = this.workspace.newBlock('text');
|
||||
block2.setCollapsed(true);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.collapseOption.preconditionFn(this.scope),
|
||||
'enabled',
|
||||
'Should be enabled when any blocks are expanded',
|
||||
@@ -180,7 +181,7 @@ suite('Context Menu Items', function () {
|
||||
|
||||
test('Disabled when all blocks collapsed', function () {
|
||||
this.workspace.newBlock('text').setCollapsed(true);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.collapseOption.preconditionFn(this.scope),
|
||||
'disabled',
|
||||
'Should be disabled when no blocks are expanded',
|
||||
@@ -194,7 +195,7 @@ suite('Context Menu Items', function () {
|
||||
this.scope.workspace = workspaceWithOptions;
|
||||
|
||||
try {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.collapseOption.preconditionFn(this.scope),
|
||||
'hidden',
|
||||
'Should be hidden if collapse is disabled in options',
|
||||
@@ -216,18 +217,18 @@ suite('Context Menu Items', function () {
|
||||
this.collapseOption.callback(this.scope);
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
block1.isCollapsed(),
|
||||
'Previously collapsed block should still be collapsed',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
block2.isCollapsed(),
|
||||
'Previously expanded block should now be collapsed',
|
||||
);
|
||||
});
|
||||
|
||||
test('Has correct label', function () {
|
||||
chai.assert.equal(this.collapseOption.displayText(), 'Collapse Blocks');
|
||||
assert.equal(this.collapseOption.displayText(), 'Collapse Blocks');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -241,7 +242,7 @@ suite('Context Menu Items', function () {
|
||||
const block2 = this.workspace.newBlock('text');
|
||||
block2.setCollapsed(true);
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.expandOption.preconditionFn(this.scope),
|
||||
'enabled',
|
||||
'Should be enabled when any blocks are collapsed',
|
||||
@@ -250,7 +251,7 @@ suite('Context Menu Items', function () {
|
||||
|
||||
test('Disabled when no collapsed blocks', function () {
|
||||
this.workspace.newBlock('text');
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.expandOption.preconditionFn(this.scope),
|
||||
'disabled',
|
||||
'Should be disabled when no blocks are collapsed',
|
||||
@@ -264,7 +265,7 @@ suite('Context Menu Items', function () {
|
||||
this.scope.workspace = workspaceWithOptions;
|
||||
|
||||
try {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.expandOption.preconditionFn(this.scope),
|
||||
'hidden',
|
||||
'Should be hidden if collapse is disabled in options',
|
||||
@@ -286,18 +287,18 @@ suite('Context Menu Items', function () {
|
||||
this.expandOption.callback(this.scope);
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
block1.isCollapsed(),
|
||||
'Previously expanded block should still be expanded',
|
||||
);
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
block2.isCollapsed(),
|
||||
'Previously collapsed block should now be expanded',
|
||||
);
|
||||
});
|
||||
|
||||
test('Has correct label', function () {
|
||||
chai.assert.equal(this.expandOption.displayText(), 'Expand Blocks');
|
||||
assert.equal(this.expandOption.displayText(), 'Expand Blocks');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -308,17 +309,11 @@ suite('Context Menu Items', function () {
|
||||
|
||||
test('Enabled when blocks to delete', function () {
|
||||
this.workspace.newBlock('text');
|
||||
chai.assert.equal(
|
||||
this.deleteOption.preconditionFn(this.scope),
|
||||
'enabled',
|
||||
);
|
||||
assert.equal(this.deleteOption.preconditionFn(this.scope), 'enabled');
|
||||
});
|
||||
|
||||
test('Disabled when no blocks to delete', function () {
|
||||
chai.assert.equal(
|
||||
this.deleteOption.preconditionFn(this.scope),
|
||||
'disabled',
|
||||
);
|
||||
assert.equal(this.deleteOption.preconditionFn(this.scope), 'disabled');
|
||||
});
|
||||
|
||||
test('Deletes all blocks after confirming', function () {
|
||||
@@ -332,7 +327,7 @@ suite('Context Menu Items', function () {
|
||||
this.deleteOption.callback(this.scope);
|
||||
this.clock.runAll();
|
||||
sinon.assert.calledOnce(confirmStub);
|
||||
chai.assert.equal(this.workspace.getTopBlocks(false).length, 0);
|
||||
assert.equal(this.workspace.getTopBlocks(false).length, 0);
|
||||
});
|
||||
|
||||
test('Does not delete blocks if not confirmed', function () {
|
||||
@@ -346,7 +341,7 @@ suite('Context Menu Items', function () {
|
||||
this.deleteOption.callback(this.scope);
|
||||
this.clock.runAll();
|
||||
sinon.assert.calledOnce(confirmStub);
|
||||
chai.assert.equal(this.workspace.getTopBlocks(false).length, 2);
|
||||
assert.equal(this.workspace.getTopBlocks(false).length, 2);
|
||||
});
|
||||
|
||||
test('No dialog for single block', function () {
|
||||
@@ -359,14 +354,14 @@ suite('Context Menu Items', function () {
|
||||
this.clock.runAll();
|
||||
|
||||
sinon.assert.notCalled(confirmStub);
|
||||
chai.assert.equal(this.workspace.getTopBlocks(false).length, 0);
|
||||
assert.equal(this.workspace.getTopBlocks(false).length, 0);
|
||||
});
|
||||
|
||||
test('Has correct label for multiple blocks', function () {
|
||||
this.workspace.newBlock('text');
|
||||
this.workspace.newBlock('text');
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.deleteOption.displayText(this.scope),
|
||||
'Delete 2 Blocks',
|
||||
);
|
||||
@@ -374,10 +369,7 @@ suite('Context Menu Items', function () {
|
||||
|
||||
test('Has correct label for single block', function () {
|
||||
this.workspace.newBlock('text');
|
||||
chai.assert.equal(
|
||||
this.deleteOption.displayText(this.scope),
|
||||
'Delete Block',
|
||||
);
|
||||
assert.equal(this.deleteOption.displayText(this.scope), 'Delete Block');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -395,7 +387,7 @@ suite('Context Menu Items', function () {
|
||||
|
||||
test('Enabled when block is duplicatable', function () {
|
||||
// Block is duplicatable by default
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.duplicateOption.preconditionFn(this.scope),
|
||||
'enabled',
|
||||
);
|
||||
@@ -403,7 +395,7 @@ suite('Context Menu Items', function () {
|
||||
|
||||
test('Disabled when block is not dupicatable', function () {
|
||||
sinon.stub(this.block, 'isDuplicatable').returns(false);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.duplicateOption.preconditionFn(this.scope),
|
||||
'disabled',
|
||||
);
|
||||
@@ -411,15 +403,12 @@ suite('Context Menu Items', function () {
|
||||
|
||||
test('Hidden when in flyout', function () {
|
||||
this.block.isInFlyout = true;
|
||||
chai.assert.equal(
|
||||
this.duplicateOption.preconditionFn(this.scope),
|
||||
'hidden',
|
||||
);
|
||||
assert.equal(this.duplicateOption.preconditionFn(this.scope), 'hidden');
|
||||
});
|
||||
|
||||
test('the block is duplicated', function () {
|
||||
this.duplicateOption.callback(this.scope);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.workspace.getTopBlocks(false).length,
|
||||
2,
|
||||
'Expected a second block',
|
||||
@@ -427,7 +416,7 @@ suite('Context Menu Items', function () {
|
||||
});
|
||||
|
||||
test('Has correct label', function () {
|
||||
chai.assert.equal(this.duplicateOption.displayText(), 'Duplicate');
|
||||
assert.equal(this.duplicateOption.displayText(), 'Duplicate');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -437,10 +426,7 @@ suite('Context Menu Items', function () {
|
||||
});
|
||||
|
||||
test('Enabled for normal block', function () {
|
||||
chai.assert.equal(
|
||||
this.commentOption.preconditionFn(this.scope),
|
||||
'enabled',
|
||||
);
|
||||
assert.equal(this.commentOption.preconditionFn(this.scope), 'enabled');
|
||||
});
|
||||
|
||||
test('Hidden for collapsed block', function () {
|
||||
@@ -449,20 +435,17 @@ suite('Context Menu Items', function () {
|
||||
this.block.render();
|
||||
this.block.setCollapsed(true);
|
||||
|
||||
chai.assert.equal(
|
||||
this.commentOption.preconditionFn(this.scope),
|
||||
'hidden',
|
||||
);
|
||||
assert.equal(this.commentOption.preconditionFn(this.scope), 'hidden');
|
||||
});
|
||||
|
||||
test('Creates comment if one did not exist', function () {
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
this.block.getIcon(Blockly.icons.CommentIcon.TYPE),
|
||||
'New block should not have a comment',
|
||||
);
|
||||
this.commentOption.callback(this.scope);
|
||||
chai.assert.exists(this.block.getIcon(Blockly.icons.CommentIcon.TYPE));
|
||||
chai.assert.isEmpty(
|
||||
assert.exists(this.block.getIcon(Blockly.icons.CommentIcon.TYPE));
|
||||
assert.isEmpty(
|
||||
this.block.getCommentText(),
|
||||
'Block should have empty comment text',
|
||||
);
|
||||
@@ -471,22 +454,19 @@ suite('Context Menu Items', function () {
|
||||
test('Removes comment if block had one', function () {
|
||||
this.block.setCommentText('Test comment');
|
||||
this.commentOption.callback(this.scope);
|
||||
chai.assert.isNull(
|
||||
assert.isNull(
|
||||
this.block.getCommentText(),
|
||||
'Block should not have comment after removal',
|
||||
);
|
||||
});
|
||||
|
||||
test('Has correct label for add comment', function () {
|
||||
chai.assert.equal(
|
||||
this.commentOption.displayText(this.scope),
|
||||
'Add Comment',
|
||||
);
|
||||
assert.equal(this.commentOption.displayText(this.scope), 'Add Comment');
|
||||
});
|
||||
|
||||
test('Has correct label for remove comment', function () {
|
||||
this.block.setCommentText('Test comment');
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.commentOption.displayText(this.scope),
|
||||
'Remove Comment',
|
||||
);
|
||||
@@ -501,10 +481,7 @@ suite('Context Menu Items', function () {
|
||||
test('Enabled when inputs to inline', function () {
|
||||
this.block.appendValueInput('test1');
|
||||
this.block.appendValueInput('test2');
|
||||
chai.assert.equal(
|
||||
this.inlineOption.preconditionFn(this.scope),
|
||||
'enabled',
|
||||
);
|
||||
assert.equal(this.inlineOption.preconditionFn(this.scope), 'enabled');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -42,9 +43,9 @@ suite('Context Menu', function () {
|
||||
const callback = callbackFactory(this.forLoopBlock, xmlBlock);
|
||||
const getVarBlock = callback();
|
||||
|
||||
chai.assert.equal(getVarBlock.type, 'variables_get');
|
||||
chai.assert.equal(getVarBlock.workspace, this.forLoopBlock.workspace);
|
||||
chai.assert.equal(
|
||||
assert.equal(getVarBlock.type, 'variables_get');
|
||||
assert.equal(getVarBlock.workspace, this.forLoopBlock.workspace);
|
||||
assert.equal(
|
||||
getVarBlock.getField('VAR').getVariable().getId(),
|
||||
this.forLoopBlock.getField('VAR').getVariable().getId(),
|
||||
);
|
||||
@@ -59,9 +60,9 @@ suite('Context Menu', function () {
|
||||
const callback = callbackFactory(this.forLoopBlock, jsonState);
|
||||
const getVarBlock = callback();
|
||||
|
||||
chai.assert.equal(getVarBlock.type, 'variables_get');
|
||||
chai.assert.equal(getVarBlock.workspace, this.forLoopBlock.workspace);
|
||||
chai.assert.equal(
|
||||
assert.equal(getVarBlock.type, 'variables_get');
|
||||
assert.equal(getVarBlock.workspace, this.forLoopBlock.workspace);
|
||||
assert.equal(
|
||||
getVarBlock.getField('VAR').getVariable().getId(),
|
||||
this.forLoopBlock.getField('VAR').getVariable().getId(),
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -90,7 +91,7 @@ suite('Cursor', function () {
|
||||
this.cursor.setCurNode(prevNode);
|
||||
this.cursor.next();
|
||||
const curNode = this.cursor.getCurNode();
|
||||
chai.assert.equal(curNode.getLocation(), this.blocks.B.previousConnection);
|
||||
assert.equal(curNode.getLocation(), this.blocks.B.previousConnection);
|
||||
});
|
||||
test('Next - From last block in a stack go to next connection', function () {
|
||||
const prevNode = ASTNode.createConnectionNode(
|
||||
@@ -99,7 +100,7 @@ suite('Cursor', function () {
|
||||
this.cursor.setCurNode(prevNode);
|
||||
this.cursor.next();
|
||||
const curNode = this.cursor.getCurNode();
|
||||
chai.assert.equal(curNode.getLocation(), this.blocks.B.nextConnection);
|
||||
assert.equal(curNode.getLocation(), this.blocks.B.nextConnection);
|
||||
});
|
||||
|
||||
test('In - From output connection', function () {
|
||||
@@ -110,10 +111,7 @@ suite('Cursor', function () {
|
||||
this.cursor.setCurNode(outputNode);
|
||||
this.cursor.in();
|
||||
const curNode = this.cursor.getCurNode();
|
||||
chai.assert.equal(
|
||||
curNode.getLocation(),
|
||||
fieldBlock.inputList[0].fieldRow[0],
|
||||
);
|
||||
assert.equal(curNode.getLocation(), fieldBlock.inputList[0].fieldRow[0]);
|
||||
});
|
||||
|
||||
test('Prev - From previous connection skip over next connection', function () {
|
||||
@@ -122,7 +120,7 @@ suite('Cursor', function () {
|
||||
this.cursor.setCurNode(prevConnectionNode);
|
||||
this.cursor.prev();
|
||||
const curNode = this.cursor.getCurNode();
|
||||
chai.assert.equal(curNode.getLocation(), this.blocks.A.previousConnection);
|
||||
assert.equal(curNode.getLocation(), this.blocks.A.previousConnection);
|
||||
});
|
||||
|
||||
test('Out - From field skip over block node', function () {
|
||||
@@ -131,6 +129,6 @@ suite('Cursor', function () {
|
||||
this.cursor.setCurNode(fieldNode);
|
||||
this.cursor.out();
|
||||
const curNode = this.cursor.getCurNode();
|
||||
chai.assert.equal(curNode.getLocation(), this.blocks.E.outputConnection);
|
||||
assert.equal(curNode.getLocation(), this.blocks.E.outputConnection);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -51,10 +52,10 @@ suite('DropDownDiv', function () {
|
||||
-10,
|
||||
);
|
||||
// "Above" in value actually means below in render.
|
||||
chai.assert.isAtLeast(metrics.initialY, 0);
|
||||
chai.assert.isAbove(metrics.finalY, 0);
|
||||
chai.assert.isTrue(metrics.arrowVisible);
|
||||
chai.assert.isTrue(metrics.arrowAtTop);
|
||||
assert.isAtLeast(metrics.initialY, 0);
|
||||
assert.isAbove(metrics.finalY, 0);
|
||||
assert.isTrue(metrics.arrowVisible);
|
||||
assert.isTrue(metrics.arrowAtTop);
|
||||
});
|
||||
test('Above, in Bounds', function () {
|
||||
const metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(
|
||||
@@ -64,10 +65,10 @@ suite('DropDownDiv', function () {
|
||||
90,
|
||||
);
|
||||
// "Below" in value actually means above in render.
|
||||
chai.assert.isAtMost(metrics.initialY, 100);
|
||||
chai.assert.isBelow(metrics.finalY, 100);
|
||||
chai.assert.isTrue(metrics.arrowVisible);
|
||||
chai.assert.isFalse(metrics.arrowAtTop);
|
||||
assert.isAtMost(metrics.initialY, 100);
|
||||
assert.isBelow(metrics.finalY, 100);
|
||||
assert.isTrue(metrics.arrowVisible);
|
||||
assert.isFalse(metrics.arrowAtTop);
|
||||
});
|
||||
test('Below, out of Bounds', function () {
|
||||
const metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(
|
||||
@@ -77,10 +78,10 @@ suite('DropDownDiv', function () {
|
||||
50,
|
||||
);
|
||||
// "Above" in value actually means below in render.
|
||||
chai.assert.isAtLeast(metrics.initialY, 60);
|
||||
chai.assert.isAbove(metrics.finalY, 60);
|
||||
chai.assert.isTrue(metrics.arrowVisible);
|
||||
chai.assert.isTrue(metrics.arrowAtTop);
|
||||
assert.isAtLeast(metrics.initialY, 60);
|
||||
assert.isAbove(metrics.finalY, 60);
|
||||
assert.isTrue(metrics.arrowVisible);
|
||||
assert.isTrue(metrics.arrowAtTop);
|
||||
});
|
||||
test('Above, in Bounds', function () {
|
||||
const metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(
|
||||
@@ -90,10 +91,10 @@ suite('DropDownDiv', function () {
|
||||
90,
|
||||
);
|
||||
// "Below" in value actually means above in render.
|
||||
chai.assert.isAtMost(metrics.initialY, 100);
|
||||
chai.assert.isBelow(metrics.finalY, 100);
|
||||
chai.assert.isTrue(metrics.arrowVisible);
|
||||
chai.assert.isFalse(metrics.arrowAtTop);
|
||||
assert.isAtMost(metrics.initialY, 100);
|
||||
assert.isBelow(metrics.finalY, 100);
|
||||
assert.isTrue(metrics.arrowVisible);
|
||||
assert.isFalse(metrics.arrowAtTop);
|
||||
});
|
||||
test('No Solution, Render At Top', function () {
|
||||
this.clientHeightStub.get(function () {
|
||||
@@ -106,10 +107,10 @@ suite('DropDownDiv', function () {
|
||||
50,
|
||||
);
|
||||
// "Above" in value actually means below in render.
|
||||
chai.assert.equal(metrics.initialY, 0);
|
||||
chai.assert.equal(metrics.finalY, 0);
|
||||
chai.assert.isFalse(metrics.arrowVisible);
|
||||
chai.assert.isNotOk(metrics.arrowAtTop);
|
||||
assert.equal(metrics.initialY, 0);
|
||||
assert.equal(metrics.finalY, 0);
|
||||
assert.isFalse(metrics.arrowVisible);
|
||||
assert.isNotOk(metrics.arrowAtTop);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -45,7 +46,7 @@ suite('Block Change Event', function () {
|
||||
'<mutation hasInput="true"/>',
|
||||
);
|
||||
blockChange.run(false);
|
||||
chai.assert.isFalse(block.hasInput);
|
||||
assert.isFalse(block.hasInput);
|
||||
});
|
||||
|
||||
test('Redo', function () {
|
||||
@@ -58,7 +59,7 @@ suite('Block Change Event', function () {
|
||||
'<mutation hasInput="true"/>',
|
||||
);
|
||||
blockChange.run(true);
|
||||
chai.assert.isTrue(block.hasInput);
|
||||
assert.isTrue(block.hasInput);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -74,7 +75,7 @@ suite('Block Change Event', function () {
|
||||
'{"hasInput":true}',
|
||||
);
|
||||
blockChange.run(false);
|
||||
chai.assert.isFalse(block.hasInput);
|
||||
assert.isFalse(block.hasInput);
|
||||
});
|
||||
|
||||
test('Redo', function () {
|
||||
@@ -87,7 +88,7 @@ suite('Block Change Event', function () {
|
||||
'{"hasInput":true}',
|
||||
);
|
||||
blockChange.run(true);
|
||||
chai.assert.isTrue(block.hasInput);
|
||||
assert.isTrue(block.hasInput);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -119,7 +120,7 @@ suite('Block Change Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {assertEventFired} from './test_helpers/events.js';
|
||||
import * as eventUtils from '../../build/src/core/events/utils.js';
|
||||
import {
|
||||
@@ -53,7 +54,7 @@ suite('Block Create Event', function () {
|
||||
);
|
||||
const calls = this.eventsFireStub.getCalls();
|
||||
const event = calls[calls.length - 1].args[0];
|
||||
chai.assert.equal(event.xml.tagName, 'shadow');
|
||||
assert.equal(event.xml.tagName, 'shadow');
|
||||
});
|
||||
|
||||
test('Does not create extra shadow blocks', function () {
|
||||
@@ -85,7 +86,7 @@ suite('Block Create Event', function () {
|
||||
event.run(true);
|
||||
|
||||
const blocksAfter = this.workspace.getAllBlocks();
|
||||
chai.assert.deepEqual(
|
||||
assert.deepEqual(
|
||||
blocksAfter,
|
||||
blocksBefore,
|
||||
'No new blocks should be created from an event that only creates shadow blocks',
|
||||
@@ -102,7 +103,7 @@ suite('Block Create Event', function () {
|
||||
delete origEvent.xml; // xml fails deep equals for some reason.
|
||||
delete newEvent.xml; // xml fails deep equals for some reason.
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -34,7 +35,7 @@ suite('Block Delete Event', function () {
|
||||
testBlock.dispose();
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isFalse(spy.called);
|
||||
assert.isFalse(spy.called);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,7 +49,7 @@ suite('Block Delete Event', function () {
|
||||
delete origEvent.oldXml; // xml fails deep equals for some reason.
|
||||
delete newEvent.oldXml; // xml fails deep equals for some reason.
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -29,7 +30,7 @@ suite('Block Drag Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -32,7 +33,7 @@ suite('Field Intermediate Change Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,10 +48,7 @@ suite('Field Intermediate Change Event', function () {
|
||||
);
|
||||
origEvent.run(true);
|
||||
|
||||
chai.assert.deepEqual(
|
||||
block.getField(origEvent.name).getValue(),
|
||||
'new value',
|
||||
);
|
||||
assert.deepEqual(block.getField(origEvent.name).getValue(), 'new value');
|
||||
});
|
||||
|
||||
test("running backward changes the block's value to old value", function () {
|
||||
@@ -63,10 +61,7 @@ suite('Field Intermediate Change Event', function () {
|
||||
);
|
||||
origEvent.run(false);
|
||||
|
||||
chai.assert.deepEqual(
|
||||
block.getField(origEvent.name).getValue(),
|
||||
'old value',
|
||||
);
|
||||
assert.deepEqual(block.getField(origEvent.name).getValue(), 'old value');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -32,7 +33,7 @@ suite('Block Move Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {defineMutatorBlocks} from './test_helpers/block_definitions.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -35,7 +36,7 @@ suite('Bubble Open Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -33,7 +34,7 @@ suite('Click Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -32,7 +33,7 @@ suite('Comment Change Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -27,7 +28,7 @@ suite('Comment Collapse Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -31,7 +32,7 @@ suite('Comment Create Event', function () {
|
||||
delete origEvent.xml; // xml fails deep equals for some reason.
|
||||
delete newEvent.xml; // xml fails deep equals for some reason.
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -31,7 +32,7 @@ suite('Comment Delete Event', function () {
|
||||
delete origEvent.xml; // xml fails deep equals for some reason.
|
||||
delete newEvent.xml; // xml fails deep equals for some reason.
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -33,7 +34,7 @@ suite('Comment Move Event', function () {
|
||||
delete origEvent.comment_; // Ignore private properties.
|
||||
delete newEvent.comment_; // Ignore private properties.
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -37,7 +38,7 @@ suite('Marker Move Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -34,7 +35,7 @@ suite('Selected Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {ASTNode} from '../../build/src/core/keyboard_nav/ast_node.js';
|
||||
import {
|
||||
@@ -916,10 +917,7 @@ suite('Events', function () {
|
||||
const json = event.toJson();
|
||||
const event2 = Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.equal(
|
||||
safeStringify(event2.toJson()),
|
||||
safeStringify(json),
|
||||
);
|
||||
assert.equal(safeStringify(event2.toJson()), safeStringify(json));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -931,10 +929,7 @@ suite('Events', function () {
|
||||
const json = event.toJson();
|
||||
const expectedJson = testCase.getExpectedJson(this);
|
||||
|
||||
chai.assert.equal(
|
||||
safeStringify(json),
|
||||
safeStringify(expectedJson),
|
||||
);
|
||||
assert.equal(safeStringify(json), safeStringify(expectedJson));
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -958,10 +953,10 @@ suite('Events', function () {
|
||||
*/
|
||||
function checkVariableValues(container, name, type, id) {
|
||||
const variable = container.getVariableById(id);
|
||||
chai.assert.isDefined(variable);
|
||||
chai.assert.equal(name, variable.name);
|
||||
chai.assert.equal(type, variable.type);
|
||||
chai.assert.equal(id, variable.getId());
|
||||
assert.isDefined(variable);
|
||||
assert.equal(name, variable.name);
|
||||
assert.equal(type, variable.type);
|
||||
assert.equal(id, variable.getId());
|
||||
}
|
||||
|
||||
suite('Constructors', function () {
|
||||
@@ -1036,29 +1031,29 @@ suite('Events', function () {
|
||||
};
|
||||
const event = eventUtils.fromJson(json, this.workspace);
|
||||
const x = this.workspace.getVariableById('id2');
|
||||
chai.assert.isNull(x);
|
||||
assert.isNull(x);
|
||||
event.run(true);
|
||||
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
|
||||
});
|
||||
|
||||
test('Var delete', function () {
|
||||
const event = new Blockly.Events.VarDelete(this.variable);
|
||||
chai.assert.isNotNull(this.workspace.getVariableById('id1'));
|
||||
assert.isNotNull(this.workspace.getVariableById('id1'));
|
||||
event.run(true);
|
||||
chai.assert.isNull(this.workspace.getVariableById('id1'));
|
||||
assert.isNull(this.workspace.getVariableById('id1'));
|
||||
});
|
||||
|
||||
test('Var rename', function () {
|
||||
const event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||
event.run(true);
|
||||
chai.assert.isNull(this.workspace.getVariable('name1'));
|
||||
assert.isNull(this.workspace.getVariable('name1'));
|
||||
checkVariableValues(this.workspace, 'name2', 'type1', 'id1');
|
||||
});
|
||||
});
|
||||
suite('Run Backward', function () {
|
||||
test('Var create', function () {
|
||||
const event = new Blockly.Events.VarCreate(this.variable);
|
||||
chai.assert.isNotNull(this.workspace.getVariableById('id1'));
|
||||
assert.isNotNull(this.workspace.getVariableById('id1'));
|
||||
event.run(false);
|
||||
});
|
||||
|
||||
@@ -1070,7 +1065,7 @@ suite('Events', function () {
|
||||
varName: 'name2',
|
||||
};
|
||||
const event = eventUtils.fromJson(json, this.workspace);
|
||||
chai.assert.isNull(this.workspace.getVariableById('id2'));
|
||||
assert.isNull(this.workspace.getVariableById('id2'));
|
||||
event.run(false);
|
||||
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
|
||||
});
|
||||
@@ -1078,7 +1073,7 @@ suite('Events', function () {
|
||||
test('Var rename', function () {
|
||||
const event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||
event.run(false);
|
||||
chai.assert.isNull(this.workspace.getVariable('name2'));
|
||||
assert.isNull(this.workspace.getVariable('name2'));
|
||||
checkVariableValues(this.workspace, 'name1', 'type1', 'id1');
|
||||
});
|
||||
});
|
||||
@@ -1106,16 +1101,12 @@ suite('Events', function () {
|
||||
new Blockly.Events.Click(block),
|
||||
];
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 4); // no event should have been removed.
|
||||
assert.equal(filteredEvents.length, 4); // no event should have been removed.
|
||||
// test that the order hasn't changed
|
||||
chai.assert.isTrue(
|
||||
filteredEvents[0] instanceof Blockly.Events.BlockCreate,
|
||||
);
|
||||
chai.assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
chai.assert.isTrue(
|
||||
filteredEvents[2] instanceof Blockly.Events.BlockChange,
|
||||
);
|
||||
chai.assert.isTrue(filteredEvents[3] instanceof Blockly.Events.Click);
|
||||
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||
assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
assert.isTrue(filteredEvents[2] instanceof Blockly.Events.BlockChange);
|
||||
assert.isTrue(filteredEvents[3] instanceof Blockly.Events.Click);
|
||||
});
|
||||
|
||||
test('Different blocks no removed', function () {
|
||||
@@ -1128,7 +1119,7 @@ suite('Events', function () {
|
||||
new Blockly.Events.BlockMove(block2),
|
||||
];
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 4); // no event should have been removed.
|
||||
assert.equal(filteredEvents.length, 4); // no event should have been removed.
|
||||
});
|
||||
|
||||
test('Forward', function () {
|
||||
@@ -1138,14 +1129,12 @@ suite('Events', function () {
|
||||
addMoveEvent(events, block, 2, 2);
|
||||
addMoveEvent(events, block, 3, 3);
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 2); // duplicate moves should have been removed.
|
||||
assert.equal(filteredEvents.length, 2); // duplicate moves should have been removed.
|
||||
// test that the order hasn't changed
|
||||
chai.assert.isTrue(
|
||||
filteredEvents[0] instanceof Blockly.Events.BlockCreate,
|
||||
);
|
||||
chai.assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
chai.assert.equal(filteredEvents[1].newCoordinate.x, 3);
|
||||
chai.assert.equal(filteredEvents[1].newCoordinate.y, 3);
|
||||
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||
assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
assert.equal(filteredEvents[1].newCoordinate.x, 3);
|
||||
assert.equal(filteredEvents[1].newCoordinate.y, 3);
|
||||
});
|
||||
|
||||
test('Backward', function () {
|
||||
@@ -1155,14 +1144,12 @@ suite('Events', function () {
|
||||
addMoveEvent(events, block, 2, 2);
|
||||
addMoveEvent(events, block, 3, 3);
|
||||
const filteredEvents = eventUtils.filter(events, false);
|
||||
chai.assert.equal(filteredEvents.length, 2); // duplicate event should have been removed.
|
||||
assert.equal(filteredEvents.length, 2); // duplicate event should have been removed.
|
||||
// test that the order hasn't changed
|
||||
chai.assert.isTrue(
|
||||
filteredEvents[0] instanceof Blockly.Events.BlockCreate,
|
||||
);
|
||||
chai.assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
chai.assert.equal(filteredEvents[1].newCoordinate.x, 1);
|
||||
chai.assert.equal(filteredEvents[1].newCoordinate.y, 1);
|
||||
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||
assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
assert.equal(filteredEvents[1].newCoordinate.x, 1);
|
||||
assert.equal(filteredEvents[1].newCoordinate.y, 1);
|
||||
});
|
||||
|
||||
test('Merge block move events', function () {
|
||||
@@ -1171,9 +1158,9 @@ suite('Events', function () {
|
||||
addMoveEvent(events, block, 0, 0);
|
||||
addMoveEvent(events, block, 1, 1);
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 1); // second move event merged into first
|
||||
chai.assert.equal(filteredEvents[0].newCoordinate.x, 1);
|
||||
chai.assert.equal(filteredEvents[0].newCoordinate.y, 1);
|
||||
assert.equal(filteredEvents.length, 1); // second move event merged into first
|
||||
assert.equal(filteredEvents[0].newCoordinate.x, 1);
|
||||
assert.equal(filteredEvents[0].newCoordinate.y, 1);
|
||||
});
|
||||
|
||||
test('Merge block change events', function () {
|
||||
@@ -1189,9 +1176,9 @@ suite('Events', function () {
|
||||
),
|
||||
];
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 1); // second change event merged into first
|
||||
chai.assert.equal(filteredEvents[0].oldValue, 'item');
|
||||
chai.assert.equal(filteredEvents[0].newValue, 'item2');
|
||||
assert.equal(filteredEvents.length, 1); // second change event merged into first
|
||||
assert.equal(filteredEvents[0].oldValue, 'item');
|
||||
assert.equal(filteredEvents[0].newValue, 'item2');
|
||||
});
|
||||
|
||||
test('Merge viewport change events', function () {
|
||||
@@ -1200,11 +1187,11 @@ suite('Events', function () {
|
||||
new Blockly.Events.ViewportChange(5, 6, 7, this.workspace, 8),
|
||||
];
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 1); // second change event merged into first
|
||||
chai.assert.equal(filteredEvents[0].viewTop, 5);
|
||||
chai.assert.equal(filteredEvents[0].viewLeft, 6);
|
||||
chai.assert.equal(filteredEvents[0].scale, 7);
|
||||
chai.assert.equal(filteredEvents[0].oldScale, 8);
|
||||
assert.equal(filteredEvents.length, 1); // second change event merged into first
|
||||
assert.equal(filteredEvents[0].viewTop, 5);
|
||||
assert.equal(filteredEvents[0].viewLeft, 6);
|
||||
assert.equal(filteredEvents[0].scale, 7);
|
||||
assert.equal(filteredEvents[0].oldScale, 8);
|
||||
});
|
||||
|
||||
test('Merge ui events', function () {
|
||||
@@ -1221,19 +1208,13 @@ suite('Events', function () {
|
||||
];
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
// click event merged into corresponding *Open event
|
||||
chai.assert.equal(filteredEvents.length, 3);
|
||||
chai.assert.isTrue(
|
||||
filteredEvents[0] instanceof Blockly.Events.BubbleOpen,
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
filteredEvents[1] instanceof Blockly.Events.BubbleOpen,
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
filteredEvents[2] instanceof Blockly.Events.BubbleOpen,
|
||||
);
|
||||
chai.assert.equal(filteredEvents[0].bubbleType, 'comment');
|
||||
chai.assert.equal(filteredEvents[1].bubbleType, 'mutator');
|
||||
chai.assert.equal(filteredEvents[2].bubbleType, 'warning');
|
||||
assert.equal(filteredEvents.length, 3);
|
||||
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BubbleOpen);
|
||||
assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BubbleOpen);
|
||||
assert.isTrue(filteredEvents[2] instanceof Blockly.Events.BubbleOpen);
|
||||
assert.equal(filteredEvents[0].bubbleType, 'comment');
|
||||
assert.equal(filteredEvents[1].bubbleType, 'mutator');
|
||||
assert.equal(filteredEvents[2].bubbleType, 'warning');
|
||||
});
|
||||
|
||||
test('Colliding events not dropped', function () {
|
||||
@@ -1246,9 +1227,9 @@ suite('Events', function () {
|
||||
];
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
// click and stackclick should both exist
|
||||
chai.assert.equal(filteredEvents.length, 2);
|
||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.Click);
|
||||
chai.assert.equal(filteredEvents[1].isStart, true);
|
||||
assert.equal(filteredEvents.length, 2);
|
||||
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.Click);
|
||||
assert.equal(filteredEvents[1].isStart, true);
|
||||
});
|
||||
|
||||
test('Merging null operations dropped', function () {
|
||||
@@ -1267,7 +1248,7 @@ suite('Events', function () {
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
// The two events should be merged, but because nothing has changed
|
||||
// they will be filtered out.
|
||||
chai.assert.equal(filteredEvents.length, 0);
|
||||
assert.equal(filteredEvents.length, 0);
|
||||
});
|
||||
|
||||
test('Move events different blocks not merged', function () {
|
||||
@@ -1287,14 +1268,12 @@ suite('Events', function () {
|
||||
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
// Nothing should have merged.
|
||||
chai.assert.equal(filteredEvents.length, 4);
|
||||
assert.equal(filteredEvents.length, 4);
|
||||
// test that the order hasn't changed
|
||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockMove);
|
||||
chai.assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
chai.assert.isTrue(
|
||||
filteredEvents[2] instanceof Blockly.Events.BlockDelete,
|
||||
);
|
||||
chai.assert.isTrue(filteredEvents[3] instanceof Blockly.Events.BlockMove);
|
||||
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockMove);
|
||||
assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
assert.isTrue(filteredEvents[2] instanceof Blockly.Events.BlockDelete);
|
||||
assert.isTrue(filteredEvents[3] instanceof Blockly.Events.BlockMove);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1344,7 +1323,7 @@ suite('Events', function () {
|
||||
);
|
||||
|
||||
// Expect the workspace to not have a variable with ID 'test_block_id'.
|
||||
chai.assert.isNull(this.workspace.getVariableById(TEST_BLOCK_ID));
|
||||
assert.isNull(this.workspace.getVariableById(TEST_BLOCK_ID));
|
||||
} finally {
|
||||
workspaceTeardown.call(this, workspaceSvg);
|
||||
}
|
||||
@@ -1374,11 +1353,7 @@ suite('Events', function () {
|
||||
// Expect both events to trigger change listener.
|
||||
sinon.assert.calledTwice(this.changeListenerSpy);
|
||||
// Both events should be on undo stack
|
||||
chai.assert.equal(
|
||||
this.workspace.undoStack_.length,
|
||||
2,
|
||||
'Undo stack length',
|
||||
);
|
||||
assert.equal(this.workspace.undoStack_.length, 2, 'Undo stack length');
|
||||
|
||||
assertNthCallEventArgEquals(
|
||||
this.changeListenerSpy,
|
||||
@@ -1398,7 +1373,7 @@ suite('Events', function () {
|
||||
);
|
||||
|
||||
// Expect the workspace to have a variable with ID 'test_var_id'.
|
||||
chai.assert.isNotNull(this.workspace.getVariableById(TEST_VAR_ID));
|
||||
assert.isNotNull(this.workspace.getVariableById(TEST_VAR_ID));
|
||||
});
|
||||
|
||||
test('New block new var xml', function () {
|
||||
@@ -1432,11 +1407,7 @@ suite('Events', function () {
|
||||
// The first varCreate and move event should have been ignored.
|
||||
sinon.assert.callCount(this.changeListenerSpy, 3);
|
||||
// Expect two events on undo stack: varCreate and block create.
|
||||
chai.assert.equal(
|
||||
this.workspace.undoStack_.length,
|
||||
2,
|
||||
'Undo stack length',
|
||||
);
|
||||
assert.equal(this.workspace.undoStack_.length, 2, 'Undo stack length');
|
||||
|
||||
assertNthCallEventArgEquals(
|
||||
this.changeListenerSpy,
|
||||
@@ -1466,7 +1437,7 @@ suite('Events', function () {
|
||||
);
|
||||
|
||||
// Expect the workspace to have a variable with ID 'test_var_id'.
|
||||
chai.assert.isNotNull(this.workspace.getVariableById(TEST_VAR_ID));
|
||||
assert.isNotNull(this.workspace.getVariableById(TEST_VAR_ID));
|
||||
});
|
||||
});
|
||||
suite('Disable orphans', function () {
|
||||
@@ -1487,7 +1458,7 @@ suite('Events', function () {
|
||||
// Fire all events
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
block.isEnabled(),
|
||||
'Expected orphan block to be disabled after creation',
|
||||
);
|
||||
@@ -1503,7 +1474,7 @@ suite('Events', function () {
|
||||
// Fire all events
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
functionBlock.isEnabled(),
|
||||
'Expected top-level procedure block to be enabled',
|
||||
);
|
||||
@@ -1527,7 +1498,7 @@ suite('Events', function () {
|
||||
// Fire all events
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
block.isEnabled(),
|
||||
'Expected disconnected block to be disabled',
|
||||
);
|
||||
@@ -1548,7 +1519,7 @@ suite('Events', function () {
|
||||
// Fire all events
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
block.isEnabled(),
|
||||
'Expected block to be enabled after connecting to parent',
|
||||
);
|
||||
@@ -1575,7 +1546,7 @@ suite('Events', function () {
|
||||
const disabledEvents = this.workspace.getUndoStack().filter(function (e) {
|
||||
return e.element === 'disabled';
|
||||
});
|
||||
chai.assert.isEmpty(
|
||||
assert.isEmpty(
|
||||
disabledEvents,
|
||||
'Undo stack should not contain any disabled events',
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -29,7 +30,7 @@ suite('Theme Change Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -57,7 +58,7 @@ suite('Toolbox Item Select Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -29,7 +30,7 @@ suite('Trashcan Open Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -32,7 +33,7 @@ suite('Var Create Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
|
||||
test('typed variable events round-trip through JSON', function () {
|
||||
@@ -47,7 +48,7 @@ suite('Var Create Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -32,7 +33,7 @@ suite('Var Delete Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
|
||||
test('typed variable events round-trip through JSON', function () {
|
||||
@@ -47,7 +48,7 @@ suite('Var Delete Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -32,7 +33,7 @@ suite('Var Rename Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -32,7 +33,7 @@ suite('Viewport Change Event', function () {
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -27,7 +28,7 @@ suite('Extensions', function () {
|
||||
this.extensionsCleanup_.push('extensions_test_before');
|
||||
this.extensionsCleanup_.push('extensions_test_after');
|
||||
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test_before'],
|
||||
);
|
||||
const beforeCallback = sinon.spy();
|
||||
@@ -42,18 +43,18 @@ suite('Extensions', function () {
|
||||
},
|
||||
]);
|
||||
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test_after'],
|
||||
);
|
||||
const afterCallback = sinon.spy();
|
||||
// Extension defined after the block type (but before instantiation).
|
||||
Blockly.Extensions.register('extensions_test_after', afterCallback);
|
||||
|
||||
chai.assert.typeOf(
|
||||
assert.typeOf(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test_before'],
|
||||
'function',
|
||||
);
|
||||
chai.assert.typeOf(
|
||||
assert.typeOf(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test_after'],
|
||||
'function',
|
||||
);
|
||||
@@ -98,27 +99,27 @@ suite('Extensions', function () {
|
||||
);
|
||||
|
||||
// Tooltip is dynamic after extension initialization.
|
||||
chai.assert.typeOf(block.tooltip, 'function');
|
||||
chai.assert.equal(block.tooltip(), defaultTooltip);
|
||||
assert.typeOf(block.tooltip, 'function');
|
||||
assert.equal(block.tooltip(), defaultTooltip);
|
||||
|
||||
// Tooltip is normal before connected to parent.
|
||||
const parent = new Blockly.Block(this.workspace, 'test_parent');
|
||||
chai.assert.equal(parent.tooltip, parentTooltip);
|
||||
chai.assert.notExists(parent.inputsInline);
|
||||
assert.equal(parent.tooltip, parentTooltip);
|
||||
assert.notExists(parent.inputsInline);
|
||||
|
||||
// Tooltip is normal when parent is not inline.
|
||||
parent.getInput('INPUT').connection.connect(block.outputConnection);
|
||||
chai.assert.equal(block.getParent(), parent);
|
||||
chai.assert.equal(block.tooltip(), defaultTooltip);
|
||||
assert.equal(block.getParent(), parent);
|
||||
assert.equal(block.tooltip(), defaultTooltip);
|
||||
|
||||
// Tooltip is parent's when parent is inline.
|
||||
parent.setInputsInline(true);
|
||||
chai.assert.equal(block.tooltip(), parentTooltip);
|
||||
assert.equal(block.tooltip(), parentTooltip);
|
||||
|
||||
// Tooltip revert when disconnected.
|
||||
parent.getInput('INPUT').connection.disconnect();
|
||||
chai.assert.notExists(block.getParent());
|
||||
chai.assert.equal(block.tooltip(), defaultTooltip);
|
||||
assert.notExists(block.getParent());
|
||||
assert.equal(block.tooltip(), defaultTooltip);
|
||||
});
|
||||
|
||||
suite('Mixin', function () {
|
||||
@@ -132,13 +133,13 @@ suite('Extensions', function () {
|
||||
},
|
||||
};
|
||||
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mixin_test'],
|
||||
);
|
||||
// Extension defined before the block type is defined.
|
||||
Blockly.Extensions.registerMixin('mixin_test', testMixin);
|
||||
|
||||
chai.assert.typeOf(
|
||||
assert.typeOf(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mixin_test'],
|
||||
'function',
|
||||
);
|
||||
@@ -153,8 +154,8 @@ suite('Extensions', function () {
|
||||
|
||||
const block = new Blockly.Block(this.workspace, 'test_block_mixin');
|
||||
|
||||
chai.assert.equal(testMixin.field, block.field);
|
||||
chai.assert.equal(testMixin.method, block.method);
|
||||
assert.equal(testMixin.field, block.field);
|
||||
assert.equal(testMixin.method, block.method);
|
||||
});
|
||||
|
||||
suite('Mutator', function () {
|
||||
@@ -190,10 +191,10 @@ suite('Extensions', function () {
|
||||
const block = new Blockly.Block(this.workspace, 'mutator_test_block');
|
||||
|
||||
// Make sure all of the functions were installed correctly.
|
||||
chai.assert.equal(block.domToMutation(), 'domToMutationFn');
|
||||
chai.assert.equal(block.mutationToDom(), 'mutationToDomFn');
|
||||
chai.assert.equal(block.compose(), 'composeFn');
|
||||
chai.assert.equal(block.decompose(), 'decomposeFn');
|
||||
assert.equal(block.domToMutation(), 'domToMutationFn');
|
||||
assert.equal(block.mutationToDom(), 'mutationToDomFn');
|
||||
assert.equal(block.compose(), 'composeFn');
|
||||
assert.equal(block.decompose(), 'decomposeFn');
|
||||
});
|
||||
|
||||
test('With helper function', function () {
|
||||
@@ -210,7 +211,7 @@ suite('Extensions', function () {
|
||||
// Events code calls mutationToDom and expects it to give back a
|
||||
// meaningful value.
|
||||
Blockly.Events.disable();
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test'],
|
||||
);
|
||||
const helperFunctionSpy = sinon.spy();
|
||||
@@ -246,7 +247,7 @@ suite('Extensions', function () {
|
||||
// Events code calls mutationToDom and expects it to give back a
|
||||
// meaningful value.
|
||||
Blockly.Events.disable();
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mutator_test'],
|
||||
);
|
||||
Blockly.Extensions.registerMutator('mutator_test', {
|
||||
@@ -261,10 +262,10 @@ suite('Extensions', function () {
|
||||
const block = new Blockly.Block(this.workspace, 'mutator_test_block');
|
||||
|
||||
// Make sure all of the functions were installed correctly.
|
||||
chai.assert.equal(block.domToMutation(), 'domToMutationFn');
|
||||
chai.assert.equal(block.mutationToDom(), 'mutationToDomFn');
|
||||
chai.assert.isUndefined(block['compose']);
|
||||
chai.assert.isUndefined(block['decompose']);
|
||||
assert.equal(block.domToMutation(), 'domToMutationFn');
|
||||
assert.equal(block.mutationToDom(), 'mutationToDomFn');
|
||||
assert.isUndefined(block['compose']);
|
||||
assert.isUndefined(block['decompose']);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -279,11 +280,11 @@ suite('Extensions', function () {
|
||||
},
|
||||
]);
|
||||
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['missing_extension'],
|
||||
);
|
||||
const workspace = this.workspace;
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
const _ = new Blockly.Block(workspace, 'missing_extension_block');
|
||||
});
|
||||
});
|
||||
@@ -295,7 +296,7 @@ suite('Extensions', function () {
|
||||
inputList: 'bad inputList', // Defined in constructor
|
||||
};
|
||||
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mixin_bad_inputList'],
|
||||
);
|
||||
// Extension defined before the block type is defined.
|
||||
@@ -303,7 +304,7 @@ suite('Extensions', function () {
|
||||
'mixin_bad_inputList',
|
||||
TEST_MIXIN_BAD_INPUTLIST,
|
||||
);
|
||||
chai.assert.typeOf(
|
||||
assert.typeOf(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mixin_bad_inputList'],
|
||||
'function',
|
||||
);
|
||||
@@ -317,7 +318,7 @@ suite('Extensions', function () {
|
||||
]);
|
||||
|
||||
const workspace = this.workspace;
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
const _ = new Blockly.Block(workspace, 'test_block_bad_inputList');
|
||||
}, /inputList/);
|
||||
});
|
||||
@@ -329,7 +330,7 @@ suite('Extensions', function () {
|
||||
colour_: 'bad colour_', // Defined on prototype
|
||||
};
|
||||
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mixin_bad_colour_'],
|
||||
);
|
||||
// Extension defined before the block type is defined.
|
||||
@@ -337,7 +338,7 @@ suite('Extensions', function () {
|
||||
'mixin_bad_colour_',
|
||||
TEST_MIXIN_BAD_COLOUR,
|
||||
);
|
||||
chai.assert.typeOf(
|
||||
assert.typeOf(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mixin_bad_colour_'],
|
||||
'function',
|
||||
);
|
||||
@@ -351,7 +352,7 @@ suite('Extensions', function () {
|
||||
]);
|
||||
|
||||
const workspace = this.workspace;
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
const _ = new Blockly.Block(workspace, 'test_block_bad_colour');
|
||||
}, /colour_/);
|
||||
});
|
||||
@@ -370,7 +371,7 @@ suite('Extensions', function () {
|
||||
// Events code calls mutationToDom and expects it to give back a
|
||||
// meaningful value.
|
||||
Blockly.Events.disable();
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mutator_test'],
|
||||
);
|
||||
Blockly.Extensions.registerMutator('mutator_test', {
|
||||
@@ -383,11 +384,11 @@ suite('Extensions', function () {
|
||||
});
|
||||
|
||||
const workspace = this.workspace;
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
const _ = new Blockly.Block(workspace, 'mutator_test_block');
|
||||
});
|
||||
// Should have failed on apply, not on register.
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mutator_test'],
|
||||
);
|
||||
});
|
||||
@@ -406,7 +407,7 @@ suite('Extensions', function () {
|
||||
// Events code calls mutationToDom and expects it to give back a
|
||||
// meaningful value.
|
||||
Blockly.Events.disable();
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mutator_test'],
|
||||
);
|
||||
Blockly.Extensions.registerMixin('mutator_test', {
|
||||
@@ -419,11 +420,11 @@ suite('Extensions', function () {
|
||||
});
|
||||
|
||||
const workspace = this.workspace;
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
const _ = new Blockly.Block(workspace, 'mutator_test_block');
|
||||
});
|
||||
// Should have failed on apply, not on register.
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['mutator_test'],
|
||||
);
|
||||
});
|
||||
@@ -442,7 +443,7 @@ suite('Extensions', function () {
|
||||
// Events code calls mutationToDom and expects it to give back a
|
||||
// meaningful value.
|
||||
Blockly.Events.disable();
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test'],
|
||||
);
|
||||
Blockly.Extensions.register('extensions_test', function () {
|
||||
@@ -450,11 +451,11 @@ suite('Extensions', function () {
|
||||
});
|
||||
|
||||
const workspace = this.workspace;
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
const _ = new Blockly.Block(workspace, 'mutator_test_block');
|
||||
});
|
||||
// Should have failed on apply, not on register.
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test'],
|
||||
);
|
||||
});
|
||||
@@ -462,30 +463,30 @@ suite('Extensions', function () {
|
||||
suite('register', function () {
|
||||
test('Just a string', function () {
|
||||
this.extensionsCleanup_.push('extension_just_a_string');
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['extension_just_a_string'],
|
||||
);
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.Extensions.register('extension_just_a_string', null);
|
||||
});
|
||||
});
|
||||
|
||||
test('Null', function () {
|
||||
this.extensionsCleanup_.push('extension_is_null');
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['extension_is_null'],
|
||||
);
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.Extensions.register('extension_is_null', null);
|
||||
});
|
||||
});
|
||||
|
||||
test('Undefined', function () {
|
||||
this.extensionsCleanup_.push('extension_is_undefined');
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
Blockly.Extensions.TEST_ONLY.allExtensions['extension_is_undefined'],
|
||||
);
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.Extensions.register('extension_is_undefined', null);
|
||||
});
|
||||
});
|
||||
@@ -494,7 +495,7 @@ suite('Extensions', function () {
|
||||
suite('registerMutator', function () {
|
||||
test('No domToMutation', function () {
|
||||
this.extensionsCleanup_.push('mutator_test');
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.Extensions.registerMutator('mutator_test', {
|
||||
mutationToDom: function () {
|
||||
return 'mutationToDomFn';
|
||||
@@ -511,7 +512,7 @@ suite('Extensions', function () {
|
||||
|
||||
test('No mutationToDom', function () {
|
||||
this.extensionsCleanup_.push('mutator_test');
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.Extensions.registerMutator('mutator_test', {
|
||||
domToMutation: function () {
|
||||
return 'domToMutationFn';
|
||||
@@ -528,7 +529,7 @@ suite('Extensions', function () {
|
||||
|
||||
test('No saveExtraState', function () {
|
||||
this.extensionsCleanup_.push('mutator_test');
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.Extensions.registerMutator('mutator_test', {
|
||||
loadExtraState: function () {
|
||||
return 'loadExtraState';
|
||||
@@ -545,7 +546,7 @@ suite('Extensions', function () {
|
||||
|
||||
test('No loadExtraState', function () {
|
||||
this.extensionsCleanup_.push('mutator_test');
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.Extensions.registerMutator('mutator_test', {
|
||||
saveExtraState: function () {
|
||||
return 'saveExtraState';
|
||||
@@ -562,7 +563,7 @@ suite('Extensions', function () {
|
||||
|
||||
test('No serialization hooks', function () {
|
||||
this.extensionsCleanup_.push('mutator_test');
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.Extensions.registerMutator('mutator_test', {
|
||||
compose: function () {
|
||||
return 'composeFn';
|
||||
@@ -576,7 +577,7 @@ suite('Extensions', function () {
|
||||
|
||||
test('Has decompose but no compose', function () {
|
||||
this.extensionsCleanup_.push('mutator_test');
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.Extensions.registerMutator('mutator_test', {
|
||||
domToMutation: function () {
|
||||
return 'domToMutationFn';
|
||||
@@ -593,7 +594,7 @@ suite('Extensions', function () {
|
||||
|
||||
test('Has compose but no decompose', function () {
|
||||
this.extensionsCleanup_.push('mutator_test');
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.Extensions.registerMutator('mutator_test', {
|
||||
domToMutation: function () {
|
||||
return 'domToMutationFn';
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
assertFieldValue,
|
||||
@@ -223,7 +224,7 @@ suite('Checkbox Fields', function () {
|
||||
};
|
||||
field.initView();
|
||||
field.render_();
|
||||
chai.assert(field.textContent_.nodeValue, char);
|
||||
assert(field.textContent_.nodeValue, char);
|
||||
}
|
||||
test('Constant', function () {
|
||||
const checkChar = Blockly.FieldCheckbox.CHECK_CHAR;
|
||||
@@ -251,7 +252,7 @@ suite('Checkbox Fields', function () {
|
||||
assertCharacter(field, Blockly.FieldCheckbox.CHECK_CHAR);
|
||||
field.setCheckCharacter('\u2661');
|
||||
// Don't call assertCharacter b/c we don't want to re-initialize.
|
||||
chai.assert.equal(field.textContent_.nodeValue, '\u2661');
|
||||
assert.equal(field.textContent_.nodeValue, '\u2661');
|
||||
});
|
||||
test('setCheckCharacter Before Init', function () {
|
||||
const field = new Blockly.FieldCheckbox();
|
||||
@@ -264,10 +265,7 @@ suite('Checkbox Fields', function () {
|
||||
});
|
||||
assertCharacter(field, '\u2661');
|
||||
field.setCheckCharacter(null);
|
||||
chai.assert(
|
||||
field.textContent_.nodeValue,
|
||||
Blockly.FieldCheckbox.CHECK_CHAR,
|
||||
);
|
||||
assert(field.textContent_.nodeValue, Blockly.FieldCheckbox.CHECK_CHAR);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -282,7 +280,7 @@ suite('Checkbox Fields', function () {
|
||||
const field = new Blockly.FieldCheckbox(value);
|
||||
block.getInput('INPUT').appendField(field, 'CHECK');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields'], {'CHECK': value});
|
||||
assert.deepEqual(jso['fields'], {'CHECK': value});
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
assertFieldValue,
|
||||
@@ -253,8 +254,8 @@ suite('Colour Fields', function () {
|
||||
let index = 0;
|
||||
let node = field.picker.firstChild.firstChild;
|
||||
while (node) {
|
||||
chai.assert.equal(node.getAttribute('title'), titles[index]);
|
||||
chai.assert.equal(
|
||||
assert.equal(node.getAttribute('title'), titles[index]);
|
||||
assert.equal(
|
||||
Blockly.utils.colour.parse(node.style.backgroundColor),
|
||||
colours[index],
|
||||
);
|
||||
@@ -331,7 +332,7 @@ suite('Colour Fields', function () {
|
||||
suite('Columns', function () {
|
||||
function assertColumns(field, columns) {
|
||||
field.dropdownCreate();
|
||||
chai.assert.equal(field.picker.firstChild.children.length, columns);
|
||||
assert.equal(field.picker.firstChild.children.length, columns);
|
||||
}
|
||||
test('Constants', function () {
|
||||
const columns = Blockly.FieldColour.COLUMNS;
|
||||
@@ -375,7 +376,7 @@ suite('Colour Fields', function () {
|
||||
const field = new Blockly.FieldColour(value);
|
||||
block.getInput('INPUT').appendField(field, 'COLOUR');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields'], {'COLOUR': value});
|
||||
assert.deepEqual(jso['fields'], {'COLOUR': value});
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
assertFieldValue,
|
||||
@@ -252,7 +253,7 @@ suite('Dropdown Fields', function () {
|
||||
field.setValue(value);
|
||||
block.getInput('INPUT').appendField(field, 'DROPDOWN');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields'], {'DROPDOWN': value});
|
||||
assert.deepEqual(jso['fields'], {'DROPDOWN': value});
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
assertFieldValue,
|
||||
@@ -134,23 +135,23 @@ suite('Image Fields', function () {
|
||||
});
|
||||
test('JS Constructor', function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, null, this.onClick);
|
||||
chai.assert.equal(field.clickHandler, this.onClick);
|
||||
assert.equal(field.clickHandler, this.onClick);
|
||||
});
|
||||
test('setOnClickHandler', function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10);
|
||||
field.setOnClickHandler(this.onClick);
|
||||
chai.assert.equal(field.clickHandler, this.onClick);
|
||||
assert.equal(field.clickHandler, this.onClick);
|
||||
});
|
||||
test('Remove Click Handler', function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, null, this.onClick);
|
||||
field.setOnClickHandler(null);
|
||||
chai.assert.isNull(field.clickHandler);
|
||||
assert.isNull(field.clickHandler);
|
||||
});
|
||||
});
|
||||
suite('Alt', function () {
|
||||
test('JS Constructor', function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, 'alt');
|
||||
chai.assert.equal(field.getText(), 'alt');
|
||||
assert.equal(field.getText(), 'alt');
|
||||
});
|
||||
test('JSON Definition', function () {
|
||||
const field = Blockly.FieldImage.fromJson({
|
||||
@@ -159,7 +160,7 @@ suite('Image Fields', function () {
|
||||
height: 10,
|
||||
alt: 'alt',
|
||||
});
|
||||
chai.assert.equal(field.getText(), 'alt');
|
||||
assert.equal(field.getText(), 'alt');
|
||||
});
|
||||
suite('SetAlt', function () {
|
||||
setup(function () {
|
||||
@@ -182,31 +183,31 @@ suite('Image Fields', function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, null, null, null, {
|
||||
alt: 'alt',
|
||||
});
|
||||
chai.assert.equal(field.getText(), 'alt');
|
||||
assert.equal(field.getText(), 'alt');
|
||||
});
|
||||
test('JS Configuration - Ignore', function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, 'alt', null, null, {
|
||||
alt: 'configAlt',
|
||||
});
|
||||
chai.assert.equal(field.getText(), 'configAlt');
|
||||
assert.equal(field.getText(), 'configAlt');
|
||||
});
|
||||
test("JS Configuration - Ignore - ''", function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, '', null, null, {
|
||||
alt: 'configAlt',
|
||||
});
|
||||
chai.assert.equal(field.getText(), 'configAlt');
|
||||
assert.equal(field.getText(), 'configAlt');
|
||||
});
|
||||
test("JS Configuration - Ignore - Config ''", function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, 'alt', null, null, {
|
||||
alt: '',
|
||||
});
|
||||
chai.assert.equal(field.getText(), '');
|
||||
assert.equal(field.getText(), '');
|
||||
});
|
||||
});
|
||||
suite('Flip RTL', function () {
|
||||
test('JS Constructor', function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, null, null, true);
|
||||
chai.assert.isTrue(field.getFlipRtl());
|
||||
assert.isTrue(field.getFlipRtl());
|
||||
});
|
||||
test('JSON Definition', function () {
|
||||
const field = Blockly.FieldImage.fromJson({
|
||||
@@ -215,25 +216,25 @@ suite('Image Fields', function () {
|
||||
height: 10,
|
||||
flipRtl: true,
|
||||
});
|
||||
chai.assert.isTrue(field.getFlipRtl());
|
||||
assert.isTrue(field.getFlipRtl());
|
||||
});
|
||||
test('JS Configuration - Simple', function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, null, null, null, {
|
||||
flipRtl: true,
|
||||
});
|
||||
chai.assert.isTrue(field.getFlipRtl());
|
||||
assert.isTrue(field.getFlipRtl());
|
||||
});
|
||||
test('JS Configuration - Ignore - True', function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, null, null, true, {
|
||||
flipRtl: false,
|
||||
});
|
||||
chai.assert.isFalse(field.getFlipRtl());
|
||||
assert.isFalse(field.getFlipRtl());
|
||||
});
|
||||
test('JS Configuration - Ignore - False', function () {
|
||||
const field = new Blockly.FieldImage('src', 10, 10, null, null, false, {
|
||||
flipRtl: true,
|
||||
});
|
||||
chai.assert.isTrue(field.getFlipRtl());
|
||||
assert.isTrue(field.getFlipRtl());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
assertFieldValue,
|
||||
@@ -137,7 +138,7 @@ suite('Label Serializable Fields', function () {
|
||||
FIELD_TEXT_BASELINE_Y: 13,
|
||||
};
|
||||
labelField.initView();
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
Blockly.utils.dom.hasClass(labelField.textElement_, cssClass),
|
||||
);
|
||||
}
|
||||
@@ -151,7 +152,7 @@ suite('Label Serializable Fields', function () {
|
||||
FIELD_TEXT_BASELINE_Y: 13,
|
||||
};
|
||||
labelField.initView();
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
Blockly.utils.dom.hasClass(labelField.textElement_, cssClass),
|
||||
);
|
||||
}
|
||||
@@ -204,7 +205,7 @@ suite('Label Serializable Fields', function () {
|
||||
field.initView();
|
||||
field.setClass('testClass');
|
||||
// Don't call assertHasClass b/c we don't want to re-initialize.
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
Blockly.utils.dom.hasClass(field.textElement_, 'testClass'),
|
||||
);
|
||||
});
|
||||
@@ -219,7 +220,7 @@ suite('Label Serializable Fields', function () {
|
||||
});
|
||||
assertHasClass(field, 'testClass');
|
||||
field.setClass(null);
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
Blockly.utils.dom.hasClass(field.textElement_, 'testClass'),
|
||||
);
|
||||
});
|
||||
@@ -236,7 +237,7 @@ suite('Label Serializable Fields', function () {
|
||||
const field = new Blockly.FieldLabelSerializable(value);
|
||||
block.getInput('INPUT').appendField(field, 'LABEL');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields'], {'LABEL': value});
|
||||
assert.deepEqual(jso['fields'], {'LABEL': value});
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
assertFieldValue,
|
||||
@@ -133,7 +134,7 @@ suite('Label Fields', function () {
|
||||
FIELD_TEXT_BASELINE_Y: 13,
|
||||
};
|
||||
labelField.initView();
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
Blockly.utils.dom.hasClass(labelField.textElement_, cssClass),
|
||||
);
|
||||
}
|
||||
@@ -147,7 +148,7 @@ suite('Label Fields', function () {
|
||||
FIELD_TEXT_BASELINE_Y: 13,
|
||||
};
|
||||
labelField.initView();
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
Blockly.utils.dom.hasClass(labelField.textElement_, cssClass),
|
||||
);
|
||||
}
|
||||
@@ -201,7 +202,7 @@ suite('Label Fields', function () {
|
||||
field.initView();
|
||||
field.setClass('testClass');
|
||||
// Don't call assertHasClass b/c we don't want to re-initialize.
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
Blockly.utils.dom.hasClass(field.textElement_, 'testClass'),
|
||||
);
|
||||
});
|
||||
@@ -216,7 +217,7 @@ suite('Label Fields', function () {
|
||||
});
|
||||
assertHasClass(field, 'testClass');
|
||||
field.setClass(null);
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
Blockly.utils.dom.hasClass(field.textElement_, 'testClass'),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
assertFieldValue,
|
||||
@@ -87,9 +88,9 @@ suite('Number Fields', function () {
|
||||
expectedValue,
|
||||
) {
|
||||
assertFieldValue(field, expectedValue);
|
||||
chai.assert.equal(field.getMin(), expectedMin, 'Min');
|
||||
chai.assert.equal(field.getMax(), expectedMax, 'Max');
|
||||
chai.assert.equal(field.getPrecision(), expectedPrecision, 'Precision');
|
||||
assert.equal(field.getMin(), expectedMin, 'Min');
|
||||
assert.equal(field.getMax(), expectedMax, 'Max');
|
||||
assert.equal(field.getPrecision(), expectedPrecision, 'Precision');
|
||||
}
|
||||
/**
|
||||
* Asserts that the field property values are set to default.
|
||||
@@ -190,7 +191,7 @@ suite('Number Fields', function () {
|
||||
});
|
||||
test('Null', function () {
|
||||
const field = Blockly.FieldNumber.fromJson({precision: null});
|
||||
chai.assert.equal(field.getPrecision(), 0);
|
||||
assert.equal(field.getPrecision(), 0);
|
||||
});
|
||||
});
|
||||
const setValueBoundsTestFn = function (testCase) {
|
||||
@@ -226,7 +227,7 @@ suite('Number Fields', function () {
|
||||
runTestCases(testCases, setValueBoundsTestFn);
|
||||
test('Null', function () {
|
||||
const field = Blockly.FieldNumber.fromJson({min: null});
|
||||
chai.assert.equal(field.getMin(), -Infinity);
|
||||
assert.equal(field.getMin(), -Infinity);
|
||||
});
|
||||
});
|
||||
suite('Max', function () {
|
||||
@@ -253,7 +254,7 @@ suite('Number Fields', function () {
|
||||
runTestCases(testCases, setValueBoundsTestFn);
|
||||
test('Null', function () {
|
||||
const field = Blockly.FieldNumber.fromJson({max: null});
|
||||
chai.assert.equal(field.getMax(), Infinity);
|
||||
assert.equal(field.getMax(), Infinity);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -473,7 +474,7 @@ suite('Number Fields', function () {
|
||||
const field = new Blockly.FieldNumber(value);
|
||||
block.getInput('INPUT').appendField(field, 'NUMBER');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields'], {'NUMBER': value});
|
||||
assert.deepEqual(jso['fields'], {'NUMBER': value});
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {createDeprecationWarningStub} from './test_helpers/warnings.js';
|
||||
import {
|
||||
@@ -37,20 +38,20 @@ suite('Field Registry', function () {
|
||||
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
|
||||
});
|
||||
test('fromJson as Key', function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.fieldRegistry.register(CustomFieldType.fromJson, '');
|
||||
}, 'Invalid name');
|
||||
});
|
||||
test('No fromJson', function () {
|
||||
class IncorrectField {}
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.fieldRegistry.register('field_custom_test', IncorrectField);
|
||||
}, 'must have a fromJson function');
|
||||
});
|
||||
test('fromJson not a function', function () {
|
||||
const fromJson = CustomFieldType.fromJson;
|
||||
CustomFieldType.fromJson = true;
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
|
||||
}, 'must have a fromJson function');
|
||||
CustomFieldType.fromJson = fromJson;
|
||||
@@ -67,8 +68,8 @@ suite('Field Registry', function () {
|
||||
|
||||
const field = Blockly.fieldRegistry.fromJson(json);
|
||||
|
||||
chai.assert.isNotNull(field);
|
||||
chai.assert.equal(field.getValue(), 'ok');
|
||||
assert.isNotNull(field);
|
||||
assert.equal(field.getValue(), 'ok');
|
||||
});
|
||||
test('Not Registered', function () {
|
||||
const json = {
|
||||
@@ -78,8 +79,8 @@ suite('Field Registry', function () {
|
||||
|
||||
const spy = sinon.stub(console, 'warn');
|
||||
const field = Blockly.fieldRegistry.fromJson(json);
|
||||
chai.assert.isNull(field);
|
||||
chai.assert.isTrue(spy.called);
|
||||
assert.isNull(field);
|
||||
assert.isTrue(spy.called);
|
||||
spy.restore();
|
||||
});
|
||||
test('Case Different', function () {
|
||||
@@ -92,8 +93,8 @@ suite('Field Registry', function () {
|
||||
|
||||
const field = Blockly.fieldRegistry.fromJson(json);
|
||||
|
||||
chai.assert.isNotNull(field);
|
||||
chai.assert.equal(field.getValue(), 'ok');
|
||||
assert.isNotNull(field);
|
||||
assert.equal(field.getValue(), 'ok');
|
||||
});
|
||||
test('Did not override fromJson', function () {
|
||||
// This class will have a fromJson method, so it can be registered
|
||||
@@ -107,7 +108,7 @@ suite('Field Registry', function () {
|
||||
value: 'ok',
|
||||
};
|
||||
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.fieldRegistry.fromJson(json);
|
||||
}, 'Attempted to instantiate a field from the registry');
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
addBlockTypeToCleanup,
|
||||
@@ -65,26 +66,26 @@ suite('Abstract Fields', function () {
|
||||
// An old default field should be serialized.
|
||||
const field = new FieldDefault();
|
||||
const stub = sinon.stub(console, 'warn');
|
||||
chai.assert.isTrue(field.isSerializable());
|
||||
assert.isTrue(field.isSerializable());
|
||||
sinon.assert.calledOnce(stub);
|
||||
stub.restore();
|
||||
});
|
||||
test('Editable False, Serializable Default(false)', function () {
|
||||
// An old non-editable field should not be serialized.
|
||||
const field = new FieldFalseDefault();
|
||||
chai.assert.isFalse(field.isSerializable());
|
||||
assert.isFalse(field.isSerializable());
|
||||
});
|
||||
/* Test Other Cases */
|
||||
test('Editable Default(true), Serializable True', function () {
|
||||
// A field that is both editable and serializable should be serialized.
|
||||
const field = new FieldDefaultTrue();
|
||||
chai.assert.isTrue(field.isSerializable());
|
||||
assert.isTrue(field.isSerializable());
|
||||
});
|
||||
test('Editable False, Serializable True', function () {
|
||||
// A field that is not editable, but overrides serializable to true
|
||||
// should be serialized (e.g. field_label_serializable)
|
||||
const field = new FieldFalseTrue();
|
||||
chai.assert.isTrue(field.isSerializable());
|
||||
assert.isTrue(field.isSerializable());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -193,19 +194,19 @@ suite('Abstract Fields', function () {
|
||||
test('No implementations', function () {
|
||||
const field = new DefaultSerializationField('test value');
|
||||
const value = field.saveState();
|
||||
chai.assert.equal(value, 'test value');
|
||||
assert.equal(value, 'test value');
|
||||
});
|
||||
|
||||
test('Xml implementations', function () {
|
||||
const field = new CustomXmlField('test value');
|
||||
const value = field.saveState();
|
||||
chai.assert.equal(value, '<field name="">custom value</field>');
|
||||
assert.equal(value, '<field name="">custom value</field>');
|
||||
});
|
||||
|
||||
test('Xml super implementation', function () {
|
||||
const field = new CustomXmlCallSuperField('test value');
|
||||
const value = field.saveState();
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
value,
|
||||
'<field name="" attribute="custom value">test value</field>',
|
||||
);
|
||||
@@ -214,13 +215,13 @@ suite('Abstract Fields', function () {
|
||||
test('JSO implementations', function () {
|
||||
const field = new CustomJsoField('test value');
|
||||
const value = field.saveState();
|
||||
chai.assert.equal(value, 'custom value');
|
||||
assert.equal(value, 'custom value');
|
||||
});
|
||||
|
||||
test('JSO super implementations', function () {
|
||||
const field = new CustomJsoCallSuperField('test value');
|
||||
const value = field.saveState();
|
||||
chai.assert.deepEqual(value, {
|
||||
assert.deepEqual(value, {
|
||||
default: 'test value',
|
||||
val: 'custom value',
|
||||
});
|
||||
@@ -229,7 +230,7 @@ suite('Abstract Fields', function () {
|
||||
test('Xml and JSO implementations', function () {
|
||||
const field = new CustomXmlAndJsoField('test value');
|
||||
const value = field.saveState();
|
||||
chai.assert.equal(value, 'custom value');
|
||||
assert.equal(value, 'custom value');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -238,7 +239,7 @@ suite('Abstract Fields', function () {
|
||||
const field = new DefaultSerializationField('test value');
|
||||
const element = document.createElement('field');
|
||||
const value = Blockly.Xml.domToText(field.toXml(element));
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
value,
|
||||
'<field xmlns="http://www.w3.org/1999/xhtml">test value</field>',
|
||||
);
|
||||
@@ -248,7 +249,7 @@ suite('Abstract Fields', function () {
|
||||
const field = new CustomXmlField('test value');
|
||||
const element = document.createElement('field');
|
||||
const value = Blockly.Xml.domToText(field.toXml(element));
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
value,
|
||||
'<field xmlns="http://www.w3.org/1999/xhtml">custom value</field>',
|
||||
);
|
||||
@@ -258,7 +259,7 @@ suite('Abstract Fields', function () {
|
||||
const field = new CustomXmlCallSuperField('test value');
|
||||
const element = document.createElement('field');
|
||||
const value = Blockly.Xml.domToText(field.toXml(element));
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
value,
|
||||
'<field xmlns="http://www.w3.org/1999/xhtml" ' +
|
||||
'attribute="custom value">test value</field>',
|
||||
@@ -269,7 +270,7 @@ suite('Abstract Fields', function () {
|
||||
const field = new CustomXmlAndJsoField('test value');
|
||||
const element = document.createElement('field');
|
||||
const value = Blockly.Xml.domToText(field.toXml(element));
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
value,
|
||||
'<field xmlns="http://www.w3.org/1999/xhtml">custom value</field>',
|
||||
);
|
||||
@@ -282,13 +283,13 @@ suite('Abstract Fields', function () {
|
||||
test('No implementations', function () {
|
||||
const field = new DefaultSerializationField('');
|
||||
field.loadState('test value');
|
||||
chai.assert.equal(field.getValue(), 'test value');
|
||||
assert.equal(field.getValue(), 'test value');
|
||||
});
|
||||
|
||||
test('Xml implementations', function () {
|
||||
const field = new CustomXmlField('');
|
||||
field.loadState('<field name="">custom value</field>');
|
||||
chai.assert.equal(field.someProperty, 'custom value');
|
||||
assert.equal(field.someProperty, 'custom value');
|
||||
});
|
||||
|
||||
test('Xml super implementation', function () {
|
||||
@@ -296,27 +297,27 @@ suite('Abstract Fields', function () {
|
||||
field.loadState(
|
||||
'<field attribute="custom value" name="">test value</field>',
|
||||
);
|
||||
chai.assert.equal(field.getValue(), 'test value');
|
||||
chai.assert.equal(field.someProperty, 'custom value');
|
||||
assert.equal(field.getValue(), 'test value');
|
||||
assert.equal(field.someProperty, 'custom value');
|
||||
});
|
||||
|
||||
test('JSO implementations', function () {
|
||||
const field = new CustomJsoField('');
|
||||
field.loadState('custom value');
|
||||
chai.assert.equal(field.someProperty, 'custom value');
|
||||
assert.equal(field.someProperty, 'custom value');
|
||||
});
|
||||
|
||||
test('JSO super implementations', function () {
|
||||
const field = new CustomJsoCallSuperField('');
|
||||
field.loadState({default: 'test value', val: 'custom value'});
|
||||
chai.assert.equal(field.getValue(), 'test value');
|
||||
chai.assert.equal(field.someProperty, 'custom value');
|
||||
assert.equal(field.getValue(), 'test value');
|
||||
assert.equal(field.someProperty, 'custom value');
|
||||
});
|
||||
|
||||
test('Xml and JSO implementations', function () {
|
||||
const field = new CustomXmlAndJsoField('');
|
||||
field.loadState('custom value');
|
||||
chai.assert.equal(field.someProperty, 'custom value');
|
||||
assert.equal(field.someProperty, 'custom value');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -326,7 +327,7 @@ suite('Abstract Fields', function () {
|
||||
field.fromXml(
|
||||
Blockly.utils.xml.textToDom('<field name="">test value</field>'),
|
||||
);
|
||||
chai.assert.equal(field.getValue(), 'test value');
|
||||
assert.equal(field.getValue(), 'test value');
|
||||
});
|
||||
|
||||
test('Xml implementations', function () {
|
||||
@@ -334,7 +335,7 @@ suite('Abstract Fields', function () {
|
||||
field.fromXml(
|
||||
Blockly.utils.xml.textToDom('<field name="">custom value</field>'),
|
||||
);
|
||||
chai.assert.equal(field.someProperty, 'custom value');
|
||||
assert.equal(field.someProperty, 'custom value');
|
||||
});
|
||||
|
||||
test('Xml super implementation', function () {
|
||||
@@ -344,8 +345,8 @@ suite('Abstract Fields', function () {
|
||||
'<field attribute="custom value" name="">test value</field>',
|
||||
),
|
||||
);
|
||||
chai.assert.equal(field.getValue(), 'test value');
|
||||
chai.assert.equal(field.someProperty, 'custom value');
|
||||
assert.equal(field.getValue(), 'test value');
|
||||
assert.equal(field.someProperty, 'custom value');
|
||||
});
|
||||
|
||||
test('XML andd JSO implementations', function () {
|
||||
@@ -353,7 +354,7 @@ suite('Abstract Fields', function () {
|
||||
field.fromXml(
|
||||
Blockly.utils.xml.textToDom('<field name="">custom value</field>'),
|
||||
);
|
||||
chai.assert.equal(field.someProperty, 'custom value');
|
||||
assert.equal(field.someProperty, 'custom value');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -572,7 +573,7 @@ suite('Abstract Fields', function () {
|
||||
stubClassValidatorWithReturn(this.field, undefined);
|
||||
addSpies(this.field);
|
||||
this.field.setValue('value');
|
||||
chai.assert.equal(this.field.getValue(), 'value');
|
||||
assert.equal(this.field.getValue(), 'value');
|
||||
sinon.assert.notCalled(this.field.doValueInvalid_);
|
||||
sinon.assert.calledOnce(this.field.doValueUpdate_);
|
||||
});
|
||||
@@ -603,7 +604,7 @@ suite('Abstract Fields', function () {
|
||||
setLocalValidatorWithReturn(this.field, undefined);
|
||||
addSpies(this.field);
|
||||
this.field.setValue('value');
|
||||
chai.assert.equal(this.field.getValue(), 'value');
|
||||
assert.equal(this.field.getValue(), 'value');
|
||||
sinon.assert.notCalled(this.field.doValueInvalid_);
|
||||
sinon.assert.calledOnce(this.field.doValueUpdate_);
|
||||
});
|
||||
@@ -626,7 +627,7 @@ suite('Abstract Fields', function () {
|
||||
const field = new Blockly.Field('value', null, {
|
||||
tooltip: 'test tooltip',
|
||||
});
|
||||
chai.assert.equal(field.tooltip_, 'test tooltip');
|
||||
assert.equal(field.tooltip_, 'test tooltip');
|
||||
});
|
||||
test('JS Constructor - Dynamic', function () {
|
||||
const returnTooltip = function () {
|
||||
@@ -635,13 +636,13 @@ suite('Abstract Fields', function () {
|
||||
const field = new Blockly.Field('value', null, {
|
||||
tooltip: returnTooltip,
|
||||
});
|
||||
chai.assert.equal(field.tooltip_, returnTooltip);
|
||||
assert.equal(field.tooltip_, returnTooltip);
|
||||
});
|
||||
test('JSON Definition', function () {
|
||||
const field = CustomField.fromJson({
|
||||
tooltip: 'test tooltip',
|
||||
});
|
||||
chai.assert.equal(field.tooltip_, 'test tooltip');
|
||||
assert.equal(field.tooltip_, 'test tooltip');
|
||||
});
|
||||
suite('W/ Msg References', function () {
|
||||
setup(function () {
|
||||
@@ -652,13 +653,13 @@ suite('Abstract Fields', function () {
|
||||
const field = new Blockly.Field('value', null, {
|
||||
tooltip: '%{BKY_TOOLTIP}',
|
||||
});
|
||||
chai.assert.equal(field.tooltip_, 'test tooltip');
|
||||
assert.equal(field.tooltip_, 'test tooltip');
|
||||
});
|
||||
test('JSON Definition', function () {
|
||||
const field = CustomField.fromJson({
|
||||
tooltip: '%{BKY_TOOLTIP}',
|
||||
});
|
||||
chai.assert.equal(field.tooltip_, 'test tooltip');
|
||||
assert.equal(field.tooltip_, 'test tooltip');
|
||||
});
|
||||
});
|
||||
suite('setTooltip', function () {
|
||||
@@ -687,7 +688,7 @@ suite('Abstract Fields', function () {
|
||||
this.workspace,
|
||||
);
|
||||
const field = block.getField('TOOLTIP');
|
||||
chai.assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
||||
assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
||||
});
|
||||
test('After Append', function () {
|
||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||
@@ -707,7 +708,7 @@ suite('Abstract Fields', function () {
|
||||
this.workspace,
|
||||
);
|
||||
const field = block.getField('TOOLTIP');
|
||||
chai.assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
||||
assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
||||
});
|
||||
test('After Block Creation', function () {
|
||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||
@@ -727,7 +728,7 @@ suite('Abstract Fields', function () {
|
||||
);
|
||||
const field = block.getField('TOOLTIP');
|
||||
field.setTooltip('tooltip');
|
||||
chai.assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
||||
assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
||||
});
|
||||
test('Dynamic Function', function () {
|
||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||
@@ -751,7 +752,7 @@ suite('Abstract Fields', function () {
|
||||
this.workspace,
|
||||
);
|
||||
const field = block.getField('TOOLTIP');
|
||||
chai.assert.equal(field.getClickTarget_().tooltip, block.tooltipFunc);
|
||||
assert.equal(field.getClickTarget_().tooltip, block.tooltipFunc);
|
||||
});
|
||||
test('Element', function () {
|
||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||
@@ -774,7 +775,7 @@ suite('Abstract Fields', function () {
|
||||
this.workspace,
|
||||
);
|
||||
const field = block.getField('TOOLTIP');
|
||||
chai.assert.equal(field.getClickTarget_().tooltip, block.element);
|
||||
assert.equal(field.getClickTarget_().tooltip, block.element);
|
||||
});
|
||||
test('Null', function () {
|
||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||
@@ -794,7 +795,7 @@ suite('Abstract Fields', function () {
|
||||
this.workspace,
|
||||
);
|
||||
const field = block.getField('TOOLTIP');
|
||||
chai.assert.equal(field.getClickTarget_().tooltip, block);
|
||||
assert.equal(field.getClickTarget_().tooltip, block);
|
||||
});
|
||||
test('Undefined', function () {
|
||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||
@@ -813,7 +814,7 @@ suite('Abstract Fields', function () {
|
||||
this.workspace,
|
||||
);
|
||||
const field = block.getField('TOOLTIP');
|
||||
chai.assert.equal(field.getClickTarget_().tooltip, block);
|
||||
assert.equal(field.getClickTarget_().tooltip, block);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
assertFieldValue,
|
||||
@@ -228,7 +229,7 @@ suite('Text Input Fields', function () {
|
||||
this.assertSpellcheck = function (field, value) {
|
||||
this.prepField(field);
|
||||
field.showEditor_();
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
field.htmlInput_.getAttribute('spellcheck'),
|
||||
value.toString(),
|
||||
);
|
||||
@@ -266,7 +267,7 @@ suite('Text Input Fields', function () {
|
||||
this.prepField(field);
|
||||
field.showEditor_();
|
||||
field.setSpellcheck(false);
|
||||
chai.assert.equal(field.htmlInput_.getAttribute('spellcheck'), 'false');
|
||||
assert.equal(field.htmlInput_.getAttribute('spellcheck'), 'false');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -281,7 +282,7 @@ suite('Text Input Fields', function () {
|
||||
const field = new Blockly.FieldTextInput(value);
|
||||
block.getInput('INPUT').appendField(field, 'TEXT');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields'], {'TEXT': value});
|
||||
assert.deepEqual(jso['fields'], {'TEXT': value});
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
assertFieldValue,
|
||||
@@ -135,8 +136,8 @@ suite('Variable Fields', function () {
|
||||
suite('initModel', function () {
|
||||
test('No Value Before InitModel', function () {
|
||||
const fieldVariable = new Blockly.FieldVariable('name1');
|
||||
chai.assert.equal(fieldVariable.getText(), '');
|
||||
chai.assert.isNull(fieldVariable.getValue());
|
||||
assert.equal(fieldVariable.getText(), '');
|
||||
assert.isNull(fieldVariable.getValue());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -199,19 +200,13 @@ suite('Variable Fields', function () {
|
||||
const dropdownOptions =
|
||||
Blockly.FieldVariable.dropdownCreate.call(fieldVariable);
|
||||
// Expect variable options, a rename option, and a delete option.
|
||||
chai.assert.lengthOf(dropdownOptions, expectedVarOptions.length + 2);
|
||||
assert.lengthOf(dropdownOptions, expectedVarOptions.length + 2);
|
||||
for (let i = 0, option; (option = expectedVarOptions[i]); i++) {
|
||||
chai.assert.deepEqual(dropdownOptions[i], option);
|
||||
assert.deepEqual(dropdownOptions[i], option);
|
||||
}
|
||||
chai.assert.include(
|
||||
dropdownOptions[dropdownOptions.length - 2][0],
|
||||
'Rename',
|
||||
);
|
||||
assert.include(dropdownOptions[dropdownOptions.length - 2][0], 'Rename');
|
||||
|
||||
chai.assert.include(
|
||||
dropdownOptions[dropdownOptions.length - 1][0],
|
||||
'Delete',
|
||||
);
|
||||
assert.include(dropdownOptions[dropdownOptions.length - 1][0], 'Delete');
|
||||
};
|
||||
test('Contains variables created before field', function () {
|
||||
this.workspace.createVariable('name1', '', 'id1');
|
||||
@@ -311,8 +306,8 @@ suite('Variable Fields', function () {
|
||||
['Type1'],
|
||||
'Type1',
|
||||
);
|
||||
chai.assert.deepEqual(field.variableTypes, ['Type1']);
|
||||
chai.assert.equal(field.defaultType, 'Type1');
|
||||
assert.deepEqual(field.variableTypes, ['Type1']);
|
||||
assert.equal(field.defaultType, 'Type1');
|
||||
});
|
||||
test('JSON Definition', function () {
|
||||
const field = Blockly.FieldVariable.fromJson({
|
||||
@@ -320,8 +315,8 @@ suite('Variable Fields', function () {
|
||||
variableTypes: ['Type1'],
|
||||
defaultType: 'Type1',
|
||||
});
|
||||
chai.assert.deepEqual(field.variableTypes, ['Type1']);
|
||||
chai.assert.equal(field.defaultType, 'Type1');
|
||||
assert.deepEqual(field.variableTypes, ['Type1']);
|
||||
assert.equal(field.defaultType, 'Type1');
|
||||
});
|
||||
test('JS Configuration - Simple', function () {
|
||||
const field = new Blockly.FieldVariable(
|
||||
@@ -334,8 +329,8 @@ suite('Variable Fields', function () {
|
||||
defaultType: 'Type1',
|
||||
},
|
||||
);
|
||||
chai.assert.deepEqual(field.variableTypes, ['Type1']);
|
||||
chai.assert.equal(field.defaultType, 'Type1');
|
||||
assert.deepEqual(field.variableTypes, ['Type1']);
|
||||
assert.equal(field.defaultType, 'Type1');
|
||||
});
|
||||
test('JS Configuration - Ignore', function () {
|
||||
const field = new Blockly.FieldVariable(
|
||||
@@ -348,8 +343,8 @@ suite('Variable Fields', function () {
|
||||
defaultType: 'Type1',
|
||||
},
|
||||
);
|
||||
chai.assert.deepEqual(field.variableTypes, ['Type1']);
|
||||
chai.assert.equal(field.defaultType, 'Type1');
|
||||
assert.deepEqual(field.variableTypes, ['Type1']);
|
||||
assert.equal(field.defaultType, 'Type1');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -363,7 +358,7 @@ suite('Variable Fields', function () {
|
||||
// will be returned (regardless of what types are available on the workspace).
|
||||
const fieldVariable = new Blockly.FieldVariable('name1');
|
||||
const resultTypes = fieldVariable.getVariableTypes();
|
||||
chai.assert.deepEqual(resultTypes, ['']);
|
||||
assert.deepEqual(resultTypes, ['']);
|
||||
});
|
||||
test('variableTypes is explicit', function () {
|
||||
// Expect that since variableTypes is defined, it will be the return
|
||||
@@ -375,8 +370,8 @@ suite('Variable Fields', function () {
|
||||
'type1',
|
||||
);
|
||||
const resultTypes = fieldVariable.getVariableTypes();
|
||||
chai.assert.deepEqual(resultTypes, ['type1', 'type2']);
|
||||
chai.assert.equal(
|
||||
assert.deepEqual(resultTypes, ['type1', 'type2']);
|
||||
assert.equal(
|
||||
fieldVariable.defaultType,
|
||||
'type1',
|
||||
'Default type was wrong',
|
||||
@@ -394,7 +389,7 @@ suite('Variable Fields', function () {
|
||||
|
||||
const resultTypes = fieldVariable.getVariableTypes();
|
||||
// The empty string is always one of the options.
|
||||
chai.assert.deepEqual(resultTypes, ['type1', 'type2', '']);
|
||||
assert.deepEqual(resultTypes, ['type1', 'type2', '']);
|
||||
});
|
||||
test('variableTypes is the empty list', function () {
|
||||
const fieldVariable = new Blockly.FieldVariable('name1');
|
||||
@@ -403,7 +398,7 @@ suite('Variable Fields', function () {
|
||||
fieldVariable.setSourceBlock(mockBlock);
|
||||
fieldVariable.variableTypes = [];
|
||||
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
fieldVariable.getVariableTypes();
|
||||
});
|
||||
});
|
||||
@@ -411,7 +406,7 @@ suite('Variable Fields', function () {
|
||||
suite('Default types', function () {
|
||||
test('Default type exists', function () {
|
||||
const fieldVariable = new Blockly.FieldVariable(null, null, ['b'], 'b');
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
fieldVariable.defaultType,
|
||||
'b',
|
||||
'The variable field\'s default type should be "b"',
|
||||
@@ -419,25 +414,25 @@ suite('Variable Fields', function () {
|
||||
});
|
||||
test('No default type', function () {
|
||||
const fieldVariable = new Blockly.FieldVariable(null);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
fieldVariable.defaultType,
|
||||
'',
|
||||
"The variable field's default type should be the empty string",
|
||||
);
|
||||
chai.assert.isNull(
|
||||
assert.isNull(
|
||||
fieldVariable.variableTypes,
|
||||
"The variable field's allowed types should be null",
|
||||
);
|
||||
});
|
||||
test('Default type mismatch', function () {
|
||||
// Invalid default type when creating a variable field.
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
new Blockly.FieldVariable(null, null, ['a'], 'b');
|
||||
});
|
||||
});
|
||||
test('Default type mismatch with empty array', function () {
|
||||
// Invalid default type when creating a variable field.
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
new Blockly.FieldVariable(null, null, ['a']);
|
||||
});
|
||||
});
|
||||
@@ -466,14 +461,14 @@ suite('Variable Fields', function () {
|
||||
});
|
||||
test('Rename & Keep Old ID', function () {
|
||||
this.workspace.renameVariableById('id1', 'name2');
|
||||
chai.assert.equal(this.variableField.getText(), 'name2');
|
||||
chai.assert.equal(this.variableField.getValue(), 'id1');
|
||||
assert.equal(this.variableField.getText(), 'name2');
|
||||
assert.equal(this.variableField.getValue(), 'id1');
|
||||
});
|
||||
test('Rename & Get New ID', function () {
|
||||
this.workspace.createVariable('name2', null, 'id2');
|
||||
this.workspace.renameVariableById('id1', 'name2');
|
||||
chai.assert.equal(this.variableField.getText(), 'name2');
|
||||
chai.assert.equal(this.variableField.getValue(), 'id2');
|
||||
assert.equal(this.variableField.getText(), 'name2');
|
||||
assert.equal(this.variableField.getValue(), 'id2');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -494,7 +489,7 @@ suite('Variable Fields', function () {
|
||||
const field = new Blockly.FieldVariable('x');
|
||||
block.getInput('INPUT').appendField(field, 'VAR');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields'], {
|
||||
assert.deepEqual(jso['fields'], {
|
||||
'VAR': {'id': 'id2', 'name': 'x', 'type': ''},
|
||||
});
|
||||
});
|
||||
@@ -509,7 +504,7 @@ suite('Variable Fields', function () {
|
||||
);
|
||||
block.getInput('INPUT').appendField(field, 'VAR');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields'], {
|
||||
assert.deepEqual(jso['fields'], {
|
||||
'VAR': {'id': 'id2', 'name': 'x', 'type': 'String'},
|
||||
});
|
||||
});
|
||||
@@ -523,9 +518,9 @@ suite('Variable Fields', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
doFullSerialization: false,
|
||||
});
|
||||
chai.assert.deepEqual(jso['fields'], {'VAR': {'id': 'id2'}});
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['name']);
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['type']);
|
||||
assert.deepEqual(jso['fields'], {'VAR': {'id': 'id2'}});
|
||||
assert.isUndefined(jso['fields']['VAR']['name']);
|
||||
assert.isUndefined(jso['fields']['VAR']['type']);
|
||||
});
|
||||
|
||||
test('Typed', function () {
|
||||
@@ -540,9 +535,9 @@ suite('Variable Fields', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
doFullSerialization: false,
|
||||
});
|
||||
chai.assert.deepEqual(jso['fields'], {'VAR': {'id': 'id2'}});
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['name']);
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['type']);
|
||||
assert.deepEqual(jso['fields'], {'VAR': {'id': 'id2'}});
|
||||
assert.isUndefined(jso['fields']['VAR']['name']);
|
||||
assert.isUndefined(jso['fields']['VAR']['type']);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -572,9 +567,9 @@ suite('Variable Fields', function () {
|
||||
this.workspace,
|
||||
);
|
||||
const variable = block.getField('VAR').getVariable();
|
||||
chai.assert.equal(variable.name, 'test');
|
||||
chai.assert.equal(variable.type, '');
|
||||
chai.assert.equal(variable.getId(), 'id1');
|
||||
assert.equal(variable.name, 'test');
|
||||
assert.equal(variable.type, '');
|
||||
assert.equal(variable.getId(), 'id1');
|
||||
});
|
||||
|
||||
test('Name, untyped', function () {
|
||||
@@ -590,9 +585,9 @@ suite('Variable Fields', function () {
|
||||
this.workspace,
|
||||
);
|
||||
const variable = block.getField('VAR').getVariable();
|
||||
chai.assert.equal(variable.name, 'test');
|
||||
chai.assert.equal(variable.type, '');
|
||||
chai.assert.equal(variable.getId(), 'id2');
|
||||
assert.equal(variable.name, 'test');
|
||||
assert.equal(variable.type, '');
|
||||
assert.equal(variable.getId(), 'id2');
|
||||
});
|
||||
|
||||
test('Name, typed', function () {
|
||||
@@ -609,9 +604,9 @@ suite('Variable Fields', function () {
|
||||
this.workspace,
|
||||
);
|
||||
const variable = block.getField('VAR').getVariable();
|
||||
chai.assert.equal(variable.name, 'test');
|
||||
chai.assert.equal(variable.type, 'string');
|
||||
chai.assert.equal(variable.getId(), 'id2');
|
||||
assert.equal(variable.name, 'test');
|
||||
assert.equal(variable.type, 'string');
|
||||
assert.equal(variable.getId(), 'id2');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -59,7 +60,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.getMetricsManager();
|
||||
});
|
||||
test('y is always 0', function () {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getY(),
|
||||
0,
|
||||
'y coordinate in vertical flyout should be 0',
|
||||
@@ -72,7 +73,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
Blockly.utils.toolbox.Position.RIGHT;
|
||||
this.flyout.toolboxPosition_ = Blockly.utils.toolbox.Position.RIGHT;
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getX(),
|
||||
100,
|
||||
'x should be right of workspace',
|
||||
@@ -82,7 +83,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
Blockly.utils.toolbox.Position.LEFT;
|
||||
this.flyout.toolboxPosition_ = Blockly.utils.toolbox.Position.LEFT;
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getX(),
|
||||
0,
|
||||
'x should be 0 if the flyout is on the left',
|
||||
@@ -110,7 +111,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
Blockly.utils.toolbox.Position.LEFT;
|
||||
this.flyout.toolboxPosition_ = Blockly.utils.toolbox.Position.LEFT;
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getX(),
|
||||
20,
|
||||
'x should be aligned with toolbox',
|
||||
@@ -128,7 +129,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
Blockly.utils.toolbox.Position.RIGHT;
|
||||
this.flyout.toolboxPosition_ = Blockly.utils.toolbox.Position.RIGHT;
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getX(),
|
||||
90,
|
||||
'x + width should be aligned with toolbox',
|
||||
@@ -150,7 +151,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
Blockly.utils.toolbox.Position.RIGHT;
|
||||
this.flyout.toolboxPosition_ = Blockly.utils.toolbox.Position.LEFT;
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getX(),
|
||||
0,
|
||||
'x should be aligned with left edge',
|
||||
@@ -169,7 +170,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
Blockly.utils.toolbox.Position.LEFT;
|
||||
this.flyout.toolboxPosition_ = Blockly.utils.toolbox.Position.RIGHT;
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getX(),
|
||||
90,
|
||||
'x + width should be aligned with right edge',
|
||||
@@ -195,7 +196,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.getMetricsManager();
|
||||
});
|
||||
test('x is always 0', function () {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getX(),
|
||||
0,
|
||||
'x coordinate in horizontal flyout should be 0',
|
||||
@@ -205,7 +206,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
Blockly.utils.toolbox.Position.TOP;
|
||||
this.flyout.toolboxPosition_ = Blockly.utils.toolbox.Position.TOP;
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getY(),
|
||||
0,
|
||||
'y should be 0 if flyout is at the top',
|
||||
@@ -218,7 +219,7 @@ suite('Flyout', function () {
|
||||
sinon.stub(this.targetMetricsManager, 'getViewMetrics').returns({
|
||||
height: 50,
|
||||
});
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getY(),
|
||||
50,
|
||||
'y should be below the workspace',
|
||||
@@ -247,7 +248,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
Blockly.utils.toolbox.Position.TOP;
|
||||
this.flyout.toolboxPosition_ = Blockly.utils.toolbox.Position.TOP;
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getY(),
|
||||
20,
|
||||
'y should be aligned with toolbox',
|
||||
@@ -265,7 +266,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
Blockly.utils.toolbox.Position.BOTTOM;
|
||||
this.flyout.toolboxPosition_ = Blockly.utils.toolbox.Position.BOTTOM;
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getY(),
|
||||
70,
|
||||
'y + height should be aligned with toolbox',
|
||||
@@ -284,11 +285,7 @@ suite('Flyout', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
Blockly.utils.toolbox.Position.BOTTOM;
|
||||
this.flyout.toolboxPosition_ = Blockly.utils.toolbox.Position.TOP;
|
||||
chai.assert.equal(
|
||||
this.flyout.getY(),
|
||||
0,
|
||||
'y should be aligned with top',
|
||||
);
|
||||
assert.equal(this.flyout.getY(), 0, 'y should be aligned with top');
|
||||
});
|
||||
test('trashcan on bottom covers bottom of workspace', function () {
|
||||
this.flyout.targetWorkspace.toolboxPosition =
|
||||
@@ -302,7 +299,7 @@ suite('Flyout', function () {
|
||||
});
|
||||
this.flyout.setVisible(true);
|
||||
this.flyout.height_ = 20;
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.flyout.getY(),
|
||||
40,
|
||||
'y + height should be aligned with bottom',
|
||||
@@ -324,26 +321,26 @@ suite('Flyout', function () {
|
||||
const gaps = flyoutInfo.gaps;
|
||||
|
||||
const expectedGaps = [20, 24, 24];
|
||||
chai.assert.deepEqual(gaps, expectedGaps);
|
||||
assert.deepEqual(gaps, expectedGaps);
|
||||
|
||||
chai.assert.equal(contents.length, 3, 'Contents');
|
||||
assert.equal(contents.length, 3, 'Contents');
|
||||
|
||||
chai.assert.equal(contents[0].type, 'block', 'Contents');
|
||||
assert.equal(contents[0].type, 'block', 'Contents');
|
||||
const block = contents[0]['block'];
|
||||
chai.assert.instanceOf(block, Blockly.BlockSvg);
|
||||
chai.assert.equal(block.getFieldValue('OP'), 'NEQ');
|
||||
assert.instanceOf(block, Blockly.BlockSvg);
|
||||
assert.equal(block.getFieldValue('OP'), 'NEQ');
|
||||
const childA = block.getInputTargetBlock('A');
|
||||
const childB = block.getInputTargetBlock('B');
|
||||
chai.assert.isTrue(childA.isShadow());
|
||||
chai.assert.isFalse(childB.isShadow());
|
||||
chai.assert.equal(childA.getFieldValue('NUM'), 1);
|
||||
chai.assert.equal(childB.getFieldValue('NUM'), 2);
|
||||
assert.isTrue(childA.isShadow());
|
||||
assert.isFalse(childB.isShadow());
|
||||
assert.equal(childA.getFieldValue('NUM'), 1);
|
||||
assert.equal(childB.getFieldValue('NUM'), 2);
|
||||
|
||||
chai.assert.equal(contents[1].type, 'button', 'Contents');
|
||||
chai.assert.instanceOf(contents[1]['button'], Blockly.FlyoutButton);
|
||||
assert.equal(contents[1].type, 'button', 'Contents');
|
||||
assert.instanceOf(contents[1]['button'], Blockly.FlyoutButton);
|
||||
|
||||
chai.assert.equal(contents[2].type, 'button', 'Contents');
|
||||
chai.assert.instanceOf(contents[2]['button'], Blockly.FlyoutButton);
|
||||
assert.equal(contents[2].type, 'button', 'Contents');
|
||||
assert.instanceOf(contents[2]['button'], Blockly.FlyoutButton);
|
||||
}
|
||||
|
||||
suite('Direct show', function () {
|
||||
@@ -391,7 +388,7 @@ suite('Flyout', function () {
|
||||
});
|
||||
|
||||
test('No category available', function () {
|
||||
chai.assert.throws(
|
||||
assert.throws(
|
||||
function () {
|
||||
this.flyout.show('someString');
|
||||
}.bind(this),
|
||||
@@ -431,7 +428,7 @@ suite('Flyout', function () {
|
||||
|
||||
this.assertDisabled = function (disabled) {
|
||||
const block = this.flyout.getWorkspace().getTopBlocks(false)[0];
|
||||
chai.assert.equal(!block.isEnabled(), disabled);
|
||||
assert.equal(!block.isEnabled(), disabled);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -630,7 +627,7 @@ suite('Flyout', function () {
|
||||
],
|
||||
});
|
||||
const block = this.flyout.workspace_.getAllBlocks()[0];
|
||||
chai.assert.equal(block.getFieldValue('NUM'), 321);
|
||||
assert.equal(block.getFieldValue('NUM'), 321);
|
||||
});
|
||||
|
||||
test('Recycling enabled', function () {
|
||||
@@ -660,7 +657,7 @@ suite('Flyout', function () {
|
||||
],
|
||||
});
|
||||
const block = this.flyout.workspace_.getAllBlocks()[0];
|
||||
chai.assert.equal(block.getFieldValue('NUM'), 123);
|
||||
assert.equal(block.getFieldValue('NUM'), 123);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {DartGenerator} from '../../build/src/generators/dart/dart_generator.js';
|
||||
import {JavascriptGenerator} from '../../build/src/generators/javascript/javascript_generator.js';
|
||||
@@ -31,22 +32,19 @@ suite('Generator', function () {
|
||||
});
|
||||
|
||||
test('Nothing', function () {
|
||||
chai.assert.equal(this.generator.prefixLines('', ''), '');
|
||||
assert.equal(this.generator.prefixLines('', ''), '');
|
||||
});
|
||||
|
||||
test('One word', function () {
|
||||
chai.assert.equal(this.generator.prefixLines('Hello', '@'), '@Hello');
|
||||
assert.equal(this.generator.prefixLines('Hello', '@'), '@Hello');
|
||||
});
|
||||
|
||||
test('One line', function () {
|
||||
chai.assert.equal(
|
||||
this.generator.prefixLines('Hello\n', '12'),
|
||||
'12Hello\n',
|
||||
);
|
||||
assert.equal(this.generator.prefixLines('Hello\n', '12'), '12Hello\n');
|
||||
});
|
||||
|
||||
test('Two lines', function () {
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.generator.prefixLines('Hello\nWorld\n', '***'),
|
||||
'***Hello\n***World\n',
|
||||
);
|
||||
@@ -97,7 +95,7 @@ suite('Generator', function () {
|
||||
const code = generator.blockToCode(rowBlock, opt_thisOnly);
|
||||
delete generator.forBlock['stack_block'];
|
||||
delete generator.forBlock['row_block'];
|
||||
chai.assert.equal(code, expectedCode, opt_message);
|
||||
assert.equal(code, expectedCode, opt_message);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -187,7 +185,7 @@ suite('Generator', function () {
|
||||
blockA.nextConnection.connect(blockC.previousConnection);
|
||||
|
||||
const code = generator.blockToCode(blockA, opt_thisOnly);
|
||||
chai.assert.equal(code, expectedCode, opt_message);
|
||||
assert.equal(code, expectedCode, opt_message);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -214,7 +212,7 @@ suite('Generator', function () {
|
||||
this.generator = new TestGenerator();
|
||||
});
|
||||
test('No nameDB_ initialized', function () {
|
||||
chai.assert.throws(() => {
|
||||
assert.throws(() => {
|
||||
this.generator.getVariableName('foo');
|
||||
});
|
||||
});
|
||||
@@ -222,13 +220,13 @@ suite('Generator', function () {
|
||||
test('Get variable name', function () {
|
||||
this.generator.init();
|
||||
|
||||
chai.assert.equal(this.generator.getVariableName('foo'), 'foo');
|
||||
assert.equal(this.generator.getVariableName('foo'), 'foo');
|
||||
});
|
||||
|
||||
test('Get procedure name', function () {
|
||||
this.generator.init();
|
||||
|
||||
chai.assert.equal(this.generator.getProcedureName('foo'), 'foo');
|
||||
assert.equal(this.generator.getProcedureName('foo'), 'foo');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {assertEventFired, assertEventNotFired} from './test_helpers/events.js';
|
||||
import {defineBasicBlockWithField} from './test_helpers/block_definitions.js';
|
||||
import {dispatchPointerEvent} from './test_helpers/user_input.js';
|
||||
@@ -17,10 +18,7 @@ suite('Gesture', function () {
|
||||
function testGestureIsFieldClick(block, isFieldClick, eventsFireStub) {
|
||||
const field = block.getField('NAME');
|
||||
const eventTarget = field.getClickTarget_();
|
||||
chai.assert.exists(
|
||||
eventTarget,
|
||||
'Precondition: missing click target for field',
|
||||
);
|
||||
assert.exists(eventTarget, 'Precondition: missing click target for field');
|
||||
|
||||
eventsFireStub.resetHistory();
|
||||
dispatchPointerEvent(eventTarget, 'pointerdown');
|
||||
@@ -29,14 +27,14 @@ suite('Gesture', function () {
|
||||
// Gestures triggered on flyouts are stored on targetWorkspace.
|
||||
const gestureWorkspace = fieldWorkspace.targetWorkspace || fieldWorkspace;
|
||||
const gesture = gestureWorkspace.currentGesture_;
|
||||
chai.assert.exists(gesture, 'Gesture exists after pointerdown.');
|
||||
assert.exists(gesture, 'Gesture exists after pointerdown.');
|
||||
const isFieldClickSpy = sinon.spy(gesture, 'isFieldClick');
|
||||
|
||||
dispatchPointerEvent(eventTarget, 'pointerup');
|
||||
dispatchPointerEvent(eventTarget, 'click');
|
||||
|
||||
sinon.assert.called(isFieldClickSpy);
|
||||
chai.assert.isTrue(isFieldClickSpy.alwaysReturned(isFieldClick));
|
||||
assert.isTrue(isFieldClickSpy.alwaysReturned(isFieldClick));
|
||||
|
||||
assertEventFired(
|
||||
eventsFireStub,
|
||||
@@ -67,8 +65,8 @@ suite('Gesture', function () {
|
||||
test('Constructor', function () {
|
||||
const e = {id: 'dummy_test_event'};
|
||||
const gesture = new Blockly.Gesture(e, this.workspace);
|
||||
chai.assert.equal(gesture.mostRecentEvent, e);
|
||||
chai.assert.equal(gesture.creatorWorkspace, this.workspace);
|
||||
assert.equal(gesture.mostRecentEvent, e);
|
||||
assert.equal(gesture.creatorWorkspace, this.workspace);
|
||||
});
|
||||
|
||||
test('Field click - Click in workspace', function () {
|
||||
@@ -81,7 +79,7 @@ suite('Gesture', function () {
|
||||
|
||||
test('Field click - Auto close flyout', function () {
|
||||
const flyout = this.workspace.getFlyout(true);
|
||||
chai.assert.exists(flyout, 'Precondition: missing flyout');
|
||||
assert.exists(flyout, 'Precondition: missing flyout');
|
||||
flyout.autoClose = true;
|
||||
|
||||
const block = getTopFlyoutBlock(flyout);
|
||||
@@ -90,7 +88,7 @@ suite('Gesture', function () {
|
||||
|
||||
test('Field click - Always open flyout', function () {
|
||||
const flyout = this.workspace.getFlyout(true);
|
||||
chai.assert.exists(flyout, 'Precondition: missing flyout');
|
||||
assert.exists(flyout, 'Precondition: missing flyout');
|
||||
flyout.autoClose = false;
|
||||
|
||||
const block = getTopFlyoutBlock(flyout);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -62,7 +63,7 @@ suite('Icon', function () {
|
||||
|
||||
block.addIcon(icon);
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
initViewSpy.called,
|
||||
'Expected initView to not be called',
|
||||
);
|
||||
@@ -79,7 +80,7 @@ suite('Icon', function () {
|
||||
const initViewSpy = sinon.spy(icon, 'initView');
|
||||
|
||||
block.addIcon(icon);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
initViewSpy.calledOnce,
|
||||
'Expected initView to be called',
|
||||
);
|
||||
@@ -96,7 +97,7 @@ suite('Icon', function () {
|
||||
|
||||
block.addIcon(icon);
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
applyColourSpy.called,
|
||||
'Expected applyColour to not be called',
|
||||
);
|
||||
@@ -112,7 +113,7 @@ suite('Icon', function () {
|
||||
const applyColourSpy = sinon.spy(icon, 'applyColour');
|
||||
|
||||
block.addIcon(icon);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
applyColourSpy.calledOnce,
|
||||
'Expected applyColour to be called',
|
||||
);
|
||||
@@ -128,7 +129,7 @@ suite('Icon', function () {
|
||||
block.addIcon(icon);
|
||||
applyColourSpy.resetHistory();
|
||||
block.setColour('#cccccc');
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
applyColourSpy.calledOnce,
|
||||
'Expected applyColour to be called',
|
||||
);
|
||||
@@ -143,7 +144,7 @@ suite('Icon', function () {
|
||||
block.addIcon(icon);
|
||||
applyColourSpy.resetHistory();
|
||||
block.setStyle('logic_block');
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
applyColourSpy.calledOnce,
|
||||
'Expected applyColour to be called',
|
||||
);
|
||||
@@ -158,7 +159,7 @@ suite('Icon', function () {
|
||||
block.addIcon(icon);
|
||||
applyColourSpy.resetHistory();
|
||||
block.setDisabledReason(true, 'test reason');
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
applyColourSpy.calledOnce,
|
||||
'Expected applyColour to be called',
|
||||
);
|
||||
@@ -173,7 +174,7 @@ suite('Icon', function () {
|
||||
block.addIcon(icon);
|
||||
applyColourSpy.resetHistory();
|
||||
block.setShadow(true);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
applyColourSpy.calledOnce,
|
||||
'Expected applyColour to be called',
|
||||
);
|
||||
@@ -189,7 +190,7 @@ suite('Icon', function () {
|
||||
|
||||
block.addIcon(icon);
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
updateEditableSpy.called,
|
||||
'Expected updateEditable to not be called',
|
||||
);
|
||||
@@ -205,7 +206,7 @@ suite('Icon', function () {
|
||||
const updateEditableSpy = sinon.spy(icon, 'updateEditable');
|
||||
|
||||
block.addIcon(icon);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
updateEditableSpy.calledOnce,
|
||||
'Expected updateEditable to be called',
|
||||
);
|
||||
@@ -221,7 +222,7 @@ suite('Icon', function () {
|
||||
block.addIcon(icon);
|
||||
updateEditableSpy.resetHistory();
|
||||
block.setEditable(false);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
updateEditableSpy.calledOnce,
|
||||
'Expected updateEditable to be called',
|
||||
);
|
||||
@@ -237,7 +238,7 @@ suite('Icon', function () {
|
||||
block.setEditable(false);
|
||||
updateEditableSpy.resetHistory();
|
||||
block.setEditable(true);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
updateEditableSpy.calledOnce,
|
||||
'Expected updateEditable to be called',
|
||||
);
|
||||
@@ -255,7 +256,7 @@ suite('Icon', function () {
|
||||
block.setCollapsed(true);
|
||||
block.setCollapsed(false);
|
||||
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
updateCollapsedSpy.called,
|
||||
'Expected updateCollapsed to not be called',
|
||||
);
|
||||
@@ -272,7 +273,7 @@ suite('Icon', function () {
|
||||
block.setCollapsed(true);
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
updateCollapsedSpy.called,
|
||||
'Expected updateCollapsed to be called',
|
||||
);
|
||||
@@ -289,7 +290,7 @@ suite('Icon', function () {
|
||||
block.setCollapsed(false);
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
updateCollapsedSpy.called,
|
||||
'Expected updateCollapsed to be called',
|
||||
);
|
||||
@@ -302,7 +303,7 @@ suite('Icon', function () {
|
||||
const block = createHeadlessBlock(createHeadlessWorkspace());
|
||||
block.addIcon(new MockSerializableIcon());
|
||||
const json = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepNestedInclude(
|
||||
assert.deepNestedInclude(
|
||||
json,
|
||||
{'icons': {'serializable icon': 'some state'}},
|
||||
'Expected the JSON to include the saved state of the ' +
|
||||
@@ -314,7 +315,7 @@ suite('Icon', function () {
|
||||
const block = createHeadlessBlock(createHeadlessWorkspace());
|
||||
block.addIcon(new MockNonSerializableIcon());
|
||||
const json = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.notProperty(
|
||||
assert.notProperty(
|
||||
json,
|
||||
'icons',
|
||||
'Expected the JSON to not include any saved state for icons',
|
||||
@@ -337,7 +338,7 @@ suite('Icon', function () {
|
||||
},
|
||||
};
|
||||
const block = Blockly.serialization.blocks.append(json, workspace);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
block.getIcon('serializable icon').state,
|
||||
'some state',
|
||||
'Expected the icon to have been properly instantiated and ' +
|
||||
@@ -355,7 +356,7 @@ suite('Icon', function () {
|
||||
'serializable icon': 'some state',
|
||||
},
|
||||
};
|
||||
chai.assert.throws(
|
||||
assert.throws(
|
||||
() => {
|
||||
Blockly.serialization.blocks.append(json, workspace);
|
||||
},
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
<!-- Load mocha et al. before Blockly and the test modules so that
|
||||
we can safely import the test modules that make calls
|
||||
to (e.g.) suite() at the top level. -->
|
||||
<script src="../../node_modules/chai/chai.js"></script>
|
||||
<script src="../../node_modules/mocha/mocha.js"></script>
|
||||
<script src="../../node_modules/sinon/pkg/sinon.js"></script>
|
||||
<script>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -41,13 +42,13 @@ suite('Inputs', function () {
|
||||
suite('Index Bounds', function () {
|
||||
test('< 0', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
this.dummy.insertFieldAt(-1, field);
|
||||
});
|
||||
});
|
||||
test('> length', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
this.dummy.insertFieldAt(1, field);
|
||||
});
|
||||
});
|
||||
@@ -57,37 +58,37 @@ suite('Inputs', function () {
|
||||
test('Field', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
this.dummy.insertFieldAt(0, field);
|
||||
chai.assert.equal(this.dummy.fieldRow[0], field);
|
||||
assert.equal(this.dummy.fieldRow[0], field);
|
||||
});
|
||||
test('String', function () {
|
||||
this.dummy.insertFieldAt(0, 'field');
|
||||
chai.assert.instanceOf(this.dummy.fieldRow[0], Blockly.FieldLabel);
|
||||
assert.instanceOf(this.dummy.fieldRow[0], Blockly.FieldLabel);
|
||||
});
|
||||
test('String w/ field_label overwritten', function () {
|
||||
Blockly.fieldRegistry.unregister('field_label');
|
||||
Blockly.fieldRegistry.register('field_label', Blockly.FieldNumber);
|
||||
|
||||
this.dummy.insertFieldAt(0, '1');
|
||||
chai.assert.instanceOf(this.dummy.fieldRow[0], Blockly.FieldNumber);
|
||||
assert.instanceOf(this.dummy.fieldRow[0], Blockly.FieldNumber);
|
||||
|
||||
Blockly.fieldRegistry.unregister('field_label');
|
||||
Blockly.fieldRegistry.register('field_label', Blockly.FieldLabel);
|
||||
});
|
||||
test('Empty String', function () {
|
||||
this.dummy.insertFieldAt(0, '');
|
||||
chai.assert.isEmpty(this.dummy.fieldRow);
|
||||
assert.isEmpty(this.dummy.fieldRow);
|
||||
});
|
||||
test('Empty String W/ Name', function () {
|
||||
this.dummy.insertFieldAt(0, '', 'NAME');
|
||||
chai.assert.instanceOf(this.dummy.fieldRow[0], Blockly.FieldLabel);
|
||||
assert.instanceOf(this.dummy.fieldRow[0], Blockly.FieldLabel);
|
||||
});
|
||||
test('Null', function () {
|
||||
this.dummy.insertFieldAt(0, null);
|
||||
chai.assert.isEmpty(this.dummy.fieldRow);
|
||||
assert.isEmpty(this.dummy.fieldRow);
|
||||
});
|
||||
test('Undefined', function () {
|
||||
this.dummy.insertFieldAt(0, undefined);
|
||||
chai.assert.isEmpty(this.dummy.fieldRow);
|
||||
assert.isEmpty(this.dummy.fieldRow);
|
||||
});
|
||||
});
|
||||
suite('Prefixes and Suffixes', function () {
|
||||
@@ -97,7 +98,7 @@ suite('Inputs', function () {
|
||||
field.prefixField = prefix;
|
||||
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [prefix, field]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [prefix, field]);
|
||||
});
|
||||
test('Suffix', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
@@ -105,7 +106,7 @@ suite('Inputs', function () {
|
||||
field.suffixField = suffix;
|
||||
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [field, suffix]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [field, suffix]);
|
||||
});
|
||||
test('Prefix and Suffix', function () {
|
||||
const field = new Blockly.FieldLabel('field');
|
||||
@@ -115,7 +116,7 @@ suite('Inputs', function () {
|
||||
field.suffixField = suffix;
|
||||
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [prefix, field, suffix]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [prefix, field, suffix]);
|
||||
});
|
||||
test('Dropdown - Prefix', function () {
|
||||
const field = new Blockly.FieldDropdown([
|
||||
@@ -124,7 +125,7 @@ suite('Inputs', function () {
|
||||
]);
|
||||
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.equal(this.dummy.fieldRow.length, 2);
|
||||
assert.equal(this.dummy.fieldRow.length, 2);
|
||||
});
|
||||
test('Dropdown - Suffix', function () {
|
||||
const field = new Blockly.FieldDropdown([
|
||||
@@ -133,7 +134,7 @@ suite('Inputs', function () {
|
||||
]);
|
||||
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.equal(this.dummy.fieldRow.length, 2);
|
||||
assert.equal(this.dummy.fieldRow.length, 2);
|
||||
});
|
||||
test('Dropdown - Prefix and Suffix', function () {
|
||||
const field = new Blockly.FieldDropdown([
|
||||
@@ -142,7 +143,7 @@ suite('Inputs', function () {
|
||||
]);
|
||||
|
||||
this.dummy.appendField(field);
|
||||
chai.assert.equal(this.dummy.fieldRow.length, 3);
|
||||
assert.equal(this.dummy.fieldRow.length, 3);
|
||||
});
|
||||
});
|
||||
suite('Field Initialization', function () {
|
||||
@@ -153,7 +154,7 @@ suite('Inputs', function () {
|
||||
|
||||
this.dummy.insertFieldAt(0, field);
|
||||
sinon.assert.calledOnce(setBlockSpy);
|
||||
chai.assert.equal(setBlockSpy.getCall(0).args[0], this.block);
|
||||
assert.equal(setBlockSpy.getCall(0).args[0], this.block);
|
||||
sinon.assert.calledOnce(initSpy);
|
||||
sinon.assert.calledOnce(this.renderStub);
|
||||
|
||||
@@ -171,7 +172,7 @@ suite('Inputs', function () {
|
||||
|
||||
this.dummy.insertFieldAt(0, field);
|
||||
sinon.assert.calledOnce(setBlockSpy);
|
||||
chai.assert.equal(setBlockSpy.getCall(0).args[0], this.block);
|
||||
assert.equal(setBlockSpy.getCall(0).args[0], this.block);
|
||||
sinon.assert.calledOnce(initModelSpy);
|
||||
sinon.assert.notCalled(this.renderStub);
|
||||
|
||||
@@ -182,7 +183,7 @@ suite('Inputs', function () {
|
||||
});
|
||||
suite('Remove Field', function () {
|
||||
test('Field Not Found', function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
this.dummy.removeField('FIELD');
|
||||
});
|
||||
});
|
||||
@@ -222,28 +223,28 @@ suite('Inputs', function () {
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
});
|
||||
test('Append B, C; Insert A at Start', function () {
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
this.dummy.insertFieldAt(0, this.a, 'A');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
});
|
||||
test('Append A, C; Insert B Between', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
this.dummy.insertFieldAt(1, this.b, 'B');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
});
|
||||
test('Append A, B; Insert C at End', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
this.dummy.appendField(this.b, 'B');
|
||||
this.dummy.insertFieldAt(2, this.c, 'C');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [this.a, this.b, this.c]);
|
||||
});
|
||||
test('Append A, B, C; Remove A, B, C', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
@@ -254,7 +255,7 @@ suite('Inputs', function () {
|
||||
this.dummy.removeField('B');
|
||||
this.dummy.removeField('C');
|
||||
|
||||
chai.assert.isEmpty(this.dummy.fieldRow);
|
||||
assert.isEmpty(this.dummy.fieldRow);
|
||||
});
|
||||
test('Append A, B, C; Remove A', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
@@ -263,7 +264,7 @@ suite('Inputs', function () {
|
||||
|
||||
this.dummy.removeField('A');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.b, this.c]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [this.b, this.c]);
|
||||
});
|
||||
test('Append A, B, C; Remove B', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
@@ -272,7 +273,7 @@ suite('Inputs', function () {
|
||||
|
||||
this.dummy.removeField('B');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.c]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [this.a, this.c]);
|
||||
});
|
||||
test('Append A, B, C; Remove C', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
@@ -281,7 +282,7 @@ suite('Inputs', function () {
|
||||
|
||||
this.dummy.removeField('C');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.a, this.b]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [this.a, this.b]);
|
||||
});
|
||||
test('Append A, B; Remove A; Append C', function () {
|
||||
this.dummy.appendField(this.a, 'A');
|
||||
@@ -289,7 +290,7 @@ suite('Inputs', function () {
|
||||
this.dummy.removeField('A');
|
||||
this.dummy.appendField(this.c, 'C');
|
||||
|
||||
chai.assert.deepEqual(this.dummy.fieldRow, [this.b, this.c]);
|
||||
assert.deepEqual(this.dummy.fieldRow, [this.b, this.c]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -47,7 +48,7 @@ suite('Insertion marker manager', function () {
|
||||
};
|
||||
const manager = createBlocksAndManager(this.workspace, state);
|
||||
const markers = manager.getInsertionMarkers();
|
||||
chai.assert.equal(markers.length, 1);
|
||||
assert.equal(markers.length, 1);
|
||||
});
|
||||
|
||||
test('Two stack blocks create two markers', function () {
|
||||
@@ -69,7 +70,7 @@ suite('Insertion marker manager', function () {
|
||||
};
|
||||
const manager = createBlocksAndManager(this.workspace, state);
|
||||
const markers = manager.getInsertionMarkers();
|
||||
chai.assert.equal(markers.length, 2);
|
||||
assert.equal(markers.length, 2);
|
||||
});
|
||||
|
||||
test('Three stack blocks create two markers', function () {
|
||||
@@ -97,7 +98,7 @@ suite('Insertion marker manager', function () {
|
||||
};
|
||||
const manager = createBlocksAndManager(this.workspace, state);
|
||||
const markers = manager.getInsertionMarkers();
|
||||
chai.assert.equal(markers.length, 2);
|
||||
assert.equal(markers.length, 2);
|
||||
});
|
||||
|
||||
test('One value block creates one marker', function () {
|
||||
@@ -113,7 +114,7 @@ suite('Insertion marker manager', function () {
|
||||
};
|
||||
const manager = createBlocksAndManager(this.workspace, state);
|
||||
const markers = manager.getInsertionMarkers();
|
||||
chai.assert.equal(markers.length, 1);
|
||||
assert.equal(markers.length, 1);
|
||||
});
|
||||
|
||||
test('Two value blocks create one marker', function () {
|
||||
@@ -137,7 +138,7 @@ suite('Insertion marker manager', function () {
|
||||
};
|
||||
const manager = createBlocksAndManager(this.workspace, state);
|
||||
const markers = manager.getInsertionMarkers();
|
||||
chai.assert.equal(markers.length, 1);
|
||||
assert.equal(markers.length, 1);
|
||||
});
|
||||
|
||||
test('One row to stack block creates one marker', function () {
|
||||
@@ -153,7 +154,7 @@ suite('Insertion marker manager', function () {
|
||||
};
|
||||
const manager = createBlocksAndManager(this.workspace, state);
|
||||
const markers = manager.getInsertionMarkers();
|
||||
chai.assert.equal(markers.length, 1);
|
||||
assert.equal(markers.length, 1);
|
||||
});
|
||||
|
||||
test('Row to stack block with child creates two markers', function () {
|
||||
@@ -175,7 +176,7 @@ suite('Insertion marker manager', function () {
|
||||
};
|
||||
const manager = createBlocksAndManager(this.workspace, state);
|
||||
const markers = manager.getInsertionMarkers();
|
||||
chai.assert.equal(markers.length, 2);
|
||||
assert.equal(markers.length, 2);
|
||||
});
|
||||
|
||||
suite('children being set as insertion markers', function () {
|
||||
@@ -225,7 +226,7 @@ suite('Insertion marker manager', function () {
|
||||
};
|
||||
const manager = createBlocksAndManager(this.workspace, state);
|
||||
const markers = manager.getInsertionMarkers();
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
markers[0].getChildren()[0].isInsertionMarker(),
|
||||
'Expected the shadow block to be an insertion maker',
|
||||
);
|
||||
@@ -244,7 +245,7 @@ suite('Insertion marker manager', function () {
|
||||
};
|
||||
const manager = createBlocksAndManager(this.workspace, state);
|
||||
const markers = manager.getInsertionMarkers();
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
markers[0].getChildren()[0].isInsertionMarker(),
|
||||
'Expected the shadow block to be an insertion maker',
|
||||
);
|
||||
@@ -285,7 +286,7 @@ suite('Insertion marker manager', function () {
|
||||
id: 'fakeDragTarget',
|
||||
};
|
||||
this.manager.update(this.dxy, fakeDragTarget);
|
||||
chai.assert.isTrue(this.manager.wouldDeleteBlock);
|
||||
assert.isTrue(this.manager.wouldDeleteBlock);
|
||||
});
|
||||
|
||||
test('Over delete area and rejected would not delete', function () {
|
||||
@@ -300,7 +301,7 @@ suite('Insertion marker manager', function () {
|
||||
id: 'fakeDragTarget',
|
||||
};
|
||||
this.manager.update(this.dxy, fakeDragTarget);
|
||||
chai.assert.isFalse(this.manager.wouldDeleteBlock);
|
||||
assert.isFalse(this.manager.wouldDeleteBlock);
|
||||
});
|
||||
|
||||
test('Drag target is not a delete area would not delete', function () {
|
||||
@@ -315,12 +316,12 @@ suite('Insertion marker manager', function () {
|
||||
id: 'fakeDragTarget',
|
||||
};
|
||||
this.manager.update(this.dxy, fakeDragTarget);
|
||||
chai.assert.isFalse(this.manager.wouldDeleteBlock);
|
||||
assert.isFalse(this.manager.wouldDeleteBlock);
|
||||
});
|
||||
|
||||
test('Not over drag target would not delete', function () {
|
||||
this.manager.update(this.dxy, null);
|
||||
chai.assert.isFalse(this.manager.wouldDeleteBlock);
|
||||
assert.isFalse(this.manager.wouldDeleteBlock);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -352,35 +353,35 @@ suite('Insertion marker manager', function () {
|
||||
|
||||
test('No other blocks nearby would not connect', function () {
|
||||
this.manager.update(new Blockly.utils.Coordinate(0, 0), null);
|
||||
chai.assert.isFalse(this.manager.wouldConnectBlock());
|
||||
assert.isFalse(this.manager.wouldConnectBlock());
|
||||
});
|
||||
|
||||
test('Near other block and above would connect before', function () {
|
||||
this.manager.update(new Blockly.utils.Coordinate(200, 190), null);
|
||||
chai.assert.isTrue(this.manager.wouldConnectBlock());
|
||||
assert.isTrue(this.manager.wouldConnectBlock());
|
||||
const markers = this.manager.getInsertionMarkers();
|
||||
chai.assert.equal(markers.length, 1);
|
||||
assert.equal(markers.length, 1);
|
||||
const marker = markers[0];
|
||||
chai.assert.isTrue(marker.nextConnection.isConnected());
|
||||
assert.isTrue(marker.nextConnection.isConnected());
|
||||
});
|
||||
|
||||
test('Near other block and below would connect after', function () {
|
||||
this.manager.update(new Blockly.utils.Coordinate(200, 210), null);
|
||||
chai.assert.isTrue(this.manager.wouldConnectBlock());
|
||||
assert.isTrue(this.manager.wouldConnectBlock());
|
||||
const markers = this.manager.getInsertionMarkers();
|
||||
chai.assert.equal(markers.length, 1);
|
||||
assert.equal(markers.length, 1);
|
||||
const marker = markers[0];
|
||||
chai.assert.isTrue(marker.previousConnection.isConnected());
|
||||
assert.isTrue(marker.previousConnection.isConnected());
|
||||
});
|
||||
|
||||
test('Near other block and left would connect', function () {
|
||||
this.manager.update(new Blockly.utils.Coordinate(190, 200), null);
|
||||
chai.assert.isTrue(this.manager.wouldConnectBlock());
|
||||
assert.isTrue(this.manager.wouldConnectBlock());
|
||||
});
|
||||
|
||||
test('Near other block and right would connect', function () {
|
||||
this.manager.update(new Blockly.utils.Coordinate(210, 200), null);
|
||||
chai.assert.isTrue(this.manager.wouldConnectBlock());
|
||||
assert.isTrue(this.manager.wouldConnectBlock());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -412,31 +413,31 @@ suite('Insertion marker manager', function () {
|
||||
|
||||
test('No other blocks nearby would not connect', function () {
|
||||
this.manager.update(new Blockly.utils.Coordinate(0, 0), null);
|
||||
chai.assert.isFalse(this.manager.wouldConnectBlock());
|
||||
assert.isFalse(this.manager.wouldConnectBlock());
|
||||
});
|
||||
|
||||
test('Near other block and above would connect', function () {
|
||||
this.manager.update(new Blockly.utils.Coordinate(200, 190), null);
|
||||
chai.assert.isTrue(this.manager.wouldConnectBlock());
|
||||
assert.isTrue(this.manager.wouldConnectBlock());
|
||||
});
|
||||
|
||||
test('Near other block and below would connect', function () {
|
||||
this.manager.update(new Blockly.utils.Coordinate(200, 210), null);
|
||||
chai.assert.isTrue(this.manager.wouldConnectBlock());
|
||||
assert.isTrue(this.manager.wouldConnectBlock());
|
||||
});
|
||||
|
||||
test('Near other block and left would connect before', function () {
|
||||
this.manager.update(new Blockly.utils.Coordinate(190, 200), null);
|
||||
chai.assert.isTrue(this.manager.wouldConnectBlock());
|
||||
assert.isTrue(this.manager.wouldConnectBlock());
|
||||
const markers = this.manager.getInsertionMarkers();
|
||||
chai.assert.isTrue(markers[0].getInput('INPUT').connection.isConnected());
|
||||
assert.isTrue(markers[0].getInput('INPUT').connection.isConnected());
|
||||
});
|
||||
|
||||
test('Near other block and right would connect after', function () {
|
||||
this.manager.update(new Blockly.utils.Coordinate(210, 200), null);
|
||||
chai.assert.isTrue(this.manager.wouldConnectBlock());
|
||||
assert.isTrue(this.manager.wouldConnectBlock());
|
||||
const markers = this.manager.getInsertionMarkers();
|
||||
chai.assert.isTrue(markers[0].outputConnection.isConnected());
|
||||
assert.isTrue(markers[0].outputConnection.isConnected());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -77,7 +78,7 @@ suite('InsertionMarkers', function () {
|
||||
const block = this.workspace.getBlockById('insertion');
|
||||
block.isInsertionMarker_ = true;
|
||||
const code = javascriptGenerator.workspaceToCode(this.workspace);
|
||||
chai.assert.equal(code, expectedCode);
|
||||
assert.equal(code, expectedCode);
|
||||
};
|
||||
});
|
||||
teardown(function () {
|
||||
@@ -227,7 +228,7 @@ suite('InsertionMarkers', function () {
|
||||
let xml = Blockly.Xml.workspaceToDom(this.workspace);
|
||||
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
||||
xml = Blockly.Xml.domToText(xml);
|
||||
chai.assert.equal(xml, expectXml);
|
||||
assert.equal(xml, expectXml);
|
||||
};
|
||||
});
|
||||
test('Marker Surrounds', function () {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -39,10 +40,10 @@ suite('JSO Deserialization', function () {
|
||||
],
|
||||
},
|
||||
};
|
||||
chai.assert.throws(() => {
|
||||
assert.throws(() => {
|
||||
Blockly.serialization.workspaces.load(state, this.workspace);
|
||||
});
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
Blockly.Events.isEnabled(),
|
||||
'Expected events to be enabled',
|
||||
);
|
||||
@@ -121,7 +122,7 @@ suite('JSO Deserialization', function () {
|
||||
Blockly.serialization.workspaces.load(state, this.workspace);
|
||||
const calls = this.eventsFireStub.getCalls();
|
||||
const group = calls[0].args[0].group;
|
||||
chai.assert.isTrue(calls.every((call) => call.args[0].group == group));
|
||||
assert.isTrue(calls.every((call) => call.args[0].group == group));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -217,7 +218,7 @@ suite('JSO Deserialization', function () {
|
||||
Blockly.serialization.workspaces.load(state, this.workspace);
|
||||
const calls = this.eventsFireStub.getCalls();
|
||||
const group = calls[0].args[0].group;
|
||||
chai.assert.isTrue(calls.every((call) => call.args[0].group == group));
|
||||
assert.isTrue(calls.every((call) => call.args[0].group == group));
|
||||
});
|
||||
|
||||
test('Var with block', function () {
|
||||
@@ -252,7 +253,7 @@ suite('JSO Deserialization', function () {
|
||||
}
|
||||
return acc;
|
||||
}, 0);
|
||||
chai.assert.equal(count, 1);
|
||||
assert.equal(count, 1);
|
||||
assertEventFired(
|
||||
this.eventsFireStub,
|
||||
Blockly.Events.VarCreate,
|
||||
@@ -363,9 +364,7 @@ suite('JSO Deserialization', function () {
|
||||
Blockly.serialization.workspaces.load(state, this.workspace);
|
||||
const calls = this.eventsFireStub.getCalls();
|
||||
const group = calls[0].args[0].group;
|
||||
chai.assert.isTrue(
|
||||
calls.every((call) => call.args[0].group == group),
|
||||
);
|
||||
assert.isTrue(calls.every((call) => call.args[0].group == group));
|
||||
});
|
||||
|
||||
test('With children', function () {
|
||||
@@ -467,7 +466,7 @@ suite('JSO Deserialization', function () {
|
||||
suite('Exceptions', function () {
|
||||
setup(function () {
|
||||
this.assertThrows = function (state, error) {
|
||||
chai.assert.throws(() => {
|
||||
assert.throws(() => {
|
||||
Blockly.serialization.workspaces.load(state, this.workspace);
|
||||
}, error);
|
||||
};
|
||||
@@ -748,7 +747,7 @@ suite('JSO Deserialization', function () {
|
||||
Blockly.serialization.registry.register('blocks', blocksSerializer);
|
||||
Blockly.serialization.registry.register('variables', variablesSerializer);
|
||||
|
||||
chai.assert.deepEqual(calls, [
|
||||
assert.deepEqual(calls, [
|
||||
'third-clear',
|
||||
'second-clear',
|
||||
'first-clear',
|
||||
@@ -786,7 +785,7 @@ suite('JSO Deserialization', function () {
|
||||
|
||||
delete Blockly.Blocks['test_block'];
|
||||
|
||||
chai.assert.equal(block.someProperty, 'some value');
|
||||
assert.equal(block.someProperty, 'some value');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -816,7 +815,7 @@ suite('JSO Deserialization', function () {
|
||||
|
||||
this.procedureSerializer.load(state, this.workspace);
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
spy.calledOnce,
|
||||
'Expected the loadState method to be called',
|
||||
);
|
||||
@@ -841,7 +840,7 @@ suite('JSO Deserialization', function () {
|
||||
|
||||
this.procedureSerializer.load(state, this.workspace);
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
spy.calledTwice,
|
||||
'Expected the loadState method to be called once for each parameter',
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
createGenUidStubWithReturns,
|
||||
@@ -41,7 +42,7 @@ suite('JSO Serialization', function () {
|
||||
});
|
||||
|
||||
function assertProperty(obj, property, value) {
|
||||
chai.assert.deepEqual(obj[property], value);
|
||||
assert.deepEqual(obj[property], value);
|
||||
}
|
||||
|
||||
function assertNoProperty(obj, property) {
|
||||
@@ -53,7 +54,7 @@ suite('JSO Serialization', function () {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
block.setInsertionMarker(true);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.isNull(jso);
|
||||
assert.isNull(jso);
|
||||
});
|
||||
|
||||
test('Basic', function () {
|
||||
@@ -384,7 +385,7 @@ suite('JSO Serialization', function () {
|
||||
suite('Connected blocks', function () {
|
||||
setup(function () {
|
||||
this.assertInput = function (jso, name, value) {
|
||||
chai.assert.deepInclude(jso['inputs'][name], value);
|
||||
assert.deepInclude(jso['inputs'][name], value);
|
||||
};
|
||||
|
||||
this.createBlockWithChild = function (blockType, inputName) {
|
||||
@@ -467,7 +468,7 @@ suite('JSO Serialization', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
addInputBlocks: false,
|
||||
});
|
||||
chai.assert.isUndefined(jso['inputs']);
|
||||
assert.isUndefined(jso['inputs']);
|
||||
};
|
||||
|
||||
this.assertNoShadow = function (blockType, inputName) {
|
||||
@@ -475,7 +476,7 @@ suite('JSO Serialization', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
addInputBlocks: false,
|
||||
});
|
||||
chai.assert.isUndefined(jso['inputs']);
|
||||
assert.isUndefined(jso['inputs']);
|
||||
};
|
||||
|
||||
this.assertNoOverwrittenShadow = function (blockType, inputName) {
|
||||
@@ -486,7 +487,7 @@ suite('JSO Serialization', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
addInputBlocks: false,
|
||||
});
|
||||
chai.assert.isUndefined(jso['inputs']);
|
||||
assert.isUndefined(jso['inputs']);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -662,7 +663,7 @@ suite('JSO Serialization', function () {
|
||||
test('Child', function () {
|
||||
const block = this.createNextWithChild();
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepInclude(jso['next'], {
|
||||
assert.deepInclude(jso['next'], {
|
||||
'block': {'type': 'stack_block', 'id': 'id2'},
|
||||
});
|
||||
});
|
||||
@@ -670,7 +671,7 @@ suite('JSO Serialization', function () {
|
||||
test('Shadow', function () {
|
||||
const block = this.createNextWithShadow();
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepInclude(jso['next'], {
|
||||
assert.deepInclude(jso['next'], {
|
||||
'shadow': {'type': 'stack_block', 'id': 'test'},
|
||||
});
|
||||
});
|
||||
@@ -678,7 +679,7 @@ suite('JSO Serialization', function () {
|
||||
test('Overwritten shadow', function () {
|
||||
const block = this.createNextWithShadowAndChild();
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepInclude(jso['next'], {
|
||||
assert.deepInclude(jso['next'], {
|
||||
'block': {
|
||||
'type': 'stack_block',
|
||||
'id': 'id2',
|
||||
@@ -699,7 +700,7 @@ suite('JSO Serialization', function () {
|
||||
.getInput('NAME')
|
||||
.connection.connect(grandChildBlock.previousConnection);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepInclude(jso['next'], {
|
||||
assert.deepInclude(jso['next'], {
|
||||
'block': {
|
||||
'type': 'statement_block',
|
||||
'id': 'id2',
|
||||
@@ -722,7 +723,7 @@ suite('JSO Serialization', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
addNextBlocks: false,
|
||||
});
|
||||
chai.assert.isUndefined(jso['next']);
|
||||
assert.isUndefined(jso['next']);
|
||||
});
|
||||
|
||||
test('Shadow', function () {
|
||||
@@ -730,7 +731,7 @@ suite('JSO Serialization', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
addNextBlocks: false,
|
||||
});
|
||||
chai.assert.isUndefined(jso['next']);
|
||||
assert.isUndefined(jso['next']);
|
||||
});
|
||||
|
||||
test('Overwritten shadow', function () {
|
||||
@@ -738,7 +739,7 @@ suite('JSO Serialization', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
addNextBlocks: false,
|
||||
});
|
||||
chai.assert.isUndefined(jso['next']);
|
||||
assert.isUndefined(jso['next']);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -749,7 +750,7 @@ suite('JSO Serialization', function () {
|
||||
test('Single block', function () {
|
||||
const block = this.workspace.newBlock('variables_get');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields']['VAR'], {
|
||||
assert.deepEqual(jso['fields']['VAR'], {
|
||||
'id': 'id2',
|
||||
'name': 'item',
|
||||
'type': '',
|
||||
@@ -763,10 +764,11 @@ suite('JSO Serialization', function () {
|
||||
.getInput('INPUT')
|
||||
.connection.connect(childBlock.outputConnection);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(
|
||||
jso['inputs']['INPUT']['block']['fields']['VAR'],
|
||||
{'id': 'id4', 'name': 'item', 'type': ''},
|
||||
);
|
||||
assert.deepEqual(jso['inputs']['INPUT']['block']['fields']['VAR'], {
|
||||
'id': 'id4',
|
||||
'name': 'item',
|
||||
'type': '',
|
||||
});
|
||||
});
|
||||
|
||||
test('Next block', function () {
|
||||
@@ -774,7 +776,7 @@ suite('JSO Serialization', function () {
|
||||
const childBlock = this.workspace.newBlock('variables_set');
|
||||
block.nextConnection.connect(childBlock.previousConnection);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['next']['block']['fields']['VAR'], {
|
||||
assert.deepEqual(jso['next']['block']['fields']['VAR'], {
|
||||
'id': 'id4',
|
||||
'name': 'item',
|
||||
'type': '',
|
||||
@@ -788,9 +790,9 @@ suite('JSO Serialization', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
doFullSerialization: false,
|
||||
});
|
||||
chai.assert.deepEqual(jso['fields']['VAR'], {'id': 'id2'});
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['name']);
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['type']);
|
||||
assert.deepEqual(jso['fields']['VAR'], {'id': 'id2'});
|
||||
assert.isUndefined(jso['fields']['VAR']['name']);
|
||||
assert.isUndefined(jso['fields']['VAR']['type']);
|
||||
});
|
||||
|
||||
test('Input block', function () {
|
||||
@@ -802,14 +804,13 @@ suite('JSO Serialization', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
doFullSerialization: false,
|
||||
});
|
||||
chai.assert.deepEqual(
|
||||
jso['inputs']['INPUT']['block']['fields']['VAR'],
|
||||
{'id': 'id4'},
|
||||
);
|
||||
chai.assert.isUndefined(
|
||||
assert.deepEqual(jso['inputs']['INPUT']['block']['fields']['VAR'], {
|
||||
'id': 'id4',
|
||||
});
|
||||
assert.isUndefined(
|
||||
jso['inputs']['INPUT']['block']['fields']['VAR']['name'],
|
||||
);
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
jso['inputs']['INPUT']['block']['fields']['VAR']['type'],
|
||||
);
|
||||
});
|
||||
@@ -821,15 +822,11 @@ suite('JSO Serialization', function () {
|
||||
const jso = Blockly.serialization.blocks.save(block, {
|
||||
doFullSerialization: false,
|
||||
});
|
||||
chai.assert.deepEqual(jso['next']['block']['fields']['VAR'], {
|
||||
assert.deepEqual(jso['next']['block']['fields']['VAR'], {
|
||||
'id': 'id4',
|
||||
});
|
||||
chai.assert.isUndefined(
|
||||
jso['next']['block']['fields']['VAR']['name'],
|
||||
);
|
||||
chai.assert.isUndefined(
|
||||
jso['next']['block']['fields']['VAR']['type'],
|
||||
);
|
||||
assert.isUndefined(jso['next']['block']['fields']['VAR']['name']);
|
||||
assert.isUndefined(jso['next']['block']['fields']['VAR']['type']);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -877,7 +874,7 @@ suite('JSO Serialization', function () {
|
||||
|
||||
this.serializer.save(this.workspace);
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
spy.calledOnce,
|
||||
'Expected the saveState method to be called on the procedure model',
|
||||
);
|
||||
@@ -895,11 +892,11 @@ suite('JSO Serialization', function () {
|
||||
|
||||
this.serializer.save(this.workspace);
|
||||
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
spy1.calledOnce,
|
||||
'Expected the saveState method to be called on the first parameter model',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
spy2.calledOnce,
|
||||
'Expected the saveState method to be called on the first parameter model',
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
addMessageToCleanup,
|
||||
sharedTestSetup,
|
||||
@@ -35,16 +36,16 @@ suite('JSON Block Definitions', function () {
|
||||
block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||
});
|
||||
|
||||
chai.assert.isNotNull(block);
|
||||
chai.assert.equal(BLOCK_TYPE, block.type);
|
||||
assert.isNotNull(block);
|
||||
assert.equal(BLOCK_TYPE, block.type);
|
||||
});
|
||||
|
||||
test('Null or undefined type id', function () {
|
||||
const BLOCK_TYPE1 = 'test_json_before_bad_blocks';
|
||||
const BLOCK_TYPE2 = 'test_json_after_bad_blocks';
|
||||
|
||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||
assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||
assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||
const blockTypeCount = Object.keys(Blockly.Blocks).length;
|
||||
|
||||
assertWarnings(() => {
|
||||
@@ -55,23 +56,23 @@ suite('JSON Block Definitions', function () {
|
||||
{'type': BLOCK_TYPE2},
|
||||
]);
|
||||
}, [/missing a type attribute/, /missing a type attribute/]);
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
Blockly.Blocks[BLOCK_TYPE1],
|
||||
'Block before bad blocks should be defined.',
|
||||
);
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
Blockly.Blocks[BLOCK_TYPE2],
|
||||
'Block after bad blocks should be defined.',
|
||||
);
|
||||
chai.assert.equal(Object.keys(Blockly.Blocks).length, blockTypeCount + 2);
|
||||
assert.equal(Object.keys(Blockly.Blocks).length, blockTypeCount + 2);
|
||||
});
|
||||
|
||||
test('Null item', function () {
|
||||
const BLOCK_TYPE1 = 'test_block_before_null';
|
||||
const BLOCK_TYPE2 = 'test_block_after_null';
|
||||
|
||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||
assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||
assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||
const blockTypeCount = Object.keys(Blockly.Blocks).length;
|
||||
|
||||
assertWarnings(() => {
|
||||
@@ -87,23 +88,23 @@ suite('JSON Block Definitions', function () {
|
||||
},
|
||||
]);
|
||||
}, /is null/);
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
Blockly.Blocks[BLOCK_TYPE1],
|
||||
'Block before null in array should be defined.',
|
||||
);
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
Blockly.Blocks[BLOCK_TYPE2],
|
||||
'Block after null in array should be defined.',
|
||||
);
|
||||
chai.assert.equal(Object.keys(Blockly.Blocks).length, blockTypeCount + 2);
|
||||
assert.equal(Object.keys(Blockly.Blocks).length, blockTypeCount + 2);
|
||||
});
|
||||
|
||||
test('Undefined item', function () {
|
||||
const BLOCK_TYPE1 = 'test_block_before_undefined';
|
||||
const BLOCK_TYPE2 = 'test_block_after_undefined';
|
||||
|
||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||
assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||
assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||
const blockTypeCount = Object.keys(Blockly.Blocks).length;
|
||||
assertWarnings(() => {
|
||||
Blockly.defineBlocksWithJsonArray([
|
||||
@@ -118,15 +119,15 @@ suite('JSON Block Definitions', function () {
|
||||
},
|
||||
]);
|
||||
}, /is undefined/);
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
Blockly.Blocks[BLOCK_TYPE1],
|
||||
'Block before undefined in array should be defined.',
|
||||
);
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
Blockly.Blocks[BLOCK_TYPE2],
|
||||
'Block after undefined in array should be defined.',
|
||||
);
|
||||
chai.assert.equal(Object.keys(Blockly.Blocks).length, blockTypeCount + 2);
|
||||
assert.equal(Object.keys(Blockly.Blocks).length, blockTypeCount + 2);
|
||||
});
|
||||
|
||||
test('message0 creates input', function () {
|
||||
@@ -140,11 +141,11 @@ suite('JSON Block Definitions', function () {
|
||||
]);
|
||||
|
||||
const block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||
chai.assert.equal(block.inputList.length, 1);
|
||||
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||
assert.equal(block.inputList.length, 1);
|
||||
assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||
const textField = block.inputList[0].fieldRow[0];
|
||||
chai.assert.equal(Blockly.FieldLabel, textField.constructor);
|
||||
chai.assert.equal(MESSAGE0, textField.getText());
|
||||
assert.equal(Blockly.FieldLabel, textField.constructor);
|
||||
assert.equal(MESSAGE0, textField.getText());
|
||||
});
|
||||
|
||||
test('message1 and message0 creates two inputs', function () {
|
||||
@@ -161,17 +162,17 @@ suite('JSON Block Definitions', function () {
|
||||
]);
|
||||
|
||||
const block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||
chai.assert.equal(block.inputList.length, 2);
|
||||
assert.equal(block.inputList.length, 2);
|
||||
|
||||
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||
assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||
const firstTextField = block.inputList[0].fieldRow[0];
|
||||
chai.assert.equal(Blockly.FieldLabel, firstTextField.constructor);
|
||||
chai.assert.equal(MESSAGE0, firstTextField.getText());
|
||||
assert.equal(Blockly.FieldLabel, firstTextField.constructor);
|
||||
assert.equal(MESSAGE0, firstTextField.getText());
|
||||
|
||||
chai.assert.equal(block.inputList[1].fieldRow.length, 1);
|
||||
assert.equal(block.inputList[1].fieldRow.length, 1);
|
||||
const secondTextField = block.inputList[1].fieldRow[0];
|
||||
chai.assert.equal(Blockly.FieldLabel, secondTextField.constructor);
|
||||
chai.assert.equal(MESSAGE1, secondTextField.getText());
|
||||
assert.equal(Blockly.FieldLabel, secondTextField.constructor);
|
||||
assert.equal(MESSAGE1, secondTextField.getText());
|
||||
});
|
||||
|
||||
test('Message string is dereferenced', function () {
|
||||
@@ -189,11 +190,11 @@ suite('JSON Block Definitions', function () {
|
||||
]);
|
||||
|
||||
const block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||
chai.assert.equal(block.inputList.length, 1);
|
||||
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||
assert.equal(block.inputList.length, 1);
|
||||
assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||
const textField = block.inputList[0].fieldRow[0];
|
||||
chai.assert.equal(Blockly.FieldLabel, textField.constructor);
|
||||
chai.assert.equal(MESSAGE, textField.getText());
|
||||
assert.equal(Blockly.FieldLabel, textField.constructor);
|
||||
assert.equal(MESSAGE, textField.getText());
|
||||
});
|
||||
|
||||
test('Dropdown', function () {
|
||||
@@ -221,18 +222,18 @@ suite('JSON Block Definitions', function () {
|
||||
]);
|
||||
|
||||
const block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||
chai.assert.equal(block.inputList.length, 1);
|
||||
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||
assert.equal(block.inputList.length, 1);
|
||||
assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||
const dropdown = block.inputList[0].fieldRow[0];
|
||||
chai.assert.equal(dropdown, block.getField(FIELD_NAME));
|
||||
chai.assert.equal(Blockly.FieldDropdown, dropdown.constructor);
|
||||
chai.assert.equal(VALUE0, dropdown.getValue());
|
||||
assert.equal(dropdown, block.getField(FIELD_NAME));
|
||||
assert.equal(Blockly.FieldDropdown, dropdown.constructor);
|
||||
assert.equal(VALUE0, dropdown.getValue());
|
||||
|
||||
const options = dropdown.getOptions();
|
||||
chai.assert.equal(LABEL0, options[0][0]);
|
||||
chai.assert.equal(VALUE0, options[0][1]);
|
||||
chai.assert.equal(LABEL1, options[1][0]);
|
||||
chai.assert.equal(VALUE1, options[1][1]);
|
||||
assert.equal(LABEL0, options[0][0]);
|
||||
assert.equal(VALUE0, options[0][1]);
|
||||
assert.equal(LABEL1, options[1][0]);
|
||||
assert.equal(VALUE1, options[1][1]);
|
||||
});
|
||||
|
||||
test('Dropdown with images', function () {
|
||||
@@ -281,34 +282,34 @@ suite('JSON Block Definitions', function () {
|
||||
]);
|
||||
|
||||
const block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||
chai.assert.equal(block.inputList.length, 1);
|
||||
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||
assert.equal(block.inputList.length, 1);
|
||||
assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||
const dropdown = block.inputList[0].fieldRow[0];
|
||||
chai.assert.equal(dropdown, block.getField(FIELD_NAME));
|
||||
chai.assert.equal(Blockly.FieldDropdown, dropdown.constructor);
|
||||
chai.assert.equal(VALUE0, dropdown.getValue());
|
||||
assert.equal(dropdown, block.getField(FIELD_NAME));
|
||||
assert.equal(Blockly.FieldDropdown, dropdown.constructor);
|
||||
assert.equal(VALUE0, dropdown.getValue());
|
||||
|
||||
function assertImageEquals(actualImage, expectedImage) {
|
||||
chai.assert.equal(actualImage.width, expectedImage.width);
|
||||
chai.assert.equal(actualImage.height, expectedImage.height);
|
||||
chai.assert.equal(actualImage.src, expectedImage.src);
|
||||
assert.equal(actualImage.width, expectedImage.width);
|
||||
assert.equal(actualImage.height, expectedImage.height);
|
||||
assert.equal(actualImage.src, expectedImage.src);
|
||||
}
|
||||
|
||||
const options = dropdown.getOptions();
|
||||
const image0 = options[0][0];
|
||||
assertImageEquals(IMAGE0, image0);
|
||||
chai.assert.equal(IMAGE0.alt, image0.alt);
|
||||
chai.assert.equal(options[0][1], VALUE0);
|
||||
assert.equal(IMAGE0.alt, image0.alt);
|
||||
assert.equal(options[0][1], VALUE0);
|
||||
|
||||
const image1 = options[1][0];
|
||||
assertImageEquals(IMAGE1, image1);
|
||||
chai.assert.equal(image1.alt, IMAGE1_ALT_TEXT); // Via Msg reference
|
||||
chai.assert.equal(VALUE1, options[1][1]);
|
||||
assert.equal(image1.alt, IMAGE1_ALT_TEXT); // Via Msg reference
|
||||
assert.equal(VALUE1, options[1][1]);
|
||||
|
||||
const image2 = options[2][0];
|
||||
assertImageEquals(IMAGE1, image1);
|
||||
chai.assert.notExists(image2.alt); // No alt specified.
|
||||
chai.assert.equal(VALUE2, options[2][1]);
|
||||
assert.notExists(image2.alt); // No alt specified.
|
||||
assert.equal(VALUE2, options[2][1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,6 +16,7 @@ suite('Key Down', function () {
|
||||
setup(function () {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = Blockly.inject('blocklyDiv', {});
|
||||
this.injectionDiv = this.workspace.getInjectionDiv();
|
||||
});
|
||||
teardown(function () {
|
||||
sharedTestTeardown.call(this);
|
||||
@@ -42,7 +43,7 @@ suite('Key Down', function () {
|
||||
const name = opt_name ? opt_name : 'Not called when readOnly is true';
|
||||
test(name, function () {
|
||||
this.workspace.options.readOnly = true;
|
||||
document.dispatchEvent(keyEvent);
|
||||
this.injectionDiv.dispatchEvent(keyEvent);
|
||||
sinon.assert.notCalled(this.hideChaffSpy);
|
||||
});
|
||||
}
|
||||
@@ -56,7 +57,7 @@ suite('Key Down', function () {
|
||||
);
|
||||
});
|
||||
test('Simple', function () {
|
||||
document.dispatchEvent(this.event);
|
||||
this.injectionDiv.dispatchEvent(this.event);
|
||||
sinon.assert.calledOnce(this.hideChaffSpy);
|
||||
});
|
||||
runReadOnlyTest(createKeyDownEvent(Blockly.utils.KeyCodes.ESC));
|
||||
@@ -68,7 +69,7 @@ suite('Key Down', function () {
|
||||
});
|
||||
test('Not called on hidden workspaces', function () {
|
||||
this.workspace.isVisible_ = false;
|
||||
document.dispatchEvent(this.event);
|
||||
this.injectionDiv.dispatchEvent(this.event);
|
||||
sinon.assert.notCalled(this.hideChaffSpy);
|
||||
});
|
||||
});
|
||||
@@ -92,7 +93,7 @@ suite('Key Down', function () {
|
||||
const testCaseName = testCase[0];
|
||||
const keyEvent = testCase[1];
|
||||
test(testCaseName, function () {
|
||||
document.dispatchEvent(keyEvent);
|
||||
this.injectionDiv.dispatchEvent(keyEvent);
|
||||
sinon.assert.calledOnce(this.hideChaffSpy);
|
||||
sinon.assert.calledOnce(this.deleteSpy);
|
||||
});
|
||||
@@ -143,7 +144,7 @@ suite('Key Down', function () {
|
||||
const testCaseName = testCase[0];
|
||||
const keyEvent = testCase[1];
|
||||
test(testCaseName, function () {
|
||||
document.dispatchEvent(keyEvent);
|
||||
this.injectionDiv.dispatchEvent(keyEvent);
|
||||
sinon.assert.calledOnce(this.copySpy);
|
||||
sinon.assert.calledOnce(this.hideChaffSpy);
|
||||
});
|
||||
@@ -164,7 +165,7 @@ suite('Key Down', function () {
|
||||
const keyEvent = testCase[1];
|
||||
test(testCaseName, function () {
|
||||
sinon.stub(Blockly.Gesture, 'inProgress').returns(true);
|
||||
document.dispatchEvent(keyEvent);
|
||||
this.injectionDiv.dispatchEvent(keyEvent);
|
||||
sinon.assert.notCalled(this.copySpy);
|
||||
sinon.assert.notCalled(this.hideChaffSpy);
|
||||
});
|
||||
@@ -179,7 +180,7 @@ suite('Key Down', function () {
|
||||
sinon
|
||||
.stub(Blockly.common.getSelected(), 'isDeletable')
|
||||
.returns(false);
|
||||
document.dispatchEvent(keyEvent);
|
||||
this.injectionDiv.dispatchEvent(keyEvent);
|
||||
sinon.assert.notCalled(this.copySpy);
|
||||
sinon.assert.notCalled(this.hideChaffSpy);
|
||||
});
|
||||
@@ -192,7 +193,7 @@ suite('Key Down', function () {
|
||||
const keyEvent = testCase[1];
|
||||
test(testCaseName, function () {
|
||||
sinon.stub(Blockly.common.getSelected(), 'isMovable').returns(false);
|
||||
document.dispatchEvent(keyEvent);
|
||||
this.injectionDiv.dispatchEvent(keyEvent);
|
||||
sinon.assert.notCalled(this.copySpy);
|
||||
sinon.assert.notCalled(this.hideChaffSpy);
|
||||
});
|
||||
@@ -234,7 +235,7 @@ suite('Key Down', function () {
|
||||
const testCaseName = testCase[0];
|
||||
const keyEvent = testCase[1];
|
||||
test(testCaseName, function () {
|
||||
document.dispatchEvent(keyEvent);
|
||||
this.injectionDiv.dispatchEvent(keyEvent);
|
||||
sinon.assert.calledOnce(this.undoSpy);
|
||||
sinon.assert.calledWith(this.undoSpy, false);
|
||||
sinon.assert.calledOnce(this.hideChaffSpy);
|
||||
@@ -248,7 +249,7 @@ suite('Key Down', function () {
|
||||
const keyEvent = testCase[1];
|
||||
test(testCaseName, function () {
|
||||
sinon.stub(Blockly.Gesture, 'inProgress').returns(true);
|
||||
document.dispatchEvent(keyEvent);
|
||||
this.injectionDiv.dispatchEvent(keyEvent);
|
||||
sinon.assert.notCalled(this.undoSpy);
|
||||
sinon.assert.notCalled(this.hideChaffSpy);
|
||||
});
|
||||
@@ -301,7 +302,7 @@ suite('Key Down', function () {
|
||||
const testCaseName = testCase[0];
|
||||
const keyEvent = testCase[1];
|
||||
test(testCaseName, function () {
|
||||
document.dispatchEvent(keyEvent);
|
||||
this.injectionDiv.dispatchEvent(keyEvent);
|
||||
sinon.assert.calledOnce(this.redoSpy);
|
||||
sinon.assert.calledWith(this.redoSpy, true);
|
||||
sinon.assert.calledOnce(this.hideChaffSpy);
|
||||
@@ -315,7 +316,7 @@ suite('Key Down', function () {
|
||||
const keyEvent = testCase[1];
|
||||
test(testCaseName, function () {
|
||||
sinon.stub(Blockly.Gesture, 'inProgress').returns(true);
|
||||
document.dispatchEvent(keyEvent);
|
||||
this.injectionDiv.dispatchEvent(keyEvent);
|
||||
sinon.assert.notCalled(this.redoSpy);
|
||||
sinon.assert.notCalled(this.hideChaffSpy);
|
||||
});
|
||||
@@ -343,14 +344,14 @@ suite('Key Down', function () {
|
||||
);
|
||||
});
|
||||
test('Simple', function () {
|
||||
document.dispatchEvent(this.ctrlYEvent);
|
||||
this.injectionDiv.dispatchEvent(this.ctrlYEvent);
|
||||
sinon.assert.calledOnce(this.undoSpy);
|
||||
sinon.assert.calledWith(this.undoSpy, true);
|
||||
sinon.assert.calledOnce(this.hideChaffSpy);
|
||||
});
|
||||
test('Not called when a gesture is in progress', function () {
|
||||
sinon.stub(Blockly.Gesture, 'inProgress').returns(true);
|
||||
document.dispatchEvent(this.ctrlYEvent);
|
||||
this.injectionDiv.dispatchEvent(this.ctrlYEvent);
|
||||
sinon.assert.notCalled(this.undoSpy);
|
||||
sinon.assert.notCalled(this.hideChaffSpy);
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Copyright 2023 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -35,7 +36,7 @@ suite('Layering', function () {
|
||||
const layerCount = this.layerManager.layers.size;
|
||||
this.layerManager.append(elem2, 999);
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.layerManager.layers.size,
|
||||
layerCount,
|
||||
'Expected the element to be appended to the existing layer',
|
||||
@@ -54,7 +55,7 @@ suite('Layering', function () {
|
||||
|
||||
const layer1000 = this.layerManager.layers.get(1000);
|
||||
const layer1010 = this.layerManager.layers.get(1010);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
layer1000.nextSibling,
|
||||
layer1010,
|
||||
'Expected layer 1000 to be direclty before layer 1010',
|
||||
@@ -70,7 +71,7 @@ suite('Layering', function () {
|
||||
|
||||
const layer1010 = this.layerManager.layers.get(1010);
|
||||
const layer1000 = this.layerManager.layers.get(1000);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
layer1000.nextSibling,
|
||||
layer1010,
|
||||
'Expected layer 1000 to be direclty before layer 1010',
|
||||
@@ -84,7 +85,7 @@ suite('Layering', function () {
|
||||
|
||||
this.layerManager.moveToDragLayer(elem);
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.layerManager.dragLayer.firstChild,
|
||||
elem.getSvgRoot(),
|
||||
'Expected the element to be the first element in the drag layer.',
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -13,10 +14,10 @@ suite('Metrics', function () {
|
||||
const SCROLL_X = 10;
|
||||
const SCROLL_Y = 10;
|
||||
function assertDimensionsMatch(toCheck, left, top, width, height) {
|
||||
chai.assert.equal(top, toCheck.top, 'Top did not match.');
|
||||
chai.assert.equal(left, toCheck.left, 'Left did not match.');
|
||||
chai.assert.equal(width, toCheck.width, 'Width did not match.');
|
||||
chai.assert.equal(height, toCheck.height, 'Height did not match.');
|
||||
assert.equal(top, toCheck.top, 'Top did not match.');
|
||||
assert.equal(left, toCheck.left, 'Left did not match.');
|
||||
assert.equal(width, toCheck.width, 'Width did not match.');
|
||||
assert.equal(height, toCheck.height, 'Height did not match.');
|
||||
}
|
||||
|
||||
// Make a mock workspace object with two properties:
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -51,7 +52,7 @@ suite('Mutator', function () {
|
||||
mutatorWorkspace
|
||||
.getBlockById('check_block')
|
||||
.setFieldValue('TRUE', 'CHECK');
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
this.eventsFireStub
|
||||
.getCalls()
|
||||
.some(
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -19,71 +20,35 @@ suite('Names', function () {
|
||||
|
||||
test('Safe name', function () {
|
||||
const varDB = new Blockly.Names('window,door');
|
||||
chai.assert.equal(varDB.safeName(''), 'unnamed', 'SafeName empty.');
|
||||
chai.assert.equal(varDB.safeName('foobar'), 'foobar', 'SafeName ok.');
|
||||
chai.assert.equal(
|
||||
assert.equal(varDB.safeName(''), 'unnamed', 'SafeName empty.');
|
||||
assert.equal(varDB.safeName('foobar'), 'foobar', 'SafeName ok.');
|
||||
assert.equal(
|
||||
varDB.safeName('9lives'),
|
||||
'my_9lives',
|
||||
'SafeName number start.',
|
||||
);
|
||||
chai.assert.equal(
|
||||
varDB.safeName('lives9'),
|
||||
'lives9',
|
||||
'SafeName number end.',
|
||||
);
|
||||
chai.assert.equal(
|
||||
varDB.safeName('!@#$'),
|
||||
'____',
|
||||
'SafeName special chars.',
|
||||
);
|
||||
chai.assert.equal(varDB.safeName('door'), 'door', 'SafeName reserved.');
|
||||
assert.equal(varDB.safeName('lives9'), 'lives9', 'SafeName number end.');
|
||||
assert.equal(varDB.safeName('!@#$'), '____', 'SafeName special chars.');
|
||||
assert.equal(varDB.safeName('door'), 'door', 'SafeName reserved.');
|
||||
});
|
||||
|
||||
test('Get name', function () {
|
||||
const varDB = new Blockly.Names('window,door');
|
||||
chai.assert.equal(
|
||||
varDB.getName('Foo.bar', 'var'),
|
||||
'Foo_bar',
|
||||
'Name add #1.',
|
||||
);
|
||||
chai.assert.equal(
|
||||
varDB.getName('Foo.bar', 'var'),
|
||||
'Foo_bar',
|
||||
'Name get #1.',
|
||||
);
|
||||
chai.assert.equal(
|
||||
varDB.getName('Foo bar', 'var'),
|
||||
'Foo_bar2',
|
||||
'Name add #2.',
|
||||
);
|
||||
chai.assert.equal(
|
||||
varDB.getName('foo BAR', 'var'),
|
||||
'Foo_bar2',
|
||||
'Name get #2.',
|
||||
);
|
||||
chai.assert.equal(varDB.getName('door', 'var'), 'door2', 'Name add #3.');
|
||||
chai.assert.equal(
|
||||
varDB.getName('Foo.bar', 'proc'),
|
||||
'Foo_bar3',
|
||||
'Name add #4.',
|
||||
);
|
||||
chai.assert.equal(
|
||||
varDB.getName('Foo.bar', 'var'),
|
||||
'Foo_bar',
|
||||
'Name get #1b.',
|
||||
);
|
||||
chai.assert.equal(
|
||||
varDB.getName('Foo.bar', 'proc'),
|
||||
'Foo_bar3',
|
||||
'Name get #4.',
|
||||
);
|
||||
assert.equal(varDB.getName('Foo.bar', 'var'), 'Foo_bar', 'Name add #1.');
|
||||
assert.equal(varDB.getName('Foo.bar', 'var'), 'Foo_bar', 'Name get #1.');
|
||||
assert.equal(varDB.getName('Foo bar', 'var'), 'Foo_bar2', 'Name add #2.');
|
||||
assert.equal(varDB.getName('foo BAR', 'var'), 'Foo_bar2', 'Name get #2.');
|
||||
assert.equal(varDB.getName('door', 'var'), 'door2', 'Name add #3.');
|
||||
assert.equal(varDB.getName('Foo.bar', 'proc'), 'Foo_bar3', 'Name add #4.');
|
||||
assert.equal(varDB.getName('Foo.bar', 'var'), 'Foo_bar', 'Name get #1b.');
|
||||
assert.equal(varDB.getName('Foo.bar', 'proc'), 'Foo_bar3', 'Name get #4.');
|
||||
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
String(varDB.getUserNames('var')),
|
||||
'foo.bar,foo bar,door',
|
||||
'Get var names.',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
String(varDB.getUserNames('proc')),
|
||||
'foo.bar',
|
||||
'Get proc names.',
|
||||
@@ -92,23 +57,23 @@ suite('Names', function () {
|
||||
|
||||
test('Get distinct name', function () {
|
||||
const varDB = new Blockly.Names('window,door');
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
varDB.getDistinctName('Foo.bar', 'var'),
|
||||
'Foo_bar',
|
||||
'Name distinct #1.',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
varDB.getDistinctName('Foo.bar', 'var'),
|
||||
'Foo_bar2',
|
||||
'Name distinct #2.',
|
||||
);
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
varDB.getDistinctName('Foo.bar', 'proc'),
|
||||
'Foo_bar3',
|
||||
'Name distinct #3.',
|
||||
);
|
||||
varDB.reset();
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
varDB.getDistinctName('Foo.bar', 'var'),
|
||||
'Foo_bar',
|
||||
'Name distinct #4.',
|
||||
@@ -116,15 +81,15 @@ suite('Names', function () {
|
||||
});
|
||||
|
||||
test('name equals', function () {
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
Blockly.Names.equals('Foo.bar', 'Foo.bar'),
|
||||
'Name equals #1.',
|
||||
);
|
||||
chai.assert.isFalse(
|
||||
assert.isFalse(
|
||||
Blockly.Names.equals('Foo.bar', 'Foo_bar'),
|
||||
'Name equals #2.',
|
||||
);
|
||||
chai.assert.isTrue(
|
||||
assert.isTrue(
|
||||
Blockly.Names.equals('Foo.bar', 'FOO.BAR'),
|
||||
'Name equals #3.',
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -21,7 +22,7 @@ suite.skip('Workspace comment', function () {
|
||||
|
||||
suite('getTopComments(ordered=true)', function () {
|
||||
test('No comments', function () {
|
||||
chai.assert.equal(this.workspace.getTopComments(true).length, 0);
|
||||
assert.equal(this.workspace.getTopComments(true).length, 0);
|
||||
});
|
||||
|
||||
test('One comment', function () {
|
||||
@@ -32,13 +33,13 @@ suite.skip('Workspace comment', function () {
|
||||
0,
|
||||
'comment id',
|
||||
);
|
||||
chai.assert.equal(this.workspace.getTopComments(true).length, 1);
|
||||
chai.assert.equal(this.workspace.commentDB.get('comment id'), comment);
|
||||
assert.equal(this.workspace.getTopComments(true).length, 1);
|
||||
assert.equal(this.workspace.commentDB.get('comment id'), comment);
|
||||
});
|
||||
|
||||
test('After clear empty workspace', function () {
|
||||
this.workspace.clear();
|
||||
chai.assert.equal(this.workspace.getTopComments(true).length, 0);
|
||||
assert.equal(this.workspace.getTopComments(true).length, 0);
|
||||
});
|
||||
|
||||
test('After clear non-empty workspace', function () {
|
||||
@@ -50,8 +51,8 @@ suite.skip('Workspace comment', function () {
|
||||
'comment id',
|
||||
);
|
||||
this.workspace.clear();
|
||||
chai.assert.equal(this.workspace.getTopComments(true).length, 0);
|
||||
chai.assert.isFalse(this.workspace.commentDB.has('comment id'));
|
||||
assert.equal(this.workspace.getTopComments(true).length, 0);
|
||||
assert.isFalse(this.workspace.commentDB.has('comment id'));
|
||||
});
|
||||
|
||||
test('After dispose', function () {
|
||||
@@ -63,14 +64,14 @@ suite.skip('Workspace comment', function () {
|
||||
'comment id',
|
||||
);
|
||||
comment.dispose();
|
||||
chai.assert.equal(this.workspace.getTopComments(true).length, 0);
|
||||
chai.assert.isFalse(this.workspace.commentDB.has('comment id'));
|
||||
assert.equal(this.workspace.getTopComments(true).length, 0);
|
||||
assert.isFalse(this.workspace.commentDB.has('comment id'));
|
||||
});
|
||||
});
|
||||
|
||||
suite('getTopComments(ordered=false)', function () {
|
||||
test('No comments', function () {
|
||||
chai.assert.equal(this.workspace.getTopComments(false).length, 0);
|
||||
assert.equal(this.workspace.getTopComments(false).length, 0);
|
||||
});
|
||||
|
||||
test('One comment', function () {
|
||||
@@ -81,13 +82,13 @@ suite.skip('Workspace comment', function () {
|
||||
0,
|
||||
'comment id',
|
||||
);
|
||||
chai.assert.equal(this.workspace.getTopComments(false).length, 1);
|
||||
chai.assert.equal(this.workspace.commentDB.get('comment id'), comment);
|
||||
assert.equal(this.workspace.getTopComments(false).length, 1);
|
||||
assert.equal(this.workspace.commentDB.get('comment id'), comment);
|
||||
});
|
||||
|
||||
test('After clear empty workspace', function () {
|
||||
this.workspace.clear();
|
||||
chai.assert.equal(this.workspace.getTopComments(false).length, 0);
|
||||
assert.equal(this.workspace.getTopComments(false).length, 0);
|
||||
});
|
||||
|
||||
test('After clear non-empty workspace', function () {
|
||||
@@ -99,8 +100,8 @@ suite.skip('Workspace comment', function () {
|
||||
'comment id',
|
||||
);
|
||||
this.workspace.clear();
|
||||
chai.assert.equal(this.workspace.getTopComments(false).length, 0);
|
||||
chai.assert.isFalse(this.workspace.commentDB.has('comment id'));
|
||||
assert.equal(this.workspace.getTopComments(false).length, 0);
|
||||
assert.isFalse(this.workspace.commentDB.has('comment id'));
|
||||
});
|
||||
|
||||
test('After dispose', function () {
|
||||
@@ -112,8 +113,8 @@ suite.skip('Workspace comment', function () {
|
||||
'comment id',
|
||||
);
|
||||
comment.dispose();
|
||||
chai.assert.equal(this.workspace.getTopComments(false).length, 0);
|
||||
chai.assert.isFalse(this.workspace.commentDB.has('comment id'));
|
||||
assert.equal(this.workspace.getTopComments(false).length, 0);
|
||||
assert.isFalse(this.workspace.commentDB.has('comment id'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -126,15 +127,15 @@ suite.skip('Workspace comment', function () {
|
||||
0,
|
||||
'comment id',
|
||||
);
|
||||
chai.assert.equal(this.workspace.getCommentById(comment.id), comment);
|
||||
assert.equal(this.workspace.getCommentById(comment.id), comment);
|
||||
});
|
||||
|
||||
test('Null id', function () {
|
||||
chai.assert.isNull(this.workspace.getCommentById(null));
|
||||
assert.isNull(this.workspace.getCommentById(null));
|
||||
});
|
||||
|
||||
test('Non-existent id', function () {
|
||||
chai.assert.isNull(this.workspace.getCommentById('badId'));
|
||||
assert.isNull(this.workspace.getCommentById('badId'));
|
||||
});
|
||||
|
||||
test('After dispose', function () {
|
||||
@@ -146,7 +147,7 @@ suite.skip('Workspace comment', function () {
|
||||
'comment id',
|
||||
);
|
||||
comment.dispose();
|
||||
chai.assert.isNull(this.workspace.getCommentById(comment.id));
|
||||
assert.isNull(this.workspace.getCommentById(comment.id));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -177,20 +178,20 @@ suite.skip('Workspace comment', function () {
|
||||
});
|
||||
|
||||
test('Initial values', function () {
|
||||
chai.assert.equal(this.comment.getWidth(), 20, 'Width');
|
||||
chai.assert.equal(this.comment.getHeight(), 10, 'Height');
|
||||
assert.equal(this.comment.getWidth(), 20, 'Width');
|
||||
assert.equal(this.comment.getHeight(), 10, 'Height');
|
||||
});
|
||||
|
||||
test('setWidth does not affect height', function () {
|
||||
this.comment.setWidth(30);
|
||||
chai.assert.equal(this.comment.getWidth(), 30, 'Width');
|
||||
chai.assert.equal(this.comment.getHeight(), 10, 'Height');
|
||||
assert.equal(this.comment.getWidth(), 30, 'Width');
|
||||
assert.equal(this.comment.getHeight(), 10, 'Height');
|
||||
});
|
||||
|
||||
test('setHeight does not affect width', function () {
|
||||
this.comment.setHeight(30);
|
||||
chai.assert.equal(this.comment.getWidth(), 20, 'Width');
|
||||
chai.assert.equal(this.comment.getHeight(), 30, 'Height');
|
||||
assert.equal(this.comment.getWidth(), 20, 'Width');
|
||||
assert.equal(this.comment.getHeight(), 30, 'Height');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -207,15 +208,15 @@ suite.skip('Workspace comment', function () {
|
||||
|
||||
test('Initial position', function () {
|
||||
const xy = this.comment.getRelativeToSurfaceXY();
|
||||
chai.assert.equal(xy.x, 0, 'Initial X position');
|
||||
chai.assert.equal(xy.y, 0, 'Initial Y position');
|
||||
assert.equal(xy.x, 0, 'Initial X position');
|
||||
assert.equal(xy.y, 0, 'Initial Y position');
|
||||
});
|
||||
|
||||
test('moveBy', function () {
|
||||
this.comment.moveBy(10, 100);
|
||||
const xy = this.comment.getRelativeToSurfaceXY();
|
||||
chai.assert.equal(xy.x, 10, 'New X position');
|
||||
chai.assert.equal(xy.y, 100, 'New Y position');
|
||||
assert.equal(xy.x, 10, 'New X position');
|
||||
assert.equal(xy.y, 100, 'New Y position');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -235,33 +236,21 @@ suite.skip('Workspace comment', function () {
|
||||
});
|
||||
|
||||
test('After creation', function () {
|
||||
chai.assert.equal(this.comment.getContent(), 'comment text');
|
||||
chai.assert.equal(
|
||||
this.workspace.undoStack_.length,
|
||||
1,
|
||||
'Workspace undo stack',
|
||||
);
|
||||
assert.equal(this.comment.getContent(), 'comment text');
|
||||
assert.equal(this.workspace.undoStack_.length, 1, 'Workspace undo stack');
|
||||
});
|
||||
|
||||
test('Set to same value', function () {
|
||||
this.comment.setContent('comment text');
|
||||
chai.assert.equal(this.comment.getContent(), 'comment text');
|
||||
assert.equal(this.comment.getContent(), 'comment text');
|
||||
// Setting the text to the old value does not fire an event.
|
||||
chai.assert.equal(
|
||||
this.workspace.undoStack_.length,
|
||||
1,
|
||||
'Workspace undo stack',
|
||||
);
|
||||
assert.equal(this.workspace.undoStack_.length, 1, 'Workspace undo stack');
|
||||
});
|
||||
|
||||
test('Set to different value', function () {
|
||||
this.comment.setContent('new comment text');
|
||||
chai.assert.equal(this.comment.getContent(), 'new comment text');
|
||||
chai.assert.equal(
|
||||
this.workspace.undoStack_.length,
|
||||
2,
|
||||
'Workspace undo stack',
|
||||
);
|
||||
assert.equal(this.comment.getContent(), 'new comment text');
|
||||
assert.equal(this.workspace.undoStack_.length, 2, 'Workspace undo stack');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -32,7 +33,7 @@ suite('Procedure Map', function () {
|
||||
const spy = sinon.spy(procedureModel, 'startPublishing');
|
||||
this.procedureMap.set(procedureModel.getId(), procedureModel);
|
||||
|
||||
chai.assert.isTrue(spy.called, 'Expected the model to start publishing');
|
||||
assert.isTrue(spy.called, 'Expected the model to start publishing');
|
||||
});
|
||||
|
||||
test('adding a procedure tells it to start publishing', function () {
|
||||
@@ -40,7 +41,7 @@ suite('Procedure Map', function () {
|
||||
const spy = sinon.spy(procedureModel, 'startPublishing');
|
||||
this.procedureMap.add(procedureModel);
|
||||
|
||||
chai.assert.isTrue(spy.called, 'Expected the model to start publishing');
|
||||
assert.isTrue(spy.called, 'Expected the model to start publishing');
|
||||
});
|
||||
|
||||
test('deleting a procedure tells it to stop publishing', function () {
|
||||
@@ -50,7 +51,7 @@ suite('Procedure Map', function () {
|
||||
|
||||
this.procedureMap.delete(procedureModel.getId());
|
||||
|
||||
chai.assert.isTrue(spy.calledOnce, 'Expected the model stop publishing');
|
||||
assert.isTrue(spy.calledOnce, 'Expected the model stop publishing');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {assertWarnings} from './test_helpers/warnings.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -33,20 +34,20 @@ suite('Registry', function () {
|
||||
});
|
||||
|
||||
test('Empty String Key', function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.registry.register('test', '', TestClass);
|
||||
}, 'Invalid name');
|
||||
});
|
||||
|
||||
test('Class as Key', function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.registry.register('test', TestClass, '');
|
||||
}, 'Invalid name');
|
||||
});
|
||||
|
||||
test('Overwrite a Key', function () {
|
||||
Blockly.registry.register('test', 'test_name', TestClass);
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
// Registers a different object under the same name
|
||||
Blockly.registry.register('test', 'test_name', {});
|
||||
}, 'already registered');
|
||||
@@ -54,14 +55,14 @@ suite('Registry', function () {
|
||||
|
||||
test('Register a Duplicate Item', function () {
|
||||
Blockly.registry.register('test', 'test_name', TestClass);
|
||||
chai.assert.doesNotThrow(function () {
|
||||
assert.doesNotThrow(function () {
|
||||
// Registering the same object under the same name is allowed
|
||||
Blockly.registry.register('test', 'test_name', TestClass);
|
||||
}, 'already registered');
|
||||
});
|
||||
|
||||
test('Null Value', function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.registry.register('test', 'field_custom_test', null);
|
||||
}, 'Can not register a null value');
|
||||
});
|
||||
@@ -73,26 +74,26 @@ suite('Registry', function () {
|
||||
});
|
||||
|
||||
test('Has', function () {
|
||||
chai.assert.isTrue(Blockly.registry.hasItem('test', 'test_name'));
|
||||
assert.isTrue(Blockly.registry.hasItem('test', 'test_name'));
|
||||
});
|
||||
|
||||
suite('Does not have', function () {
|
||||
test('Type', function () {
|
||||
chai.assert.isFalse(Blockly.registry.hasItem('bad_type', 'test_name'));
|
||||
assert.isFalse(Blockly.registry.hasItem('bad_type', 'test_name'));
|
||||
});
|
||||
|
||||
test('Name', function () {
|
||||
chai.assert.isFalse(Blockly.registry.hasItem('test', 'bad_name'));
|
||||
assert.isFalse(Blockly.registry.hasItem('test', 'bad_name'));
|
||||
});
|
||||
});
|
||||
|
||||
suite('Case', function () {
|
||||
test('Caseless type', function () {
|
||||
chai.assert.isTrue(Blockly.registry.hasItem('TEST', 'test_name'));
|
||||
assert.isTrue(Blockly.registry.hasItem('TEST', 'test_name'));
|
||||
});
|
||||
|
||||
test('Caseless name', function () {
|
||||
chai.assert.isTrue(Blockly.registry.hasItem('test', 'TEST_NAME'));
|
||||
assert.isTrue(Blockly.registry.hasItem('test', 'TEST_NAME'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -103,26 +104,24 @@ suite('Registry', function () {
|
||||
});
|
||||
|
||||
test('Has', function () {
|
||||
chai.assert.isNotNull(Blockly.registry.getClass('test', 'test_name'));
|
||||
assert.isNotNull(Blockly.registry.getClass('test', 'test_name'));
|
||||
});
|
||||
|
||||
suite('Does not have', function () {
|
||||
test('Type', function () {
|
||||
assertWarnings(() => {
|
||||
chai.assert.isNull(
|
||||
Blockly.registry.getClass('bad_type', 'test_name'),
|
||||
);
|
||||
assert.isNull(Blockly.registry.getClass('bad_type', 'test_name'));
|
||||
}, /Unable to find/);
|
||||
});
|
||||
|
||||
test('Name', function () {
|
||||
assertWarnings(() => {
|
||||
chai.assert.isNull(Blockly.registry.getClass('test', 'bad_name'));
|
||||
assert.isNull(Blockly.registry.getClass('test', 'bad_name'));
|
||||
}, /Unable to find/);
|
||||
});
|
||||
|
||||
test('Throw if missing', function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.registry.getClass('test', 'bad_name', true);
|
||||
});
|
||||
});
|
||||
@@ -130,11 +129,11 @@ suite('Registry', function () {
|
||||
|
||||
suite('Case', function () {
|
||||
test('Caseless type', function () {
|
||||
chai.assert.isNotNull(Blockly.registry.getClass('TEST', 'test_name'));
|
||||
assert.isNotNull(Blockly.registry.getClass('TEST', 'test_name'));
|
||||
});
|
||||
|
||||
test('Caseless name', function () {
|
||||
chai.assert.isNotNull(Blockly.registry.getClass('test', 'TEST_NAME'));
|
||||
assert.isNotNull(Blockly.registry.getClass('test', 'TEST_NAME'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -145,26 +144,24 @@ suite('Registry', function () {
|
||||
});
|
||||
|
||||
test('Has', function () {
|
||||
chai.assert.isNotNull(Blockly.registry.getObject('test', 'test_name'));
|
||||
assert.isNotNull(Blockly.registry.getObject('test', 'test_name'));
|
||||
});
|
||||
|
||||
suite('Does not have', function () {
|
||||
test('Type', function () {
|
||||
assertWarnings(() => {
|
||||
chai.assert.isNull(
|
||||
Blockly.registry.getObject('bad_type', 'test_name'),
|
||||
);
|
||||
assert.isNull(Blockly.registry.getObject('bad_type', 'test_name'));
|
||||
}, /Unable to find/);
|
||||
});
|
||||
|
||||
test('Name', function () {
|
||||
assertWarnings(() => {
|
||||
chai.assert.isNull(Blockly.registry.getObject('test', 'bad_name'));
|
||||
assert.isNull(Blockly.registry.getObject('test', 'bad_name'));
|
||||
}, /Unable to find/);
|
||||
});
|
||||
|
||||
test('Throw if missing', function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.registry.getObject('test', 'bad_name', true);
|
||||
});
|
||||
});
|
||||
@@ -172,11 +169,11 @@ suite('Registry', function () {
|
||||
|
||||
suite('Case', function () {
|
||||
test('Caseless type', function () {
|
||||
chai.assert.isNotNull(Blockly.registry.getObject('TEST', 'test_name'));
|
||||
assert.isNotNull(Blockly.registry.getObject('TEST', 'test_name'));
|
||||
});
|
||||
|
||||
test('Caseless name', function () {
|
||||
chai.assert.isNotNull(Blockly.registry.getObject('test', 'TEST_NAME'));
|
||||
assert.isNotNull(Blockly.registry.getObject('test', 'TEST_NAME'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -192,27 +189,27 @@ suite('Registry', function () {
|
||||
});
|
||||
|
||||
test('Has', function () {
|
||||
chai.assert.isNotNull(Blockly.registry.getAllItems('test'));
|
||||
assert.isNotNull(Blockly.registry.getAllItems('test'));
|
||||
});
|
||||
|
||||
test('Does not have', function () {
|
||||
assertWarnings(() => {
|
||||
chai.assert.isNull(Blockly.registry.getAllItems('bad_type'));
|
||||
assert.isNull(Blockly.registry.getAllItems('bad_type'));
|
||||
}, /Unable to find/);
|
||||
});
|
||||
|
||||
test('Throw if missing', function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
Blockly.registry.getAllItems('bad_type', false, true);
|
||||
});
|
||||
});
|
||||
|
||||
test('Ignore type case', function () {
|
||||
chai.assert.isNotNull(Blockly.registry.getAllItems('TEST'));
|
||||
assert.isNotNull(Blockly.registry.getAllItems('TEST'));
|
||||
});
|
||||
|
||||
test('Respect name case', function () {
|
||||
chai.assert.deepEqual(Blockly.registry.getAllItems('test', true), {
|
||||
assert.deepEqual(Blockly.registry.getAllItems('test', true), {
|
||||
'test_name': {},
|
||||
'casedNAME': {},
|
||||
});
|
||||
@@ -220,7 +217,7 @@ suite('Registry', function () {
|
||||
|
||||
test('Respect overwriting name case', function () {
|
||||
Blockly.registry.register('test', 'CASEDname', {}, true);
|
||||
chai.assert.deepEqual(Blockly.registry.getAllItems('test', true), {
|
||||
assert.deepEqual(Blockly.registry.getAllItems('test', true), {
|
||||
'test_name': {},
|
||||
'CASEDname': {},
|
||||
});
|
||||
@@ -251,7 +248,7 @@ suite('Registry', function () {
|
||||
'test',
|
||||
this.options,
|
||||
);
|
||||
chai.assert.instanceOf(new testClass(), TestClass);
|
||||
assert.instanceOf(new testClass(), TestClass);
|
||||
});
|
||||
|
||||
test('Simple - Plugin class given', function () {
|
||||
@@ -260,7 +257,7 @@ suite('Registry', function () {
|
||||
'test',
|
||||
this.options,
|
||||
);
|
||||
chai.assert.instanceOf(new testClass(), TestClass);
|
||||
assert.instanceOf(new testClass(), TestClass);
|
||||
});
|
||||
|
||||
test('No Plugin Name Given', function () {
|
||||
@@ -269,7 +266,7 @@ suite('Registry', function () {
|
||||
'test',
|
||||
this.options,
|
||||
);
|
||||
chai.assert.instanceOf(new testClass(), this.defaultClass);
|
||||
assert.instanceOf(new testClass(), this.defaultClass);
|
||||
});
|
||||
|
||||
test('Incorrect Plugin Name', function () {
|
||||
@@ -278,7 +275,7 @@ suite('Registry', function () {
|
||||
assertWarnings(() => {
|
||||
testClass = Blockly.registry.getClassFromOptions('test', this.options);
|
||||
}, /Unable to find/);
|
||||
chai.assert.isNull(testClass);
|
||||
assert.isNull(testClass);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
@@ -43,7 +44,7 @@ suite('Render Management', function () {
|
||||
test('the queueRender promise is properly resolved after rendering', function () {
|
||||
const block = createMockBlock();
|
||||
const promise = Blockly.renderManagement.queueRender(block).then(() => {
|
||||
chai.assert.isTrue(block.hasRendered, 'Expected block to be rendered');
|
||||
assert.isTrue(block.hasRendered, 'Expected block to be rendered');
|
||||
});
|
||||
this.clock.runAll();
|
||||
return promise;
|
||||
@@ -53,7 +54,7 @@ suite('Render Management', function () {
|
||||
const block = createMockBlock();
|
||||
Blockly.renderManagement.queueRender(block);
|
||||
const promise = Blockly.renderManagement.finishQueuedRenders(() => {
|
||||
chai.assert.isTrue(block.hasRendered, 'Expected block to be rendered');
|
||||
assert.isTrue(block.hasRendered, 'Expected block to be rendered');
|
||||
});
|
||||
this.clock.runAll();
|
||||
return promise;
|
||||
@@ -92,7 +93,7 @@ suite('Render Management', function () {
|
||||
|
||||
Blockly.renderManagement.triggerQueuedRenders();
|
||||
|
||||
chai.assert.isTrue(block.hasRendered, 'Expected block to be rendered');
|
||||
assert.isTrue(block.hasRendered, 'Expected block to be rendered');
|
||||
});
|
||||
|
||||
test('triggering queued renders rerenders blocks in all workspaces', function () {
|
||||
@@ -105,8 +106,8 @@ suite('Render Management', function () {
|
||||
|
||||
Blockly.renderManagement.triggerQueuedRenders();
|
||||
|
||||
chai.assert.isTrue(block1.hasRendered, 'Expected block1 to be rendered');
|
||||
chai.assert.isTrue(block2.hasRendered, 'Expected block2 to be rendered');
|
||||
assert.isTrue(block1.hasRendered, 'Expected block1 to be rendered');
|
||||
assert.isTrue(block2.hasRendered, 'Expected block2 to be rendered');
|
||||
});
|
||||
|
||||
test('triggering queued renders in one workspace does not rerender blocks in another workspace', function () {
|
||||
@@ -119,11 +120,8 @@ suite('Render Management', function () {
|
||||
|
||||
Blockly.renderManagement.triggerQueuedRenders(workspace1);
|
||||
|
||||
chai.assert.isTrue(block1.hasRendered, 'Expected block1 to be rendered');
|
||||
chai.assert.isFalse(
|
||||
block2.hasRendered,
|
||||
'Expected block2 to not be rendered',
|
||||
);
|
||||
assert.isTrue(block1.hasRendered, 'Expected block1 to be rendered');
|
||||
assert.isFalse(block2.hasRendered, 'Expected block2 to not be rendered');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import {
|
||||
TestCase,
|
||||
@@ -2067,7 +2068,7 @@ const runSerializerTestSuite = (serializer, deserializer, testSuite) => {
|
||||
workspaces.load(deserializer(save), this.workspace);
|
||||
}
|
||||
const newXml = Blockly.Xml.workspaceToDom(this.workspace);
|
||||
chai.assert.equal(Blockly.Xml.domToText(newXml), test.xml);
|
||||
assert.equal(Blockly.Xml.domToText(newXml), test.xml);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {createKeyDownEvent} from './test_helpers/user_input.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
@@ -26,7 +27,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
const testShortcut = {'name': 'test_shortcut'};
|
||||
this.registry.register(testShortcut, true);
|
||||
const shortcut = this.registry.getRegistry()['test_shortcut'];
|
||||
chai.assert.equal(shortcut.name, 'test_shortcut');
|
||||
assert.equal(shortcut.name, 'test_shortcut');
|
||||
});
|
||||
test('Registers shortcut with same name', function () {
|
||||
const registry = this.registry;
|
||||
@@ -37,7 +38,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
const shouldThrow = function () {
|
||||
registry.register(testShortcut);
|
||||
};
|
||||
chai.assert.throws(
|
||||
assert.throws(
|
||||
shouldThrow,
|
||||
Error,
|
||||
'Shortcut named "test_shortcut" already exists.',
|
||||
@@ -56,8 +57,8 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
const shouldNotThrow = function () {
|
||||
registry.register(otherShortcut, true);
|
||||
};
|
||||
chai.assert.doesNotThrow(shouldNotThrow);
|
||||
chai.assert.exists(registry.getRegistry()['test_shortcut'].callback);
|
||||
assert.doesNotThrow(shouldNotThrow);
|
||||
assert.exists(registry.getRegistry()['test_shortcut'].callback);
|
||||
});
|
||||
test('Registering a shortcut with keycodes', function () {
|
||||
const shiftA = this.registry.createSerializedKey('65', [
|
||||
@@ -68,9 +69,9 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
'keyCodes': ['65', 66, shiftA],
|
||||
};
|
||||
this.registry.register(testShortcut, true);
|
||||
chai.assert.lengthOf(this.registry.getKeyMap()[shiftA], 1);
|
||||
chai.assert.lengthOf(this.registry.getKeyMap()['65'], 1);
|
||||
chai.assert.lengthOf(this.registry.getKeyMap()['66'], 1);
|
||||
assert.lengthOf(this.registry.getKeyMap()[shiftA], 1);
|
||||
assert.lengthOf(this.registry.getKeyMap()['65'], 1);
|
||||
assert.lengthOf(this.registry.getKeyMap()['66'], 1);
|
||||
});
|
||||
test('Registering a shortcut with allowCollision', function () {
|
||||
const testShortcut = {
|
||||
@@ -87,7 +88,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
const shouldNotThrow = function () {
|
||||
registry.register(duplicateShortcut);
|
||||
};
|
||||
chai.assert.doesNotThrow(shouldNotThrow);
|
||||
assert.doesNotThrow(shouldNotThrow);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -95,16 +96,16 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
test('Unregistering a shortcut', function () {
|
||||
const testShortcut = {'name': 'test_shortcut'};
|
||||
this.registry.register(testShortcut);
|
||||
chai.assert.isOk(this.registry.getRegistry()['test_shortcut']);
|
||||
assert.isOk(this.registry.getRegistry()['test_shortcut']);
|
||||
this.registry.unregister('test_shortcut');
|
||||
chai.assert.isUndefined(this.registry.getRegistry()['test_shortcut']);
|
||||
assert.isUndefined(this.registry.getRegistry()['test_shortcut']);
|
||||
});
|
||||
test('Unregistering a nonexistent shortcut', function () {
|
||||
const consoleStub = sinon.stub(console, 'warn');
|
||||
chai.assert.isUndefined(this.registry.getRegistry['test']);
|
||||
assert.isUndefined(this.registry.getRegistry['test']);
|
||||
|
||||
const registry = this.registry;
|
||||
chai.assert.isFalse(registry.unregister('test'));
|
||||
assert.isFalse(registry.unregister('test'));
|
||||
sinon.assert.calledOnceWithExactly(
|
||||
consoleStub,
|
||||
'Keyboard shortcut named "test" not found.',
|
||||
@@ -119,8 +120,8 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
|
||||
const shortcut = this.registry.getRegistry()['test_shortcut'];
|
||||
const keyMappings = this.registry.getKeyMap()['keyCode'];
|
||||
chai.assert.isUndefined(shortcut);
|
||||
chai.assert.isUndefined(keyMappings);
|
||||
assert.isUndefined(shortcut);
|
||||
assert.isUndefined(keyMappings);
|
||||
});
|
||||
test('Unregistering a shortcut with colliding key mappings', function () {
|
||||
const testShortcut = {'name': 'test_shortcut'};
|
||||
@@ -134,8 +135,8 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
|
||||
const shortcut = this.registry.getRegistry()['test_shortcut'];
|
||||
const keyMappings = this.registry.getKeyMap()['keyCode'];
|
||||
chai.assert.lengthOf(keyMappings, 1);
|
||||
chai.assert.isUndefined(shortcut);
|
||||
assert.lengthOf(keyMappings, 1);
|
||||
assert.isUndefined(shortcut);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -147,8 +148,8 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
this.registry.addKeyMapping('keyCode', 'test_shortcut');
|
||||
|
||||
const shortcutNames = this.registry.getKeyMap()['keyCode'];
|
||||
chai.assert.lengthOf(shortcutNames, 1);
|
||||
chai.assert.equal(shortcutNames[0], 'test_shortcut');
|
||||
assert.lengthOf(shortcutNames, 1);
|
||||
assert.equal(shortcutNames[0], 'test_shortcut');
|
||||
});
|
||||
test('Adds a colliding key mapping - opt_allowCollision=true', function () {
|
||||
const testShortcut = {'name': 'test_shortcut'};
|
||||
@@ -160,9 +161,9 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
this.registry.addKeyMapping('keyCode', 'test_shortcut', true);
|
||||
|
||||
const shortcutNames = this.registry.getKeyMap()['keyCode'];
|
||||
chai.assert.lengthOf(shortcutNames, 2);
|
||||
chai.assert.equal(shortcutNames[0], 'test_shortcut');
|
||||
chai.assert.equal(shortcutNames[1], 'test_shortcut_2');
|
||||
assert.lengthOf(shortcutNames, 2);
|
||||
assert.equal(shortcutNames[0], 'test_shortcut');
|
||||
assert.equal(shortcutNames[1], 'test_shortcut_2');
|
||||
});
|
||||
test('Adds a colliding key mapping - opt_allowCollision=false', function () {
|
||||
const testShortcut = {'name': 'test_shortcut'};
|
||||
@@ -175,7 +176,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
const shouldThrow = function () {
|
||||
registry.addKeyMapping('keyCode', 'test_shortcut');
|
||||
};
|
||||
chai.assert.throws(
|
||||
assert.throws(
|
||||
shouldThrow,
|
||||
Error,
|
||||
'Shortcut named "test_shortcut" collides with shortcuts "test_shortcut_2"',
|
||||
@@ -198,9 +199,9 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
);
|
||||
|
||||
const shortcutNames = this.registry.getKeyMap()['keyCode'];
|
||||
chai.assert.lengthOf(shortcutNames, 1);
|
||||
chai.assert.equal(shortcutNames[0], 'test_shortcut_2');
|
||||
chai.assert.isTrue(isRemoved);
|
||||
assert.lengthOf(shortcutNames, 1);
|
||||
assert.equal(shortcutNames[0], 'test_shortcut_2');
|
||||
assert.isTrue(isRemoved);
|
||||
});
|
||||
test('Removes last key mapping for a key', function () {
|
||||
const testShortcut = {'name': 'test_shortcut'};
|
||||
@@ -210,7 +211,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
this.registry.removeKeyMapping('keyCode', 'test_shortcut');
|
||||
|
||||
const shortcutNames = this.registry.getKeyMap()['keyCode'];
|
||||
chai.assert.isUndefined(shortcutNames);
|
||||
assert.isUndefined(shortcutNames);
|
||||
});
|
||||
test('Removes a key map that does not exist opt_quiet=false', function () {
|
||||
const consoleStub = sinon.stub(console, 'warn');
|
||||
@@ -223,7 +224,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
'test_shortcut',
|
||||
);
|
||||
|
||||
chai.assert.isFalse(isRemoved);
|
||||
assert.isFalse(isRemoved);
|
||||
sinon.assert.calledOnceWithExactly(
|
||||
consoleStub,
|
||||
'No keyboard shortcut named "test_shortcut" registered with key code "keyCode"',
|
||||
@@ -237,7 +238,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
'test_shortcut',
|
||||
);
|
||||
|
||||
chai.assert.isFalse(isRemoved);
|
||||
assert.isFalse(isRemoved);
|
||||
sinon.assert.calledOnceWithExactly(
|
||||
consoleStub,
|
||||
'No keyboard shortcut named "test_shortcut" registered with key code "keyCode"',
|
||||
@@ -248,24 +249,21 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
suite('Setters/Getters', function () {
|
||||
test('Sets the key map', function () {
|
||||
this.registry.setKeyMap({'keyCode': ['test_shortcut']});
|
||||
chai.assert.equal(Object.keys(this.registry.getKeyMap()).length, 1);
|
||||
chai.assert.equal(
|
||||
this.registry.getKeyMap()['keyCode'][0],
|
||||
'test_shortcut',
|
||||
);
|
||||
assert.equal(Object.keys(this.registry.getKeyMap()).length, 1);
|
||||
assert.equal(this.registry.getKeyMap()['keyCode'][0], 'test_shortcut');
|
||||
});
|
||||
test('Gets a copy of the key map', function () {
|
||||
this.registry.setKeyMap({'keyCode': ['a']});
|
||||
const keyMapCopy = this.registry.getKeyMap();
|
||||
keyMapCopy['keyCode'] = ['b'];
|
||||
chai.assert.equal(this.registry.getKeyMap()['keyCode'][0], 'a');
|
||||
assert.equal(this.registry.getKeyMap()['keyCode'][0], 'a');
|
||||
});
|
||||
test('Gets a copy of the registry', function () {
|
||||
const shortcut = {'name': 'shortcutName'};
|
||||
this.registry.register(shortcut);
|
||||
const registrycopy = this.registry.getRegistry();
|
||||
registrycopy['shortcutName']['name'] = 'shortcutName1';
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
this.registry.getRegistry()['shortcutName']['name'],
|
||||
'shortcutName',
|
||||
);
|
||||
@@ -273,7 +271,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
test('Gets keyboard shortcuts from a key code', function () {
|
||||
this.registry.setKeyMap({'keyCode': ['shortcutName']});
|
||||
const shortcutNames = this.registry.getShortcutNamesByKeyCode('keyCode');
|
||||
chai.assert.equal(shortcutNames[0], 'shortcutName');
|
||||
assert.equal(shortcutNames[0], 'shortcutName');
|
||||
});
|
||||
test('Gets keycodes by shortcut name', function () {
|
||||
this.registry.setKeyMap({
|
||||
@@ -282,9 +280,9 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
});
|
||||
const shortcutNames =
|
||||
this.registry.getKeyCodesByShortcutName('shortcutName');
|
||||
chai.assert.lengthOf(shortcutNames, 2);
|
||||
chai.assert.equal(shortcutNames[0], 'keyCode');
|
||||
chai.assert.equal(shortcutNames[1], 'keyCode1');
|
||||
assert.lengthOf(shortcutNames, 2);
|
||||
assert.equal(shortcutNames[0], 'keyCode');
|
||||
assert.equal(shortcutNames[1], 'keyCode1');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -314,17 +312,17 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
});
|
||||
test('Execute a shortcut from event', function () {
|
||||
const event = createKeyDownEvent(Blockly.utils.KeyCodes.C);
|
||||
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||
assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||
sinon.assert.calledOnce(this.callBackStub);
|
||||
});
|
||||
test('No shortcut executed from event', function () {
|
||||
const event = createKeyDownEvent(Blockly.utils.KeyCodes.D);
|
||||
chai.assert.isFalse(this.registry.onKeyDown(this.workspace, event));
|
||||
assert.isFalse(this.registry.onKeyDown(this.workspace, event));
|
||||
});
|
||||
test('No precondition available - execute callback', function () {
|
||||
delete this.testShortcut['precondition'];
|
||||
const event = createKeyDownEvent(Blockly.utils.KeyCodes.C);
|
||||
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||
assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||
sinon.assert.calledOnce(this.callBackStub);
|
||||
});
|
||||
test('Execute all shortcuts in list', function () {
|
||||
@@ -344,7 +342,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
Blockly.utils.KeyCodes.C,
|
||||
false,
|
||||
);
|
||||
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||
assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||
sinon.assert.calledOnce(testShortcut2Stub);
|
||||
sinon.assert.calledOnce(this.callBackStub);
|
||||
});
|
||||
@@ -365,7 +363,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
Blockly.utils.KeyCodes.C,
|
||||
true,
|
||||
);
|
||||
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||
assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||
sinon.assert.calledOnce(testShortcut2Stub);
|
||||
sinon.assert.notCalled(this.callBackStub);
|
||||
});
|
||||
@@ -376,7 +374,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
const serializedKey = this.registry.createSerializedKey(
|
||||
Blockly.utils.KeyCodes.A,
|
||||
);
|
||||
chai.assert.equal(serializedKey, '65');
|
||||
assert.equal(serializedKey, '65');
|
||||
});
|
||||
|
||||
test('Serialize key code and modifier', function () {
|
||||
@@ -384,32 +382,32 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
Blockly.utils.KeyCodes.A,
|
||||
[Blockly.utils.KeyCodes.CTRL],
|
||||
);
|
||||
chai.assert.equal(serializedKey, 'Control+65');
|
||||
assert.equal(serializedKey, 'Control+65');
|
||||
});
|
||||
test('Serialize only a modifier', function () {
|
||||
const serializedKey = this.registry.createSerializedKey(null, [
|
||||
Blockly.utils.KeyCodes.CTRL,
|
||||
]);
|
||||
chai.assert.equal(serializedKey, 'Control');
|
||||
assert.equal(serializedKey, 'Control');
|
||||
});
|
||||
test('Serialize multiple modifiers', function () {
|
||||
const serializedKey = this.registry.createSerializedKey(null, [
|
||||
Blockly.utils.KeyCodes.CTRL,
|
||||
Blockly.utils.KeyCodes.SHIFT,
|
||||
]);
|
||||
chai.assert.equal(serializedKey, 'Shift+Control');
|
||||
assert.equal(serializedKey, 'Shift+Control');
|
||||
});
|
||||
test('Order of modifiers should result in same serialized key', function () {
|
||||
const serializedKey = this.registry.createSerializedKey(null, [
|
||||
Blockly.utils.KeyCodes.CTRL,
|
||||
Blockly.utils.KeyCodes.SHIFT,
|
||||
]);
|
||||
chai.assert.equal(serializedKey, 'Shift+Control');
|
||||
assert.equal(serializedKey, 'Shift+Control');
|
||||
const serializedKeyNewOrder = this.registry.createSerializedKey(null, [
|
||||
Blockly.utils.KeyCodes.SHIFT,
|
||||
Blockly.utils.KeyCodes.CTRL,
|
||||
]);
|
||||
chai.assert.equal(serializedKeyNewOrder, 'Shift+Control');
|
||||
assert.equal(serializedKeyNewOrder, 'Shift+Control');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -417,19 +415,19 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
test('Serialize key', function () {
|
||||
const mockEvent = createKeyDownEvent(Blockly.utils.KeyCodes.A);
|
||||
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||
chai.assert.equal(serializedKey, '65');
|
||||
assert.equal(serializedKey, '65');
|
||||
});
|
||||
test('Serialize key code and modifier', function () {
|
||||
const mockEvent = createKeyDownEvent(Blockly.utils.KeyCodes.A, [
|
||||
Blockly.utils.KeyCodes.CTRL,
|
||||
]);
|
||||
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||
chai.assert.equal(serializedKey, 'Control+65');
|
||||
assert.equal(serializedKey, 'Control+65');
|
||||
});
|
||||
test('Serialize only a modifier', function () {
|
||||
const mockEvent = createKeyDownEvent(null, [Blockly.utils.KeyCodes.CTRL]);
|
||||
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||
chai.assert.equal(serializedKey, 'Control');
|
||||
assert.equal(serializedKey, 'Control');
|
||||
});
|
||||
test('Serialize multiple modifiers', function () {
|
||||
const mockEvent = createKeyDownEvent(null, [
|
||||
@@ -437,14 +435,14 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
Blockly.utils.KeyCodes.SHIFT,
|
||||
]);
|
||||
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||
chai.assert.equal(serializedKey, 'Shift+Control');
|
||||
assert.equal(serializedKey, 'Shift+Control');
|
||||
});
|
||||
test('Throw error when incorrect modifier', function () {
|
||||
const registry = this.registry;
|
||||
const shouldThrow = function () {
|
||||
registry.createSerializedKey(Blockly.utils.KeyCodes.K, ['s']);
|
||||
};
|
||||
chai.assert.throws(shouldThrow, Error, 's is not a valid modifier key.');
|
||||
assert.throws(shouldThrow, Error, 's is not a valid modifier key.');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../../node_modules/chai/chai.js';
|
||||
import {runTestSuites} from './common.js';
|
||||
|
||||
/**
|
||||
@@ -83,15 +84,13 @@ const createCodeGenerationTestFn_ = (generator) => {
|
||||
}
|
||||
}
|
||||
const assertFunc =
|
||||
typeof testCase.expectedCode === 'string'
|
||||
? chai.assert.equal
|
||||
: chai.assert.match;
|
||||
typeof testCase.expectedCode === 'string' ? assert.equal : assert.match;
|
||||
assertFunc(code, testCase.expectedCode);
|
||||
if (
|
||||
!testCase.useWorkspaceToCode &&
|
||||
testCase.expectedInnerOrder !== undefined
|
||||
) {
|
||||
chai.assert.equal(innerOrder, testCase.expectedInnerOrder);
|
||||
assert.equal(innerOrder, testCase.expectedInnerOrder);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../../node_modules/chai/chai.js';
|
||||
|
||||
/**
|
||||
* Creates spy for workspace fireChangeListener
|
||||
* @param {!Blockly.Workspace} workspace The workspace to spy fireChangeListener
|
||||
@@ -40,7 +42,7 @@ function assertXmlPropertyEqual_(xmlValue, expectedValue, message) {
|
||||
if (expectedValue instanceof Node) {
|
||||
expectedValue = Blockly.Xml.domToText(expectedValue);
|
||||
}
|
||||
chai.assert.equal(value, expectedValue, message);
|
||||
assert.equal(value, expectedValue, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,13 +57,13 @@ function assertXmlProperties_(obj, expectedXmlProperties) {
|
||||
const value = obj[key];
|
||||
const expectedValue = expectedXmlProperties[key];
|
||||
if (expectedValue === undefined) {
|
||||
chai.assert.isUndefined(
|
||||
assert.isUndefined(
|
||||
value,
|
||||
'Expected ' + key + ' property to be undefined',
|
||||
);
|
||||
return;
|
||||
}
|
||||
chai.assert.exists(value, 'Expected ' + key + ' property to exist');
|
||||
assert.exists(value, 'Expected ' + key + ' property to exist');
|
||||
assertXmlPropertyEqual_(value, expectedValue, 'Checking property ' + key);
|
||||
});
|
||||
}
|
||||
@@ -98,35 +100,31 @@ export function assertEventEquals(
|
||||
) {
|
||||
let prependMessage = message ? message + ' ' : '';
|
||||
prependMessage += 'Event fired ';
|
||||
chai.assert.equal(event.type, expectedType, prependMessage + 'type');
|
||||
chai.assert.equal(
|
||||
assert.equal(event.type, expectedType, prependMessage + 'type');
|
||||
assert.equal(
|
||||
event.workspaceId,
|
||||
expectedWorkspaceId,
|
||||
prependMessage + 'workspace id',
|
||||
);
|
||||
chai.assert.equal(
|
||||
event.blockId,
|
||||
expectedBlockId,
|
||||
prependMessage + 'block id',
|
||||
);
|
||||
assert.equal(event.blockId, expectedBlockId, prependMessage + 'block id');
|
||||
Object.keys(expectedProperties).map((key) => {
|
||||
const value = event[key];
|
||||
const expectedValue = expectedProperties[key];
|
||||
if (expectedValue === undefined) {
|
||||
chai.assert.isUndefined(value, prependMessage + key);
|
||||
assert.isUndefined(value, prependMessage + key);
|
||||
return;
|
||||
}
|
||||
chai.assert.exists(value, prependMessage + key);
|
||||
assert.exists(value, prependMessage + key);
|
||||
if (isXmlProperty_(key)) {
|
||||
assertXmlPropertyEqual_(value, expectedValue, prependMessage + key);
|
||||
} else {
|
||||
chai.assert.equal(value, expectedValue, prependMessage + key);
|
||||
assert.equal(value, expectedValue, prependMessage + key);
|
||||
}
|
||||
});
|
||||
if (isUiEvent) {
|
||||
chai.assert.isTrue(event.isUiEvent);
|
||||
assert.isTrue(event.isUiEvent);
|
||||
} else {
|
||||
chai.assert.isFalse(event.isUiEvent);
|
||||
assert.isFalse(event.isUiEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../../node_modules/chai/chai.js';
|
||||
import {runTestCases, TestCase} from './common.js';
|
||||
|
||||
/**
|
||||
@@ -74,8 +75,8 @@ export function assertFieldValue(
|
||||
if (expectedText === undefined) {
|
||||
expectedText = String(expectedValue);
|
||||
}
|
||||
chai.assert.deepEqual(actualValue, expectedValue);
|
||||
chai.assert.deepEqual(actualText, expectedText);
|
||||
assert.deepEqual(actualValue, expectedValue);
|
||||
assert.deepEqual(actualText, expectedText);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +120,7 @@ function runCreationTestsAssertThrows_(testCases, creation) {
|
||||
*/
|
||||
const createTestFn = (testCase) => {
|
||||
return function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
creation.call(this, testCase);
|
||||
}, testCase.errMsgMatcher);
|
||||
};
|
||||
@@ -161,7 +162,7 @@ export function runConstructorSuiteTests(
|
||||
});
|
||||
} else {
|
||||
test('Empty', function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
customCreateWithJs
|
||||
? customCreateWithJs.call(this)
|
||||
: new TestedField();
|
||||
@@ -226,7 +227,7 @@ export function runFromJsonSuiteTests(
|
||||
});
|
||||
} else {
|
||||
test('Empty', function () {
|
||||
chai.assert.throws(function () {
|
||||
assert.throws(function () {
|
||||
customCreateWithJson
|
||||
? customCreateWithJson.call(this)
|
||||
: TestedField.fromJson({});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../../node_modules/chai/chai.js';
|
||||
import {ConnectionType} from '../../../build/src/core/connection_type.js';
|
||||
import {VariableModel} from '../../../build/src/core/variable_model.js';
|
||||
|
||||
@@ -19,7 +20,7 @@ function assertBlockVarModels(block, varIds) {
|
||||
for (let i = 0; i < varIds.length; i++) {
|
||||
expectedVarModels.push(block.workspace.getVariableById(varIds[i]));
|
||||
}
|
||||
chai.assert.sameDeepOrderedMembers(block.getVarModels(), expectedVarModels);
|
||||
assert.sameDeepOrderedMembers(block.getVarModels(), expectedVarModels);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,7 +30,7 @@ function assertBlockVarModels(block, varIds) {
|
||||
*/
|
||||
function assertCallBlockArgsStructure(callBlock, args) {
|
||||
// inputList also contains "TOPROW"
|
||||
chai.assert.equal(
|
||||
assert.equal(
|
||||
callBlock.inputList.length - 1,
|
||||
args.length,
|
||||
'call block has the expected number of args',
|
||||
@@ -38,15 +39,15 @@ function assertCallBlockArgsStructure(callBlock, args) {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const expectedName = args[i];
|
||||
const callInput = callBlock.inputList[i + 1];
|
||||
chai.assert.equal(callInput.type, ConnectionType.INPUT_VALUE);
|
||||
chai.assert.equal(callInput.name, 'ARG' + i);
|
||||
chai.assert.equal(
|
||||
assert.equal(callInput.type, ConnectionType.INPUT_VALUE);
|
||||
assert.equal(callInput.name, 'ARG' + i);
|
||||
assert.equal(
|
||||
callInput.fieldRow[0].getValue(),
|
||||
expectedName,
|
||||
'Call block consts did not match expected.',
|
||||
);
|
||||
}
|
||||
chai.assert.sameOrderedMembers(callBlock.getVars(), args);
|
||||
assert.sameOrderedMembers(callBlock.getVars(), args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,42 +69,42 @@ export function assertDefBlockStructure(
|
||||
hasStatements = true,
|
||||
) {
|
||||
if (hasStatements) {
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
defBlock.getInput('STACK'),
|
||||
'Def block should have STACK input',
|
||||
);
|
||||
} else {
|
||||
chai.assert.isNull(
|
||||
assert.isNull(
|
||||
defBlock.getInput('STACK'),
|
||||
'Def block should not have STACK input',
|
||||
);
|
||||
}
|
||||
if (hasReturn) {
|
||||
chai.assert.isNotNull(
|
||||
assert.isNotNull(
|
||||
defBlock.getInput('RETURN'),
|
||||
'Def block should have RETURN input',
|
||||
);
|
||||
} else {
|
||||
chai.assert.isNull(
|
||||
assert.isNull(
|
||||
defBlock.getInput('RETURN'),
|
||||
'Def block should not have RETURN input',
|
||||
);
|
||||
}
|
||||
if (args.length) {
|
||||
chai.assert.include(
|
||||
assert.include(
|
||||
defBlock.toString(),
|
||||
'with',
|
||||
'Def block string should include "with"',
|
||||
);
|
||||
} else {
|
||||
chai.assert.notInclude(
|
||||
assert.notInclude(
|
||||
defBlock.toString(),
|
||||
'with',
|
||||
'Def block string should not include "with"',
|
||||
);
|
||||
}
|
||||
|
||||
chai.assert.sameOrderedMembers(defBlock.getVars(), args);
|
||||
assert.sameOrderedMembers(defBlock.getVars(), args);
|
||||
assertBlockVarModels(defBlock, varIds);
|
||||
}
|
||||
|
||||
@@ -122,15 +123,15 @@ export function assertCallBlockStructure(
|
||||
name = undefined,
|
||||
) {
|
||||
if (args.length) {
|
||||
chai.assert.include(callBlock.toString(), 'with');
|
||||
assert.include(callBlock.toString(), 'with');
|
||||
} else {
|
||||
chai.assert.notInclude(callBlock.toString(), 'with');
|
||||
assert.notInclude(callBlock.toString(), 'with');
|
||||
}
|
||||
|
||||
assertCallBlockArgsStructure(callBlock, args);
|
||||
assertBlockVarModels(callBlock, varIds);
|
||||
if (name !== undefined) {
|
||||
chai.assert.equal(callBlock.getFieldValue('NAME'), name);
|
||||
assert.equal(callBlock.getFieldValue('NAME'), name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user