fix: bad order of checks for setting flyout visibility (#5681)

* chore: fix redeclares in tests

* fix: bad order of checks for setting flyout visibility
This commit is contained in:
Rachel Fenichel
2021-11-05 12:07:38 -07:00
committed by GitHub
parent 1c3f4f0524
commit 3eb5c95478
3 changed files with 7 additions and 4 deletions

View File

@@ -968,7 +968,7 @@ Toolbox.prototype.selectItemByPosition = function(position) {
* @protected
*/
Toolbox.prototype.updateFlyout_ = function(oldItem, newItem) {
if ((oldItem === newItem && !newItem.isCollapsible()) || !newItem ||
if (!newItem || (oldItem === newItem && !newItem.isCollapsible()) ||
!newItem.getContents().length) {
this.flyout_.hide();
} else {

View File

@@ -204,8 +204,8 @@ suite('InsertionMarkers', function() {
});
suite('Serialization', function() {
setup(function() {
this.assertXml = function(xml, expectXml) {
Blockly.Xml.domToWorkspace(xml, this.workspace);
this.assertXml = function(xmlIn, expectXml) {
Blockly.Xml.domToWorkspace(xmlIn, this.workspace);
let block = this.workspace.getBlockById('insertion');
block.setInsertionMarker(true);
let xml = Blockly.Xml.workspaceToDom(this.workspace);

View File

@@ -407,7 +407,6 @@ suite('Toolbox', function() {
function testHideFlyout(toolbox, oldItem, newItem) {
let updateFlyoutStub = sinon.stub(toolbox.flyout_, 'hide');
const newItem = getNonCollapsibleItem(toolbox);
toolbox.updateFlyout_(oldItem, newItem);
sinon.assert.called(updateFlyoutStub);
}
@@ -419,6 +418,10 @@ suite('Toolbox', function() {
test('No new item -> Should close flyout', function() {
testHideFlyout(this.toolbox, null, null);
});
test('Old item but no new item -> Should close flyout', function() {
let oldItem = getNonCollapsibleItem(this.toolbox);
testHideFlyout(this.toolbox, oldItem, null);
});
test('Select collapsible item -> Should close flyout', function() {
let newItem = getCollapsibleItem(this.toolbox);
testHideFlyout(this.toolbox, null, newItem);