#| viewerHeight: 500 ## file: app.R library(shiny) ui <- fluidPage() server <- function(input, output) {} shinyApp(ui, server)
# Test peek_shinylive_app() ---- test_that("peek_shinylive_app(): handles HTML content correctly", { # Create sample HTML content with an embedded R Shiny application # The content simulates a Quarto document structure with a shinylive-r code block html_content <- '
#| viewerHeight: 500 ## file: app.R library(shiny) ui <- fluidPage() server <- function(input, output) {} shinyApp(ui, server)
#| viewerHeight: 500 ## file: app.R library(shiny) ui <- fluidPage() server <- function(input, output) {} shinyApp(ui, server)' # Mock HTTP-related functions testthat::local_mocked_bindings( GET = function(...) base::structure( list( headers = list("content-type" = "text/html"), content = base::charToRaw(html_content) ), class = "response" ), http_error = function(...) FALSE, content = function(...) html_content, .package = "httr" ) # Create temporary directory for output temp_dir <- base::tempfile() # Test the function with app-dir output format result <- peek_quarto_shinylive_app( "http://example.com", output_format = "app-dir", output_path = temp_dir ) # Verify result type and format testthat::expect_s3_class(result, "quarto_shinylive_apps") testthat::expect_equal(result$output_format, "app-dir") # Clean up temporary directory base::unlink(temp_dir, recursive = TRUE) }) # Test peek_standalone_shinylive_app() ---- test_that("peek_standalone_shinylive_app(): processes standalone app correctly", { # Create sample app.json content app_json <- list( list( name = "app.R", content = "library(shiny)\n...", type = "text" ) ) # Mock HTTP-related functions testthat::local_mocked_bindings( # Mock GET to return JSON content with appropriate headers GET = function(...) base::structure( list( headers = list("content-type" = "application/json"), content = base::charToRaw(jsonlite::toJSON(app_json)) ), class = "response" ), http_error = function(...) FALSE, content = function(...) jsonlite::toJSON(app_json), .package = "httr" ) # Create temporary directory for output temp_dir <- base::tempfile() # Test standalone app processing result <- peek_standalone_shinylive_app( "http://example.com/app.json", output_dir = temp_dir ) # Verify result type and file creation testthat::expect_s3_class(result, "standalone_shinylive_app") testthat::expect_true(base::file.exists(base::file.path(temp_dir, "app.R"))) # Clean up temporary directory base::unlink(temp_dir, recursive = TRUE) })