@@ -271,6 +271,70 @@ test_that("Check check_namespace_in_file", {
271
271
)
272
272
})
273
273
274
+ test_that(" Check fix_ns_in_data works" , {
275
+ path <- tempfile(fileext = " .R" )
276
+
277
+ writeLines(
278
+ c(
279
+ " mod_test_module_ui <- function(id) {" ,
280
+ " ns <- NS(id)" ,
281
+ " tagList(" ,
282
+ " selectInput(" ,
283
+ " inputId = 'selectinput'," , # Missing NS
284
+ " label = 'Select input'," ,
285
+ " choices = c(LETTERS[1:10])" ,
286
+ " )," ,
287
+ " actionButton(" ,
288
+ " inputId = 'actionbutton'," , # Missing NS
289
+ " label = 'Action button'" ,
290
+ " )" ,
291
+ " )" ,
292
+ " }" ,
293
+ " " ,
294
+ " mod_test_module_server <- function(id) {" ,
295
+ " observeEvent(input$actionbutton, {" ,
296
+ " message(input$actionbutton)" ,
297
+ " message(input$selectinput)" ,
298
+ " })" ,
299
+ " }"
300
+ ),
301
+ con = path
302
+ )
303
+
304
+ data <- check_namespace_in_file(
305
+ path = path
306
+ )
307
+
308
+ fix_ns_in_data(data )
309
+
310
+ expect_equal(
311
+ readLines(path ),
312
+ c(
313
+ " mod_test_module_ui <- function(id) {" ,
314
+ " ns <- NS(id)" ,
315
+ " tagList(" ,
316
+ " selectInput(" ,
317
+ " inputId = ns('selectinput')," , # NS present
318
+ " label = 'Select input'," ,
319
+ " choices = c(LETTERS[1:10])" ,
320
+ " )," ,
321
+ " actionButton(" ,
322
+ " inputId = ns('actionbutton')," , # NS present
323
+ " label = 'Action button'" ,
324
+ " )" ,
325
+ " )" ,
326
+ " }" ,
327
+ " " ,
328
+ " mod_test_module_server <- function(id) {" ,
329
+ " observeEvent(input$actionbutton, {" ,
330
+ " message(input$actionbutton)" ,
331
+ " message(input$selectinput)" ,
332
+ " })" ,
333
+ " }"
334
+ )
335
+ )
336
+ })
337
+
274
338
dummy_dir_check_ns <- tempfile(pattern = " dummy" )
275
339
dir.create(dummy_dir_check_ns )
276
340
@@ -403,5 +467,47 @@ withr::with_dir(dummy_dir_check_ns, {
403
467
),
404
468
" NS check passed"
405
469
)
470
+
471
+ expect_equal(
472
+ readLines(file.path(dummy_golem_path , " R" , " mod_test_module.R" )),
473
+ c(
474
+ " #' first UI Function" ,
475
+ " #'" ,
476
+ " #' @description A shiny Module." ,
477
+ " #'" ,
478
+ " #' @param id,input,output,session Internal parameters for {shiny}." ,
479
+ " #'" ,
480
+ " #' @shinyModule A Golem module." ,
481
+ " #'" ,
482
+ " #' @importFrom shiny NS tagList" ,
483
+ " mod_test_module_ui <- function(id) {" ,
484
+ " ns <- NS(id)" ,
485
+ " tagList(" ,
486
+ " selectInput(" ,
487
+ " inputId = ns('selectinput')," ,
488
+ " label = 'Select input'," ,
489
+ " choices = c(LETTERS[1:10])" ,
490
+ " )," ,
491
+ " actionButton(" ,
492
+ " inputId = ns('actionbutton')," ,
493
+ " label = 'Action button'" ,
494
+ " )" ,
495
+ " )" ,
496
+ " }" ,
497
+ " " ,
498
+ " #' first Server Functions" ,
499
+ " #'" ,
500
+ " mod_test_module_server <- function(id) {" ,
501
+ " moduleServer(id, function(input, output, session) {" ,
502
+ " ns <- session$ns" ,
503
+ " " ,
504
+ " observeEvent(input$actionbutton, {" ,
505
+ " message(input$actionbutton)" ,
506
+ " message(input$selectinput)" ,
507
+ " })" ,
508
+ " })" ,
509
+ " }"
510
+ )
511
+ )
406
512
})
407
513
})
0 commit comments