I am testing a RoR app using Cucumber and Capybara with capybara-webkit as my javascript driver. I'm using jQuery on the client side.
I don't want to use the default file picker generated by my browser. This is my javascript code:
$(document).ready( function() {
$('#upload_button').click( function() {
$('#upload_file').click();
});
$('#upload_file').on( 'change', function () {
$(this).parents('form:first').submit();
});
});
This is my markup (edited to emphasize my problem):
<form action="/guests/upload_list" enctype="multipart/form-data" method="post">
<input class="invisible" id="upload_file" name="upload_file" type="file">
<button id="upload_button" name="button" type="button">Upload guest list...</button>
</form>
I can test, via Capybara, that my file uploads work, but I also need to test that my 'fake' button works. One thought was to use Capybara to click on the fake button and to check if a file dialog appears, but I don't know how to do the latter.
What are some good strategies for testing this? I've looked at poltergeist as a possible solution for a driver but it's still not clear how to test to see that this actually works. I've also looked at Jasmine as a javascript testing framework, but ideally I would like my current system to work (i.e. using Cucumber, Capybara, etc).