]> git.openstreetmap.org Git - rails.git/blob - test/system/user_status_change_test.rb
Add UI for admins to suspend users
[rails.git] / test / system / user_status_change_test.rb
1 # frozen_string_literal: true
2
3 require "application_system_test_case"
4
5 class UserStatusChangeTest < ApplicationSystemTestCase
6   def setup
7     admin = create(:administrator_user)
8     sign_in_as(admin)
9   end
10
11   test "Admin can unsuspend a user" do
12     user = create(:user, :suspended)
13     visit user_path(user)
14     accept_confirm do
15       click_on "Unsuspend"
16     end
17
18     assert_no_content "Unsuspend"
19     user.reload
20     assert_equal "active", user.status
21   end
22
23   test "Admin can suspend a user" do
24     # There's another instance of "Suspend" in the page.
25     # This test uses a more specific text, putting it in
26     # a variable to avoid a misspelling when doing
27     # `assert_no_content` later
28     suspend_action_text = "Suspend this User"
29
30     user = create(:user)
31     visit user_path(user)
32     accept_confirm do
33       click_on suspend_action_text
34     end
35
36     assert_no_content suspend_action_text
37     user.reload
38     assert_equal "suspended", user.status
39   end
40
41   test "Admin can confirm a user" do
42     user = create(:user, :suspended)
43     visit user_path(user)
44     accept_confirm do
45       click_on "Confirm"
46     end
47
48     assert_no_content "Unsuspend"
49     user.reload
50     assert_equal "confirmed", user.status
51   end
52 end