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 'Add a new name, then edit it, without creating a duplicate' do
29 project_uuid = api_fixture('groups')['aproject']['uuid']
30 specimen_uuid = api_fixture('traits')['owned_by_aproject_with_no_name']['uuid']
31 visit page_with_token 'active', '/projects/' + project_uuid
32 click_link 'Other objects'
33 within '.selection-action-container' do
34 # Wait for the tab to load:
35 assert_selector 'tr[data-kind="arvados#trait"]'
36 within first('tr', text: 'Trait') do
37 find(".fa-pencil").click
38 find('.editable-input input').set('Now I have a name.')
39 find('.glyphicon-ok').click
40 assert_selector '.editable', text: 'Now I have a name.'
41 find(".fa-pencil").click
42 find('.editable-input input').set('Now I have a new name.')
43 find('.glyphicon-ok').click
46 assert_selector '.editable', text: 'Now I have a new name.'
49 click_link 'Other objects'
50 within '.selection-action-container' do
51 find '.editable', text: 'Now I have a new name.'
52 page.assert_no_selector '.editable', text: 'Now I have a name.'
56 test 'Create a project and move it into a different project' do
57 visit page_with_token 'active', '/projects'
58 find('.btn', text: "Add new project").click
60 # within('.editable', text: 'New project') do
62 find('.fa-pencil').click
63 find('.editable-input input').set('Project 1234')
64 find('.glyphicon-ok').click
69 find('.btn', text: "Add new project").click
71 find('.fa-pencil').click
72 find('.editable-input input').set('Project 5678')
73 find('.glyphicon-ok').click
77 click_link 'Move project...'
78 find('.selectable', text: 'Project 1234').click
79 find('.modal-footer a,button', text: 'Move').click
82 # Wait for the page to refresh and show the new parent in Sharing panel
84 assert(page.has_link?("Project 1234"),
85 "Project 5678 should now be inside project 1234")
88 def show_project_using(auth_key, proj_key='aproject')
89 project_uuid = api_fixture('groups')[proj_key]['uuid']
90 visit(page_with_token(auth_key, "/projects/#{project_uuid}"))
91 assert(page.has_text?("A Project"), "not on expected project page")
95 find('#project_sharing').all('tr')
98 def add_share_and_check(share_type, name)
99 assert(page.has_no_text?(name), "project is already shared with #{name}")
100 start_share_count = share_rows.size
101 click_on("Share with #{share_type}")
102 within(".modal-container") do
103 # Order is important here: we should find something that appears in the
104 # modal before we make any assertions about what's not in the modal.
105 # Otherwise, the not-included assertions might falsely pass because
106 # the modal hasn't loaded yet.
107 find(".selectable", text: name).click
108 assert(has_no_selector?(".modal-dialog-preview-pane"),
109 "preview pane available in sharing dialog")
110 assert_raises(Capybara::ElementNotFound,
111 "Projects pulldown available from sharing dialog") do
112 click_on "All projects"
116 using_wait_time(Capybara.default_wait_time * 3) do
117 assert(page.has_link?(name),
118 "new share was not added to sharing table")
119 assert_equal(start_share_count + 1, share_rows.size,
120 "new share did not add row to sharing table")
124 def modify_share_and_check(name)
125 start_rows = share_rows
126 link_row = start_rows.select { |row| row.has_text?(name) }
127 assert_equal(1, link_row.size, "row with new permission not found")
128 within(link_row.first) do
130 select("Write", from: "share_change_level")
131 click_on("editable-submit")
132 assert(has_link?("Write"),
133 "failed to change access level on new share")
136 using_wait_time(Capybara.default_wait_time * 3) do
137 assert(page.has_no_text?(name),
138 "new share row still exists after being revoked")
139 assert_equal(start_rows.size - 1, share_rows.size,
140 "revoking share did not remove row from sharing table")
144 test "project viewer can't see project sharing tab" do
145 show_project_using("project_viewer")
146 assert(page.has_no_link?("Sharing"),
147 "read-only project user sees sharing tab")
150 test "project owner can manage sharing for another user" do
151 add_user = api_fixture('users')['future_project_user']
152 new_name = ["first_name", "last_name"].map { |k| add_user[k] }.join(" ")
154 show_project_using("active")
156 add_share_and_check("users", new_name)
157 modify_share_and_check(new_name)
160 test "project owner can manage sharing for another group" do
161 new_name = api_fixture('groups')['future_project_viewing_group']['name']
163 show_project_using("active")
165 add_share_and_check("groups", new_name)
166 modify_share_and_check(new_name)
169 test "'share with group' listing does not offer projects" do
170 show_project_using("active")
172 click_on "Share with groups"
173 good_uuid = api_fixture("groups")["private"]["uuid"]
174 assert(page.has_selector?(".selectable[data-object-uuid=\"#{good_uuid}\"]"),
175 "'share with groups' listing missing owned user group")
176 bad_uuid = api_fixture("groups")["asubproject"]["uuid"]
177 assert(page.has_no_selector?(".selectable[data-object-uuid=\"#{bad_uuid}\"]"),
178 "'share with groups' listing includes project")