fix!: deepMerge for arrays, shortcut keycodes returned as array (#9047)

This commit is contained in:
Maribeth Moffatt
2025-05-14 12:23:12 -07:00
committed by GitHub
parent 523dca92bd
commit 205ef6c7d7
3 changed files with 32 additions and 2 deletions

View File

@@ -260,7 +260,7 @@ suite('Keyboard Shortcut Registry Test', function () {
assert.equal(this.registry.getKeyMap()['keyCode'][0], 'a');
});
test('Gets a copy of the registry', function () {
const shortcut = {'name': 'shortcutName'};
const shortcut = {'name': 'shortcutName', 'keyCodes': ['2', '4']};
this.registry.register(shortcut);
const registrycopy = this.registry.getRegistry();
registrycopy['shortcutName']['name'] = 'shortcutName1';
@@ -268,6 +268,10 @@ suite('Keyboard Shortcut Registry Test', function () {
this.registry.getRegistry()['shortcutName']['name'],
'shortcutName',
);
assert.deepEqual(
this.registry.getRegistry()['shortcutName']['keyCodes'],
shortcut['keyCodes'],
);
});
test('Gets keyboard shortcuts from a key code', function () {
this.registry.setKeyMap({'keyCode': ['shortcutName']});

View File

@@ -533,4 +533,25 @@ suite('Utils', function () {
assert.equal(Blockly.utils.math.toDegrees(5 * quarter), 360 + 90, '450');
});
});
suite('deepMerge', function () {
test('Merges two objects', function () {
const target = {a: 1, b: '2', shared: 'this should be overwritten'};
const source = {c: {deeplyNested: true}, shared: 'I overwrote it'};
const expected = {...target, ...source};
const actual = Blockly.utils.object.deepMerge(target, source);
assert.deepEqual(expected, actual);
});
test('Merges objects with arrays', function () {
const target = {a: 1};
const source = {b: ['orange', 'lime']};
const expected = {...target, ...source};
const actual = Blockly.utils.object.deepMerge(target, source);
assert.deepEqual(expected, actual);
});
});
});