Skip to content

Instantly share code, notes, and snippets.

@cored
Created March 20, 2018 15:35
Show Gist options
  • Save cored/2e2c2ef23250a4d6859aeabda07e5a18 to your computer and use it in GitHub Desktop.
Save cored/2e2c2ef23250a4d6859aeabda07e5a18 to your computer and use it in GitHub Desktop.
require "rails_helper"
feature "Users search shipment", :as_admin_user do
context 'with sorting' do
scenario 'takes the user-defined sorting' do
shipment1 = create :shipment, number: 'Shipment 1', order_completed_at: 2.days.ago
shipment2 = create :shipment, number: 'Shipment 2', vip: true
shipment3 = create :shipment, number: 'Shipment 3', status: 'canceled'
visit shipments_path
expect(page).to have_result_at_position(shipment2, 1)
expect(page).to have_result_at_position(shipment3, 2)
expect(page).to have_result_at_position(shipment1, 3)
click_link "Status"
expect(page).to have_current_path(/q\[s\]=status\+asc/)
expect(page).to have_result_at_position(shipment3, 1)
expect(page).to have_result_at_position(shipment1, 2)
expect(page).to have_result_at_position(shipment2, 3)
end
end
def have_result_at_position(shipment, pos)
selector = ".shipments-search-results tr:nth-child(#{pos}) td:first-child"
have_selector(selector, text: "#{shipment.order_number} #{shipment.number}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment