2659: more asserts in dashboard testing
[arvados.git] / apps / workbench / test / integration / anonymous_access_test.rb
1 require 'integration_helper'
2
3 class AnonymousAccessTest < ActionDispatch::IntegrationTest
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   setup do
10     need_javascript
11   end
12
13   def verify_homepage_anonymous_enabled user, is_active, has_profile
14     if user
15       if user['is_active']
16         if has_profile
17           assert_text 'Unrestricted public data'
18           assert_selector 'a', text: 'Projects'
19         else
20           assert_text 'All required fields must be completed before you can proceed'
21         end
22       else
23         assert_text 'indicate that you have read and accepted the user agreement'
24       end
25       within('.navbar-fixed-top') do
26         assert_no_text 'You are viewing public data'
27         assert_selector 'a', text: "#{user['email']}"
28         find('a', text: "#{user['email']}").click
29         within('.dropdown-menu') do
30           assert_selector 'a', text: 'Log out'
31         end
32       end
33     else
34       assert_text 'Unrestricted public data'
35       within('.navbar-fixed-top') do
36         assert_text 'You are viewing public data'
37         anonymous_user = api_fixture('users')['anonymous']
38         assert_selector 'a', "#{anonymous_user['email']}"
39         find('a', text: "#{anonymous_user['email']}").click
40         within('.dropdown-menu') do
41           assert_selector 'a', text: 'Log in'
42           assert_no_selector 'a', text: 'Log out'
43         end
44       end
45     end
46   end
47
48   [
49     [nil, nil, false, false],
50     ['inactive', api_fixture('users')['inactive'], false, false],
51     ['active', api_fixture('users')['active'], true, true],
52     ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
53   ].each do |token, user, is_active, has_profile|
54     test "visit public project as user #{token} when anonymous browsing is enabled" do
55       Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
56
57       path = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
58
59       if !token
60         visit path
61       else
62         visit page_with_token(token, path)
63       end
64       verify_homepage_anonymous_enabled user, is_active, has_profile
65     end
66   end
67
68   test "anonymous user visit public project when anonymous browsing not enabled and expect to see login page" do
69     Rails.configuration.anonymous_user_token = false
70     visit "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
71     assert_text 'Please log in'
72   end
73
74   test "visit non-public project as anonymous when anonymous browsing is enabled and expect page not found" do
75     Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
76     visit "/projects/#{api_fixture('groups')['aproject']['uuid']}/?public_data=true"
77     assert_text 'Not Found'
78   end
79
80   test "selection actions when anonymous user accesses shared project" do
81     Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
82     visit "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
83
84     assert_selector 'a', text: 'Data collections'
85     assert_selector 'a', text: 'Jobs and pipelines'
86     assert_selector 'a', text: 'Pipeline templates'
87     assert_selector 'a', text: 'Advanced'
88     assert_no_selector 'a', text: 'Subprojects'
89     assert_no_selector 'a', text: 'Other objects'
90     assert_no_selector 'button', text: 'Add data'
91
92     click_button 'Selection'
93     within('.selection-action-container') do
94       assert_selector 'li', text: 'Compare selected'
95       assert_no_selector 'li', text: 'Create new collection with selected collections'
96       assert_no_selector 'li', text: 'Copy selected'
97       assert_no_selector 'li', text: 'Move selected'
98       assert_no_selector 'li', text: 'Remove selected'
99     end
100   end
101
102   def visit_publicly_accessible_project
103     Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
104     visit "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
105   end
106
107   [
108     ['All pipelines', 'Pipeline in publicly accessible project'],
109     ['All jobs', 'job submitted'],
110     ['All collections', 'GNU_General_Public_License,_version_3.pdf'],
111   ].each do |selector, expectation|
112     test "verify dashboard when anonymous user accesses shared project and click #{selector}" do
113       visit_publicly_accessible_project
114
115       # go to dashboard
116       click_link 'You are viewing public data'
117
118       assert_no_selector 'a', text: 'Run a pipeline'
119       assert_selector 'a', text: selector
120       click_link selector
121       assert_text expectation
122     end
123   end
124
125   test "anonymous user accesses data collections tab in shared project" do
126     visit_publicly_accessible_project
127
128     assert_selector 'a', text: 'Data collections (1)'
129
130     # click on show collection
131     within first('tr[data-kind="arvados#collection"]') do
132       click_link 'Show'
133     end
134
135     # in collection page
136     assert_no_selector 'input', text: 'Create sharing link'
137     assert_no_selector 'a', text: 'Upload'
138     assert_no_selector 'button', 'Selection'
139
140     within ('#collection_files') do
141       assert_text 'GNU_General_Public_License,_version_3.pdf'
142       # how do i assert the view and download links?
143     end
144   end
145
146   [ 'job', 'pipelineInstance' ].each do |type|
147     test "anonymous user accesses jobs and pipelines tab in shared project and clicks on #{type}" do
148       visit_publicly_accessible_project
149
150       assert_selector 'a', 'Jobs and pipelines (2)'
151
152       click_link 'Jobs and pipelines'
153       assert_text 'hash job'
154
155       # click on type specified collection
156       if type == 'job'
157         verify_job_row
158       else
159         verify_pipeline_instance_row
160       end
161     end
162   end
163
164   def verify_job_row
165     within first('tr[data-kind="arvados#job"]') do
166       assert_text 'hash job using'
167       click_link 'Show'
168     end
169
170     # in job page
171     assert_no_selector 'button', text: 'Re-run job'
172     assert_text 'script_version'
173   end
174
175   def verify_pipeline_instance_row
176     within first('tr[data-kind="arvados#pipelineInstance"]') do
177       assert_text 'Pipeline in publicly accessible project'
178       click_link 'Show'
179     end
180
181     # in pipeline instance page
182     assert_no_selector 'a', text: 'Re-run with latest'
183     assert_no_selector 'a', text: 'Re-run options'
184     assert_text 'This pipeline is complete'
185   end
186
187   test "anonymous user accesses pipeline templates tab in shared project" do
188     visit_publicly_accessible_project
189
190     assert_selector 'a', 'Pipeline templates (1)'
191
192     click_link 'Pipeline templates'
193     assert_text 'Pipeline template in publicly accessible project'
194
195     within first('tr[data-kind="arvados#pipelineTemplate"]') do
196       click_link 'Show'
197     end
198
199     # in template page
200     assert_text 'script version'
201     assert_no_selector 'a', text: 'Run this pipeline'
202   end
203 end