Files
blockly/tests/browser/test/basic_playground_test.mjs
dependabot[bot] bfb5b1dd49 chore(deps): Bump chai from 4.3.10 to 5.1.1 (#8092)
* 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>
2024-06-17 16:48:21 +01:00

199 lines
5.9 KiB
JavaScript

/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Node.js script to run Automated tests in Chrome, via webdriver.
*/
import * as chai from 'chai';
import {
testSetup,
testFileLocations,
dragNthBlockFromFlyout,
dragBlockTypeFromFlyout,
connect,
contextMenuSelect,
PAUSE_TIME,
} from './test_setup.mjs';
async function getIsCollapsed(browser, blockId) {
return await browser.execute((blockId) => {
return Blockly.getMainWorkspace().getBlockById(blockId).isCollapsed();
}, blockId);
}
async function getIsDisabled(browser, blockId) {
return await browser.execute((blockId) => {
const block = Blockly.getMainWorkspace().getBlockById(blockId);
return !block.isEnabled() || block.getInheritedDisabled();
}, blockId);
}
async function getCommentText(browser, blockId) {
return await browser.execute((blockId) => {
return Blockly.getMainWorkspace().getBlockById(blockId).getCommentText();
}, blockId);
}
suite('Testing Connecting Blocks', function () {
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test
this.timeout(0);
// Setup Selenium for all of the tests
suiteSetup(async function () {
this.browser = await testSetup(testFileLocations.PLAYGROUND);
});
test('dragging a block from the flyout results in a block on the workspace', async function () {
await dragBlockTypeFromFlyout(this.browser, 'Logic', 'controls_if', 20, 20);
const blockCount = await this.browser.execute(() => {
return Blockly.getMainWorkspace().getAllBlocks(false).length;
});
chai.assert.equal(blockCount, 1);
});
});
/**
* These tests have to run together. Each test acts on the state left by the
* previous test, and each test has a single assertion.
*/
suite('Right Clicking on Blocks', function () {
// Setting timeout to unlimited as the webdriver takes a longer time to run than most mocha test
this.timeout(0);
// Setup Selenium for all of the tests
suiteSetup(async function () {
this.browser = await testSetup(testFileLocations.PLAYGROUND);
this.block = await dragNthBlockFromFlyout(this.browser, 'Loops', 0, 20, 20);
});
test('clicking the collapse option collapses the block', async function () {
await contextMenuSelect(this.browser, this.block, 'Collapse Block');
chai.assert.isTrue(await getIsCollapsed(this.browser, this.block.id));
});
// Assumes that
test('clicking the expand option expands the block', async function () {
await contextMenuSelect(this.browser, this.block, 'Expand Block');
chai.assert.isFalse(await getIsCollapsed(this.browser, this.block.id));
});
test('clicking the disable option disables the block', async function () {
await contextMenuSelect(this.browser, this.block, 'Disable Block');
chai.assert.isTrue(await getIsDisabled(this.browser, this.block.id));
});
test('clicking the enable option enables the block', async function () {
await contextMenuSelect(this.browser, this.block, 'Enable Block');
chai.assert.isFalse(await getIsDisabled(this.browser, this.block.id));
});
test('clicking the add comment option adds a comment to the block', async function () {
await contextMenuSelect(this.browser, this.block, 'Add Comment');
chai.assert.equal(await getCommentText(this.browser, this.block.id), '');
});
test('clicking the remove comment option removes a comment from the block', async function () {
await contextMenuSelect(this.browser, this.block, 'Remove Comment');
chai.assert.isNull(await getCommentText(this.browser, this.block.id));
});
});
suite('Disabling', function () {
// Setting timeout to unlimited as the webdriver takes a longer
// time to run than most mocha tests.
this.timeout(0);
suiteSetup(async function () {
this.browser = await testSetup(testFileLocations.PLAYGROUND);
});
setup(async function () {
await this.browser.refresh();
// Pause to allow refresh time to work.
await this.browser.pause(PAUSE_TIME + 150);
});
test(
'children connected to value inputs are disabled when the ' +
'parent is disabled',
async function () {
const parent = await dragBlockTypeFromFlyout(
this.browser,
'Logic',
'controls_if',
10,
10,
);
const child = await dragBlockTypeFromFlyout(
this.browser,
'Logic',
'logic_boolean',
110,
110,
);
await connect(this.browser, child, 'OUTPUT', parent, 'IF0');
await contextMenuSelect(this.browser, parent, 'Disable Block');
chai.assert.isTrue(await getIsDisabled(this.browser, child.id));
},
);
test(
'children connected to statement inputs are disabled when the ' +
'parent is disabled',
async function () {
const parent = await dragBlockTypeFromFlyout(
this.browser,
'Logic',
'controls_if',
10,
10,
);
const child = await dragBlockTypeFromFlyout(
this.browser,
'Logic',
'controls_if',
110,
110,
);
await connect(this.browser, child, 'PREVIOUS', parent, 'DO0');
await contextMenuSelect(this.browser, parent, 'Disable Block');
chai.assert.isTrue(await getIsDisabled(this.browser, child.id));
},
);
test(
'children connected to next connections are not disabled when the ' +
'parent is disabled',
async function () {
const parent = await dragBlockTypeFromFlyout(
this.browser,
'Logic',
'controls_if',
10,
10,
);
const child = await dragBlockTypeFromFlyout(
this.browser,
'Logic',
'controls_if',
110,
110,
);
await connect(this.browser, child, 'PREVIOUS', parent, 'NEXT');
await contextMenuSelect(this.browser, parent, 'Disable Block');
chai.assert.isFalse(await getIsDisabled(this.browser, child.id));
},
);
});