4836: Trigger Workbench infinite scroll load on tab show.
authorBrett Smith <brett@curoverse.com>
Fri, 19 Dec 2014 22:40:13 +0000 (17:40 -0500)
committerBrett Smith <brett@curoverse.com>
Tue, 6 Jan 2015 17:09:23 +0000 (12:09 -0500)
If an infinite scroller is in the first tab of a show page, but the
user is going to a different tab, we'll queue up the first event
to load data for the container, but when it fires the container won't
be visible so it will decline to load anything.  Then you can only get
data to load if you resize the window.

Fire a scroll event when a new tab is shown, to spur the infinite
scroller to load data as appropriate.

apps/workbench/app/assets/javascripts/infinite_scroll.js
apps/workbench/test/integration/projects_test.rb
apps/workbench/test/integration_helper.rb

index 7bdf574ed9964802d6dab2b011ad3d8ca8b7fd1d..d7ad41abdd1779d727a6d6aae0435cc4f816d27d 100644 (file)
@@ -225,6 +225,10 @@ $(document).
                 trigger('scroll');
         });
     }).
+    on('shown.bs.tab', 'a[data-toggle="tab"]', function(event) {
+        $(event.target.getAttribute('href') + ' [data-infinite-scroller]').
+            trigger('scroll');
+    }).
     on('click', 'th[data-sort-order]', function() {
         var direction = $(this).data('sort-order-direction');
         // reverse the current direction, or do ascending if none
index 97e1a542bafcfad5f7a7e930c48c21f9417ec149..e5aa791de7c9494023d7c3d93f9d3f8f3b662fb0 100644 (file)
@@ -744,4 +744,15 @@ class ProjectsTest < ActionDispatch::IntegrationTest
     assert match, 'Expected project name not found'
     assert_text 'No description provided'
   end
+
+  test "first tab loads data when visiting other tab directly" do
+    # As of 2014-12-19, the first tab of project#show uses infinite scrolling.
+    # Make sure that it loads data even if we visit another tab directly.
+    project = api_fixture("groups", "aproject")
+    visit(page_with_token("active_trustedclient",
+                          "/projects/#{project['uuid']}#Advanced"))
+    assert_text("API response")
+    find("#page-wrapper .nav-tabs :first-child a").click
+    assert_text("bytes Collection")
+  end
 end
index febcfcfec0eb2c87122ba00594dfffc9a3958d37..2cf6bca2ad37b9064945957933b737158d44421b 100644 (file)
@@ -32,9 +32,11 @@ class ActionDispatch::IntegrationTest
     # fixture, or passed as a raw string.
     api_token = ((@@API_AUTHS.include? token) ?
                  @@API_AUTHS[token]['api_token'] : token)
-    sep = (path.include? '?') ? '&' : '?'
+    path_parts = path.partition("#")
+    sep = (path_parts.first.include? '?') ? '&' : '?'
     q_string = URI.encode_www_form('api_token' => api_token)
-    "#{path}#{sep}#{q_string}"
+    path_parts.insert(1, "#{sep}#{q_string}")
+    path_parts.join("")
   end
 
   # Find a page element, but return false instead of raising an