Add zoom controls tests. (#4159)

This commit is contained in:
Monica Kozbial
2020-08-12 18:39:35 -07:00
committed by GitHub
parent 6daaa6747e
commit f8f98831af
3 changed files with 59 additions and 3 deletions

View File

@@ -277,7 +277,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) {
// Attach listener.
this.onZoomOutWrapper_ = Blockly.bindEventWithChecks_(
zoomoutSvg, 'mousedown', null, this.zoom_.bind(this, -1));
this.zoomOutGroup_, 'mousedown', null, this.zoom_.bind(this, -1));
};
/**
@@ -328,7 +328,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) {
// Attach listener.
this.onZoomInWrapper_ = Blockly.bindEventWithChecks_(
zoominSvg, 'mousedown', null, this.zoom_.bind(this, 1));
this.zoomInGroup_, 'mousedown', null, this.zoom_.bind(this, 1));
};
/**
@@ -396,7 +396,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) {
// Attach event listeners.
this.onZoomResetWrapper_ = Blockly.bindEventWithChecks_(
zoomresetSvg, 'mousedown', null, this.resetZoom_.bind(this));
this.zoomResetGroup_, 'mousedown', null, this.resetZoom_.bind(this));
};
/**

View File

@@ -86,6 +86,7 @@
<script src="workspace_comment_test.js"></script>
<script src="xml_procedures_test.js"></script>
<script src="xml_test.js"></script>
<script src="zoom_controls_test.js"></script>
<div id="blocklyDiv"></div>
<xml xmlns="https://developers.google.com/blockly/xml" id="toolbox-simple" style="display: none">

View File

@@ -0,0 +1,55 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
suite("Zoom Controls", function() {
setup(function() {
sharedTestSetup.call(this);
this.workspace = Blockly.inject('blocklyDiv',
{'zoom': {'controls': true}});
this.zoomControls = this.workspace.zoomControls_;
});
teardown(function() {
sharedTestTeardown.call(this);
});
suite("Events", function() {
function closeToMatcher(expectedValue, delta) {
return sinon.match(function(value) {
return Math.abs(value - expectedValue) <= delta;
});
}
test("Zoom in", function() {
simulateClick(this.zoomControls.zoomInGroup_);
assertEventFired(
this.eventsFireStub, Blockly.Events.Ui,
{element: 'zoom', oldValue: 1, newValue: closeToMatcher(1.2, 0.05)},
this.workspace.id, null);
assertEventNotFired(
this.eventsFireStub, Blockly.Events.Ui, {element: 'click'});
});
test("Zoom out", function() {
simulateClick(this.zoomControls.zoomOutGroup_);
assertEventFired(
this.eventsFireStub, Blockly.Events.Ui,
{element: 'zoom', oldValue: 1, newValue: closeToMatcher(0.8, 0.05)},
this.workspace.id, null);
assertEventNotFired(
this.eventsFireStub, Blockly.Events.Ui, {element: 'click'});
});
test("Reset zoom", function() {
simulateClick(this.zoomControls.zoomResetGroup_);
assertEventFired(
this.eventsFireStub, Blockly.Events.Ui,
{element: 'zoom', oldValue: 1, newValue: 1},
this.workspace.id, null);
assertEventNotFired(
this.eventsFireStub, Blockly.Events.Ui, {element: 'click'});
});
});
});