12125: Adding test
[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_no_text expired1['name']
50
51     # verify that the two un-trashed items are now shown in /collections page
52     visit page_with_token('active', "/collections")
53     assert_text deleted['uuid']
54     assert_text expired1['uuid']
55     assert_no_text expired2['uuid']
56   end
57
58   test "trashed projects" do
59     deleted = api_fixture('groups')['trashed_project']
60
61     # verify that the un-trashed item are missing in /groups page
62     visit page_with_token('active', "/groups")
63     assert_no_text deleted['uuid']
64
65     # visit trash page
66     visit page_with_token('active', "/trash")
67     click_on "Trashed projects"
68
69     assert_text deleted['name']
70     assert_text deleted['uuid']
71
72     # Un-trash item using the recycle button
73     within('tr', text: deleted['name']) do
74       first('.fa-recycle').click
75     end
76
77     wait_for_ajax
78
79     assert_no_text deleted['uuid']
80
81     # verify that the un-trashed item are now shown in /groups page
82     visit page_with_token('active', "/groups")
83     assert_text deleted['uuid']
84   end
85
86   test "trash page with search" do
87     deleted = api_fixture('collections')['deleted_on_next_sweep']
88     expired = api_fixture('collections')['unique_expired_collection']
89
90     visit page_with_token('active', "/trash")
91
92     assert_text deleted['name']
93     assert_text deleted['uuid']
94     assert_text deleted['portable_data_hash']
95     assert_text expired['name']
96
97     page.find_field('Search trash').set 'expired'
98
99     assert_no_text deleted['name']
100     assert_text expired['name']
101
102     page.find_field('Search trash').set deleted['portable_data_hash'][0..9]
103
104     assert_no_text expired['name']
105     assert_text deleted['name']
106     assert_text deleted['uuid']
107     assert_text deleted['portable_data_hash']
108
109     click_button 'Selection...'
110     within('.selection-action-container') do
111       assert_selector 'li.disabled', text: 'Un-trash selected items'
112     end
113
114     first('input').click
115
116     click_button 'Selection...'
117     within('.selection-action-container') do
118       assert_selector 'li', text: 'Un-trash selected items'
119       assert_selector 'li.disabled', text: 'Un-trash selected items'
120     end
121   end
122 end