From ea8be0ab950e46bef0b3877313ae54dedf0cb12d Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Feb 2019 16:13:23 +0000 Subject: [PATCH] Fine-tune angular helper --- spec/features/admin/bulk_order_management_spec.rb | 13 +++++++++++-- spec/support/request/web_helper.rb | 14 ++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb index 7e11b329c2..aaa2429d5a 100644 --- a/spec/features/admin/bulk_order_management_spec.rb +++ b/spec/features/admin/bulk_order_management_spec.rb @@ -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 diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb index 19f503d837..4cf788ae8e 100644 --- a/spec/support/request/web_helper.rb +++ b/spec/support/request/web_helper.rb @@ -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