@@ -6,6 +6,7 @@ const seleniumHelper = new SeleniumHelper();
6
6
const {
7
7
clickText,
8
8
clickXpath,
9
+ findByXpath,
9
10
scope,
10
11
getDriver,
11
12
loadUri,
@@ -14,6 +15,8 @@ const {
14
15
15
16
const rubyHelper = new RubyHelper ( seleniumHelper ) ;
16
17
const {
18
+ fillInRubyProgram,
19
+ currentRubyProgram,
17
20
expectInterconvertBetweenCodeAndRuby
18
21
} = rubyHelper ;
19
22
@@ -32,37 +35,285 @@ describe('Ruby Tab: Control category blocks', () => {
32
35
await loadUri ( urlFor ( '/' ) ) ;
33
36
await clickXpath ( '//button[@aria-label="Choose a Sprite"]' ) ;
34
37
await clickText ( 'Abby' , scope . modal ) ;
38
+ await findByXpath (
39
+ '//div[contains(@class, "sprite-selector-item_is-selected")]' +
40
+ '/*/div[contains(@class, "sprite-selector-item_sprite-name_1PXjh") and text()="Abby"]'
41
+ ) ;
35
42
await clickText ( 'Sprite1' , scope . spriteItems ) ;
36
43
37
- const code = dedent `
44
+ const ruby = dedent `
38
45
sleep(1)
46
+ sleep(x)
47
+ sleep(touching?("_edge_"))
39
48
10.times do
49
+ move(10)
50
+ end
51
+ x.times do
52
+ move(10)
53
+ end
54
+ (touching?("_edge_")).times do
55
+ move(10)
40
56
end
41
57
loop do
58
+ move(10)
42
59
end
43
60
44
61
if false
45
62
end
63
+ if touching?("_edge_")
64
+ turn_right(180)
65
+ end
46
66
if false
47
67
else
48
68
end
69
+ if touching?("_edge_")
70
+ turn_right(180)
71
+ else
72
+ move(10)
73
+ end
74
+ if touching?("_edge_")
75
+ else
76
+ move(10)
77
+ end
78
+ if touching?("_edge_")
79
+ turn_right(180)
80
+ else
81
+ end
49
82
wait until false
83
+ wait until touching?("_edge_")
50
84
until false
51
85
move(10)
52
86
end
87
+ until touching?("_edge_")
88
+ move(10)
89
+ end
53
90
stop("all")
54
91
55
92
stop("this script")
56
93
57
94
stop("other scripts in sprite")
58
95
59
- self.when(:start_as_a_clone) do
96
+ when_start_as_a_clone do
60
97
end
61
98
62
99
create_clone("_myself_")
63
100
create_clone("Abby")
64
101
delete_this_clone
65
102
` ;
66
- await expectInterconvertBetweenCodeAndRuby ( code ) ;
103
+ await expectInterconvertBetweenCodeAndRuby ( ruby ) ;
104
+ } ) ;
105
+
106
+ test ( 'Ruby -> Code -> Ruby (backward compatibility) ' , async ( ) => {
107
+ await loadUri ( urlFor ( '/' ) ) ;
108
+
109
+ const oldRuby = dedent `
110
+ self.when(:start_as_a_clone) do
111
+ end
112
+ ` ;
113
+
114
+ const newRuby = dedent `
115
+ when_start_as_a_clone do
116
+ end
117
+ ` ;
118
+
119
+ await clickText ( 'Ruby' , '*[@role="tab"]' ) ;
120
+ await fillInRubyProgram ( oldRuby ) ;
121
+ await clickText ( 'Code' , '*[@role="tab"]' ) ;
122
+ await clickXpath (
123
+ '//div[contains(@class, "menu-bar_menu-bar-item") and contains(@class, "menu-bar_hoverable")]' +
124
+ '/*/span[text()="Edit"]'
125
+ ) ;
126
+ await clickText ( 'Generate Ruby from Code' ) ;
127
+ await clickText ( 'Ruby' , '*[@role="tab"]' ) ;
128
+ expect ( await currentRubyProgram ( ) ) . toEqual ( `${ newRuby } \n` ) ;
129
+ } ) ;
130
+
131
+ test ( 'Ruby -> Code -> Ruby (remove wait) ' , async ( ) => {
132
+ await loadUri ( urlFor ( '/' ) ) ;
133
+
134
+ const beforeRuby = dedent `
135
+ 10.times { wait; move(10) }
136
+ 10.times { wait; wait; move(10) }
137
+ 10.times { move(10); wait }
138
+ 10.times { move(10); wait; wait }
139
+ 10.times { wait; move(10); wait }
140
+ 10.times { wait; wait; move(10); wait; wait }
141
+ repeat(10) { move(10); wait }
142
+ loop { wait }
143
+ loop { wait; wait }
144
+ loop { wait; wait; wait }
145
+ until touching?("_edge_")
146
+ wait; move(10)
147
+ end
148
+ until touching?("_edge_")
149
+ wait; wait; move(10)
150
+ end
151
+ until touching?("_edge_")
152
+ wait; move(10); wait
153
+ end
154
+ until touching?("_edge_")
155
+ move(10); wait
156
+ end
157
+ until touching?("_edge_")
158
+ move(10); wait; wait
159
+ end
160
+ ` ;
161
+
162
+ const afterRuby = dedent `
163
+ 10.times do
164
+ move(10)
165
+ end
166
+ 10.times do
167
+ move(10)
168
+ end
169
+ 10.times do
170
+ move(10)
171
+ end
172
+ 10.times do
173
+ move(10)
174
+ end
175
+ 10.times do
176
+ move(10)
177
+ end
178
+ 10.times do
179
+ move(10)
180
+ end
181
+ 10.times do
182
+ move(10)
183
+ end
184
+ loop do
185
+ end
186
+
187
+ loop do
188
+ end
189
+
190
+ loop do
191
+ end
192
+
193
+ until touching?("_edge_")
194
+ move(10)
195
+ end
196
+ until touching?("_edge_")
197
+ move(10)
198
+ end
199
+ until touching?("_edge_")
200
+ move(10)
201
+ end
202
+ until touching?("_edge_")
203
+ move(10)
204
+ end
205
+ until touching?("_edge_")
206
+ move(10)
207
+ end
208
+ ` ;
209
+
210
+ await clickText ( 'Ruby' , '*[@role="tab"]' ) ;
211
+ await fillInRubyProgram ( beforeRuby ) ;
212
+ await clickText ( 'Code' , '*[@role="tab"]' ) ;
213
+ await clickXpath (
214
+ '//div[contains(@class, "menu-bar_menu-bar-item") and contains(@class, "menu-bar_hoverable")]' +
215
+ '/*/span[text()="Edit"]'
216
+ ) ;
217
+ await clickText ( 'Generate Ruby from Code' ) ;
218
+ await clickText ( 'Ruby' , '*[@role="tab"]' ) ;
219
+ expect ( await currentRubyProgram ( ) ) . toEqual ( `${ afterRuby } \n` ) ;
220
+ } ) ;
221
+
222
+ test ( 'Ruby -> Code -> Ruby (alias) ' , async ( ) => {
223
+ await loadUri ( urlFor ( '/' ) ) ;
224
+
225
+ const beforeRuby = dedent `
226
+ repeat(10) { move(10); wait }
227
+ repeat(x) { move(10) }
228
+ repeat(touching?("_edge_")) { move(10) }
229
+ forever { move(10); wait }
230
+ ` ;
231
+
232
+ const afterRuby = dedent `
233
+ 10.times do
234
+ move(10)
235
+ end
236
+ x.times do
237
+ move(10)
238
+ end
239
+ (touching?("_edge_")).times do
240
+ move(10)
241
+ end
242
+ loop do
243
+ move(10)
244
+ end
245
+ ` ;
246
+
247
+ await clickText ( 'Ruby' , '*[@role="tab"]' ) ;
248
+ await fillInRubyProgram ( beforeRuby ) ;
249
+ await clickText ( 'Code' , '*[@role="tab"]' ) ;
250
+ await clickXpath (
251
+ '//div[contains(@class, "menu-bar_menu-bar-item") and contains(@class, "menu-bar_hoverable")]' +
252
+ '/*/span[text()="Edit"]'
253
+ ) ;
254
+ await clickText ( 'Generate Ruby from Code' ) ;
255
+ await clickText ( 'Ruby' , '*[@role="tab"]' ) ;
256
+ expect ( await currentRubyProgram ( ) ) . toEqual ( `${ afterRuby } \n` ) ;
257
+ } ) ;
258
+
259
+ test ( 'Ruby -> Code -> Ruby (etc) ' , async ( ) => {
260
+ await loadUri ( urlFor ( '/' ) ) ;
261
+
262
+ const beforeRuby = dedent `
263
+ if (touching?("_edge_"))
264
+ turn_right(180)
265
+ end
266
+ unless touching?("_edge_")
267
+ turn_right(180)
268
+ else
269
+ move(10)
270
+ end
271
+ unless touching?("_edge_")
272
+ else
273
+ move(10)
274
+ end
275
+ unless touching?("_edge_")
276
+ turn_right(180)
277
+ else
278
+ end
279
+ unless touching?("_edge_")
280
+ else
281
+ end
282
+ wait until (touching?("_edge_"))
283
+ ` ;
284
+
285
+ const afterRuby = dedent `
286
+ if touching?("_edge_")
287
+ turn_right(180)
288
+ end
289
+ if touching?("_edge_")
290
+ move(10)
291
+ else
292
+ turn_right(180)
293
+ end
294
+ if touching?("_edge_")
295
+ move(10)
296
+ else
297
+ end
298
+ if touching?("_edge_")
299
+ else
300
+ turn_right(180)
301
+ end
302
+ if touching?("_edge_")
303
+ else
304
+ end
305
+ wait until touching?("_edge_")
306
+ ` ;
307
+
308
+ await clickText ( 'Ruby' , '*[@role="tab"]' ) ;
309
+ await fillInRubyProgram ( beforeRuby ) ;
310
+ await clickText ( 'Code' , '*[@role="tab"]' ) ;
311
+ await clickXpath (
312
+ '//div[contains(@class, "menu-bar_menu-bar-item") and contains(@class, "menu-bar_hoverable")]' +
313
+ '/*/span[text()="Edit"]'
314
+ ) ;
315
+ await clickText ( 'Generate Ruby from Code' ) ;
316
+ await clickText ( 'Ruby' , '*[@role="tab"]' ) ;
317
+ expect ( await currentRubyProgram ( ) ) . toEqual ( `${ afterRuby } \n` ) ;
67
318
} ) ;
68
319
} ) ;
0 commit comments