10037: Added test to check for progress bar showing only on running containers
[arvados.git] / apps / workbench / test / controllers / projects_controller_test.rb
index 643aaae6c92a772161561c3d305c647fe4f5d0d9..7848444efdeb84bcd2fc375ee6806b096b2153c9 100644 (file)
@@ -387,14 +387,43 @@ class ProjectsControllerTest < ActionController::TestCase
   end
 
   [
-    ["jobs", "/jobs"],
-    ["pipelines", "/pipeline_instances"],
-    ["collections", "/collections"],
-  ].each do |target,path|
-    test "test dashboard button all #{target}" do
-      get :index, {}, session_for(:active)
-      assert_includes @response.body, "href=\"#{path}\""
-      assert_includes @response.body, "All #{target}"
+    [:admin, true],
+    [:active, false],
+  ].each do |user, expect_all_nodes|
+    test "in dashboard other index page links as #{user}" do
+      get :index, {}, session_for(user)
+
+      [["processes", "/all_processes"],
+       ["collections", "/collections"],
+      ].each do |target, path|
+        assert_includes @response.body, "href=\"#{path}\""
+        assert_includes @response.body, "All #{target}"
+      end
+
+      if expect_all_nodes
+        assert_includes @response.body, "href=\"/nodes\""
+        assert_includes @response.body, "All nodes"
+      else
+        assert_not_includes @response.body, "href=\"/nodes\""
+        assert_not_includes @response.body, "All nodes"
+      end
+    end
+  end
+
+  test "in dashboard the progress bar should only show on running containers" do
+    get :index, {}, session_for(:active)
+    assert_select 'div.panel-body.recent-processes' do
+      [
+        ['completed', false],
+        ['uncommitted', false],
+        ['queued', false],
+        ['running', true],
+      ].each do |cr_state, should_show|
+        uuid = api_fixture('container_requests')[cr_state]['uuid']
+        assert_select "div.dashboard-panel-info-row.row-#{uuid}" do
+          assert_select 'div.progress', should_show
+        end
+      end
     end
   end
 
@@ -419,6 +448,35 @@ class ProjectsControllerTest < ActionController::TestCase
     assert_select "#projects-menu + ul li.divider ~ li a[href=/projects/#{project_uuid}]"
   end
 
+  [
+    ["active", 5, ["aproject", "asubproject"], "anonymously_accessible_project"],
+    ["user1_with_load", 2, ["project_with_10_collections"], "project_with_2_pipelines_and_60_crs"],
+    ["admin", 5, ["anonymously_accessible_project", "subproject_in_anonymous_accessible_project"], "aproject"],
+  ].each do |user, page_size, tree_segment, unexpected|
+    test "build my projects tree for #{user} user and verify #{unexpected} is omitted" do
+      use_token user
+      ctrl = ProjectsController.new
+
+      current_user = User.find(api_fixture('users')[user]['uuid'])
+
+      my_tree = ctrl.send :my_wanted_projects_tree, current_user, page_size
+
+      tree_segment_at_depth_1 = api_fixture('groups')[tree_segment[0]]
+      tree_segment_at_depth_2 = api_fixture('groups')[tree_segment[1]] if tree_segment[1]
+
+      tree_nodes = {}
+      my_tree[0].each do |x|
+        tree_nodes[x[:object]['uuid']] = x[:depth]
+      end
+
+      assert_equal(1, tree_nodes[tree_segment_at_depth_1['uuid']])
+      assert_equal(2, tree_nodes[tree_segment_at_depth_2['uuid']]) if tree_segment[1]
+
+      unexpected_project = api_fixture('groups')[unexpected]
+      assert_nil(tree_nodes[unexpected_project['uuid']])
+    end
+  end
+
   [
     ["active", 1],
     ["project_viewer", 1],