Skip to content

Commit

Permalink
get_teal_bs_theme(): use checkmate for throw and check (#1318)
Browse files Browse the repository at this point in the history
one step closer towards consistent error / warning message when checking
classes
  • Loading branch information
pawelru authored Aug 14, 2024
1 parent 9c6d38c commit 232e698
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@ get_client_timezone <- function(ns) {
#' @keywords internal
get_teal_bs_theme <- function() {
bs_theme <- getOption("teal.bs_theme")

if (is.null(bs_theme)) {
NULL
} else if (!inherits(bs_theme, "bs_theme")) {
warning("teal.bs_theme has to be of a bslib::bs_theme class, the default shiny bootstrap is used.")
NULL
} else {
bs_theme
return(NULL)
}

if (!checkmate::test_class(bs_theme, "bs_theme")) {
warning(
"Assertion on 'teal.bs_theme' option value failed: ",
checkmate::check_class(bs_theme, "bs_theme"),
". The default Shiny Bootstrap theme will be used."
)
return(NULL)
}

bs_theme
}

#' Return parentnames along with datanames.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ testthat::test_that("get_teal_bs_theme", {
testthat::expect_s3_class(get_teal_bs_theme(), "bs_theme")
})
withr::with_options(list("teal.bs_theme" = 1), {
testthat::expect_warning(get_teal_bs_theme(), "the default shiny bootstrap is used")
testthat::expect_warning(get_teal_bs_theme(), ".*The default Shiny Bootstrap theme will be used.")
})
withr::with_options(list("teal.bs_theme" = "bs_theme"), {
testthat::expect_warning(get_teal_bs_theme(), "the default shiny bootstrap is used")
testthat::expect_warning(get_teal_bs_theme(), ".*The default Shiny Bootstrap theme will be used.")
})
})

Expand Down

0 comments on commit 232e698

Please sign in to comment.