Skip to content

Commit e993d3f

Browse files
committed
test: refactor
1 parent c3b7b8a commit e993d3f

File tree

2 files changed

+174
-352
lines changed

2 files changed

+174
-352
lines changed

test/integration/ruby-tab/events.test.js

Lines changed: 173 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -29,146 +29,180 @@ describe('Ruby Tab: Events category blocks', () => {
2929
await driver.quit();
3030
});
3131

32-
test('Ruby -> Code -> Ruby', async () => {
33-
await loadUri(urlFor('/'));
34-
35-
const code = dedent`
36-
when_flag_clicked do
37-
bounce_if_on_edge
38-
end
39-
40-
when_key_pressed("space") do
41-
bounce_if_on_edge
42-
end
43-
44-
when_key_pressed("any") do
45-
bounce_if_on_edge
46-
move(10)
47-
end
48-
49-
when_key_pressed("a") do
50-
end
51-
52-
when_clicked do
53-
bounce_if_on_edge
54-
end
55-
56-
when_clicked do
57-
bounce_if_on_edge
58-
move(10)
59-
end
60-
61-
when_backdrop_switches("backdrop1") do
62-
bounce_if_on_edge
63-
end
64-
65-
when_backdrop_switches("backdrop1") do
66-
bounce_if_on_edge
67-
move(10)
68-
end
69-
70-
when_greater_than("loudness", 10) do
71-
end
72-
73-
when_greater_than("loudness", 10) do
74-
bounce_if_on_edge
75-
end
76-
77-
when_greater_than("timer", x) do
78-
bounce_if_on_edge
79-
move(10)
80-
end
81-
82-
when_receive("message1") do
83-
end
84-
85-
when_receive("message1") do
86-
bounce_if_on_edge
87-
end
88-
89-
when_receive("message1") do
90-
bounce_if_on_edge
91-
move(10)
92-
end
93-
94-
broadcast("message1")
95-
broadcast(x)
96-
broadcast_and_wait("message1")
97-
broadcast_and_wait(x)
98-
`;
99-
await expectInterconvertBetweenCodeAndRuby(code);
32+
const eventsCode = dedent`
33+
when_flag_clicked do
34+
bounce_if_on_edge
35+
end
36+
37+
when_key_pressed("space") do
38+
bounce_if_on_edge
39+
end
40+
41+
when_key_pressed("any") do
42+
bounce_if_on_edge
43+
move(10)
44+
end
45+
46+
when_key_pressed("a") do
47+
end
48+
49+
when_clicked do
50+
bounce_if_on_edge
51+
end
52+
53+
when_clicked do
54+
bounce_if_on_edge
55+
move(10)
56+
end
57+
58+
when_backdrop_switches("backdrop1") do
59+
bounce_if_on_edge
60+
end
61+
62+
when_backdrop_switches("backdrop1") do
63+
bounce_if_on_edge
64+
move(10)
65+
end
66+
67+
when_greater_than("loudness", 10) do
68+
end
69+
70+
when_greater_than("loudness", 10) do
71+
bounce_if_on_edge
72+
end
73+
74+
when_greater_than("timer", x) do
75+
bounce_if_on_edge
76+
move(10)
77+
end
78+
79+
when_receive("message1") do
80+
end
81+
82+
when_receive("message1") do
83+
bounce_if_on_edge
84+
end
85+
86+
when_receive("message1") do
87+
bounce_if_on_edge
88+
move(10)
89+
end
90+
91+
broadcast("message1")
92+
broadcast(x)
93+
broadcast_and_wait("message1")
94+
broadcast_and_wait(x)
95+
`;
96+
97+
const eventsOldCode = dedent`
98+
self.when(:flag_clicked) do
99+
bounce_if_on_edge
100+
end
101+
102+
self.when(:key_pressed, "space") do
103+
bounce_if_on_edge
104+
end
105+
106+
self.when(:key_pressed, "any") do
107+
bounce_if_on_edge
108+
move(10)
109+
end
110+
111+
self.when(:key_pressed, "a") do
112+
end
113+
114+
self.when(:clicked) do
115+
bounce_if_on_edge
116+
end
117+
118+
self.when(:clicked) do
119+
bounce_if_on_edge
120+
move(10)
121+
end
122+
123+
self.when(:backdrop_switches, "backdrop1") do
124+
bounce_if_on_edge
125+
end
126+
127+
self.when(:backdrop_switches, "backdrop1") do
128+
bounce_if_on_edge
129+
move(10)
130+
end
131+
132+
self.when(:greater_than, "loudness", 10) do
133+
end
134+
135+
self.when(:greater_than, "loudness", 10) do
136+
bounce_if_on_edge
137+
end
138+
139+
self.when(:greater_than, "timer", x) do
140+
bounce_if_on_edge
141+
move(10)
142+
end
143+
144+
self.when(:receive, "message1") do
145+
end
146+
147+
self.when(:receive, "message1") do
148+
bounce_if_on_edge
149+
end
150+
151+
self.when(:receive, "message1") do
152+
bounce_if_on_edge
153+
move(10)
154+
end
155+
156+
broadcast("message1")
157+
broadcast(x)
158+
broadcast_and_wait("message1")
159+
broadcast_and_wait(x)
160+
`;
161+
162+
describe('sprite', () => {
163+
test('Ruby -> Code -> Ruby', async () => {
164+
await loadUri(urlFor('/'));
165+
await expectInterconvertBetweenCodeAndRuby(eventsCode);
166+
});
167+
168+
test('Ruby -> Code -> Ruby (backward compatibility) ', async () => {
169+
await loadUri(urlFor('/'));
170+
171+
await clickText('Ruby', '*[@role="tab"]');
172+
await fillInRubyProgram(eventsOldCode);
173+
await clickText('Code', '*[@role="tab"]');
174+
await clickXpath(
175+
'//div[contains(@class, "menu-bar_menu-bar-item") and contains(@class, "menu-bar_hoverable")]' +
176+
'/*/span[text()="Edit"]'
177+
);
178+
await clickText('Generate Ruby from Code');
179+
await clickText('Ruby', '*[@role="tab"]');
180+
expect(await currentRubyProgram()).toEqual(`${eventsCode}\n`);
181+
});
100182
});
101183

102-
test('Ruby -> Code -> Ruby (backward compatibility) ', async () => {
103-
await loadUri(urlFor('/'));
104-
105-
const oldCode = dedent`
106-
self.when(:flag_clicked) do
107-
end
108-
109-
self.when(:key_pressed, "space") do
110-
end
111-
112-
self.when(:key_pressed, "any") do
113-
end
114-
115-
self.when(:key_pressed, "a") do
116-
end
117-
118-
self.when(:clicked) do
119-
end
120-
121-
self.when(:backdrop_switches, "backdrop1") do
122-
end
123-
124-
self.when(:greater_than, "loudness", 10) do
125-
end
126-
127-
self.when(:greater_than, "timer", 10) do
128-
end
129-
130-
self.when(:receive, "message1") do
131-
end
132-
`;
133-
134-
const newCode = dedent`
135-
when_flag_clicked do
136-
end
137-
138-
when_key_pressed("space") do
139-
end
140-
141-
when_key_pressed("any") do
142-
end
143-
144-
when_key_pressed("a") do
145-
end
146-
147-
when_clicked do
148-
end
149-
150-
when_backdrop_switches("backdrop1") do
151-
end
152-
153-
when_greater_than("loudness", 10) do
154-
end
155-
156-
when_greater_than("timer", 10) do
157-
end
158-
159-
when_receive("message1") do
160-
end
161-
`;
162-
163-
await clickText('Ruby', '*[@role="tab"]');
164-
await fillInRubyProgram(oldCode);
165-
await clickText('Code', '*[@role="tab"]');
166-
await clickXpath(
167-
'//div[contains(@class, "menu-bar_menu-bar-item") and contains(@class, "menu-bar_hoverable")]' +
168-
'/*/span[text()="Edit"]'
169-
);
170-
await clickText('Generate Ruby from Code');
171-
await clickText('Ruby', '*[@role="tab"]');
172-
expect(await currentRubyProgram()).toEqual(`${newCode}\n`);
184+
describe('stage', () => {
185+
test('Ruby -> Code -> Ruby', async () => {
186+
await loadUri(urlFor('/'));
187+
await clickXpath('//span[text()="Stage"]');
188+
189+
await expectInterconvertBetweenCodeAndRuby(eventsCode);
190+
});
191+
192+
test('Ruby -> Code -> Ruby (backward compatibility) ', async () => {
193+
await loadUri(urlFor('/'));
194+
await clickXpath('//span[text()="Stage"]');
195+
196+
await clickText('Ruby', '*[@role="tab"]');
197+
await fillInRubyProgram(eventsOldCode);
198+
await clickText('Code', '*[@role="tab"]');
199+
await clickXpath(
200+
'//div[contains(@class, "menu-bar_menu-bar-item") and contains(@class, "menu-bar_hoverable")]' +
201+
'/*/span[text()="Edit"]'
202+
);
203+
await clickText('Generate Ruby from Code');
204+
await clickText('Ruby', '*[@role="tab"]');
205+
expect(await currentRubyProgram()).toEqual(`${eventsCode}\n`);
206+
});
173207
});
174208
});

0 commit comments

Comments
 (0)