Skip to content

Commit 5546360

Browse files
authored
Merge pull request #299 from integer32llc/poppin-prepare-for-merge
Redesign the playground's header
2 parents 677029e + 001bf50 commit 5546360

35 files changed

+1494
-382
lines changed

tests/spec/features/compilation_modes_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
end
1212

1313
scenario "compiling in debug mode" do
14-
choose_styled("Debug")
14+
in_mode_menu { click_on("Debug") }
1515
click_on("Run")
1616

1717
within('.output-stdout') do
@@ -21,7 +21,7 @@
2121
end
2222

2323
scenario "compiling in release mode" do
24-
choose_styled("Release")
24+
in_mode_menu { click_on("Release") }
2525
click_on("Run")
2626

2727
within('.output-stdout') do

tests/spec/features/compilation_targets_spec.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212

1313
context "when AT&T syntax is selected" do
1414
before do
15-
click_on("Config")
16-
select("AT&T")
17-
click_on("Done")
15+
in_config_menu { choose("AT&T") }
1816
end
1917

2018
scenario "compiling to assembly" do
21-
within('.header') { click_on("ASM") }
19+
in_build_menu { click_on("assembly") }
2220

2321
within('.output-code') do
2422
# We demangle the symbols
@@ -31,13 +29,11 @@
3129

3230
context "when Intel syntax is selected" do
3331
before do
34-
click_on("Config")
35-
select("Intel")
36-
click_on("Done")
32+
in_config_menu { choose("Intel") }
3733
end
3834

3935
scenario "compiling to assembly" do
40-
within('.header') { click_on("ASM") }
36+
in_build_menu { click_on("assembly") }
4137

4238
within('.output-code') do
4339
# We demangle the symbols
@@ -49,7 +45,7 @@
4945
end
5046

5147
scenario "compiling to LLVM IR" do
52-
within('.header') { click_on("LLVM IR") }
48+
in_build_menu { click_on("LLVM IR") }
5349

5450
within('.output-code') do
5551
expect(page).to have_content 'ModuleID'
@@ -59,7 +55,7 @@
5955
end
6056

6157
scenario "compiling to MIR" do
62-
within('.header') { click_on("MIR") }
58+
in_build_menu { click_on("MIR") }
6359

6460
within('.output-code') do
6561
expect(page).to have_content 'StorageLive'
@@ -68,10 +64,7 @@
6864
end
6965

7066
scenario "compiling to WebAssembly" do
71-
within('.header') do
72-
choose_styled("Nightly")
73-
click_on("WASM")
74-
end
67+
in_build_menu { click_on("WASM") }
7568

7669
within('.output-code') do
7770
expect(page).to have_content '(module'
@@ -83,7 +76,7 @@
8376
before { editor.set("fn main() {") }
8477

8578
scenario "it shows the compilation error" do
86-
within('.header') { click_on("MIR") }
79+
in_build_menu { click_on("MIR") }
8780

8881
within('.output-stderr') do
8982
expect(page).to have_content 'an un-closed delimiter'

tests/spec/features/editor_types_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
require 'spec_helper'
2+
require 'support/playground_actions'
23

34
RSpec.feature "Editing in different editors", type: :feature, js: true do
5+
include PlaygroundActions
6+
47
before { visit '/' }
58

69
scenario "using the simple editor" do
7-
click_on("Config")
8-
select("Simple")
9-
click_on("Done")
10+
in_config_menu { choose("simple") }
1011

1112
fill_in('editor-simple', with: simple_editor_code)
1213

tests/spec/features/multiple_channels_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
end
1212

1313
scenario "using stable Rust" do
14-
choose_styled("Stable")
14+
in_channel_menu { click_on("Stable") }
1515
click_on("Run")
1616

1717
within('.output-stdout') do
@@ -22,7 +22,7 @@
2222
end
2323

2424
scenario "using beta Rust" do
25-
choose_styled("Beta")
25+
in_channel_menu { click_on("Beta") }
2626
click_on("Run")
2727

2828
within('.output-stdout') do
@@ -33,7 +33,7 @@
3333
end
3434

3535
scenario "using nightly Rust" do
36-
choose_styled("Nightly")
36+
in_channel_menu { click_on("Nightly") }
3737
click_on("Run")
3838

3939
within('.output-stdout') do

tests/spec/features/navigation_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525

2626
scenario "Mode and channel buttons update the URL" do
2727
visit '/'
28-
expect(page).to have_content('Run')
28+
expect(page).to have_content('RUN')
2929

