@@ -149,3 +149,164 @@ testthat::test_that("countBar returns a div with class and two progressbars", {
149149 out <- rapply(countBar(inputId = " a" , countmax = countmax , countnow = countnow , counttotal ), unclass , how = " list" )
150150 testthat :: expect_identical(out , expected )
151151})
152+
153+ # countBarLabel ------------
154+ testthat :: test_that(" countBarLabel requires InputId to be a character(1)" , {
155+ testthat :: expect_no_error(countBarLabel(inputId = " a" , label = " a" , countmax = 50 ))
156+ testthat :: expect_error(countBarLabel(label = " a" , countmax = 50 ), " inputId" )
157+ testthat :: expect_error(countBarLabel(inputId = NULL , label = " a" , countmax = 50 ), " inputId" )
158+ testthat :: expect_error(countBarLabel(inputId = character (0 ), label = " a" , countmax = 50 ), " inputId" )
159+ testthat :: expect_error(countBarLabel(inputId = 1L , label = " a" , countmax = 50 ), " inputId" )
160+ })
161+
162+ testthat :: test_that(" countBarLabel requires label to be a character(1)" , {
163+ testthat :: expect_no_error(countBarLabel(inputId = " a" , label = " a" , countmax = 50 ))
164+ testthat :: expect_error(countBarLabel(inputId = " a" , label = character (0 ), countmax = 50 ), " label" )
165+ testthat :: expect_error(countBarLabel(inputId = " a" , label = 1 , countmax = 50 ), " label" )
166+ })
167+
168+ testthat :: test_that(" countBarLabel requires countmax to be a numeric(1)" , {
169+ testthat :: expect_no_error(countBarLabel(inputId = " a" , label = " a" , countmax = 100 ))
170+ testthat :: expect_error(countBarLabel(inputId = " a" , label = " a" , countmax = " 100" ), " countmax" )
171+ testthat :: expect_error(countBarLabel(inputId = " a" , label = " a" , countmax = numeric (0 )), " countmax" )
172+ })
173+
174+ testthat :: test_that(" countBarLabel requires countnow to be a numeric(1), NULL or missing" , {
175+ testthat :: expect_no_error(countBarLabel(inputId = " a" , label = " a" , countmax = 100 , countnow = 1 ))
176+ testthat :: expect_no_error(countBarLabel(inputId = " a" , label = " a" , countmax = 100 , countnow = NULL ))
177+ testthat :: expect_no_error(countBarLabel(inputId = " a" , label = " a" , countmax = 100 ))
178+ testthat :: expect_error(countBarLabel(inputId = " a" , label = " a" , countmax = 100 , countnow = " 50" ), " countnow" )
179+ testthat :: expect_error(countBarLabel(inputId = " a" , label = " a" , countmax = 100 , countnow = numeric (0 )), " countnow" )
180+ })
181+
182+ testthat :: test_that(" countBarLabel requires counttotal to be a numeric(1) or missing" , {
183+ testthat :: expect_no_error(countBarLabel(inputId = " a" , label = " a" , countmax = 100 , counttotal = 200 ))
184+ testthat :: expect_no_error(countBarLabel(inputId = " a" , label = " a" , countmax = 100 ))
185+ testthat :: expect_error(countBarLabel(inputId = " a" , label = " a" , countmax = 100 , counttotal = " 200" ), " counttotal" )
186+ testthat :: expect_error(
187+ countBarLabel(inputId = " a" , label = " a" , countmax = 100 , counttotal = numeric (0 )), " counttotal"
188+ )
189+ })
190+
191+ testthat :: test_that(" countBarLabel returns a div containing a progress bar and a label" , {
192+ label <- " a"
193+ countmax <- 150
194+ countnow <- 50
195+ counttotal <- 200
196+
197+ out <- countBarLabel(inputId = " a" , label = label , countmax = countmax , countnow = countnow , counttotal = counttotal )
198+
199+ expected <- tags $ div(
200+ countBar(inputId = " a" , countmax = countmax , countnow = countnow , counttotal = counttotal ),
201+ countLabel(inputId = " a" , label = label , countmax = countmax , countnow = countnow )
202+ )
203+ testthat :: expect_identical(out , expected )
204+ })
205+
206+ testthat :: test_that(" countBarLabel sets counttotal to countmax when missing" , {
207+ out <- countBarLabel(inputId = " a" , label = " a" , countmax = 100 , countnow = 50 )
208+ expected <- tags $ div(
209+ countBar(inputId = " a" , countmax = 100 , countnow = 50 , counttotal = 100 ),
210+ countLabel(inputId = " a" , label = label , countmax = 100 , countnow = 50 )
211+ )
212+ testthat :: expect_identical(out , expected )
213+ })
214+
215+ # countBarLabels -----
216+ countsmax <- c(3 , 7 , 10 )
217+ choices <- c(" a" , " b" , " c" )
218+ countsnow <- c(2 , 6 , 9 )
219+
220+ testthat :: test_that(" countBarLabels requires InputId to be a character(1)" , {
221+ testthat :: expect_no_error(
222+ countBarLabels(inputId = " a" , choices = choices , countsmax = countsmax , countsnow = countsnow )
223+ )
224+ testthat :: expect_error(
225+ countBarLabels(inputId = NULL , choices = choices , countsmax = countsmax , countsnow = countsnow ),
226+ " inputId"
227+ )
228+ testthat :: expect_error(
229+ countBarLabels(inputId = character (0 ), choices = choices , countsmax = countsmax , countsnow = countsnow ),
230+ " inputId"
231+ )
232+ testthat :: expect_error(
233+ countBarLabels(inputId = 1 , choices = choices , countsmax = countsmax , countsnow = countsnow ),
234+ " inputId"
235+ )
236+ testthat :: expect_error(
237+ countBarLabels(choices = choices , countsmax = countsmax , countsnow = countsnow ),
238+ " inputId"
239+ )
240+ })
241+
242+ testthat :: test_that(" countBarLabels requires choices to be a vector" , {
243+ testthat :: expect_no_error(
244+ countBarLabels(inputId = " a" , choices = choices , countsmax = countsmax , countsnow = countsnow )
245+ )
246+ testthat :: expect_no_error(
247+ countBarLabels(inputId = " a" , choices = c(1 , 2 , 3 ), countsmax = countsmax , countsnow = countsnow ),
248+ )
249+ testthat :: expect_error(
250+ countBarLabels(inputId = " a" , countsmax = countsmax , countsnow = countsnow ),
251+ " choices"
252+ )
253+
254+ testthat :: expect_no_error(countBarLabels(inputId = " a" , label = " a" , countmax = 100 ))
255+ testthat :: expect_error(countBarLabels(inputId = " a" , label = " a" , countmax = " 100" ), " countmax" )
256+ testthat :: expect_error(countBarLabels(inputId = " a" , label = " a" , countmax = numeric (0 )), " countmax" )
257+ })
258+
259+ testthat :: test_that(" countBarLabels requires countsmax to be a numeric of the same length as choices" , {
260+ testthat :: expect_no_error(
261+ countBarLabels(inputId = " a" , choices = choices , countsmax = countsmax , countsnow = countsnow )
262+ )
263+ testthat :: expect_error(
264+ countBarLabels(inputId = " a" , choices = choices , countsnow = countsnow ),
265+ " countsmax"
266+ )
267+ testthat :: expect_error(
268+ countBarLabels(inputId = " a" , choices = choices , countsmax = as.character(countsmax ), countsnow = countsnow ),
269+ " countsmax"
270+ )
271+ testthat :: expect_error(
272+ countBarLabels(inputId = " a" , choices = choices , countsmax = c(3 , 7 ), countsnow = countsnow ),
273+ " countsmax"
274+ )
275+ })
276+
277+
278+ testthat :: test_that(" countBarLabels requires counstnow to be a numeric lower than countsmax, NULL or missing" , {
279+ testthat :: expect_no_error(
280+ countBarLabels(inputId = " a" , choices = choices , countsmax = countsmax , countsnow = countsnow )
281+ )
282+ testthat :: expect_no_error(countBarLabels(inputId = " a" , choices = choices , countsmax = countsmax ))
283+ testthat :: expect_error(
284+ countBarLabels(inputId = " a" , choices = choices , countsmax = countsmax , countsnow = c(0 , 0 )),
285+ " countsmax"
286+ )
287+ testthat :: expect_error(
288+ countBarLabels(inputId = " a" , choices = choices , countsmax = countsmax , countsnow = c(1 , 20 , 2 )),
289+ " countsmax"
290+ )
291+ testthat :: expect_error(
292+ countBarLabels(inputId = " a" , choices = choices , countsmax = countsmax , countsnow = as.character(countsnow )),
293+ " countsmax"
294+ )
295+ })
296+
297+ testthat :: test_that(" countBarLabels returns a list of countBarLabel(s)" , {
298+ out <- countBarLabels(inputId = " a" , choices = choices , countsmax = countsmax , countsnow = countsnow )
299+
300+ ns <- NS(" a" )
301+ expected <- lapply(seq_along(choices ), function (i ) {
302+ countBarLabel(
303+ inputId = ns(i ),
304+ label = choices [i ],
305+ countmax = countsmax [i ],
306+ countnow = countsnow [i ],
307+ counttotal = sum(countsmax )
308+ )
309+ })
310+
311+ testthat :: expect_identical(out , expected )
312+ })
0 commit comments