3354: add integration tests verify textile descriptions for projects
[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 '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').
31       click
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
38       end
39       wait_for_ajax
40     end
41     visit current_path
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')
50   end
51
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').
55       click
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
62       end
63       wait_for_ajax
64     end
65     visit current_path
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')
74   end
75
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').
79       click
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
86       end
87       wait_for_ajax
88     end
89     visit current_path
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')
97   end
98
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('specimens')['owned_by_aproject_with_no_name_link']['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#specimen"]'
107       within first('tr', text: 'Specimen') 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
115       end
116       wait_for_ajax
117       assert_selector '.editable', text: 'Now I have a new name.'
118     end
119     visit current_path
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.'
124     end
125   end
126
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
130
131     # within('.editable', text: 'New project') do
132     within('h2') do
133       find('.fa-pencil').click
134       find('.editable-input input').set('Project 1234')
135       find('.glyphicon-ok').click
136     end
137     wait_for_ajax
138
139     visit '/projects'
140     find('.btn', text: "Add new project").click
141     within('h2') do
142       find('.fa-pencil').click
143       find('.editable-input input').set('Project 5678')
144       find('.glyphicon-ok').click
145     end
146     wait_for_ajax
147
148     click_link 'Move project...'
149     find('.selectable', text: 'Project 1234').click
150     find('.modal-footer a,button', text: 'Move').click
151     wait_for_ajax
152
153     # Wait for the page to refresh and show the new parent in Sharing panel
154     click_link 'Sharing'
155     assert(page.has_link?("Project 1234"),
156            "Project 5678 should now be inside project 1234")
157   end
158
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")
163   end
164
165   def share_rows
166     find('#project_sharing').all('tr')
167   end
168
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"
184       end
185       click_on "Add"
186     end
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")
192     end
193   end
194
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
200       click_on("Read")
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")
205       click_on "Revoke"
206     end
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")
212     end
213   end
214
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")
219   end
220
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(" ")
224
225     show_project_using("active")
226     click_on "Sharing"
227     add_share_and_check("users", new_name)
228     modify_share_and_check(new_name)
229   end
230
231   test "project owner can manage sharing for another group" do
232     new_name = api_fixture('groups')['future_project_viewing_group']['name']
233
234     show_project_using("active")
235     click_on "Sharing"
236     add_share_and_check("groups", new_name)
237     modify_share_and_check(new_name)
238   end
239
240   test "'share with group' listing does not offer projects" do
241     show_project_using("active")
242     click_on "Sharing"
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")
250   end
251 end