3030
editor.set("dummy")
3131
expect(page).to be_at_url('/')
3232

33-
choose_styled('Release')
33+
in_mode_menu { click_on('Release') }
3434
expect(page).to be_at_url('/', version: 'stable', mode: 'release')
3535

3636
go_back
3737
expect(page).to be_at_url('/')
3838

39-
choose_styled('Release')
40-
choose_styled('Beta')
39+
in_mode_menu { click_on('Release') }
40+
in_channel_menu { click_on('Beta') }
4141
expect(page).to be_at_url('/', version: 'beta', mode: 'release')
4242

4343
go_back
@@ -47,23 +47,23 @@
4747

4848
scenario "Navigating to help changes the URL" do
4949
visit '/'
50-
expect(page).to have_content('Run')
50+
expect(page).to have_content('RUN')
5151

52-
click_on '?'
52+
click_on 'View help'
5353
expect(page).to be_at_url('/help')
5454
expect(page).to have_content('The Rust Playground')
5555

5656
go_back
5757
expect(page).to be_at_url('/')
58-
expect(page).to have_content('Run')
58+
expect(page).to have_content('RUN')
5959

6060
go_forward
6161
expect(page).to be_at_url('/help')
6262
expect(page).to have_content('The Rust Playground')
6363

6464
click_on "Return to the playground"
6565
expect(page).to be_at_url('/')
66-
expect(page).to have_content('Run')
66+
expect(page).to have_content('RUN')
6767
end
6868

6969
scenario "Navigating from help changes the URL" do
@@ -72,7 +72,7 @@
7272

7373
click_on "Return to the playground"
7474
expect(page).to be_at_url('/')
75-
expect(page).to have_content('Run')
75+
expect(page).to have_content('RUN')
7676
end
7777

7878
def editor

tests/spec/features/tools_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
require 'spec_helper'
44
require 'support/editor'
5+
require 'support/playground_actions'
56

67
RSpec.feature "Using third-party Rust tools", type: :feature, js: true do
8+
include PlaygroundActions
9+
710
before { visit '/' }
811

912
scenario "formatting code" do
1013
editor.set 'fn main() { [1,2,3,4]; }'
11-
within('.header') { click_on("Format") }
14+
in_tools_menu { click_on("Rustfmt") }
1215

1316
within('#editor') do
1417
expect(editor).to have_line '[1, 2, 3, 4];'
@@ -17,7 +20,7 @@
1720

1821
scenario "linting code with Clippy" do
1922
editor.set code_with_lint_warnings
20-
within('.header') { click_on("Clippy") }
23+
in_tools_menu { click_on("Clippy") }
2124

2225
within(".output-stderr") do
2326
expect(page).to have_content 'deny(eq_op)'

tests/spec/features/url_parameters_spec.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
# coding: utf-8
2+
13
require 'spec_helper'
24
require 'support/editor'
35

46
RSpec.feature "Configuration by URL parameters", type: :feature, js: true do
5-
# Our headers hide the radio button proper, so we need to enable
6-
# looking for invisible elements.
7-
RSpec::Matchers.define :have_checked_header do |expected|
7+
RSpec::Matchers.define :have_mode do |expected|
8+
match do |actual|
9+
within actual.find_button("Mode — Choose the optimization level") do |page|
10+
expect(page).to have_text(expected)
11+
end
12+
end
13+
end
14+
15+
RSpec::Matchers.define :have_channel do |expected|
816
match do |actual|
9-
expect(actual).to have_checked_field(expected, visible: false)
17+
within actual.find_button("Channel — Choose the Rust version") do |page|
18+
expect(page).to have_text(expected)
19+
end
1020
end
1121
end
1222

@@ -26,7 +36,7 @@
2636
scenario "loading from a Gist with a channel preserves the channel" do
2737
visit '/?gist=20fb1e0475f890d0fdb7864e3ad0820c&version=beta'
2838

29-
expect(page).to have_checked_header('Beta')
39+
expect(page).to have_channel('Beta')
3040
end
3141

3242
scenario "loading code directly from a parameter" do
@@ -38,13 +48,13 @@
3848
scenario "loading with a channel" do
3949
visit '/?version=nightly'
4050

41-
expect(page).to have_checked_header('Nightly')
51+
expect(page).to have_channel('Nightly')
4252
end
4353

4454
scenario "loading with a mode" do
4555
visit '/?mode=release'
4656

47-
expect(page).to have_checked_header('Release')
57+
expect(page).to have_mode('Release')
4858
end
4959

