1 require "application_system_test_case"
3 class UserBlocksSystemTest < ApplicationSystemTestCase
4 test "revoke all link is absent for anonymous users when viewed user has active blocks" do
5 blocked_user = create(:user)
6 create(:user_block, :user => blocked_user)
8 visit user_path(blocked_user)
9 assert_no_link "Revoke all blocks"
12 test "revoke all link is absent for regular users when viewed user has active blocks" do
13 blocked_user = create(:user)
14 create(:user_block, :user => blocked_user)
15 sign_in_as(create(:user))
17 visit user_path(blocked_user)
18 assert_no_link "Revoke all blocks"
21 test "revoke all link is absent for moderators when viewed user has no active blocks" do
22 blocked_user = create(:user)
23 create(:user_block, :expired, :user => blocked_user)
24 sign_in_as(create(:moderator_user))
26 visit user_path(blocked_user)
27 assert_no_link "Revoke all blocks"
30 test "revoke all page has no controls when viewed user has no active blocks" do
31 blocked_user = create(:user)
32 sign_in_as(create(:moderator_user))
34 visit revoke_all_user_blocks_path(blocked_user)
35 assert_title "Revoking all blocks on #{blocked_user.display_name}"
36 assert_text "Revoking all blocks on #{blocked_user.display_name}"
37 assert_no_button "Revoke!"
40 test "revoke all link is present and working for moderators when viewed user has one active block" do
41 blocked_user = create(:user)
42 create(:user_block, :user => blocked_user)
43 sign_in_as(create(:moderator_user))
45 visit user_path(blocked_user)
46 assert_link "Revoke all blocks"
48 click_on "Revoke all blocks"
49 assert_title "Revoking all blocks on #{blocked_user.display_name}"
50 assert_text "Revoking all blocks on #{blocked_user.display_name}"
51 assert_unchecked_field "Are you sure you wish to revoke 1 active block?"
52 assert_button "Revoke!"
55 test "revoke all link is present and working for moderators when viewed user has multiple active blocks" do
56 blocked_user = create(:user)
57 create(:user_block, :user => blocked_user)
58 create(:user_block, :user => blocked_user)
59 create(:user_block, :expired, :user => blocked_user)
60 sign_in_as(create(:moderator_user))
62 visit user_path(blocked_user)
63 assert_link "Revoke all blocks"
65 click_on "Revoke all blocks"
66 assert_title "Revoking all blocks on #{blocked_user.display_name}"
67 assert_text "Revoking all blocks on #{blocked_user.display_name}"
68 assert_unchecked_field "Are you sure you wish to revoke 2 active blocks?"
69 assert_button "Revoke!"
72 test "duration controls are present for active blocks" do
73 creator_user = create(:moderator_user)
74 block = create(:user_block, :creator => creator_user, :reason => "Testing editing active blocks", :ends_at => Time.now.utc + 2.days)
75 sign_in_as(creator_user)
77 visit edit_user_block_path(block)
78 assert_field "Reason", :with => "Testing editing active blocks"
79 assert_select "user_block_period", :selected => "2 days"
80 assert_unchecked_field "Needs view"
82 fill_in "Reason", :with => "Editing active blocks works"
83 click_on "Update block"
84 assert_text(/Reason for block:\s+Editing active blocks works/)
87 test "duration controls are removed for inactive blocks" do
88 creator_user = create(:moderator_user)
89 block = create(:user_block, :expired, :creator => creator_user, :reason => "Testing editing expired blocks")
90 sign_in_as(creator_user)
92 visit edit_user_block_path(block)
93 assert_field "Reason", :with => "Testing editing expired blocks"
94 assert_no_select "user_block_period"
95 assert_no_field "Needs view"
97 fill_in "Reason", :with => "Editing expired blocks works"
98 click_on "Update block"
99 assert_text(/Reason for block:\s+Editing expired blocks works/)
102 test "other moderator can revoke 0-hour blocks" do
103 creator_user = create(:moderator_user)
104 other_moderator_user = create(:moderator_user)
105 block = create(:user_block, :zero_hour, :needs_view, :creator => creator_user, :reason => "Testing revoking 0-hour blocks")
106 sign_in_as(other_moderator_user)
108 visit edit_user_block_path(block)
109 assert_field "Reason", :with => "Testing revoking 0-hour blocks"
110 assert_no_select "user_block_period"
111 assert_no_field "Needs view"
113 fill_in "Reason", :with => "Revoking 0-hour blocks works"
114 click_on "Update block"
115 assert_text(/Revoker:\s+#{Regexp.escape other_moderator_user.display_name}/)
116 assert_text(/Status:\s+Ended/)
117 assert_text(/Reason for block:\s+Revoking 0-hour blocks works/)