From d592467e33d6bce39a12fe8c11c1fb4f3eca8ed8 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Thu, 23 Feb 2023 19:05:20 +0000 Subject: [PATCH] chore: fixup tests --- core/block_svg.ts | 16 ++++++------ core/field.ts | 11 +++++--- core/input.ts | 2 +- tests/mocha/block_test.js | 36 ++++++++++++--------------- tests/mocha/blocks/procedures_test.js | 1 + tests/mocha/field_checkbox_test.js | 2 +- tests/mocha/input_test.js | 2 +- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/core/block_svg.ts b/core/block_svg.ts index 8d503fb7480..ee21986f848 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -515,13 +515,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, return; } super.setCollapsed(collapsed); - if (!collapsed) { - this.updateCollapsed_(); - } else if (this.rendered) { - this.queueRender(); - // Don't bump neighbours. Users like to store collapsed functions together - // and bumping makes them go out of alignment. - } + this.updateCollapsed_(); } /** @@ -1452,9 +1446,10 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, const group = eventUtils.getGroup(); this.bumpNeighboursPid = setTimeout(() => { + const oldGroup = eventUtils.getGroup(); eventUtils.setGroup(group); this.getRootBlock().bumpNeighboursInternal(); - eventUtils.setGroup(false); + eventUtils.setGroup(oldGroup); this.bumpNeighboursPid = 0; }, config.bumpDelay); } @@ -1653,6 +1648,11 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, // TODO(#4592): Update all markers on the block. this.workspace.getMarker(MarkerManager.LOCAL_MARKER)!.draw(); } + for (const input of this.inputList) { + for (const field of input.fieldRow) { + field.updateMarkers_(); + } + } } /** diff --git a/core/field.ts b/core/field.ts index 3675bd1740d..6abb9516c25 100644 --- a/core/field.ts +++ b/core/field.ts @@ -962,9 +962,8 @@ export abstract class Field implements IASTNodeLocationSvg, forceRerender() { this.isDirty_ = true; if (this.sourceBlock_ && this.sourceBlock_.rendered) { - (this.sourceBlock_ as BlockSvg).render(); + (this.sourceBlock_ as BlockSvg).queueRender(); (this.sourceBlock_ as BlockSvg).bumpNeighbours(); - this.updateMarkers_(); } } @@ -1288,8 +1287,12 @@ export abstract class Field implements IASTNodeLocationSvg, this.markerSvg_ = markerSvg; } - /** Redraw any attached marker or cursor svgs if needed. */ - protected updateMarkers_() { + /** + * Redraw any attached marker or cursor svgs if needed. + * + * @internal + */ + updateMarkers_() { const block = this.getSourceBlock(); if (!block) { throw new UnattachedFieldError(); diff --git a/core/input.ts b/core/input.ts index b4611014d65..5b25f5797a0 100644 --- a/core/input.ts +++ b/core/input.ts @@ -148,7 +148,7 @@ export class Input { field.dispose(); this.fieldRow.splice(i, 1); if (this.sourceBlock.rendered) { - (this.sourceBlock as BlockSvg).render(); + (this.sourceBlock as BlockSvg).queueRender(); // Removing a field will cause the block to change shape. this.sourceBlock.bumpNeighbours(); } diff --git a/tests/mocha/block_test.js b/tests/mocha/block_test.js index 21e4ecbfc2d..d04868b560d 100644 --- a/tests/mocha/block_test.js +++ b/tests/mocha/block_test.js @@ -1112,48 +1112,42 @@ suite('Blocks', function() { suite('Add Connections Programmatically', function() { test('Output', function() { const block = createRenderedBlock(this.workspace, 'empty_block'); - // this.workspace.newBlock('empty_block'); - // block.initSvg(); - // block.render(); block.setOutput(true); + this.clock.runAll(); chai.assert.equal(this.getOutputs().length, 1); }); test('Value', function() { - const block = this.workspace.newBlock('empty_block'); - block.initSvg(); - block.render(); + const block = createRenderedBlock(this.workspace, 'empty_block'); block.appendValueInput('INPUT'); + this.clock.runAll(); chai.assert.equal(this.getInputs().length, 1); }); test('Previous', function() { - const block = this.workspace.newBlock('empty_block'); - block.initSvg(); - block.render(); + const block = createRenderedBlock(this.workspace, 'empty_block'); block.setPreviousStatement(true); + this.clock.runAll(); chai.assert.equal(this.getPrevious().length, 1); }); test('Next', function() { - const block = this.workspace.newBlock('empty_block'); - block.initSvg(); - block.render(); + const block = createRenderedBlock(this.workspace, 'empty_block'); block.setNextStatement(true); + this.clock.runAll(); chai.assert.equal(this.getNext().length, 1); }); test('Statement', function() { - const block = this.workspace.newBlock('empty_block'); - block.initSvg(); - block.render(); + const block = createRenderedBlock(this.workspace, 'empty_block'); block.appendStatementInput('STATEMENT'); + this.clock.runAll(); chai.assert.equal(this.getNext().length, 1); }); }); @@ -1719,8 +1713,10 @@ suite('Blocks', function() { test('Add Input', function() { const blockA = createRenderedBlock(this.workspace, 'empty_block'); blockA.setCollapsed(true); - assertCollapsed(blockA); + blockA.appendDummyInput('NAME'); + + this.clock.runAll(); assertCollapsed(blockA); chai.assert.isNotNull(blockA.getInput('NAME')); }); @@ -1794,20 +1790,20 @@ suite('Blocks', function() { const blockA = createRenderedBlock(this.workspace, 'variable_block'); blockA.setCollapsed(true); - assertCollapsed(blockA, 'x'); - const variable = this.workspace.getVariable('x', ''); this.workspace.renameVariableById(variable.getId(), 'y'); + + this.clock.runAll(); assertCollapsed(blockA, 'y'); }); test('Coalesce, Different Case', function() { const blockA = createRenderedBlock(this.workspace, 'variable_block'); blockA.setCollapsed(true); - assertCollapsed(blockA, 'x'); - const variable = this.workspace.createVariable('y'); this.workspace.renameVariableById(variable.getId(), 'X'); + + this.clock.runAll(); assertCollapsed(blockA, 'X'); }); }); diff --git a/tests/mocha/blocks/procedures_test.js b/tests/mocha/blocks/procedures_test.js index 911fda4d244..0f17772cdf3 100644 --- a/tests/mocha/blocks/procedures_test.js +++ b/tests/mocha/blocks/procedures_test.js @@ -541,6 +541,7 @@ suite('Procedures', function() { Blockly.Events.setGroup(false); this.workspace.undo(); + this.clock.runAll(); chai.assert.isTrue( defBlock.getFieldValue('PARAMS').includes('param1'), diff --git a/tests/mocha/field_checkbox_test.js b/tests/mocha/field_checkbox_test.js index 771ce662707..2e491c8555b 100644 --- a/tests/mocha/field_checkbox_test.js +++ b/tests/mocha/field_checkbox_test.js @@ -152,7 +152,7 @@ suite('Checkbox Fields', function() { workspace: { keyboardAccessibilityMode: false, }, - render: function() {field.render_();}, + queueRender: function() {field.render_();}, bumpNeighbours: function() {}, }; field.constants_ = { diff --git a/tests/mocha/input_test.js b/tests/mocha/input_test.js index f20f4c940c9..6016a8f53e7 100644 --- a/tests/mocha/input_test.js +++ b/tests/mocha/input_test.js @@ -23,7 +23,7 @@ suite('Inputs', function() { '' ), this.workspace); - this.renderStub = sinon.stub(this.block, 'render'); + this.renderStub = sinon.stub(this.block, 'queueRender'); this.bumpNeighboursStub = sinon.stub(this.block, 'bumpNeighbours'); this.dummy = this.block.appendDummyInput('DUMMY');