Merge branch '8784-dir-listings'
[arvados.git] / apps / workbench / test / controllers / search_controller_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class SearchControllerTest < ActionController::TestCase
8   # These tests don't do state-changing API calls. Save some time by
9   # skipping the database reset.
10   reset_api_fixtures :after_each_test, false
11   reset_api_fixtures :after_suite, true
12
13   include Rails.application.routes.url_helpers
14
15   test 'Get search dialog' do
16     xhr :get, :choose, {
17       format: :js,
18       title: 'Search',
19       action_name: 'Show',
20       action_href: url_for(host: 'localhost', controller: :actions, action: :show),
21       action_data: {}.to_json,
22     }, session_for(:active)
23     assert_response :success
24   end
25
26   test 'Get search results for all projects' do
27     xhr :get, :choose, {
28       format: :json,
29       partial: true,
30     }, session_for(:active)
31     assert_response :success
32     assert_not_empty(json_response['content'],
33                      'search results for all projects should not be empty')
34   end
35
36   test 'Get search results for empty project' do
37     xhr :get, :choose, {
38       format: :json,
39       partial: true,
40       project_uuid: api_fixture('groups')['empty_project']['uuid'],
41     }, session_for(:active)
42     assert_response :success
43     assert_empty(json_response['content'],
44                  'search results for empty project should be empty')
45   end
46
47   test 'search results for aproject and verify recursive contents' do
48     xhr :get, :choose, {
49       format: :json,
50       partial: true,
51       project_uuid: api_fixture('groups')['aproject']['uuid'],
52     }, session_for(:active)
53     assert_response :success
54     assert_not_empty(json_response['content'],
55                  'search results for aproject should not be empty')
56     items = []
57     json_response['content'].scan /<div[^>]+>/ do |div_tag|
58       div_tag.scan(/\ data-object-uuid=\"(.*?)\"/).each do |uuid,|
59         items << uuid
60       end
61     end
62
63     assert_includes(items, api_fixture('collections')['collection_to_move_around_in_aproject']['uuid'])
64     assert_includes(items, api_fixture('groups')['asubproject']['uuid'])
65     assert_includes(items, api_fixture('collections')['baz_collection_name_in_asubproject']['uuid'])
66     assert_includes(items,
67       api_fixture('groups')['subproject_in_asubproject_with_same_name_as_one_in_active_user_home']['uuid'])
68   end
69 end