-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathworkspace_comment_test.mjs
More file actions
220 lines (184 loc) · 6.55 KB
/
workspace_comment_test.mjs
File metadata and controls
220 lines (184 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import * as chai from 'chai';
import {testFileLocations, testSetup} from './test_setup.mjs';
suite('Workspace comments', function () {
// Setting timeout to unlimited as the webdriver takes a longer time
// to run than most mocha test
this.timeout(0);
suiteSetup(async function () {
this.browser = await testSetup(
testFileLocations.PLAYGROUND + '?toolbox=test-blocks',
);
});
teardown(async function () {
await this.browser.execute(() => {
Blockly.getMainWorkspace().clear();
});
});
async function createComment(browser) {
return await browser.execute(() => {
const comment = new Blockly.comments.RenderedWorkspaceComment(
Blockly.getMainWorkspace(),
);
return comment.id;
});
}
async function hasClass(elem, className) {
return (await elem.getAttribute('class')).split(' ').includes(className);
}
suite('Collapsing and uncollapsing', function () {
async function isCommentCollapsed(browser, id) {
return await browser.execute(
(id) => Blockly.getMainWorkspace().getCommentById(id).isCollapsed(),
id,
);
}
suite('Collapsing', function () {
test('collapsing updates the collapse value', async function () {
const commentId = await createComment(this.browser);
const foldout = await this.browser.$(
'.blocklyComment .blocklyFoldoutIcon',
);
await foldout.click();
chai.assert.isTrue(
await isCommentCollapsed(this.browser, commentId),
'Expected the comment to be collapsed',
);
});
test('collapsing adds the css class', async function () {
await createComment(this.browser);
const foldout = await this.browser.$(
'.blocklyComment .blocklyFoldoutIcon',
);
await foldout.click();
const comment = await this.browser.$('.blocklyComment');
chai.assert.isTrue(
await hasClass(comment, 'blocklyCollapsed'),
'Expected the comment to have the blocklyCollapsed class',
);
});
});
suite('Uncollapsing', function () {
async function collapseComment(browser, id) {
await browser.execute((id) => {
Blockly.getMainWorkspace().getCommentById(id).setCollapsed(true);
}, id);
}
test('collapsing updates the collapse value', async function () {
const commentId = await createComment(this.browser);
await collapseComment(this.browser, commentId);
const foldout = await this.browser.$(
'.blocklyComment .blocklyFoldoutIcon',
);
await foldout.click();
chai.assert.isFalse(
await isCommentCollapsed(this.browser, commentId),
'Expected the comment to not be collapsed',
);
});
test('collapsing adds the css class', async function () {
const commentId = await createComment(this.browser);
await collapseComment(this.browser, commentId);
const foldout = await this.browser.$(
'.blocklyComment .blocklyFoldoutIcon',
);
await foldout.click();
const comment = await this.browser.$('.blocklyComment');
chai.assert.isFalse(
await hasClass(comment, 'blocklyCollapsed'),
'Expected the comment to not have the blocklyCollapsed class',
);
});
});
});
suite('Deleting', function () {
async function makeDeleteVisible(browser, commentId) {
await browser.execute((id) => {
document.querySelector(
'.blocklyComment .blocklyDeleteIcon',
).style.display = 'block';
const comment = Blockly.getMainWorkspace().getCommentById(id);
comment.setSize(comment.getSize());
}, commentId);
}
async function commentIsDisposed(browser, commentId) {
return await browser.execute(
(id) => !Blockly.getMainWorkspace().getCommentById(id),
commentId,
);
}
test('deleting disposes of comment', async function () {
const commentId = await createComment(this.browser);
await makeDeleteVisible(this.browser, commentId);
const deleteIcon = await this.browser.$(
'.blocklyComment .blocklyDeleteIcon',
);
await deleteIcon.click();
chai.assert.isTrue(
await commentIsDisposed(this.browser, commentId),
'Expected the comment model to be disposed',
);
});
test('deleting disposes of DOM elements', async function () {
const commentId = await createComment(this.browser);
await makeDeleteVisible(this.browser, commentId);
const deleteIcon = await this.browser.$(
'.blocklyComment .blocklyDeleteIcon',
);
await deleteIcon.click();
chai.assert.isFalse(
await this.browser.$('.blocklyComment').isExisting(),
'Expected the comment DOM elements to not exist',
);
});
});
suite('Typing', function () {
async function getCommentText(browser, id) {
return await browser.execute(
(id) => Blockly.getMainWorkspace().getCommentById(id).getText(),
id,
);
}
test('typing updates the text value', async function () {
const commentId = await createComment(this.browser);
const textArea = await this.browser.$('.blocklyComment .blocklyTextarea');
await textArea.addValue('test text');
// Deselect text area to fire browser change event.
await this.browser.$('.blocklyWorkspace').click();
chai.assert.equal(
await getCommentText(this.browser, commentId),
'test text',
'Expected the comment model text to match the entered text',
);
});
});
suite('Resizing', function () {
async function getCommentSize(browser, id) {
return await browser.execute(
(id) => Blockly.getMainWorkspace().getCommentById(id).getSize(),
id,
);
}
test('resizing updates the size value', async function () {
const commentId = await createComment(this.browser);
const origSize = await getCommentSize(this.browser, commentId);
const delta = {x: 20, y: 20};
const resizeHandle = await this.browser.$(
'.blocklyComment .blocklyResizeHandle',
);
await resizeHandle.dragAndDrop(delta);
chai.assert.deepEqual(
await getCommentSize(this.browser, commentId),
{
width: origSize.width + delta.x,
height: origSize.height + delta.y,
},
'Expected the comment model size to match the resized size',
);
});
});
});