Skip to content

Commit ac5dc06

Browse files
committed
Add some feature tests for multiple file operations
1 parent dd66ee4 commit ac5dc06

3 files changed

Lines changed: 157 additions & 5 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
require 'spec_helper'
2+
require 'support/editor'
3+
require 'support/file_tree'
4+
require 'support/matchers/editor'
5+
require 'support/playground_actions'
6+
7+
RSpec.feature "Multi-file editor interaction", type: :feature, js: true do
8+
include PlaygroundActions
9+
10+
before do
11+
visit '/'
12+
end
13+
14+
scenario "editing and running multiple files" do
15+
in_config_menu { choose('multiple') }
16+
17+
filetree.select 'src/main.rs'
18+
editor.set(<<~CODE)
19+
mod utils;
20+
21+
fn main() {
22+
println!("Hello to the whole {}", utils::greeting());
23+
}
24+
CODE
25+
26+
filetree.create_file 'src/utils.rs'
27+
editor.set(<<~CODE)
28+
pub fn greeting() -> &'static str {
29+
"world"
30+
}
31+
CODE
32+
33+
# Verify both files retain their content
34+
filetree.select 'src/main.rs'
35+
expect(editor).to have_line 'mod utils;'
36+
expect(editor).to_not have_line 'pub fn greeting()'
37+
38+
filetree.select 'src/utils.rs'
39+
expect(editor).to have_line 'pub fn greeting()'
40+
expect(editor).to_not have_line 'mod utils;'
41+
42+
# And that the files are transferred to the server
43+
click_on "Run"
44+
45+
within(:output, :stdout) do
46+
expect(page).to have_content 'Hello to the whole world'
47+
end
48+
end
49+
50+
scenario "toggling from single to multi-file view preserves contents" do
51+
editor.set(<<~CODE)
52+
fn main() {
53+
println!("From a single file");
54+
}
55+
CODE
56+
57+
in_config_menu { choose('multiple') }
58+
59+
# The original code had a `main` function, so should be in main.rs
60+
filetree.select 'src/main.rs'
61+
62+
expect(editor).to have_line 'println!("From a single file")'
63+
end
64+
65+
scenario "toggling from multi-file to single view preserves contents" do
66+
in_config_menu { choose('multiple') }
67+
68+
filetree.select 'src/main.rs'
69+
editor.set('// Main file content')
70+
71+
filetree.create_file 'src/helper.rs'
72+
editor.set('// Helper module content')
73+
74+
# Toggle back to single-file mode
75+
in_config_menu { choose('single') }
76+
77+
# The content should be preserved
78+
expect(editor).to have_line '// src/main.rs'
79+
expect(editor).to have_line '// Main file content'
80+
expect(editor).to have_line '// src/helper.rs'
81+
expect(editor).to have_line '// Helper module content'
82+
end
83+
84+
def editor
85+
Editor.new(page)
86+
end
87+
88+
def filetree
89+
FileTree.new(page)
90+
end
91+
end

tests/spec/features/sharing_with_others_spec.rb

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'spec_helper'
22
require 'support/editor'
3+
require 'support/file_tree'
34
require 'support/matchers/be_at_url'
45
require 'support/playground_actions'
56

@@ -11,7 +12,9 @@
1112
# This test does more than one thing so we can avoid sending too
1213
# many requests to GitHub
1314
scenario "saving to a Gist" do
14-
editor.set(code)
15+
editor.set(<<~CODE)
16+
// This code was saved by an automated test for the Rust Playground
17+
CODE
1518

1619
in_channel_menu { click_on("Nightly") }
1720
in_mode_menu { click_on("Release") }
@@ -47,13 +50,51 @@
4750
expect(urlo_link).to include('automated+test')
4851
end
4952

53+
# This test does more than one thing so we can avoid sending too
54+
# many requests to GitHub
55+
scenario "saving a multi-file Gist and restoring it" do
56+
in_config_menu { choose('multiple') }
57+
58+
filetree.select 'src/main.rs'
59+
editor.set(<<~CODE)
60+
mod utils;
61+
62+
fn main() {
63+
println!("{}", utils::greet());
64+
}
65+
CODE
66+
67+
filetree.create_file 'src/utils.rs'
68+
editor.set(<<~CODE)
69+
pub fn greet() -> &'static str {
70+
"Hello from multi-file!"
71+
}
72+
CODE
73+
74+
# Save to gist
75+
within(:header) { click_on 'Share' }
76+
77+
perma_link = find_link("Permalink to the playground")[:href]
78+
79+
# Navigate away so we can tell that we go back to the same page
80+
visit 'about:blank'
81+
82+
visit perma_link
83+
84+
filetree.select 'src/main.rs'
85+
expect(editor).to have_line 'mod utils;'
86+
expect(editor).to have_line 'println!("{}", utils::greet());'
87+
88+
filetree.select 'src/utils.rs'
89+
expect(editor).to have_line 'pub fn greet()'
90+
expect(editor).to have_line '"Hello from multi-file!"'
91+
end
92+
5093
def editor
5194
Editor.new(page)
5295
end
5396

54-
def code
55-
<<~EOF
56-
// This code was saved by an automated test for the Rust Playground
57-
EOF
97+
def filetree
98+
FileTree.new(page)
5899
end
59100
end

tests/spec/support/file_tree.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class FileTree
2+
attr_reader :page
3+
def initialize(page)
4+
@page = page
5+
end
6+
7+
def create_file(name)
8+
page.within(:filetree) do
9+
page.click_on 'Create file'
10+
page.fill_in 'pathname', with: name
11+
page.click_on 'Create new file'
12+
end
13+
end
14+
15+
def select(name)
16+
page.within(:filetree) do
17+
page.click_on name
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)