5060
def editor

tests/spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
Capybara.app_host = "http://#{ADDRESS}:#{PORT}"
4444
Capybara.run_server = false
4545
Capybara.default_max_wait_time = 5
46+
Capybara.automatic_label_click = true
4647

4748
RSpec.configure do |config|
4849
config.before do
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
1+
# coding: utf-8
2+
13
module PlaygroundActions
2-
def choose_styled(label)
3-
find('label', text: label).click
4+
def in_build_menu(&block)
5+
in_menu("Select what to build", &block)
6+
end
7+
8+
def in_mode_menu(&block)
9+
in_menu("Mode — Choose the optimization level", &block)
10+
end
11+
12+
def in_channel_menu(&block)
13+
in_menu("Channel — Choose the Rust version", &block)
14+
end
15+
16+
def in_tools_menu(&block)
17+
in_menu("Tools", &block)
18+
end
19+
20+
def in_config_menu(&block)
21+
in_menu("Config", close: true, &block)
22+
end
23+
24+
private
25+
26+
def in_menu(button_locator, close: false)
27+
click_on(button_locator)
28+
yield
29+
ensure
30+
click_on(button_locator) if close
431
end
532
end

ui/frontend/BuildMenu.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react';
2+
import { connect } from 'react-redux';
3+
4+
import {
5+
changeChannel,
6+
performCompileToAssembly,
7+
performCompileToLLVM,
8+
performCompileToMir,
9+
performCompileToNightlyWasm,
10+
performExecute,
11+
} from './actions';
12+
13+
import { Channel } from './types';
14+
15+
import ButtonMenuItem from './ButtonMenuItem';
16+
import MenuGroup from './MenuGroup';
17+
18+
interface BuildMenuProps {
19+
compileToAssembly: () => any;
20+
compileToLLVM: () => any;
21+
compileToMir: () => any;
22+
compileToWasm: () => any;
23+
execute: () => any;
24+
close: () => void;
25+
}
26+
27+
const BuildMenu: React.SFC<BuildMenuProps> = props => (
28+
<MenuGroup title="What do you want to do?">
29+
<ButtonMenuItem name="Build" onClick={() => { props.execute(); props.close(); }}>
30+
No bells and whistles, regular build coming right&nbsp;up&nbsp;:D
31+
</ButtonMenuItem>
32+
<ButtonMenuItem name="ASM" onClick={() => { props.compileToAssembly(); props.close(); }}>
33+
Build and show the resulting assembly code.
34+
</ButtonMenuItem>
35+
<ButtonMenuItem name="LLVM IR" onClick={() => { props.compileToLLVM(); props.close(); }}>
36+
Build and show the resulting LLVM IR, LLVM's intermediate representation.
37+
</ButtonMenuItem>
38+
<ButtonMenuItem name="MIR" onClick={() => { props.compileToMir(); props.close(); }}>
39+
Build and show the resulting MIR, Rust's intermediate representation.
40+
</ButtonMenuItem>
41+
<ButtonMenuItem name="WASM" onClick={() => { props.compileToWasm(); props.close(); }}>
42+
Build a WebAssembly module for web browsers, in the .WAT textual representation.
43+
<p className="build-menu__aside">
44+
Note: WASM currently requires using the Nightly channel, selecting this
45+
option will switch to Nightly.
46+
</p>
47+
</ButtonMenuItem>
48+
</MenuGroup >
49+
);
50+
51+
const mapDispatchToProps = ({
52+
compileToAssembly: performCompileToAssembly,
53+
compileToLLVM: performCompileToLLVM,
54+
compileToMir: performCompileToMir,
55+
compileToWasm: performCompileToNightlyWasm,
56+
execute: performExecute,
57+
});
58+
59+
export default connect(undefined, mapDispatchToProps)(BuildMenu);

ui/frontend/ButtonMenuItem.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
3+
import MenuItem from './MenuItem';
4+
5+
interface ButtonMenuItemProps extends React.HTMLProps<HTMLButtonElement> {
6+
name: string;
7+
}
8+
9+
const ButtonMenuItem: React.SFC<ButtonMenuItemProps> = ({ name, children, ...props }) => (
10+
<MenuItem>
11+
<button className="button-menu-item" {...props}>
12+
<div className="button-menu-item__name">{name}</div>
13+
<div className="button-menu-item__description">{children}</div>
14+
</button>
15+
</MenuItem>
16+
);
17+
18+
export default ButtonMenuItem;

0 commit comments

Comments
 (0)