Files
blockly/tests/mocha/test_helpers.js
Monica Kozbial 0adf7efd5f Converting jsunit asserts to chai. (#3831)
* Converting jsunit asserts to chai.

* Move jsunit functions to test_utilities.

* Adding eslint exception for helper method.
2020-04-17 16:08:46 -07:00

93 lines
2.3 KiB
JavaScript

/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/* exported assertArrayEquals, assertVariableValues, defineRowBlock,
defineStackBlock, defineStatementBlock, createTestBlock */
/**
* Check that two arrays have the same content.
* @param {!Array.<string>} array1 The first array.
* @param {!Array.<string>} array2 The second array.
* @param {?string} opt_message Optional message to pass into assert.
*/
function isEqualArrays(array1, array2, opt_message) {
chai.assert.equal(array1.length, array2.length, opt_message);
for (var i = 0; i < array1.length; i++) {
chai.assert.equal(array1[i], array2[i], opt_message);
}
}
function assertArrayEquals(actualArray, expectedArray, opt_message) {
isEqualArrays(actualArray, expectedArray, opt_message);
}
/**
* Check if a variable with the given values exists.
* @param {Blockly.Workspace|Blockly.VariableMap} container The workspace or
* variableMap the checked variable belongs to.
* @param {!string} name The expected name of the variable.
* @param {!string} type The expected type of the variable.
* @param {!string} id The expected id of the variable.
*/
function assertVariableValues(container, name, type, id) {
var variable = container.getVariableById(id);
chai.assert.isDefined(variable);
chai.assert.equal(variable.name, name);
chai.assert.equal(variable.type, type);
chai.assert.equal(variable.getId(), id);
}
function defineStackBlock() {
Blockly.defineBlocksWithJsonArray([{
"type": "stack_block",
"message0": "",
"previousStatement": null,
"nextStatement": null
}]);
}
function defineRowBlock() {
Blockly.defineBlocksWithJsonArray([{
"type": "row_block",
"message0": "%1",
"args0": [
{
"type": "input_value",
"name": "INPUT"
}
],
"output": null
}]);
}
function defineStatementBlock() {
Blockly.defineBlocksWithJsonArray([{
"type": "statement_block",
"message0": "%1",
"args0": [
{
"type": "input_statement",
"name": "NAME"
}
],
"previousStatement": null,
"nextStatement": null,
"colour": 230,
"tooltip": "",
"helpUrl": ""
}]);
}
function createTestBlock() {
return {
id: 'test',
rendered: false,
workspace: {
rendered: false
}
};
}