Files
blockly/tests/mocha/zoom_controls_test.js
Beka Westberg 2edd228117 fix: move test helpers from samples into core (#5969)
* fix: move core test helpers into new directory

* fix: add test helpers to core and convert to goog modules

* fix: change tests to use local helpers

* fix: change local tests to use chai asserts

* fix: skip field tests in serializer b/c test blocks are unavailable

* fix: rename some helper files

* fix: rename some helper modules

* fix: split block helpers into code gen and serialization

* fix: split block defs into new helper file

* fix: split warning helpers into new file

* fix: split user input helpers into new file

* fix: split event helpers into a new file

* fix: split variable helper into new file

* fix: move remaining test helpers to new setup-teardown file

* fix: rename setup and teardown module

* fix: cleanup from rebase

* fix: undo accidental rename

* fix: lint?

* fix: bad toolbox definitions namespace

* fix: fixup warning helpers

* fix: remove inclusion of dev-tools in mocha tests

* move to modules, but break mocha

* fix: run mocha as a module

* fix: lint
2022-03-04 13:10:03 -08:00

67 lines
2.3 KiB
JavaScript

/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.module('Blockly.test.zoomControls');
const {assertEventFired, assertEventNotFired} = goog.require('Blockly.test.helpers.events');
const eventUtils = goog.require('Blockly.Events.utils');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
const {simulateClick} = goog.require('Blockly.test.helpers.userInput');
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', type: eventUtils.CLICK}, this.workspace.id, null);
assertEventNotFired(
this.eventsFireStub, Blockly.Events.Click,
{targetType: 'workspace', type: eventUtils.CLICK});
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', type: eventUtils.CLICK}, this.workspace.id, null);
assertEventNotFired(
this.eventsFireStub, Blockly.Events.Click,
{targetType: 'workspace', type: eventUtils.CLICK});
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', type: eventUtils.CLICK}, this.workspace.id, null);
assertEventNotFired(
this.eventsFireStub, Blockly.Events.Click,
{targetType: 'workspace', type: eventUtils.CLICK});
chai.assert.equal(this.workspace.getScale(), 1);
});
});
});