mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Fine-tune angular helper
This commit is contained in:
@@ -45,7 +45,7 @@ feature %q{
|
||||
|
||||
before :each do
|
||||
visit '/admin/orders/bulk_management'
|
||||
wait_for_angular_requests
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
end
|
||||
|
||||
it "displays a column for user's full name" do
|
||||
@@ -93,6 +93,7 @@ feature %q{
|
||||
|
||||
before do
|
||||
visit spree.admin_bulk_order_management_path
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
end
|
||||
|
||||
it "sorts by customer name when the customer name header is clicked" do
|
||||
@@ -261,6 +262,7 @@ feature %q{
|
||||
|
||||
before :each do
|
||||
visit '/admin/orders/bulk_management'
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
end
|
||||
|
||||
it "displays a select box for producers, which filters line items by the selected supplier" do
|
||||
@@ -299,6 +301,7 @@ feature %q{
|
||||
|
||||
before :each do
|
||||
visit '/admin/orders/bulk_management'
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
end
|
||||
|
||||
it "displays a select box for distributors, which filters line items by the selected distributor" do
|
||||
@@ -338,6 +341,7 @@ feature %q{
|
||||
|
||||
before do
|
||||
visit '/admin/orders/bulk_management'
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
end
|
||||
|
||||
it "displays a select box for order cycles, which filters line items by the selected order cycle" do
|
||||
@@ -378,6 +382,7 @@ feature %q{
|
||||
|
||||
before :each do
|
||||
visit '/admin/orders/bulk_management'
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
end
|
||||
|
||||
it "allows filters to be used in combination" do
|
||||
@@ -428,6 +433,7 @@ feature %q{
|
||||
|
||||
before :each do
|
||||
visit '/admin/orders/bulk_management'
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
end
|
||||
|
||||
it "displays a quick search input" do
|
||||
@@ -457,7 +463,7 @@ feature %q{
|
||||
|
||||
before :each do
|
||||
visit '/admin/orders/bulk_management'
|
||||
wait_for_angular_requests
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
end
|
||||
|
||||
it "displays date fields for filtering orders, with default values set" do
|
||||
@@ -530,6 +536,7 @@ feature %q{
|
||||
|
||||
before :each do
|
||||
visit '/admin/orders/bulk_management'
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
end
|
||||
|
||||
it "displays a checkbox for each line item in the list" do
|
||||
@@ -572,6 +579,7 @@ feature %q{
|
||||
expect(page).to have_no_selector "tr#li_#{li2.id}"
|
||||
check "toggle_bulk"
|
||||
fill_in "quick_search", with: ''
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
expect(find("tr#li_#{li1.id} input[type='checkbox'][name='bulk']").checked?).to be true
|
||||
expect(find("tr#li_#{li2.id} input[type='checkbox'][name='bulk']").checked?).to be false
|
||||
expect(find("input[type='checkbox'][name='toggle_bulk']").checked?).to be false
|
||||
@@ -585,6 +593,7 @@ feature %q{
|
||||
find("div#bulk-actions-dropdown div.menu_item", :text => "Delete Selected" ).click
|
||||
expect(page).to have_no_selector "tr#li_#{li1.id}"
|
||||
fill_in "quick_search", with: ''
|
||||
wait_until { request_monitor_finished 'LineItemsCtrl' }
|
||||
expect(page).to have_selector "tr#li_#{li2.id}"
|
||||
expect(page).to have_no_selector "tr#li_#{li1.id}"
|
||||
end
|
||||
|
||||
@@ -152,16 +152,18 @@ module WebHelper
|
||||
page.driver.browser.switch_to.alert.accept
|
||||
end
|
||||
|
||||
def wait_for_angular_requests
|
||||
wait_until { angular_requests_finished }
|
||||
def angular_http_requests_finished(angular_controller=nil)
|
||||
scope_element = angular_controller ? "[ng-controller=#{angular_controller}]" : '.ng-scope'
|
||||
page.evaluate_script("angular.element(document.querySelector('#{scope_element}')).injector().get('$http').pendingRequests.length == 0")
|
||||
end
|
||||
|
||||
def request_monitor_finished(angular_controller=nil)
|
||||
scope_element = angular_controller ? "[ng-controller=#{angular_controller}]" : '.ng-scope'
|
||||
page.evaluate_script("angular.element(document.querySelector('#{scope_element}')).scope().RequestMonitor.loading == false")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def angular_requests_finished
|
||||
page.evaluate_script('angular.element(".ng-scope").injector().get("$http").pendingRequests.length === 0')
|
||||
end
|
||||
|
||||
def wait_for_ajax
|
||||
wait_until { page.evaluate_script("$.active") == 0 }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user