mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
Add integration coverage for styled file inputs
Uses example from Quirksmode: http://www.quirksmode.org/dom/inputfile.html
This commit is contained in:
parent
e3a5dfdd4d
commit
0f89db1825
2 changed files with 67 additions and 0 deletions
|
@ -10,6 +10,9 @@ end
|
|||
Capybara::SpecHelper.run_specs TestSessions::Webkit, "webkit"
|
||||
|
||||
describe Capybara::Session do
|
||||
include AppRunner
|
||||
include Capybara::RSpecMatchers
|
||||
|
||||
subject { Capybara::Session.new(:reusable_webkit, @app) }
|
||||
after { subject.reset! }
|
||||
|
||||
|
@ -479,4 +482,62 @@ describe Capybara::Session do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'styled upload app' do
|
||||
let(:session) do
|
||||
session_for_app do
|
||||
get '/render_form' do
|
||||
<<-HTML
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
#wrapper { position: relative; }
|
||||
input[type=file] {
|
||||
position: relative;
|
||||
opacity: 0;
|
||||
z-index: 2;
|
||||
width: 50px;
|
||||
}
|
||||
#styled {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
width: 50px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/submit" method="post" enctype="multipart/form-data">
|
||||
<label for="file">File</label>
|
||||
<div id="wrapper">
|
||||
<input type="file" name="file" id="file" />
|
||||
<div id="styled">Upload</div>
|
||||
</div>
|
||||
<input type="submit" value="Go" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
HTML
|
||||
end
|
||||
|
||||
post '/submit' do
|
||||
contents = params[:file][:tempfile].read
|
||||
"You uploaded: #{contents}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'attaches uploads' do
|
||||
file = Tempfile.new('example')
|
||||
file.write('Hello')
|
||||
file.flush
|
||||
|
||||
session.visit('/render_form')
|
||||
session.attach_file 'File', file.path
|
||||
session.click_on 'Go'
|
||||
|
||||
session.should have_text('Hello')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,6 +36,12 @@ module AppRunner
|
|||
build_driver
|
||||
end
|
||||
|
||||
def session_for_app(&body)
|
||||
app = Class.new(ExampleApp, &body)
|
||||
run_application app
|
||||
Capybara::Session.new(:reusable_webkit, AppRunner.app)
|
||||
end
|
||||
|
||||
def run_application_for_html(html)
|
||||
run_application lambda { |env|
|
||||
[200, { 'Content-Type' => 'text/html', 'Content-Length' => html.size.to_s }, [html]]
|
||||
|
|
Loading…
Add table
Reference in a new issue