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('<p>*Textile description for A project* - "take me home":/ </p><p>And a new paragraph in description.</p>')
37 find('.editable-submit').click
44 assert(has_no_text?('.container-fluid', text: '*Textile description for A project*'),
45 "Description is not rendered properly")
46 assert(find?('.container-fluid', text: 'Textile description for A project'),
47 "Description update did not survive page refresh")
48 assert(find?('.container-fluid', text: 'And a new paragraph in description'),
49 "Description did not contain the expected new paragraph")
50 assert(page.has_link?("take me home"), "link not found in description")
52 click_link 'take me home'
55 assert(page.has_text?('My projects'), 'My projects - not found on dashboard')
56 assert(page.has_text?('Projects shared with me'), 'Projects shared with me - not found on dashboard')
57 assert(page.has_text?('Textile description for A project'), "Project description not found")
58 assert(page.has_no_text?('*Textile description for A project*'), "Project description is not rendered properly in dashboard")
59 assert(page.has_no_text?('And a new paragraph in description'), "Project description is not truncated after first paragraph")
62 test 'Find a project and edit description to html description' do
63 visit page_with_token 'active', '/'
64 find('.arv-project-list a,button', text: 'A Project').
66 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
67 find('span', text: api_fixture('groups')['aproject']['name']).click
68 within('.arv-description-as-subtitle') do
69 find('.fa-pencil').click
70 find('.editable-input textarea').set('<br>Textile description for A project</br> - <a href="/">take me home</a>')
71 find('.editable-submit').click
76 assert(find?('.container-fluid', text: 'Textile description for A project'),
77 "Description update did not survive page refresh")
78 assert(!find?('.container-fluid', text: '<br>Textile description for A project</br>'),
79 "Textile description is displayed with uninterpreted formatting characters")
80 assert(page.has_link?("take me home"),"link not found in description")
81 click_link 'take me home'
82 assert page.has_text?('My projects')
83 assert page.has_text?('Projects shared with me')
86 test 'Find a project and edit description to textile description with link to object' do
87 visit page_with_token 'active', '/'
88 find('.arv-project-list a,button', text: 'A Project').
90 within('.container-fluid', text: api_fixture('groups')['aproject']['name']) do
91 find('span', text: api_fixture('groups')['aproject']['name']).click
92 within('.arv-description-as-subtitle') do
93 find('.fa-pencil').click
94 find('.editable-input textarea').set('*Textile description for A project* - "go to sub-project":' + api_fixture('groups')['asubproject']['uuid'] + "'")
95 find('.editable-submit').click
100 assert(find?('.container-fluid', text: 'Textile description for A project'),
101 "Description update did not survive page refresh")
102 assert(!find?('.container-fluid', text: '*Textile description for A project*'),
103 "Textile description is displayed with uninterpreted formatting characters")
104 assert(page.has_link?("go to sub-project"), "link not found in description")
105 click_link 'go to sub-project'
106 assert(page.has_text?(api_fixture('groups')['asubproject']['name']), 'sub-project name not found after clicking link')
109 test 'Add a new name, then edit it, without creating a duplicate' do
110 project_uuid = api_fixture('groups')['aproject']['uuid']
111 specimen_uuid = api_fixture('traits')['owned_by_aproject_with_no_name']['uuid']
112 visit page_with_token 'active', '/projects/' + project_uuid
113 click_link 'Other objects'
114 within '.selection-action-container' do
115 # Wait for the tab to load:
116 assert_selector 'tr[data-kind="arvados#trait"]'
117 within first('tr', text: 'Trait') do
118 find(".fa-pencil").click
119 find('.editable-input input').set('Now I have a name.')
120 find('.glyphicon-ok').click
121 assert_selector '.editable', text: 'Now I have a name.'
122 find(".fa-pencil").click
123 find('.editable-input input').set('Now I have a new name.')
124 find('.glyphicon-ok').click
127 assert_selector '.editable', text: 'Now I have a new name.'
130 click_link 'Other objects'
131 within '.selection-action-container' do
132 find '.editable', text: 'Now I have a new name.'
133 page.assert_no_selector '.editable', text: 'Now I have a name.'
137 test 'Create a project and move it into a different project' do
138 visit page_with_token 'active', '/projects'
139 find('.btn', text: "Add new project").click
141 # within('.editable', text: 'New project') do
143 find('.fa-pencil').click
144 find('.editable-input input').set('Project 1234')
145 find('.glyphicon-ok').click
150 find('.btn', text: "Add new project").click
152 find('.fa-pencil').click
153 find('.editable-input input').set('Project 5678')
154 find('.glyphicon-ok').click
158 click_link 'Move project...'
159 find('.selectable', text: 'Project 1234').click
160 find('.modal-footer a,button', text: 'Move').click
163 # Wait for the page to refresh and show the new parent in Sharing panel
165 assert(page.has_link?("Project 1234"),
166 "Project 5678 should now be inside project 1234")
169 def show_project_using(auth_key, proj_key='aproject')
170 project_uuid = api_fixture('groups')[proj_key]['uuid']
171 visit(page_with_token(auth_key, "/projects/#{project_uuid}"))
172 assert(page.has_text?("A Project"), "not on expected project page")
176 find('#project_sharing').all('tr')
179 def add_share_and_check(share_type, name)
180 assert(page.has_no_text?(name), "project is already shared with #{name}")
181 start_share_count = share_rows.size
182 click_on("Share with #{share_type}")
183 within(".modal-container") do
184 # Order is important here: we should find something that appears in the
185 # modal before we make any assertions about what's not in the modal.
186 # Otherwise, the not-included assertions might falsely pass because
187 # the modal hasn't loaded yet.
188 find(".selectable", text: name).click
189 assert(has_no_selector?(".modal-dialog-preview-pane"),
190 "preview pane available in sharing dialog")
191 assert_raises(Capybara::ElementNotFound,
192 "Projects pulldown available from sharing dialog") do
193 click_on "All projects"
197 using_wait_time(Capybara.default_wait_time * 3) do
198 assert(page.has_link?(name),
199 "new share was not added to sharing table")
200 assert_equal(start_share_count + 1, share_rows.size,
201 "new share did not add row to sharing table")
205 def modify_share_and_check(name)
206 start_rows = share_rows
207 link_row = start_rows.select { |row| row.has_text?(name) }
208 assert_equal(1, link_row.size, "row with new permission not found")
209 within(link_row.first) do
211 select("Write", from: "share_change_level")
212 click_on("editable-submit")
213 assert(has_link?("Write"),
214 "failed to change access level on new share")
217 using_wait_time(Capybara.default_wait_time * 3) do
218 assert(page.has_no_text?(name),
219 "new share row still exists after being revoked")
220 assert_equal(start_rows.size - 1, share_rows.size,
221 "revoking share did not remove row from sharing table")
225 test "project viewer can't see project sharing tab" do
226 show_project_using("project_viewer")
227 assert(page.has_no_link?("Sharing"),
228 "read-only project user sees sharing tab")
231 test "project owner can manage sharing for another user" do
232 add_user = api_fixture('users')['future_project_user']
233 new_name = ["first_name", "last_name"].map { |k| add_user[k] }.join(" ")
235 show_project_using("active")
237 add_share_and_check("users", new_name)
238 modify_share_and_check(new_name)
241 test "project owner can manage sharing for another group" do
242 new_name = api_fixture('groups')['future_project_viewing_group']['name']
244 show_project_using("active")
246 add_share_and_check("groups", new_name)
247 modify_share_and_check(new_name)
250 test "'share with group' listing does not offer projects" do
251 show_project_using("active")
253 click_on "Share with groups"
254 good_uuid = api_fixture("groups")["private"]["uuid"]
255 assert(page.has_selector?(".selectable[data-object-uuid=\"#{good_uuid}\"]"),
256 "'share with groups' listing missing owned user group")
257 bad_uuid = api_fixture("groups")["asubproject"]["uuid"]
258 assert(page.has_no_selector?(".selectable[data-object-uuid=\"#{bad_uuid}\"]"),
259 "'share with groups' listing includes project")