mirror of
https://github.com/google/blockly.git
synced 2026-01-05 08:00:09 +01:00
* chore(deps): Bump chai from 4.3.10 to 5.1.1 Bumps [chai](https://github.com/chaijs/chai) from 4.3.10 to 5.1.1. - [Release notes](https://github.com/chaijs/chai/releases) - [Changelog](https://github.com/chaijs/chai/blob/main/History.md) - [Commits](https://github.com/chaijs/chai/compare/v4.3.10...v5.1.1) --- updated-dependencies: - dependency-name: chai dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix(tests): Migrate all usage of chai to ESM (#8216) * fix(tests): Migrate node tests from CJS to ESM This allows us to import (rather than require) chai, fixing failures caused by that package dropping suppport for CJS in chai v5.0.0. * fix(tests): Have mocha tests directly import chai Previously they relied on obtaining it from the global scope, but it's better if imports are explicit. * fix(tests): Remove broken load of chai as script Chai v5.0.0 no longer supports being loaded as a script, so this did nothing but emit an syntax error message on the console. * fix(tests): Migrate browser tests from CJS to ESM This allows us to import (rather than require) chai, fixing failures caused by chai no longer supporting CJS. * chore(tests): format --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Christopher Allen <cpcallen+git@google.com>
189 lines
5.8 KiB
JavaScript
189 lines
5.8 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2024 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import {assert} from '../../node_modules/chai/chai.js';
|
|
import {
|
|
sharedTestSetup,
|
|
sharedTestTeardown,
|
|
} from './test_helpers/setup_teardown.js';
|
|
|
|
suite('Workspace comment', function () {
|
|
setup(function () {
|
|
sharedTestSetup.call(this);
|
|
this.workspace = new Blockly.inject('blocklyDiv', {});
|
|
this.commentView = new Blockly.comments.CommentView(this.workspace);
|
|
});
|
|
|
|
teardown(function () {
|
|
sharedTestTeardown.call(this);
|
|
});
|
|
|
|
suite('Listeners', function () {
|
|
suite('Text change listeners', function () {
|
|
test('text change listeners are called when text is changed', function () {
|
|
const spy = sinon.spy();
|
|
this.commentView.addTextChangeListener(spy);
|
|
|
|
this.commentView.setText('test');
|
|
|
|
assert.isTrue(spy.calledOnce, 'Expected the spy to be called once');
|
|
assert.isTrue(
|
|
spy.calledWith('', 'test'),
|
|
'Expected the spy to be called with the given args',
|
|
);
|
|
});
|
|
|
|
test('text change listeners can remove themselves without skipping others', function () {
|
|
const fake1 = sinon.fake();
|
|
const fake2 = sinon.fake(() =>
|
|
this.commentView.removeTextChangeListener(fake2),
|
|
);
|
|
const fake3 = sinon.fake();
|
|
this.commentView.addTextChangeListener(fake1);
|
|
this.commentView.addTextChangeListener(fake2);
|
|
this.commentView.addTextChangeListener(fake3);
|
|
|
|
this.commentView.setText('test');
|
|
|
|
assert.isTrue(
|
|
fake1.calledOnce,
|
|
'Expected the first listener to be called',
|
|
);
|
|
assert.isTrue(
|
|
fake2.calledOnce,
|
|
'Expected the second listener to be called',
|
|
);
|
|
assert.isTrue(
|
|
fake3.calledOnce,
|
|
'Expected the third listener to be called',
|
|
);
|
|
});
|
|
});
|
|
|
|
suite('Size change listeners', function () {
|
|
test('size change listeners are called when text is changed', function () {
|
|
const spy = sinon.spy();
|
|
this.commentView.addSizeChangeListener(spy);
|
|
const originalSize = this.commentView.getSize();
|
|
const newSize = new Blockly.utils.Size(1337, 1337);
|
|
|
|
this.commentView.setSize(newSize);
|
|
|
|
assert.isTrue(spy.calledOnce, 'Expected the spy to be called once');
|
|
assert.isTrue(
|
|
spy.calledWith(originalSize, newSize),
|
|
'Expected the spy to be called with the given args',
|
|
);
|
|
});
|
|
|
|
test('size change listeners can remove themselves without skipping others', function () {
|
|
const fake1 = sinon.fake();
|
|
const fake2 = sinon.fake(() =>
|
|
this.commentView.removeSizeChangeListener(fake2),
|
|
);
|
|
const fake3 = sinon.fake();
|
|
this.commentView.addSizeChangeListener(fake1);
|
|
this.commentView.addSizeChangeListener(fake2);
|
|
this.commentView.addSizeChangeListener(fake3);
|
|
const newSize = new Blockly.utils.Size(1337, 1337);
|
|
|
|
this.commentView.setSize(newSize);
|
|
|
|
assert.isTrue(
|
|
fake1.calledOnce,
|
|
'Expected the first listener to be called',
|
|
);
|
|
assert.isTrue(
|
|
fake2.calledOnce,
|
|
'Expected the second listener to be called',
|
|
);
|
|
assert.isTrue(
|
|
fake3.calledOnce,
|
|
'Expected the third listener to be called',
|
|
);
|
|
});
|
|
});
|
|
|
|
suite('Collapse change listeners', function () {
|
|
test('collapse change listeners are called when text is changed', function () {
|
|
const spy = sinon.spy();
|
|
this.commentView.addOnCollapseListener(spy);
|
|
|
|
this.commentView.setCollapsed(true);
|
|
|
|
assert.isTrue(spy.calledOnce, 'Expected the spy to be called once');
|
|
assert.isTrue(
|
|
spy.calledWith(true),
|
|
'Expected the spy to be called with the given args',
|
|
);
|
|
});
|
|
|
|
test('collapse change listeners can remove themselves without skipping others', function () {
|
|
const fake1 = sinon.fake();
|
|
const fake2 = sinon.fake(() =>
|
|
this.commentView.removeOnCollapseListener(fake2),
|
|
);
|
|
const fake3 = sinon.fake();
|
|
this.commentView.addOnCollapseListener(fake1);
|
|
this.commentView.addOnCollapseListener(fake2);
|
|
this.commentView.addOnCollapseListener(fake3);
|
|
|
|
this.commentView.setCollapsed(true);
|
|
|
|
assert.isTrue(
|
|
fake1.calledOnce,
|
|
'Expected the first listener to be called',
|
|
);
|
|
assert.isTrue(
|
|
fake2.calledOnce,
|
|
'Expected the second listener to be called',
|
|
);
|
|
assert.isTrue(
|
|
fake3.calledOnce,
|
|
'Expected the third listener to be called',
|
|
);
|
|
});
|
|
});
|
|
|
|
suite('Dispose change listeners', function () {
|
|
test('dispose listeners are called when text is changed', function () {
|
|
const spy = sinon.spy();
|
|
this.commentView.addDisposeListener(spy);
|
|
|
|
this.commentView.dispose();
|
|
|
|
assert.isTrue(spy.calledOnce, 'Expected the spy to be called once');
|
|
});
|
|
|
|
test('dispose listeners can remove themselves without skipping others', function () {
|
|
const fake1 = sinon.fake();
|
|
const fake2 = sinon.fake(() =>
|
|
this.commentView.removeDisposeListener(fake2),
|
|
);
|
|
const fake3 = sinon.fake();
|
|
this.commentView.addDisposeListener(fake1);
|
|
this.commentView.addDisposeListener(fake2);
|
|
this.commentView.addDisposeListener(fake3);
|
|
|
|
this.commentView.dispose();
|
|
|
|
assert.isTrue(
|
|
fake1.calledOnce,
|
|
'Expected the first listener to be called',
|
|
);
|
|
assert.isTrue(
|
|
fake2.calledOnce,
|
|
'Expected the second listener to be called',
|
|
);
|
|
assert.isTrue(
|
|
fake3.calledOnce,
|
|
'Expected the third listener to be called',
|
|
);
|
|
});
|
|
});
|
|
});
|
|
});
|