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

cleanup: Change type defs for state types to records #5313

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
Add tests for plugin hooks
  • Loading branch information
BeksOmega committed Aug 19, 2021
commit 3bfb1942c53ffa47decff96221cd269c62481223
68 changes: 68 additions & 0 deletions tests/mocha/jso_deserialization_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,4 +676,72 @@ suite('JSO Deserialization', function() {
});
});
});

test('Priority', function() {
const blocksSerializer = Blockly.registry.getClass(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'blocks');
const variablesSerializer = Blockly.registry.getClass(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'variables');

Blockly.registry.unregister(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'blocks');
Blockly.registry.unregister(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'variables');

const calls = [];

const first = {
priority: 100,
save: () => null,
load: () => calls.push('first-load'),
clear: () => calls.push('first-clear'),
};
const second = {
priority: 0,
save: () => null,
load: () => calls.push('second-load'),
clear: () => calls.push('second-clear'),
};
const third = {
priority: -10,
save: () => null,
load: () => calls.push('third-load'),
clear: () => calls.push('third-clear'),
};

Blockly.registry.register(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'third', third);
Blockly.registry.register(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'first', first);
Blockly.registry.register(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'second', second);

Blockly.serialization.load(
{'first': {}, 'third': {}, 'second': {}}, this.workspace);

Blockly.registry.unregister(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'first');
Blockly.registry.unregister(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'second');
Blockly.registry.unregister(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'third');

Blockly.registry.register(
Blockly.registry.Type.PLUGIN_SERIALIZER, 'blocks', blocksSerializer);
Blockly.registry.register(
Blockly.registry.Type.PLUGIN_SERIALIZER,
'variables',
variablesSerializer);

chai.assert.deepEqual(
calls,
[
'third-clear',
'second-clear',
'first-clear',
'first-load',
'second-load',
'third-load'
]);
});
});