tests/testthat/test_log_viewer.R

context("periscope2 - Log Viewer")
local_edition(3)
# Helper functions
sample_log <- function(){
    c("actions [2022-02-19 14:03:26] Be Sure to Remember to Log ALL user actions",
      "actions [2022-02-19 14:03:27] Sample Title (click for an info pop-up) started with log level <DEBUG>",
      "actions [2022-02-19 14:04:32] Application Reset requested by user.  Resetting in  5 seconds")
}

null_log <- function() {
    NULL
}

# UI unit tests
test_that("logViewerOutput", {
    expect_snapshot_output(logViewerOutput("myid"))
})


# Server unit tests
test_that("logViewer - valid sample log", {
    testServer(logViewer,
               args = list(id = "myid", logger = sample_log),
               expr = {
                   expect_snapshot_output(output$"myid-reactTableOutputID")
               })
})


test_that("logViewer - null log", {
    testServer(logViewer,
               args = list(id = "nullLogger", logger = null_log),
               expr = {
                   expect_true(grepl('"x":null', output$"nullLogger-reactTableOutputID", fixed = TRUE))
               })
})

Try the periscope2 package in your browser

Any scripts or data that you put into this service are public.

periscope2 documentation built on Sept. 9, 2025, 5:44 p.m.