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