Files
blockly/tests/mocha/zoom_controls_test.js
alschmiedt 5b1586ee1b test: update mocha tests to use goog_module (#5440)
* Use goog.module in mocha tests

* Fix compiler warnings

* Make test helpers a module

* Name test modules Blockly.test.*

This is to be more consistent with how non-test modules are named.

Also remove top-level goog.require of TestHelpers (now
Blockly.test.helpers) since requiring a side-effect-less module does
nothing.

* Convert block_test.js and comment_test.js to goog.module syntax

* Address PR comments

* Goog modulify tests

* Goog modulify toolbox helpers

* Fixes imports and moves common tests from workspace_test.js to a helper file.

* Update test deps after rebase

Co-authored-by: Christopher Allen <cpcallen+git@google.com>
2021-09-16 13:00:38 -07:00

64 lines
2.0 KiB
JavaScript

/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.module('Blockly.test.zoomControls');
const {assertEventFired, assertEventNotFired, sharedTestSetup, sharedTestTeardown, simulateClick} = goog.require('Blockly.test.helpers');
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.Click,
{targetType: 'zoom_controls'}, this.workspace.id, null);
assertEventNotFired(
this.eventsFireStub, Blockly.Events.Click,
{targetType: 'workspace'});
chai.assert.closeTo(this.workspace.getScale(), 1.2, 0.05);
});
test("Zoom out", function() {
simulateClick(this.zoomControls.zoomOutGroup_);
assertEventFired(
this.eventsFireStub, Blockly.Events.Click,
{targetType: 'zoom_controls'}, this.workspace.id, null);
assertEventNotFired(
this.eventsFireStub, Blockly.Events.Click,
{targetType: 'workspace'});
chai.assert.closeTo(this.workspace.getScale(), 0.8, 0.05);
});
test("Reset zoom", function() {
simulateClick(this.zoomControls.zoomResetGroup_);
assertEventFired(
this.eventsFireStub, Blockly.Events.Click,
{targetType: 'zoom_controls'}, this.workspace.id, null);
assertEventNotFired(
this.eventsFireStub, Blockly.Events.Click,
{targetType: 'workspace'});
chai.assert.equal(this.workspace.getScale(), 1);
});
});
});