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!"