Merge branch '3136-stale-pipeline-instance-display' closes #3136
[arvados.git] / apps / workbench / test / integration / projects_test.rb
1 require 'integration_helper'
2 require 'selenium-webdriver'
3 require 'headless'
4
5 class ProjectsTest < ActionDispatch::IntegrationTest
6   setup do
7     Capybara.current_driver = Capybara.javascript_driver
8   end
9
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').
13       click
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
20       end
21       wait_for_ajax
22     end
23     visit current_path
24     assert(find?('.container-fluid', text: 'I just edited this.'),
25            "Description update did not survive page refresh")
26   end
27
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
44       end
45       wait_for_ajax
46       assert_selector '.editable', text: 'Now I have a new name.'
47     end
48     visit current_path
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.'
53     end
54   end
55
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
59
60     # within('.editable', text: 'New project') do
61     within('h2') do
62       find('.fa-pencil').click
63       find('.editable-input input').set('Project 1234')
64       find('.glyphicon-ok').click
65     end
66     wait_for_ajax
67
68     visit '/projects'
69     find('.btn', text: "Add new project").click
70     within('h2') do
71       find('.fa-pencil').click
72       find('.editable-input input').set('Project 5678')
73       find('.glyphicon-ok').click
74     end
75     wait_for_ajax
76
77     click_link 'Move project...'
78     find('.selectable', text: 'Project 1234').click
79     find('.modal-footer a,button', text: 'Move').click
80     wait_for_ajax
81
82     # Wait for the page to refresh and show the new parent in Sharing panel
83     click_link 'Sharing'
84     assert(page.has_link?("Project 1234"),
85            "Project 5678 should now be inside project 1234")
86   end
87
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")
92   end
93
94   def share_rows
95     find('#project_sharing').all('tr')
96   end
97
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"
113       end
114       click_on "Add"
115     end
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")
121     end
122   end
123
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
129       click_on("Read")
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")
134       click_on "Revoke"
135     end
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")
141     end
142   end
143
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")
148   end
149
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(" ")
153
154     show_project_using("active")
155     click_on "Sharing"
156     add_share_and_check("users", new_name)
157     modify_share_and_check(new_name)
158   end
159
160   test "project owner can manage sharing for another group" do
161     new_name = api_fixture('groups')['future_project_viewing_group']['name']
162
163     show_project_using("active")
164     click_on "Sharing"
165     add_share_and_check("groups", new_name)
166     modify_share_and_check(new_name)
167   end
168
169   test "'share with group' listing does not offer projects" do
170     show_project_using("active")
171     click_on "Sharing"
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")
179   end
180 end