Skip to content

Commit a21ccce

Browse files
feat: add clipboard whilst block dragging test
1 parent 295f1d2 commit a21ccce

File tree

2 files changed

+108
-11
lines changed

2 files changed

+108
-11
lines changed

test/webdriverio/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ function addP5() {
110110

111111
document.addEventListener('DOMContentLoaded', () => {
112112
addP5();
113-
createWorkspace();
113+
// Add workspace to the global scope so that test code can access it to
114+
// verify state after keypresses.
115+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
116+
// @ts-expect-error
117+
window.workspace = createWorkspace();
114118
// Add Blockly to the global scope so that test code can access it to
115119
// verify state after keypresses.
116120
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

test/webdriverio/test/clipboard_test.mjs

Lines changed: 103 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ suite('Clipboard test', function () {
2020

2121
test('Copy and paste while block selected', async function () {
2222
// Click on simple circle block
23-
const block = await this.browser.$('g.simple_circle.blocklyBlock.blocklyDraggable > g:nth-child(3)');
23+
const block = await this.browser.$(
24+
'g.simple_circle.blocklyBlock.blocklyDraggable > g:nth-child(3)',
25+
);
2426
await block.click();
2527

2628
// Copy and paste
2729
await this.browser.keys([Key.Ctrl, 'c']);
2830
await this.browser.keys([Key.Ctrl, 'v']);
2931
await this.browser.pause(PAUSE_TIME);
3032

31-
const blocks = await this.browser.$$('g.simple_circle.blocklyBlock.blocklyDraggable');
32-
const duplicatedBlockId = await blocks[0].getAttribute('data-id')
33+
const blocks = await this.browser.$$(
34+
'g.simple_circle.blocklyBlock.blocklyDraggable',
35+
);
36+
const duplicatedBlockId = await blocks[0].getAttribute('data-id');
3337
const selectedId = await this.browser.execute(() => {
3438
return Blockly.common.getSelected().id;
3539
});
@@ -40,23 +44,112 @@ suite('Clipboard test', function () {
4044

4145
test('Cut and paste while connection selected', async function () {
4246
// Click on simple circle block
43-
const block = await this.browser.$('g.simple_circle.blocklyBlock.blocklyDraggable > g:nth-child(3)');
47+
const block = await this.browser.$(
48+
'g.simple_circle.blocklyBlock.blocklyDraggable > g:nth-child(3)',
49+
);
4450
await block.click();
4551

4652
// Cut and paste
4753
await this.browser.keys([Key.Ctrl, 'x']);
48-
await block.waitForExist({ reverse: true })
54+
await block.waitForExist({reverse: true});
4955
await this.browser.keys([Key.Ctrl, 'v']);
50-
await block.waitForExist()
56+
await block.waitForExist();
5157
await this.browser.pause(PAUSE_TIME);
5258

53-
const blocks = await this.browser.$$('g.simple_circle.blocklyBlock.blocklyDraggable');
54-
const duplicatedBlockId = await blocks[0].getAttribute('data-id')
59+
const blocks = await this.browser.$$(
60+
'g.simple_circle.blocklyBlock.blocklyDraggable',
61+
);
62+
const duplicatedBlockId = await blocks[0].getAttribute('data-id');
5563
const selectedId = await this.browser.execute(() => {
5664
return Blockly.common.getSelected().id;
57-
})
65+
});
5866

5967
chai.assert.equal(blocks.length, 1);
6068
chai.assert.equal(selectedId, duplicatedBlockId);
6169
});
62-
});
70+
71+
test('Copy and paste whilst dragging block', async function () {
72+
// Click on simple circle block
73+
const block = await this.browser.$(
74+
'g.simple_circle.blocklyBlock.blocklyDraggable > g:nth-child(3)',
75+
);
76+
await block.click();
77+
78+
const blocksBeforeJson = await this.browser.execute(() => {
79+
return Blockly.serialization.workspaces.save(this.workspace);
80+
});
81+
82+
// Mouse down on circle block
83+
const blockLoc = await block.getLocation();
84+
const blockX = Math.round(blockLoc.x);
85+
const blockY = Math.round(blockLoc.y);
86+
87+
// Simultaneously drag block and Ctrl+C then Ctrl+V
88+
await this.browser.actions([
89+
this.browser
90+
.action('pointer')
91+
.move(blockX, blockY)
92+
.down()
93+
.move(blockX + 20, blockY + 20)
94+
.move(blockX, blockY),
95+
this.browser
96+
.action('key')
97+
.down(Key.Ctrl)
98+
.down('c')
99+
.pause(10)
100+
.up(Key.Ctrl)
101+
.up('c')
102+
.down(Key.Ctrl)
103+
.down('v')
104+
.pause(10)
105+
.up(Key.Ctrl)
106+
.up('v'),
107+
]);
108+
await this.browser.pause(PAUSE_TIME);
109+
const blocksAfterJson = await this.browser.execute(() => {
110+
return Blockly.serialization.workspaces.save(this.workspace);
111+
});
112+
// Assert no change in workspace blocks
113+
chai.assert.deepEqual(blocksBeforeJson, blocksAfterJson);
114+
});
115+
116+
test('Cut whilst dragging block', async function () {
117+
// Click on simple circle block
118+
const block = await this.browser.$(
119+
'g.simple_circle.blocklyBlock.blocklyDraggable > g:nth-child(3)',
120+
);
121+
await block.click();
122+
123+
const blocksBeforeJson = await this.browser.execute(() => {
124+
return Blockly.serialization.workspaces.save(this.workspace);
125+
});
126+
127+
// Mouse down on circle block
128+
const blockLoc = await block.getLocation();
129+
const blockX = Math.round(blockLoc.x);
130+
const blockY = Math.round(blockLoc.y);
131+
132+
// Simultaneously drag block and Ctrl+X
133+
await this.browser.actions([
134+
this.browser
135+
.action('pointer')
136+
.move(blockX, blockY)
137+
.down()
138+
.move(blockX + 20, blockY + 20)
139+
.move(blockX, blockY),
140+
this.browser
141+
.action('key')
142+
.down(Key.Ctrl)
143+
.down('x')
144+
.pause(10)
145+
.up(Key.Ctrl)
146+
.up('x')
147+
]);
148+
await this.browser.pause(PAUSE_TIME);
149+
const blocksAfterJson = await this.browser.execute(() => {
150+
return Blockly.serialization.workspaces.save(this.workspace);
151+
});
152+
// Assert no change in workspace blocks
153+
chai.assert.deepEqual(blocksBeforeJson, blocksAfterJson);
154+
});
155+
});

0 commit comments

Comments
 (0)