Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / test / integration / trash_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'integration_helper'
6
7 class TrashTest < ActionDispatch::IntegrationTest
8   setup do
9     need_javascript
10   end
11
12   test "trash page" do
13     deleted = api_fixture('collections')['deleted_on_next_sweep']
14     expired1 = api_fixture('collections')['unique_expired_collection']
15     expired2 = api_fixture('collections')['unique_expired_collection2']
16
17     # visit trash page
18     visit page_with_token('active', "/trash")
19
20     assert_text deleted['name']
21     assert_text deleted['uuid']
22     assert_text deleted['portable_data_hash']
23     assert_text expired1['name']
24     assert_no_text expired2['name']   # not readable by this user
25     assert_no_text 'foo_file'         # not trash
26
27     # Un-trash one item using selection dropdown
28     within('tr', text: deleted['name']) do
29       first('input').click
30     end
31
32     click_button 'Selection...'
33     within('.selection-action-container') do
34       click_link 'Un-trash selected items'
35     end
36
37     wait_for_ajax
38
39     assert_text expired1['name']      # this should still be there
40     assert_no_text deleted['name']    # this should no longer be here
41
42     # Un-trash another item using the recycle button
43     within('tr', text: expired1['name']) do
44       first('.fa-recycle').click
45     end
46
47     wait_for_ajax
48
49     assert_text "The collection with UUID #{expired1['uuid']} is in the trash"
50
51     click_on "Click here to untrash '#{expired1['name']}'"
52
53     # verify that the two un-trashed items are now shown in /collections page
54     visit page_with_token('active', "/collections")
55     assert_text deleted['uuid']
56     assert_text expired1['uuid']
57     assert_no_text expired2['uuid']
58   end
59
60   ["button","selection"].each do |method|
61     test "trashed projects using #{method}" do
62       deleted = api_fixture('groups')['trashed_project']
63       aproject = api_fixture('groups')['aproject']
64
65       # verify that the un-trashed item are missing in /groups page
66       visit page_with_token('active', "/projects/zzzzz-tpzed-xurymjxw79nv3jz")
67       click_on "Subprojects"
68       assert_no_text deleted['name']
69
70       # visit trash page
71       visit page_with_token('active', "/trash")
72       click_on "Trashed projects"
73
74       assert_text deleted['name']
75       assert_text deleted['uuid']
76       assert_no_text aproject['name']
77       assert_no_text aproject['uuid']
78
79       # Un-trash item
80       if method == "button"
81         within('tr', text: deleted['uuid']) do
82           first('.fa-recycle').click
83         end
84         assert_text "The group with UUID #{deleted['uuid']} is in the trash"
85         click_on "Click here to untrash '#{deleted['name']}'"
86       else
87         within('tr', text: deleted['uuid']) do
88           first('input').click
89         end
90         click_button 'Selection...'
91         within('.selection-action-container') do
92           click_link 'Un-trash selected items'
93         end
94         wait_for_ajax
95         assert_no_text deleted['uuid']
96       end
97
98       # check that the un-trashed item are now shown on parent project page
99       visit page_with_token('active', "/projects/zzzzz-tpzed-xurymjxw79nv3jz")
100       click_on "Subprojects"
101       assert_text deleted['name']
102       assert_text aproject['name']
103
104       # Trash another item
105       if method == "button"
106         within('tr', text: aproject['name']) do
107           first('.fa-trash-o').click
108         end
109       else
110         within('tr', text: aproject['name']) do
111           first('input').click
112         end
113         click_button 'Selection'
114         within('.selection-action-container') do
115           click_link 'Remove selected'
116         end
117       end
118
119       wait_for_ajax
120       assert_no_text aproject['name']
121       visit current_path
122       assert_no_text aproject['name']
123
124       # visit trash page
125       visit page_with_token('active', "/trash")
126       click_on "Trashed projects"
127
128       assert_text aproject['name']
129       assert_text aproject['uuid']
130     end
131   end
132
133   test "trash page with search" do
134     deleted = api_fixture('collections')['deleted_on_next_sweep']
135     expired = api_fixture('collections')['unique_expired_collection']
136
137     visit page_with_token('active', "/trash")
138
139     assert_text deleted['name']
140     assert_text deleted['uuid']
141     assert_text deleted['portable_data_hash']
142     assert_text expired['name']
143
144     page.find_field('Search trash').set 'expired'
145
146     assert_no_text deleted['name']
147     assert_text expired['name']
148
149     page.find_field('Search trash').set deleted['portable_data_hash'][0..9]
150
151     assert_no_text expired['name']
152     assert_text deleted['name']
153     assert_text deleted['uuid']
154     assert_text deleted['portable_data_hash']
155
156     click_button 'Selection...'
157     within('.selection-action-container') do
158       assert_selector 'li.disabled', text: 'Un-trash selected items'
159     end
160
161     first('input').click
162
163     click_button 'Selection...'
164     within('.selection-action-container') do
165       assert_selector 'li', text: 'Un-trash selected items'
166       assert_selector 'li.disabled', text: 'Un-trash selected items'
167     end
168   end
169 end