diff options
| -rw-r--r-- | spec/features/lines_spec.rb | 16 | ||||
| -rw-r--r-- | spec/features/users/user_edit_spec.rb | 1 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 5 | ||||
| -rw-r--r-- | spec/support/capybara.rb | 2 | ||||
| -rw-r--r-- | spec/support/helpers/token_input_helpers.rb | 77 | ||||
| -rw-r--r-- | spec/support/referential.rb | 4 |
6 files changed, 102 insertions, 3 deletions
diff --git a/spec/features/lines_spec.rb b/spec/features/lines_spec.rb index d0db27f10..104d45b99 100644 --- a/spec/features/lines_spec.rb +++ b/spec/features/lines_spec.rb @@ -7,6 +7,7 @@ describe "Lines", :type => :feature do let!(:network) { Factory(:network) } let!(:company) { Factory(:company) } let!(:lines) { Array.new(2) { Factory(:line_with_stop_areas, :network => network, :company => company) } } + let!(:group_of_line) { Factory(:group_of_line) } subject { lines.first } describe "list" do @@ -39,12 +40,25 @@ describe "Lines", :type => :feature do click_link "Ajouter une ligne" fill_in "line_name", :with => "Line 1" fill_in "Numéro d'enregistrement", :with => "1" - fill_in "Identifiant Neptune", :with => "test:Line:999" + fill_in "Identifiant Neptune", :with => "test:Line:999" click_button("Créer ligne") expect(page).to have_content("Line 1") end end + describe "new with group of line", :js => true do + it "creates line and return to show" do + visit new_referential_line_path(referential) + fill_in "line_name", :with => "Line 1" + fill_in "Numéro d'enregistrement", :with => "1" + fill_in "Identifiant Neptune", :with => "test:Line:999" + fill_in_token_input('line_group_of_line_tokens', :with => "#{group_of_line.name}") + find_button("Créer ligne").trigger("click") + expect(page).to have_text("Line 1") + expect(page).to have_text("#{group_of_line.name}") + end + end + describe "edit and return to show" do it "edit line" do visit referential_line_path(referential, subject) diff --git a/spec/features/users/user_edit_spec.rb b/spec/features/users/user_edit_spec.rb index b437b241d..cb1830a55 100644 --- a/spec/features/users/user_edit_spec.rb +++ b/spec/features/users/user_edit_spec.rb @@ -26,7 +26,6 @@ feature 'User edit', :devise do fill_in 'user_current_password', :with => user.password click_button 'Modifier' txts = [I18n.t( 'devise.registrations.updated'), I18n.t( 'devise.registrations.update_needs_confirmation')] - save_and_open_page expect(page).to have_content(/.*#{txts[0]}.*|.*#{txts[1]}.*/) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 15951834e..c831d2490 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,7 @@ require 'rspec/rails' # Add this to load Capybara integration: require 'capybara/rspec' require 'capybara/rails' +require 'capybara/poltergeist' # FIXME FactoryGirl not found in jenkins build #13 unless defined?(FactoryGirl) @@ -39,6 +40,10 @@ ActiveRecord::Migration.maintain_test_schema! RSpec.configure do |config| #Capybara.exact = true + Capybara.javascript_driver = :webkit + config.filter_run_excluding :js => true + config.run_all_when_everything_filtered = true + config.include TokenInputHelper, :type => :feature # ## Mock Framework # diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index eb8124f44..215a6fb28 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -1 +1 @@ -Capybara.asset_host = 'http://localhost:3000' +Capybara.asset_host = 'http://localhost:3001' diff --git a/spec/support/helpers/token_input_helpers.rb b/spec/support/helpers/token_input_helpers.rb new file mode 100644 index 000000000..f6db7fa2a --- /dev/null +++ b/spec/support/helpers/token_input_helpers.rb @@ -0,0 +1,77 @@ +require 'capybara' +require 'capybara/dsl' + +module TokenInputHelper + include Capybara::DSL + + # EX: fill_in_token_input 'custodian_id', with: 'M', pick: 'Market' + # EX: fill_in_token_input 'custodian_id', with: 'A', pick: 1 + # + # @param id [String] id of the original text input that has been replaced by the tokenInput + # @option with [String] *required + # @option pick [Symbol, String, Integer] result to pick, defaults to first result + # + def fill_in_token_input(id, options) + # Generate selectors for key elements + # The tokenInput-generated visible text field + text_input_selector = "#token-input-#{id}" + # The <ul> tag containing the selected tokens and visible test input + token_input_list_selector = ".token-input-list:has(li #{text_input_selector})" + # The result list + result_list_selector = ".token-input-selected-dropdown-item" + + # Trigger clicking on the token input + page.driver.execute_script("$('#{token_input_list_selector}').trigger('click');") + # Wait until the 'Type in a search term' box appears + #page.has_css? ".token-input-dropdown:contains('Type in a search term')" + + # Fill in the visible text box + page.driver.execute_script("$('#{text_input_selector}').val('#{options[:with]}');") + # Triggering keydown initiates the ajax request within tokenInput + page.driver.execute_script("$('#{text_input_selector}').trigger('keydown');") + # The result_list_selector will show when the AJAX request is complete + page.has_css? result_list_selector + + # Pick the result + if options[:pick] + textual_numbers = [:first, :second, :third, :fourth, :fifth] + if index = textual_numbers.index(options[:pick]) + selector = ":nth-child(#{index+1})" + elsif options[:pick].class == String + selector = ":contains(\"#{options[:pick]}\")" + elsif options[:pick].class == Integer + selector = ":nth-child(#{options[:pick]})" + end + else + selector = ':first-child' + end + + page.driver.execute_script("$('#{result_list_selector}#{selector}').trigger('mousedown');") + # A missing result_list_selector signifies that the selection has been made + page.has_css?(result_list_selector) + end + + # Focus on a tokenInput + # @param id [String] *required + # + def focus_on_token_input(id) + page.driver.execute_script("$('##{id}').siblings('ul').trigger('click')") + sleep(0.1) + end + + # Get the JS array of tokens in a tokenInput instance + # @param id [String] *required + # + def get_token_input(id) + page.driver.execute_script("$('##{id}').tokenInput('get')") + end + + # Clears a tokenInput + # @param id [String] *required + # + def clear_token_input(id, options={}) + page.driver.execute_script("$('##{id}').tokenInput('clear', #{options.to_json})") + sleep(0.1) + end + +end diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 7704d8510..0cfc3601e 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -47,6 +47,10 @@ RSpec.configure do |config| config.before(:each, :js => true) do DatabaseCleaner.strategy = :truncation + # Start transaction for this test + DatabaseCleaner.start + # Switch into the default tenant + first_referential.switch end config.after(:each) do |
