@@ -2735,3 +2735,147 @@ testthat::describe("teal.data code with a function defined", {
27352735 )
27362736 })
27372737})
2738+
2739+ testthat :: describe(" teal-reporter" , {
2740+ it(" Clicking Add Card adds a card to the reporter" , {
2741+ shiny :: testServer(
2742+ app = srv_teal ,
2743+ args = list (
2744+ id = " test" ,
2745+ data = within(
2746+ teal.data :: teal_data(),
2747+ iris <- iris
2748+ ),
2749+ modules = modules(
2750+ module(" module_1" , server = function (id , data ) data )
2751+ )
2752+ ),
2753+ expr = {
2754+ session $ setInputs(`teal_modules-active_module_id` = " module_1" )
2755+ session $ flushReact()
2756+ testthat :: expect_length(reporter $ get_cards(), 0 )
2757+ session $ setInputs(`teal_modules-nav-module_1-add_reporter_wrapper-reporter_add-add_report_card_button` = 1 )
2758+ session $ setInputs(`teal_modules-nav-module_1-add_reporter_wrapper-reporter_add-add_card_ok` = 1 )
2759+ testthat :: expect_length(reporter $ get_cards(), 1 )
2760+ }
2761+ )
2762+ })
2763+
2764+ it(" Card added to the report contains ## Data preparation element" , {
2765+ shiny :: testServer(
2766+ app = srv_teal ,
2767+ args = list (
2768+ id = " test" ,
2769+ data = within(
2770+ teal.data :: teal_data(),
2771+ iris <- iris
2772+ ),
2773+ modules = modules(
2774+ module(" module_1" , server = function (id , data ) data )
2775+ )
2776+ ),
2777+ expr = {
2778+ session $ setInputs(`teal_modules-active_module_id` = " module_1" )
2779+ session $ flushReact()
2780+ session $ setInputs(`teal_modules-nav-module_1-add_reporter_wrapper-reporter_add-add_report_card_button` = 1 )
2781+ session $ setInputs(`teal_modules-nav-module_1-add_reporter_wrapper-reporter_add-add_card_ok` = 1 )
2782+ testthat :: expect_contains(reporter $ get_cards()[[1 ]], " ## Data preparation" )
2783+ }
2784+ )
2785+ })
2786+
2787+ it(" Card added to the report contains concatenated code_chunks" , {
2788+ shiny :: testServer(
2789+ app = srv_teal ,
2790+ args = list (
2791+ id = " test" ,
2792+ data = within(
2793+ teal.data :: teal_data(),
2794+ iris <- iris
2795+ ),
2796+ modules = modules(
2797+ module(" module_1" , server = function (id , data ) data )
2798+ )
2799+ ),
2800+ expr = {
2801+ session $ setInputs(`teal_modules-active_module_id` = " module_1" )
2802+ session $ flushReact()
2803+ session $ setInputs(`teal_modules-nav-module_1-add_reporter_wrapper-reporter_add-add_report_card_button` = 1 )
2804+ session $ setInputs(`teal_modules-nav-module_1-add_reporter_wrapper-reporter_add-add_card_ok` = 1 )
2805+ testthat :: expect_identical(
2806+ reporter $ get_cards()[[1 ]][[2 ]],
2807+ teal.reporter :: code_chunk(
2808+ " iris <- iris\n .raw_data <- list2env(list(iris = iris))\n lockEnvironment(.raw_data) # @linksto .raw_data"
2809+ )
2810+ )
2811+ }
2812+ )
2813+ })
2814+
2815+ it(" Card added to the report contains elements added in a module" , {
2816+ shiny :: testServer(
2817+ app = srv_teal ,
2818+ args = list (
2819+ id = " test" ,
2820+ data = within(
2821+ teal.data :: teal_data(),
2822+ iris <- iris
2823+ ),
2824+ modules = modules(
2825+ module(" module_1" , server = function (id , data ) reactive(within(data(), iris2 <- iris )))
2826+ )
2827+ ),
2828+ expr = {
2829+ session $ setInputs(`teal_modules-active_module_id` = " module_1" )
2830+ session $ flushReact()
2831+ session $ setInputs(`teal_modules-nav-module_1-add_reporter_wrapper-reporter_add-add_report_card_button` = 1 )
2832+ session $ setInputs(`teal_modules-nav-module_1-add_reporter_wrapper-reporter_add-add_card_ok` = 1 )
2833+ testthat :: expect_identical(
2834+ reporter $ get_cards()[[1 ]][[2 ]],
2835+ teal.reporter :: code_chunk(c(
2836+ " iris <- iris" ,
2837+ " .raw_data <- list2env(list(iris = iris))" ,
2838+ " lockEnvironment(.raw_data) # @linksto .raw_data" ,
2839+ " iris2 <- iris"
2840+ ))
2841+ )
2842+ }
2843+ )
2844+ })
2845+
2846+ it(" Card added to the report contains Filter settings section, teal-slices-yaml and code if filters are set" , {
2847+ shiny :: testServer(
2848+ app = srv_teal ,
2849+ args = list (
2850+ id = " test" ,
2851+ data = within(
2852+ teal.data :: teal_data(),
2853+ iris <- iris
2854+ ),
2855+ modules = modules(
2856+ module(" module_1" , server = function (id , data ) data )
2857+ ),
2858+ filter = teal_slices(
2859+ teal_slice(dataname = " iris" , varname = " Species" , selected = " setosa" )
2860+ )
2861+ ),
2862+ expr = {
2863+ session $ setInputs(`teal_modules-active_module_id` = " module_1" )
2864+ session $ flushReact()
2865+ session $ setInputs(`teal_modules-nav-module_1-add_reporter_wrapper-reporter_add-add_report_card_button` = 1 )
2866+ session $ setInputs(`teal_modules-nav-module_1-add_reporter_wrapper-reporter_add-add_card_ok` = 1 )
2867+ testthat :: expect_contains(
2868+ reporter $ get_cards()[[1 ]],
2869+ c(
2870+ " ### Filter settings" ,
2871+ teal.reporter :: code_chunk(
2872+ " - Dataset name: iris\n Variable name: Species\n Selected Values: setosa\n " ,
2873+ lang = " filters"
2874+ ),
2875+ teal.reporter :: code_chunk(" iris <- dplyr::filter(iris, Species == \" setosa\" )" )
2876+ )
2877+ )
2878+ }
2879+ )
2880+ })
2881+ })
0 commit comments