@@ -7,17 +7,20 @@ defmodule FunWithFlags.UI.TemplatesTest do
7
7
import FunWithFlags.UI.TestUtils
8
8
9
9
setup_all do
10
- on_exit ( __MODULE__ , fn ( ) -> clear_redis_test_db ( ) end )
10
+ on_exit ( __MODULE__ , fn -> clear_redis_test_db ( ) end )
11
11
:ok
12
12
end
13
13
14
14
setup do
15
- conn = Plug.Conn . assign ( % Plug.Conn { } , :namespace , "/pear" )
16
- conn = Plug.Conn . assign ( conn , :csrf_token , Plug.CSRFProtection . get_csrf_token ( ) )
15
+ conn =
16
+ % Plug.Conn { }
17
+ |> Plug.Conn . assign ( :namespace , "/pear" )
18
+ |> Plug.Conn . put_private ( :csp_nonce_assign_key , % { style: :style_key , script: :script_key } )
19
+ |> Plug.Conn . assign ( :csrf_token , Plug.CSRFProtection . get_csrf_token ( ) )
20
+
17
21
{ :ok , conn: conn }
18
22
end
19
23
20
-
21
24
describe "_head()" do
22
25
test "it renders" , % { conn: conn } do
23
26
out = Templates . _head ( conn: conn , title: "Coconut" )
@@ -31,13 +34,13 @@ defmodule FunWithFlags.UI.TemplatesTest do
31
34
end
32
35
end
33
36
34
-
35
37
describe "index()" do
36
38
setup do
37
39
flags = [
38
40
% Flag { name: :pineapple , gates: [ Gate . new ( :boolean , true ) ] } ,
39
- % Flag { name: :papaya , gates: [ Gate . new ( :boolean , false ) ] } ,
41
+ % Flag { name: :papaya , gates: [ Gate . new ( :boolean , false ) ] }
40
42
]
43
+
41
44
{ :ok , flags: flags }
42
45
end
43
46
@@ -55,7 +58,6 @@ defmodule FunWithFlags.UI.TemplatesTest do
55
58
end
56
59
end
57
60
58
-
59
61
describe "details()" do
60
62
setup do
61
63
flag = % Flag { name: :avocado , gates: [ ] }
@@ -77,38 +79,65 @@ defmodule FunWithFlags.UI.TemplatesTest do
77
79
test "it includes the CSRF token" , % { conn: conn , flag: flag } do
78
80
csrf_token = Plug.CSRFProtection . get_csrf_token ( )
79
81
out = Templates . details ( conn: conn , flag: flag )
80
- assert String . contains? ( out , ~s{ <input type="hidden" name="_csrf_token" value="#{ csrf_token } ">} )
82
+
83
+ assert String . contains? (
84
+ out ,
85
+ ~s{ <input type="hidden" name="_csrf_token" value="#{ csrf_token } ">}
86
+ )
81
87
end
82
88
83
- test "it includes the global toggle, the new actor and new group forms, and the global delete form" , % { conn: conn , flag: flag } do
89
+ test "it includes the global toggle, the new actor and new group forms, and the global delete form" ,
90
+ % { conn: conn , flag: flag } do
84
91
out = Templates . details ( conn: conn , flag: flag )
85
- assert String . contains? ( out , ~s{ <form id="fwf-global-toggle-form" action="/pear/flags/avocado/boolean" method="post"} )
86
- assert String . contains? ( out , ~s{ <form id="fwf-new-actor-form" action="/pear/flags/avocado/actors" method="post"} )
87
- assert String . contains? ( out , ~s{ <form id="fwf-new-group-form" action="/pear/flags/avocado/groups" method="post"} )
88
- assert String . contains? ( out , ~s{ <form id="fwf-delete-flag-form" action="/pear/flags/avocado" method="post">} )
92
+
93
+ assert String . contains? (
94
+ out ,
95
+ ~s{ <form id="fwf-global-toggle-form" action="/pear/flags/avocado/boolean" method="post"}
96
+ )
97
+
98
+ assert String . contains? (
99
+ out ,
100
+ ~s{ <form id="fwf-new-actor-form" action="/pear/flags/avocado/actors" method="post"}
101
+ )
102
+
103
+ assert String . contains? (
104
+ out ,
105
+ ~s{ <form id="fwf-new-group-form" action="/pear/flags/avocado/groups" method="post"}
106
+ )
107
+
108
+ assert String . contains? (
109
+ out ,
110
+ ~s{ <form id="fwf-delete-flag-form" action="/pear/flags/avocado" method="post">}
111
+ )
89
112
end
90
113
91
- test "with no boolean gate, it includes both the enabled and disable boolean buttons" , % { conn: conn , flag: flag } do
114
+ test "with no boolean gate, it includes both the enabled and disable boolean buttons" , % {
115
+ conn: conn ,
116
+ flag: flag
117
+ } do
92
118
out = Templates . details ( conn: conn , flag: flag )
93
119
assert String . contains? ( out , ~s{ <button id="enable-boolean-btn" type="submit"} )
94
120
assert String . contains? ( out , ~s{ <button id="disable-boolean-btn" type="submit"} )
95
121
end
96
122
97
- test "with an enabled boolean gate, it includes both the disable and clear boolean buttons" , % { conn: conn , flag: flag } do
123
+ test "with an enabled boolean gate, it includes both the disable and clear boolean buttons" ,
124
+ % { conn: conn , flag: flag } do
98
125
f = % Flag { flag | gates: [ Gate . new ( :boolean , true ) ] }
99
126
out = Templates . details ( conn: conn , flag: f )
100
127
assert String . contains? ( out , ~s{ <button id="disable-boolean-btn" type="submit"} )
101
128
assert String . contains? ( out , ~s{ <button id="clear-boolean-btn" type="submit"} )
102
129
end
103
130
104
- test "with a disabled boolean gate, it includes both the enable and clear boolean buttons" , % { conn: conn , flag: flag } do
131
+ test "with a disabled boolean gate, it includes both the enable and clear boolean buttons" , % {
132
+ conn: conn ,
133
+ flag: flag
134
+ } do
105
135
f = % Flag { flag | gates: [ Gate . new ( :boolean , false ) ] }
106
136
out = Templates . details ( conn: conn , flag: f )
107
137
assert String . contains? ( out , ~s{ <button id="enable-boolean-btn" type="submit"} )
108
138
assert String . contains? ( out , ~s{ <button id="clear-boolean-btn" type="submit"} )
109
139
end
110
140
111
-
112
141
test "with no gates it reports the lists as empty" , % { conn: conn , flag: flag } do
113
142
group_gate = % Gate { type: :group , for: :rocks , enabled: true }
114
143
actor_gate = % Gate { type: :actor , for: "moss:123" , enabled: true }
@@ -139,28 +168,46 @@ defmodule FunWithFlags.UI.TemplatesTest do
139
168
out = Templates . details ( conn: conn , flag: flag )
140
169
141
170
assert String . contains? ( out , ~s{ <div id="actor_moss:123"} )
142
- assert String . contains? ( out , ~s{ <form action="/pear/flags/avocado/actors/moss:123" method="post"} )
171
+
172
+ assert String . contains? (
173
+ out ,
174
+ ~s{ <form action="/pear/flags/avocado/actors/moss:123" method="post"}
175
+ )
143
176
144
177
assert String . contains? ( out , ~s{ <div id="group_rocks"} )
145
- assert String . contains? ( out , ~s{ <form action="/pear/flags/avocado/groups/rocks" method="post"} )
178
+
179
+ assert String . contains? (
180
+ out ,
181
+ ~s{ <form action="/pear/flags/avocado/groups/rocks" method="post"}
182
+ )
146
183
end
147
184
148
- test "with actors and groups it contains their rows with escaped HTML and URLs" , % { conn: conn , flag: flag } do
185
+ test "with actors and groups it contains their rows with escaped HTML and URLs" , % {
186
+ conn: conn ,
187
+ flag: flag
188
+ } do
149
189
group_gate = % Gate { type: :group , for: :rocks , enabled: true }
150
190
actor_gate = % Gate { type: :actor , for: "moss:<h1>123</h1>" , enabled: true }
151
191
flag = % Flag { flag | gates: [ actor_gate , group_gate ] }
152
192
153
193
out = Templates . details ( conn: conn , flag: flag )
154
194
155
195
assert String . contains? ( out , ~s{ <div id="actor_moss:<h1>123</h1>"} )
156
- assert String . contains? ( out , ~s{ <form action="/pear/flags/avocado/actors/moss:%3Ch1%3E123%3C/h1%3E" method="post"} )
196
+
197
+ assert String . contains? (
198
+ out ,
199
+ ~s{ <form action="/pear/flags/avocado/actors/moss:%3Ch1%3E123%3C/h1%3E" method="post"}
200
+ )
157
201
158
202
assert String . contains? ( out , ~s{ <div id="group_rocks"} )
159
- assert String . contains? ( out , ~s{ <form action="/pear/flags/avocado/groups/rocks" method="post"} )
203
+
204
+ assert String . contains? (
205
+ out ,
206
+ ~s{ <form action="/pear/flags/avocado/groups/rocks" method="post"}
207
+ )
160
208
end
161
209
end
162
210
163
-
164
211
describe "new()" do
165
212
test "it renders" , % { conn: conn } do
166
213
out = Templates . new ( conn: conn )
@@ -170,7 +217,11 @@ defmodule FunWithFlags.UI.TemplatesTest do
170
217
test "it includes the right content" , % { conn: conn } do
171
218
out = Templates . new ( conn: conn )
172
219
assert String . contains? ( out , "<title>FunWithFlags - New Flag</title>" )
173
- assert String . contains? ( out , ~s{ <form id="new-flag-form" action="/pear/flags" method="post">} )
220
+
221
+ assert String . contains? (
222
+ out ,
223
+ ~s{ <form id="new-flag-form" action="/pear/flags" method="post">}
224
+ )
174
225
end
175
226
end
176
227
0 commit comments