mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
* chore(deps): Add pretter-plugin-organize-imports * chore: Remove insignificant blank lines in import sections Since prettier-plugin-organize-imports sorts imports within sections separated by blank lines, but preserves the section divisions, remove any blank lines that are not dividing imports into meaningful sections. Do not remove blank lines separating side-effect-only imports from main imports. * chore: Remove unneded eslint-disable directives * chore: Organise imports
71 lines
2.2 KiB
JavaScript
71 lines
2.2 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2023 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import {callbackFactory} from '../../build/src/core/contextmenu.js';
|
|
import * as xmlUtils from '../../build/src/core/utils/xml.js';
|
|
import * as Variables from '../../build/src/core/variables.js';
|
|
import {assert} from '../../node_modules/chai/chai.js';
|
|
import {
|
|
sharedTestSetup,
|
|
sharedTestTeardown,
|
|
} from './test_helpers/setup_teardown.js';
|
|
|
|
suite('Context Menu', function () {
|
|
setup(function () {
|
|
sharedTestSetup.call(this);
|
|
|
|
// Creates a WorkspaceSVG
|
|
const toolbox = document.getElementById('toolbox-categories');
|
|
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
|
});
|
|
|
|
teardown(function () {
|
|
sharedTestTeardown.call(this);
|
|
});
|
|
|
|
suite('Callback Factory', function () {
|
|
setup(function () {
|
|
this.forLoopBlock = this.workspace.newBlock('controls_for');
|
|
});
|
|
|
|
test('callback with xml state creates block', function () {
|
|
const xmlField = Variables.generateVariableFieldDom(
|
|
this.forLoopBlock.getField('VAR').getVariable(),
|
|
);
|
|
const xmlBlock = xmlUtils.createElement('block');
|
|
xmlBlock.setAttribute('type', 'variables_get');
|
|
xmlBlock.appendChild(xmlField);
|
|
|
|
const callback = callbackFactory(this.forLoopBlock, xmlBlock);
|
|
const getVarBlock = callback();
|
|
|
|
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(),
|
|
);
|
|
});
|
|
|
|
test('callback with json state creates block', function () {
|
|
const jsonState = {
|
|
type: 'variables_get',
|
|
fields: {VAR: this.forLoopBlock.getField('VAR').saveState(true)},
|
|
};
|
|
|
|
const callback = callbackFactory(this.forLoopBlock, jsonState);
|
|
const getVarBlock = callback();
|
|
|
|
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(),
|
|
);
|
|
});
|
|
});
|
|
});
|