1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class ProjectsTest < ActionDispatch::IntegrationTest
7 Capybara.current_driver = Capybara.javascript_driver
10 test 'Find a project and edit its description' do
11 visit page_with_token 'active', '/'
12 find('.arv-project-list a,button', text: 'A Project').
14 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
15 find('span', text: api_fixture('groups')['aproject']['name']).click
16 within('.arv-description-as-subtitle') do
17 find('.fa-pencil').click
18 find('.editable-input textarea').set('I just edited this.')
19 find('.editable-submit').click
24 assert(find?('.container-fluid', text: 'I just edited this.'),
25 "Description update did not survive page refresh")
28 test 'Find a project and edit description to textile description' do
29 visit page_with_token 'active', '/'
30 find('.arv-project-list a,button', text: 'A Project').
32 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
33 find('span', text: api_fixture('groups')['aproject']['name']).click
34 within('.arv-description-as-subtitle') do
35 find('.fa-pencil').click
36 find('.editable-input textarea').set('*Textile description for A project* - "take me home":/')
37 find('.editable-submit').click
42 assert(find?('.container-fluid', text: 'Textile description for A project'),
43 "Description update did not survive page refresh")
44 assert(!find?('.container-fluid', text: '*Textile description for A project*'),
45 "Textile description is displayed with uninterpreted formatting characters")
46 assert(page.has_link?("take me home"), "link not found in description")
47 click_link 'take me home'
48 assert page.has_text?('My projects')
49 assert page.has_text?('Projects shared with me')
52 test 'Find a project and edit description to html description' do
53 visit page_with_token 'active', '/'
54 find('.arv-project-list a,button', text: 'A Project').
56 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
57 find('span', text: api_fixture('groups')['aproject']['name']).click
58 within('.arv-description-as-subtitle') do
59 find('.fa-pencil').click
60 find('.editable-input textarea').set('<br>Textile description for A project</br> - <a href="/">take me home</a>')
61 find('.editable-submit').click
66 assert(find?('.container-fluid', text: 'Textile description for A project'),
67 "Description update did not survive page refresh")
68 assert(!find?('.container-fluid', text: '<br>Textile description for A project</br>'),
69 "Textile description is displayed with uninterpreted formatting characters")
70 assert(page.has_link?("take me home"),"link not found in description")
71 click_link 'take me home'
72 assert page.has_text?('My projects')
73 assert page.has_text?('Projects shared with me')
76 test 'Find a project and edit description to textile description with link to object' do
77 visit page_with_token 'active', '/'
78 find('.arv-project-list a,button', text: 'A Project').
80 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
81 find('span', text: api_fixture('groups')['aproject']['name']).click
82 within('.arv-description-as-subtitle') do
83 find('.fa-pencil').click
84 find('.editable-input textarea').set('*Textile description for A project* - "go to sub-project":' + api_fixture('groups')['asubproject']['uuid'] + "'")
85 find('.editable-submit').click
90 assert(find?('.container-fluid', text: 'Textile description for A project'),
91 "Description update did not survive page refresh")
92 assert(!find?('.container-fluid', text: '*Textile description for A project*'),
93 "Textile description is displayed with uninterpreted formatting characters")
94 assert(page.has_link?("go to sub-project"), "link not found in description")
95 click_link 'go to sub-project'
96 assert(page.has_text?(api_fixture('groups')['asubproject']['name']), 'sub-project name not found after clicking link')
99 test 'Add a new name, then edit it, without creating a duplicate' do
100 project_uuid = api_fixture('groups')['aproject']['uuid']
101 specimen_uuid = api_fixture('traits')['owned_by_aproject_with_no_name']['uuid']
102 visit page_with_token 'active', '/projects/' + project_uuid
103 click_link 'Other objects'
104 within '.selection-action-container' do
105 # Wait for the tab to load:
106 assert_selector 'tr[data-kind="arvados#trait"]'
107 within first('tr', text: 'Trait') do
108 find(".fa-pencil").click
109 find('.editable-input input').set('Now I have a name.')
110 find('.glyphicon-ok').click
111 assert_selector '.editable', text: 'Now I have a name.'
112 find(".fa-pencil").click
113 find('.editable-input input').set('Now I have a new name.')
114 find('.glyphicon-ok').click
117 assert_selector '.editable', text: 'Now I have a new name.'
120 click_link 'Other objects'
121 within '.selection-action-container' do
122 find '.editable', text: 'Now I have a new name.'
123 page.assert_no_selector '.editable', text: 'Now I have a name.'
127 test 'Create a project and move it into a different project' do
128 visit page_with_token 'active', '/projects'
129 find('.btn', text: "Add new project").click
131 # within('.editable', text: 'New project') do
133 find('.fa-pencil').click
134 find('.editable-input input').set('Project 1234')
135 find('.glyphicon-ok').click
140 find('.btn', text: "Add new project").click
142 find('.fa-pencil').click
143 find('.editable-input input').set('Project 5678')
144 find('.glyphicon-ok').click
148 click_link 'Move project...'
149 find('.selectable', text: 'Project 1234').click
150 find('.modal-footer a,button', text: 'Move').click
153 # Wait for the page to refresh and show the new parent in Sharing panel
155 assert(page.has_link?("Project 1234"),
156 "Project 5678 should now be inside project 1234")
159 def show_project_using(auth_key, proj_key='aproject')
160 project_uuid = api_fixture('groups')[proj_key]['uuid']
161 visit(page_with_token(auth_key, "/projects/#{project_uuid}"))
162 assert(page.has_text?("A Project"), "not on expected project page")
166 find('#project_sharing').all('tr')
169 def add_share_and_check(share_type, name)
170 assert(page.has_no_text?(name), "project is already shared with #{name}")
171 start_share_count = share_rows.size
172 click_on("Share with #{share_type}")
173 within(".modal-container") do
174 # Order is important here: we should find something that appears in the
175 # modal before we make any assertions about what's not in the modal.
176 # Otherwise, the not-included assertions might falsely pass because
177 # the modal hasn't loaded yet.
178 find(".selectable", text: name).click
179 assert(has_no_selector?(".modal-dialog-preview-pane"),
180 "preview pane available in sharing dialog")
181 assert_raises(Capybara::ElementNotFound,
182 "Projects pulldown available from sharing dialog") do
183 click_on "All projects"
187 using_wait_time(Capybara.default_wait_time * 3) do
188 assert(page.has_link?(name),
189 "new share was not added to sharing table")
190 assert_equal(start_share_count + 1, share_rows.size,
191 "new share did not add row to sharing table")
195 def modify_share_and_check(name)
196 start_rows = share_rows
197 link_row = start_rows.select { |row| row.has_text?(name) }
198 assert_equal(1, link_row.size, "row with new permission not found")
199 within(link_row.first) do
201 select("Write", from: "share_change_level")
202 click_on("editable-submit")
203 assert(has_link?("Write"),
204 "failed to change access level on new share")
207 using_wait_time(Capybara.default_wait_time * 3) do
208 assert(page.has_no_text?(name),
209 "new share row still exists after being revoked")
210 assert_equal(start_rows.size - 1, share_rows.size,
211 "revoking share did not remove row from sharing table")
215 test "project viewer can't see project sharing tab" do
216 show_project_using("project_viewer")
217 assert(page.has_no_link?("Sharing"),
218 "read-only project user sees sharing tab")
221 test "project owner can manage sharing for another user" do
222 add_user = api_fixture('users')['future_project_user']
223 new_name = ["first_name", "last_name"].map { |k| add_user[k] }.join(" ")
225 show_project_using("active")
227 add_share_and_check("users", new_name)
228 modify_share_and_check(new_name)
231 test "project owner can manage sharing for another group" do
232 new_name = api_fixture('groups')['future_project_viewing_group']['name']
234 show_project_using("active")
236 add_share_and_check("groups", new_name)
237 modify_share_and_check(new_name)
240 test "'share with group' listing does not offer projects" do
241 show_project_using("active")
243 click_on "Share with groups"
244 good_uuid = api_fixture("groups")["private"]["uuid"]
245 assert(page.has_selector?(".selectable[data-object-uuid=\"#{good_uuid}\"]"),
246 "'share with groups' listing missing owned user group")
247 bad_uuid = api_fixture("groups")["asubproject"]["uuid"]
248 assert(page.has_no_selector?(".selectable[data-object-uuid=\"#{bad_uuid}\"]"),
249 "'share with groups' listing includes project")