Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Google Blockly] Set up ability to test against Google Blockly #37148

Merged
merged 2 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
114 changes: 114 additions & 0 deletions apps/test/unit/sites/studio/pages/googleBlocklyWrapperTest.js
@@ -0,0 +1,114 @@
/* global Blockly GoogleBlockly */
import {expect} from '../../../../util/reconfiguredChai';
import '@cdo/apps/flappy/flappy'; // Importing the app forces the test to load Blockly

describe('Google Blockly Wrapper', () => {
const cdoBlockly = Blockly;
beforeEach(() => {
Blockly = GoogleBlockly; // eslint-disable-line no-global-assign
});
afterEach(() => {
// reset Blockly for other tests
Blockly = cdoBlockly; // eslint-disable-line no-global-assign
});

it('readOnly properties cannot be set', () => {
const readOnlyProperties = [
'ALIGN_CENTRE',
'ALIGN_LEFT',
'ALIGN_RIGHT',
'applab_locale',
'bindEvent_',
'blockRendering',
'Block',
'BlockFieldHelper',
'Blocks',
'BlockSvg',
'BlockValueType',
'common_locale',
'Connection',
'ContextMenu',
'contractEditor',
'createSvgElement',
'Css',
'disableVariableEditing',
'Events',
'FieldAngleDropdown',
'FieldAngleInput',
'FieldAngleTextInput',
'FieldButton',
'FieldColour',
'FieldColourDropdown',
'FieldDropdown',
'FieldIcon',
'FieldImage',
'FieldImageDropdown',
'FieldLabel',
'FieldParameter',
'FieldRectangularDropdown',
'FieldTextInput',
'FieldVariable',
'fireUiEvent',
'fish_locale',
'Flyout',
'FunctionalBlockUtils',
'FunctionalTypeColors',
'FunctionEditor',
'functionEditor',
'gamelab_locale',
'Generator',
'geras',
'getRelativeXY',
'googlecode',
'hasCategories',
'html',
'Input',
'INPUT_VALUE',
'js',
'modalBlockSpace',
'Msg',
'Names',
'netsim_locale',
'Procedures',
'removeChangeListener',
'RTL',
'selected',
'tutorialExplorer_locale',
'useContractEditor',
'useModalFunctionEditor',
'utils',
'Trashcan',
'Variables',
'weblab_locale',
'Workspace',
'WorkspaceSvg',
'Xml'
];
readOnlyProperties.forEach(property => {
expect(() => {
Blockly[property] = 'NEW VALUE';
}).to.throw('Cannot set property');
});
});

it('getGenerator returns the JS Generator', () => {
expect(Blockly.getGenerator()).to.deep.equal(Blockly.blockly_.JavaScript);
});

it('Setting SNAP_RADIUS also sets CONNECTING_SNAP_RADIUS', () => {
Blockly.SNAP_RADIUS = 0;
expect(Blockly.blockly_.CONNECTING_SNAP_RADIUS).to.equal(0);
Blockly.SNAP_RADIUS = 100;
expect(Blockly.blockly_.CONNECTING_SNAP_RADIUS).to.equal(100);
});

it('fieldToDom_ creates title tags', () => {
const field = new Blockly.blockly_.Field(null);
field.SERIALIZABLE = true;
field.name = 'test';
const expectedXml = `<title xmlns="https://developers.google.com/blockly/xml" name="test"></title>`;
expect(Blockly.Xml.domToText(Blockly.Xml.fieldToDom_(field))).to.equal(
expectedXml
);
});
});
10 changes: 10 additions & 0 deletions apps/test/util/frame.js
@@ -1,3 +1,8 @@
import GoogleBlockly from 'blockly/core';
import locale from 'blockly/msg/en';
import 'blockly/blocks';
import 'blockly/javascript';

/**
* Provides the basic frame for running Blockly. In particular, this will
* create a basic dom, load blockly.js and put the contents into the global
Expand All @@ -11,6 +16,11 @@ function setGlobals() {
var blockly = require('@code-dot-org/blockly');
var initializeCdoBlocklyWrapper = require('../../src/sites/studio/pages/cdoBlocklyWrapper');
window.Blockly = initializeCdoBlocklyWrapper(blockly);

GoogleBlockly.setLocale(locale);
var initializeGoogleBlocklyWrapper = require('../../src/sites/studio/pages/googleBlocklyWrapper');
window.GoogleBlockly = initializeGoogleBlocklyWrapper(GoogleBlockly);

try {
require('../../lib/blockly/en_us');
} catch (err) {
Expand Down