Skip to content

Commit 295f1d2

Browse files
feat: add initial test for clipboard
1 parent dd35c9e commit 295f1d2

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import * as chai from 'chai';
8+
import {testSetup, testFileLocations, PAUSE_TIME} from './test_setup.mjs';
9+
import {Key} from 'webdriverio';
10+
11+
suite('Clipboard test', function () {
12+
// Setting timeout to unlimited as these tests take a longer time to run than most mocha test
13+
this.timeout(0);
14+
15+
// Clear the workspace and load start blocks
16+
setup(async function () {
17+
this.browser = await testSetup(testFileLocations.BASE);
18+
await this.browser.pause(PAUSE_TIME);
19+
});
20+
21+
test('Copy and paste while block selected', async function () {
22+
// Click on simple circle block
23+
const block = await this.browser.$('g.simple_circle.blocklyBlock.blocklyDraggable > g:nth-child(3)');
24+
await block.click();
25+
26+
// Copy and paste
27+
await this.browser.keys([Key.Ctrl, 'c']);
28+
await this.browser.keys([Key.Ctrl, 'v']);
29+
await this.browser.pause(PAUSE_TIME);
30+
31+
const blocks = await this.browser.$$('g.simple_circle.blocklyBlock.blocklyDraggable');
32+
const duplicatedBlockId = await blocks[0].getAttribute('data-id')
33+
const selectedId = await this.browser.execute(() => {
34+
return Blockly.common.getSelected().id;
35+
});
36+
37+
chai.assert.equal(blocks.length, 2);
38+
chai.assert.equal(selectedId, duplicatedBlockId);
39+
});
40+
41+
test('Cut and paste while connection selected', async function () {
42+
// Click on simple circle block
43+
const block = await this.browser.$('g.simple_circle.blocklyBlock.blocklyDraggable > g:nth-child(3)');
44+
await block.click();
45+
46+
// Cut and paste
47+
await this.browser.keys([Key.Ctrl, 'x']);
48+
await block.waitForExist({ reverse: true })
49+
await this.browser.keys([Key.Ctrl, 'v']);
50+
await block.waitForExist()
51+
await this.browser.pause(PAUSE_TIME);
52+
53+
const blocks = await this.browser.$$('g.simple_circle.blocklyBlock.blocklyDraggable');
54+
const duplicatedBlockId = await blocks[0].getAttribute('data-id')
55+
const selectedId = await this.browser.execute(() => {
56+
return Blockly.common.getSelected().id;
57+
})
58+
59+
chai.assert.equal(blocks.length, 1);
60+
chai.assert.equal(selectedId, duplicatedBlockId);
61+
});
62+
});

0 commit comments

Comments
 (0)