]> git.openstreetmap.org Git - rails.git/blob - test/helpers/user_roles_helper_test.rb
Colour preview moved into new browse_tags_helper
[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       <picture>
15       <source srcset="/images/roles/moderator.svg" type="image/svg+xml" />
16       <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" />
17       </picture>
18     HTML
19     assert_dom_equal expected, icon
20   end
21
22   def test_role_icon_administrator
23     self.current_user = create(:administrator_user)
24
25     user = create(:user)
26     icon = role_icon(user, "moderator")
27     expected = <<~HTML.delete("\n")
28       <a 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">
29       <picture>
30       <source srcset="/images/roles/blank_moderator.svg" type="image/svg+xml" />
31       <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" />
32       </picture>
33       </a>
34     HTML
35     assert_dom_equal expected, icon
36
37     moderator_user = create(:moderator_user)
38     icon = role_icon(moderator_user, "moderator")
39     expected = <<~HTML.delete("\n")
40       <a 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">
41       <picture>
42       <source srcset="/images/roles/moderator.svg" type="image/svg+xml" />
43       <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" />
44       </picture>
45       </a>
46     HTML
47     assert_dom_equal expected, icon
48   end
49
50   def test_role_icons_normal
51     self.current_user = create(:user)
52
53     icons = role_icons(current_user)
54     assert_dom_equal "  ", icons
55
56     icons = role_icons(create(:moderator_user))
57     expected = "  " + <<~HTML.delete("\n")
58       <picture>
59       <source srcset="/images/roles/moderator.svg" type="image/svg+xml" />
60       <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" />
61       </picture>
62     HTML
63     assert_dom_equal expected, icons
64
65     icons = role_icons(create(:super_user))
66     expected = " " + <<~HTML.delete("\n")
67       <picture>
68       <source srcset="/images/roles/administrator.svg" type="image/svg+xml" />
69       <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" />
70       </picture>
71        <picture>
72       <source srcset="/images/roles/moderator.svg" type="image/svg+xml" />
73       <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" />
74       </picture>
75     HTML
76     assert_dom_equal expected, icons
77   end
78
79   def test_role_icons_administrator
80     self.current_user = create(:administrator_user)
81
82     user = create(:user)
83     icons = role_icons(user)
84     expected = " " + <<~HTML.delete("\n")
85       <a 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">
86       <picture>
87       <source srcset="/images/roles/blank_administrator.svg" type="image/svg+xml" />
88       <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" />
89       </picture>
90       </a>
91        <a 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">
92       <picture>
93       <source srcset="/images/roles/blank_moderator.svg" type="image/svg+xml" />
94       <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" />
95       </picture>
96       </a>
97     HTML
98     assert_dom_equal expected, icons
99
100     moderator_user = create(:moderator_user)
101     icons = role_icons(moderator_user)
102     expected = " " + <<~HTML.delete("\n")
103       <a 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">
104       <picture>
105       <source srcset="/images/roles/blank_administrator.svg" type="image/svg+xml" />
106       <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" />
107       </picture>
108       </a>
109        <a 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">
110       <picture>
111       <source srcset="/images/roles/moderator.svg" type="image/svg+xml" />
112       <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" />
113       </picture>
114       </a>
115     HTML
116     assert_dom_equal expected, icons
117
118     super_user = create(:super_user)
119     icons = role_icons(super_user)
120     expected = " " + <<~HTML.delete("\n")
121       <a 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">
122       <picture>
123       <source srcset="/images/roles/administrator.svg" type="image/svg+xml" />
124       <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" />
125       </picture>
126       </a>
127        <a 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">
128       <picture>
129       <source srcset="/images/roles/moderator.svg" type="image/svg+xml" />
130       <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" />
131       </picture>
132       </a>
133     HTML
134     assert_dom_equal expected, icons
135   end
136 end