Skip to content

Commit baff667

Browse files
authored
Merge pull request #324 from smalruby/309-block-to-ruby-when-flag-clicked
test: add test for event blocks to generate ruby
2 parents fb8d8ad + 551b19b commit baff667

File tree

5 files changed

+107
-14
lines changed

5 files changed

+107
-14
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"babel-eslint": "10.0.3",
121121
"babel-loader": "8.2.2",
122122
"chromedriver": "107.0.3",
123+
"dedent": "^0.7.0",
123124
"enzyme": "3.10.0",
124125
"enzyme-adapter-react-16": "1.3.0",
125126
"eslint": "5.16.0",

test/helpers/ruby-helper.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const setRubyCode = function (driver, code) {
2+
code = code.replace(/\n/g, '\\n');
3+
return driver.executeScript(`ace.edit('ruby-editor').setValue('${code}');`);
4+
};
5+
6+
const getRubyCode = function (driver) {
7+
return driver.executeScript(`return ace.edit('ruby-editor').getValue();`);
8+
};
9+
10+
export {
11+
setRubyCode,
12+
getRubyCode
13+
};

test/integration/ruby-tab.test.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import path from 'path';
22
import SeleniumHelper from '../helpers/selenium-helper';
3+
import {
4+
setRubyCode,
5+
getRubyCode
6+
} from '../helpers/ruby-helper';
37

48
const {
59
/* eslint-disable no-unused-vars */
@@ -30,20 +34,11 @@ describe('convert Code from Ruby', () => {
3034
await driver.quit();
3135
});
3236

33-
const setRubyCode = function (code) {
34-
code = code.replace(/\n/g, '\\n');
35-
return driver.executeScript(`ace.edit('ruby-editor').setValue('${code}');`);
36-
};
37-
38-
const getRubyCode = function () {
39-
return driver.executeScript(`return ace.edit('ruby-editor').getValue();`);
40-
};
41-
4237
test('Code from Ruby -> Ruby from Code', async () => {
4338
await loadUri(uri);
4439

4540
await clickText('Ruby', '*[@role="tab"]');
46-
await setRubyCode('move(\\n10\\n)\\n');
41+
await setRubyCode(driver, 'move(\\n10\\n)\\n');
4742

4843
await clickText('Code', '*[@role="tab"]');
4944

@@ -55,17 +50,17 @@ describe('convert Code from Ruby', () => {
5550

5651
await clickText('Ruby', '*[@role="tab"]');
5752

58-
expect(await getRubyCode()).toEqual('move(10)\n');
53+
expect(await getRubyCode(driver)).toEqual('move(10)\n');
5954
});
6055

6156
describe('syntax error', () => {
6257
beforeEach(async () => {
6358
await loadUri(uri);
6459
await clickText('Ruby', '*[@role="tab"]');
65-
await setRubyCode('move(10)');
60+
await setRubyCode(driver, 'move(10)');
6661
await clickText('Code', '*[@role="tab"]');
6762
await clickText('Ruby', '*[@role="tab"]');
68-
await setRubyCode('move(10');
63+
await setRubyCode(driver, 'move(10');
6964
});
7065

7166
test('clicked Code', async () => {
@@ -148,7 +143,7 @@ describe('convert Code from Ruby', () => {
148143
);
149144
await clickText('Generate Ruby from Code');
150145

151-
expect(await getRubyCode()).toEqual('move(10)\n');
146+
expect(await getRubyCode(driver)).toEqual('move(10)\n');
152147

153148
await clickText('Code', '*[@role="tab"]');
154149
await findByXpath('//li[contains(@id, "react-tabs-") and @aria-selected="true"]/span[text()="Code"]');
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import path from 'path';
2+
import dedent from 'dedent';
3+
import SeleniumHelper from '../../helpers/selenium-helper';
4+
import {
5+
setRubyCode,
6+
getRubyCode
7+
} from '../../helpers/ruby-helper';
8+
9+
const {
10+
clickText,
11+
clickXpath,
12+
getDriver,
13+
loadUri
14+
} = new SeleniumHelper();
15+
16+
const uri = path.resolve(__dirname, '../../../build/index.html');
17+
18+
let driver;
19+
20+
describe('Ruby Tab: event', () => {
21+
beforeAll(() => {
22+
driver = getDriver();
23+
});
24+
25+
afterAll(async () => {
26+
await driver.quit();
27+
});
28+
29+
test('Ruby -> Code -> Ruby', async () => {
30+
await loadUri(uri);
31+
32+
await clickText('Ruby', '*[@role="tab"]');
33+
const code = dedent`
34+
self.when(:flag_clicked) do
35+
end
36+
37+
self.when(:key_pressed, "space") do
38+
end
39+
40+
self.when(:clicked) do
41+
end
42+
43+
self.when(:key_pressed, "any") do
44+
end
45+
46+
self.when(:key_pressed, "a") do
47+
end
48+
49+
self.when(:backdrop_switches, "backdrop1") do
50+
end
51+
52+
self.when(:greater_than, "loudness", 10) do
53+
end
54+
55+
self.when(:greater_than, "timer", 10) do
56+
end
57+
58+
self.when(:receive, "message1") do
59+
end
60+
61+
broadcast("message1")
62+
broadcast_and_wait("message1")
63+
`;
64+
await setRubyCode(driver, code);
65+
66+
await clickText('Code', '*[@role="tab"]');
67+
68+
await clickXpath(
69+
'//div[contains(@class, "menu-bar_menu-bar-item") and contains(@class, "menu-bar_hoverable")]' +
70+
'/*/span[text()="Edit"]'
71+
);
72+
await clickText('Generate Ruby from Code');
73+
74+
await clickText('Ruby', '*[@role="tab"]');
75+
76+
expect(await getRubyCode(driver)).toEqual(`${code}\n`);
77+
});
78+
});

0 commit comments

Comments
 (0)