Skip to content

Commit 4353f90

Browse files
authored
Merge pull request #9393 from tashee/tashee-8945-take2
fix: Replace deprecated variable methods in tests (#8945)
2 parents 2c9732d + 38b96dd commit 4353f90

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

tests/mocha/event_test.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -904,19 +904,20 @@ suite('Events', function () {
904904

905905
suite('Variable events', function () {
906906
setup(function () {
907-
this.variable = this.workspace.createVariable('name1', 'type1', 'id1');
907+
this.variableMap = this.workspace.getVariableMap();
908+
this.variable = this.variableMap.createVariable('name1', 'type1', 'id1');
908909
});
909910

910911
/**
911912
* Check if a variable with the given values exists.
912-
* @param {Blockly.Workspace|Blockly.VariableMap} container The workspace or
913-
* variableMap the checked variable belongs to.
913+
* @param {Blockly.VariableMap} variableMap The variableMap
914+
* the checked variable belongs to.
914915
* @param {!string} name The expected name of the variable.
915916
* @param {!string} type The expected type of the variable.
916917
* @param {!string} id The expected id of the variable.
917918
*/
918-
function checkVariableValues(container, name, type, id) {
919-
const variable = container.getVariableById(id);
919+
function checkVariableValues(variableMap, name, type, id) {
920+
const variable = variableMap.getVariableById(id);
920921
assert.isDefined(variable);
921922
assert.equal(name, variable.name);
922923
assert.equal(type, variable.type);
@@ -994,30 +995,30 @@ suite('Events', function () {
994995
varName: 'name2',
995996
};
996997
const event = eventUtils.fromJson(json, this.workspace);
997-
const x = this.workspace.getVariableById('id2');
998+
const x = this.variableMap.getVariableById('id2');
998999
assert.isNull(x);
9991000
event.run(true);
10001001
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
10011002
});
10021003

10031004
test('Var delete', function () {
10041005
const event = new Blockly.Events.VarDelete(this.variable);
1005-
assert.isNotNull(this.workspace.getVariableById('id1'));
1006+
assert.isNotNull(this.variableMap.getVariableById('id1'));
10061007
event.run(true);
1007-
assert.isNull(this.workspace.getVariableById('id1'));
1008+
assert.isNull(this.variableMap.getVariableById('id1'));
10081009
});
10091010

10101011
test('Var rename', function () {
10111012
const event = new Blockly.Events.VarRename(this.variable, 'name2');
10121013
event.run(true);
1013-
assert.isNull(this.workspace.getVariable('name1'));
1014-
checkVariableValues(this.workspace, 'name2', 'type1', 'id1');
1014+
assert.isNull(this.variableMap.getVariable('name1'));
1015+
checkVariableValues(this.variableMap, 'name2', 'type1', 'id1');
10151016
});
10161017
});
10171018
suite('Run Backward', function () {
10181019
test('Var create', function () {
10191020
const event = new Blockly.Events.VarCreate(this.variable);
1020-
assert.isNotNull(this.workspace.getVariableById('id1'));
1021+
assert.isNotNull(this.variableMap.getVariableById('id1'));
10211022
event.run(false);
10221023
});
10231024

@@ -1029,16 +1030,16 @@ suite('Events', function () {
10291030
varName: 'name2',
10301031
};
10311032
const event = eventUtils.fromJson(json, this.workspace);
1032-
assert.isNull(this.workspace.getVariableById('id2'));
1033+
assert.isNull(this.variableMap.getVariableById('id2'));
10331034
event.run(false);
1034-
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
1035+
assertVariableValues(this.variableMap, 'name2', 'type2', 'id2');
10351036
});
10361037

10371038
test('Var rename', function () {
10381039
const event = new Blockly.Events.VarRename(this.variable, 'name2');
10391040
event.run(false);
1040-
assert.isNull(this.workspace.getVariable('name2'));
1041-
checkVariableValues(this.workspace, 'name1', 'type1', 'id1');
1041+
assert.isNull(this.variableMap.getVariable('name2'));
1042+
checkVariableValues(this.variableMap, 'name1', 'type1', 'id1');
10421043
});
10431044
});
10441045
});
@@ -1431,7 +1432,9 @@ suite('Events', function () {
14311432
);
14321433

14331434
// Expect the workspace to not have a variable with ID 'test_block_id'.
1434-
assert.isNull(this.workspace.getVariableById(TEST_BLOCK_ID));
1435+
assert.isNull(
1436+
this.workspace.getVariableMap().getVariableById(TEST_BLOCK_ID),
1437+
);
14351438
} finally {
14361439
workspaceTeardown.call(this, workspaceSvg);
14371440
}
@@ -1481,7 +1484,9 @@ suite('Events', function () {
14811484
);
14821485

14831486
// Expect the workspace to have a variable with ID 'test_var_id'.
1484-
assert.isNotNull(this.workspace.getVariableById(TEST_VAR_ID));
1487+
assert.isNotNull(
1488+
this.workspace.getVariableMap().getVariableById(TEST_VAR_ID),
1489+
);
14851490
});
14861491

14871492
test('New block new var xml', function () {

0 commit comments

Comments
 (0)