]> git.openstreetmap.org Git - rails.git/blob - test/helpers/user_roles_helper_test.rb
Underline time elements that have a title
[rails.git] / test / helpers / user_roles_helper_test.rb
1 require "test_helper"
2
3 class UserRolesHelperTest < ActionView::TestCase
4   attr_accessor :current_user
5
6   def test_role_icon_normal
7     self.current_user = create(:user)
8
9     icon = role_icon(current_user, "moderator")
10     assert_dom_equal "", icon
11
12     icon = role_icon(create(:moderator_user), "moderator")
13     expected = <<~HTML.delete("\n")
14       <img srcset="/images/roles/moderator.svg" border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />
15     HTML
16     assert_dom_equal expected, icon
17   end
18
19   def test_role_icon_administrator
20     self.current_user = create(:administrator_user)
21
22     user = create(:user)
23     icon = role_icon(user, "moderator")
24     expected = <<~HTML.delete("\n")
25       <a data-confirm="Are you sure you want to grant the role `moderator&#39; to the user `#{user.display_name}&#39;?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(user.display_name)}/role/moderator/grant">
26       <img srcset="/images/roles/blank_moderator.svg" border="0" alt="Grant moderator access" title="Grant moderator access" src="/images/roles/blank_moderator.png" width="20" height="20" />
27       </a>
28     HTML
29     assert_dom_equal expected, icon
30
31     moderator_user = create(:moderator_user)
32     icon = role_icon(moderator_user, "moderator")
33     expected = <<~HTML.delete("\n")
34       <a data-confirm="Are you sure you want to revoke the role `moderator&#39; from the user `#{moderator_user.display_name}&#39;?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(moderator_user.display_name)}/role/moderator/revoke">
35       <img srcset="/images/roles/moderator.svg" border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" />
36       </a>
37     HTML
38     assert_dom_equal expected, icon
39   end
40
41   def test_role_icons_normal
42     self.current_user = create(:user)
43
44     icons = role_icons(current_user)
45     assert_dom_equal "", icons
46
47     icons = role_icons(create(:moderator_user))
48     expected = <<~HTML.delete("\n")
49       <img srcset="/images/roles/moderator.svg" border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />
50     HTML
51     assert_dom_equal expected, icons
52
53     icons = role_icons(create(:super_user))
54     expected = <<~HTML.delete("\n")
55       <img srcset="/images/roles/administrator.svg" border="0" alt="This user is an administrator" title="This user is an administrator" src="/images/roles/administrator.png" width="20" height="20" />
56       <img srcset="/images/roles/moderator.svg" border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />
57     HTML
58     assert_dom_equal expected, icons
59   end
60
61   def test_role_icons_administrator
62     self.current_user = create(:administrator_user)
63
64     user = create(:user)
65     icons = role_icons(user)
66     expected = <<~HTML.delete("\n")
67       <a data-confirm="Are you sure you want to grant the role `administrator&#39; to the user `#{user.display_name}&#39;?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(user.display_name)}/role/administrator/grant">
68       <img srcset="/images/roles/blank_administrator.svg" border="0" alt="Grant administrator access" title="Grant administrator access" src="/images/roles/blank_administrator.png" width="20" height="20" />
69       </a>
70       <a data-confirm="Are you sure you want to grant the role `moderator&#39; to the user `#{user.display_name}&#39;?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(user.display_name)}/role/moderator/grant">
71       <img srcset="/images/roles/blank_moderator.svg" border="0" alt="Grant moderator access" title="Grant moderator access" src="/images/roles/blank_moderator.png" width="20" height="20" />
72       </a>
73     HTML
74     assert_dom_equal expected, icons
75
76     moderator_user = create(:moderator_user)
77     icons = role_icons(moderator_user)
78     expected = <<~HTML.delete("\n")
79       <a data-confirm="Are you sure you want to grant the role `administrator&#39; to the user `#{moderator_user.display_name}&#39;?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(moderator_user.display_name)}/role/administrator/grant">
80       <img srcset="/images/roles/blank_administrator.svg" border="0" alt="Grant administrator access" title="Grant administrator access" src="/images/roles/blank_administrator.png" width="20" height="20" />
81       </a>
82       <a data-confirm="Are you sure you want to revoke the role `moderator&#39; from the user `#{moderator_user.display_name}&#39;?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(moderator_user.display_name)}/role/moderator/revoke">
83       <img srcset="/images/roles/moderator.svg" border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" />
84       </a>
85     HTML
86     assert_dom_equal expected, icons
87
88     super_user = create(:super_user)
89     icons = role_icons(super_user)
90     expected = <<~HTML.delete("\n")
91       <a data-confirm="Are you sure you want to revoke the role `administrator&#39; from the user `#{super_user.display_name}&#39;?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(super_user.display_name)}/role/administrator/revoke">
92       <img srcset="/images/roles/administrator.svg" border="0" alt="Revoke administrator access" title="Revoke administrator access" src="/images/roles/administrator.png" width="20" height="20" />
93       </a>
94       <a data-confirm="Are you sure you want to revoke the role `moderator&#39; from the user `#{super_user.display_name}&#39;?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(super_user.display_name)}/role/moderator/revoke">
95       <img srcset="/images/roles/moderator.svg" border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" />
96       </a>
97     HTML
98     assert_dom_equal expected, icons
99   end
100 end