Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c4fc0e3
tests: load library testthat to simplify tests and reuse units.
Nov 5, 2025
c063bc9
tests: add snapshot test for standard_layout to increase coverage
Nov 5, 2025
bc96824
tests: add more scenarios for draggable_buckets to increase coverage
Nov 6, 2025
9b00ed4
tests: add more scenarios and snapshot tests for optionalInput functions
Nov 6, 2025
d78e6a1
tests: add more tests for verbatim_popup_ui and get_dt_rows in order …
Nov 6, 2025
0181418
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 6, 2025
ad29134
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 6, 2025
39550e1
chore: fix lintr
Nov 6, 2025
c9d4904
Merge branch 'oriol.new_commit' into 318_coverage_unit_tests@main
Nov 6, 2025
6b78aac
fix: add conditional statement for running tests
osenan Nov 10, 2025
4bc7adc
refactor: include local random seed to control random numbers and oth…
osenan Nov 10, 2025
e01cbe6
chore: remove nocov tags
osenan Nov 10, 2025
2d3bdad
docs: update package documentation
osenan Nov 10, 2025
d0e3f82
tests: change uncontrolable snapshot tests
osenan Nov 10, 2025
121ddae
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 10, 2025
26a7ce6
tests: add test for white small well
osenan Nov 10, 2025
4464af6
tests: refactor failing snapshot test for a simpler test
osenan Nov 10, 2025
8d95268
chore: remove nocov comment
osenan Nov 10, 2025
fd3aa75
docs: update documenation
osenan Nov 10, 2025
b72eb28
tests: add more test for optionalSliderInput for conditionals to incr…
osenan Nov 10, 2025
bcadfa6
chore: fix lintr errors
osenan Nov 10, 2025
fbf8fd5
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 10, 2025
3b39663
refactor: reorder calls and use testthat as is loaded in the same script
osenan Nov 12, 2025
0dac843
tests:
osenan Nov 13, 2025
5168efb
chore: call testthat edition 3 in DESCRIPTION not in tests
osenan Nov 13, 2025
fc77004
Merge branch 'main' into 318_coverage_unit_tests@main
osenan Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
4 changes: 2 additions & 2 deletions R/draggable_buckets.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @keywords internal
#' @noRd
draggable_buckets_deps <- function() {
draggable_buckets_deps <- function() { # nocov start
htmltools::htmlDependency(
name = "teal-widgets-draggable-buckets",
version = utils::packageVersion("teal.widgets"),
Expand All @@ -9,7 +9,7 @@ draggable_buckets_deps <- function() {
script = "draggable-buckets.js",
stylesheet = "draggable-buckets.css"
)
}
} # nocovend

#' @title Draggable Buckets
#' @description
Expand Down
20 changes: 10 additions & 10 deletions R/optionalInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ updateOptionalSelectInput <- function(session, # nolint
#' vector of HTML icons corresponding to data type in each column.
#' @keywords internal
#'
variable_type_icons <- function(var_type) {
variable_type_icons <- function(var_type) { # nocov start
checkmate::assert_character(var_type, any.missing = FALSE)

class_to_icon <- list(
Expand Down Expand Up @@ -343,7 +343,7 @@ variable_type_icons <- function(var_type) {
))

res
}
} # nocov end

#' Optional content for `optionalSelectInput`
#'
Expand All @@ -359,7 +359,7 @@ variable_type_icons <- function(var_type) {
#' @return (`character`) HTML contents with all elements combined
#' @keywords internal
#'
picker_options_content <- function(var_name, var_label, var_type) {
picker_options_content <- function(var_name, var_label, var_type) { # nocov start
if (length(var_name) == 0) {
res <- character(0)
} else if (length(var_type) == 0 && length(var_label) == 0) {
Expand Down Expand Up @@ -387,7 +387,7 @@ picker_options_content <- function(var_name, var_label, var_type) {
}

res
}
} # nocov end

#' Create `choicesOpt` for `pickerInput`
#'
Expand All @@ -397,7 +397,7 @@ picker_options_content <- function(var_name, var_label, var_type) {
#' @return (`list`)\cr
#' to be passed as `choicesOpt` argument.
#' @keywords internal
picker_options <- function(choices) {
picker_options <- function(choices) { # nocov start
if (inherits(choices, "choices_labeled")) {
raw_choices <- extract_raw_choices(choices, sep = attr(choices, "sep"))
res <- list(
Expand All @@ -418,7 +418,7 @@ picker_options <- function(choices) {
res <- NULL
}
res
}
} # nocov end

#' Extract raw values from choices
#'
Expand All @@ -429,15 +429,15 @@ picker_options <- function(choices) {
#' the different columns.
#' @return choices simplified
#' @keywords internal
extract_raw_choices <- function(choices, sep) {
extract_raw_choices <- function(choices, sep) { # nocov start
if (!is.null(sep)) {
vapply(choices, paste, collapse = sep, character(1))
} else if (inherits(choices, "choices_labeled")) {
unname(unlist(choices))
} else {
choices
}
}
} # nocov end

#' Optional Slider Input Widget
#'
Expand Down Expand Up @@ -579,7 +579,7 @@ optionalSliderInputValMinMax <- function(inputId, label, value_min_max, label_he
#'
#' @return (`character`) vector with labels
#' @keywords internal
extract_choices_labels <- function(choices, values = NULL) {
extract_choices_labels <- function(choices, values = NULL) { # nocov start
res <- if (inherits(choices, "choices_labeled")) {
attr(choices, "raw_labels")
} else if (!is.null(names(choices)) && !setequal(names(choices), unlist(unname(choices)))) {
Expand All @@ -594,4 +594,4 @@ extract_choices_labels <- function(choices, values = NULL) {
}

res
}
} # nocov end
4 changes: 2 additions & 2 deletions R/plot_with_settings.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @keywords internal
#' @noRd
plot_with_settings_deps <- function() {
plot_with_settings_deps <- function() { # nocov start
htmltools::htmlDependency(
name = "teal-widgets-plot-with-settings",
version = utils::packageVersion("teal.widgets"),
Expand All @@ -9,7 +9,7 @@ plot_with_settings_deps <- function() {
stylesheet = "plot-with-settings.css",
script = "plot-with-settings.js"
)
}
} # nocov end

#' @name plot_with_settings
#' @rdname plot_with_settings
Expand Down
4 changes: 2 additions & 2 deletions R/standard_layout.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' @keywords internal
#' @noRd
standard_layout_deps <- function() {
standard_layout_deps <- function() { # nocov start
htmltools::htmlDependency(
name = "teal-widgets-standard-layout",
version = utils::packageVersion("teal.widgets"),
package = "teal.widgets",
src = "standard-layout",
stylesheet = "standard-layout.css"
)
}
} # nocov end

#' Standard UI layout
#'
Expand Down
4 changes: 2 additions & 2 deletions R/verbatim_popup.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @keywords internal
#' @noRd
verbatim_popup_deps <- function() {
verbatim_popup_deps <- function() { # nocov start
htmltools::htmlDependency(
name = "teal-widgets-verbatim-popup",
version = utils::packageVersion("teal.widgets"),
Expand All @@ -9,7 +9,7 @@ verbatim_popup_deps <- function() {
stylesheet = "verbatim-popup.css",
script = "verbatim-popup.js"
)
}
} # nocov end

#' A `shiny` module that pops up verbatim text.
#' @name verbatim_popup
Expand Down
2 changes: 1 addition & 1 deletion man/get_dt_rows.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pkg_name <- "teal.widgets"
library(pkg_name, character.only = TRUE)
testthat::test_check(pkg_name)
library(testthat)
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/draggable_buckets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Snapshot test for ui component dragable buckets

Code
as.character(draggable_buckets("my_input_id", "test_label", "element_1", "buckets_1"))
Output
[1] "<div class=\"draggableBuckets\" id=\"my_input_id\">\n <span>test_label</span>\n <div id=\"my_input_idelements\" class=\"form-control elements\" ondragover=\"allowDrop(event)\" ondrop=\"drop(event)\" data-widget=\"my_input_id\">\n <div id=\"my_input_iddraggable1\" class=\"element\" draggable=\"true\" ondragstart=\"drag(event)\" ondragover=\"allowDrop(event)\" ondrop=\"dropReorder(event)\" data-widget=\"my_input_id\">element_1</div>\n </div>\n <div class=\"form-control bucket\" ondragover=\"allowDrop(event)\" ondrop=\"drop(event)\" data-label=\"buckets_1\" data-widget=\"my_input_id\">\n <div class=\"bucket-name\" ondragover=\"allowDrop(event)\" ondrop=\"dropBucketName(event)\" data-widget=\"my_input_id\">buckets_1:</div>\n </div>\n</div>"

5 changes: 5 additions & 0 deletions tests/testthat/_snaps/standard_layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# checks snapshot with encoding and null forms

Code
mock_layout

7 changes: 7 additions & 0 deletions tests/testthat/_snaps/verbatim_popup_ui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# snapshot test for verbatim_popup_ui

Code
verbatim_popup_ui("STH", "STH2")
Output
<button class="btn btn-default action-button teal-widgets-busy-disable button" id="STH-button" type="button">STH2</button>

17 changes: 17 additions & 0 deletions tests/testthat/test-draggable_buckets.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,20 @@ testthat::test_that(
app_driver$stop()
}
)

testthat::test_that("fails when inputId is not from the expected type", {
expect_error(draggable_buckets(numeric(1), "test_label", "element_1", "bucket_1"))
})

testthat::test_that("fails when label is not from the expected type", {
expect_error(draggable_buckets("my_input_id", numeric(), "element_1", "bucket_1"))
})

testthat::test_that("fails when buckets is not from the expected type", {
expect_error(draggable_buckets("my_input_id", "test_label", "element_1", numeric()))
})

testthat::test_that("Snapshot test for ui component dragable buckets", {
testthat::local_edition(3)
expect_snapshot(as.character(draggable_buckets("my_input_id", "test_label", "element_1", "buckets_1")))
})
4 changes: 4 additions & 0 deletions tests/testthat/test-get_dt_rows_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ testthat::test_that(
app_driver$stop()
}
)

testthat::test_that("Check class of get_dt_rows", {
testthat::expect_s3_class(get_dt_rows("my table", "0"), "shiny.tag")
})
56 changes: 56 additions & 0 deletions tests/testthat/test-optionalInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,59 @@ testthat::test_that("optionalSliderInput min/max NA", {
testthat::expect_no_error(optionalSliderInput("a", "b", NA, NA, 0.2))
testthat::expect_no_error(optionalSliderInput("a", "b", 0, 1, 0.2))
})

testthat::test_that("if inputId is not a string returns an error", {
testthat::expect_error(optionalSelectInput(TRUE, "my label", c("choice_1", "choice_2")))
})

testthat::test_that("if inputId is not a string returns an error", {
testthat::expect_error(optionalSelectInput(TRUE, "my label", c("choice_1", "choice_2")))
})

testthat::test_that("if label is not a string returns an error", {
testthat::expect_error(optionalSelectInput("my_input_id", TRUE, c("choice_1", "choice_2")))
})

testthat::test_that("optionalSelectInput is a Shiny ui component", {
testthat::expect_s3_class(
optionalSelectInput(
"my_input_id",
"my label",
c("choice_1", "choice_2"),
label_help = shiny::helpText("This is a sample help text")
),
"shiny.tag"
)
})

testthat::test_that("if inputId is not a string optionalSliderInputValMinMax returns error", {
testthat::expect_error(optionalSliderInputValMinMax(
list,
"label",
c(5, 1, 10),
label_help = shiny::helpText("Help")
))
})

testthat::test_that("value_min_max with invalid length throws error", {
testthat::expect_error(optionalSliderInputValMinMax("id", "label", c(1, 2)))
})

testthat::test_that("value out of range in value_min_max throws error", {
testthat::expect_error(
optionalSliderInputValMinMax("id", "label", c(10, 1, 5)),
"value_min_max"
)
})

testthat::test_that("optionalSliderInputValMinMax is a Shiny ui component", {
testthat::expect_s3_class(
optionalSliderInputValMinMax(
"id",
"label",
c(5, 1, 10),
label_help = shiny::helpText("Help")
),
"shiny.tag"
)
})
7 changes: 7 additions & 0 deletions tests/testthat/test-optionalSelectInput_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,10 @@ testthat::test_that(
app_driver$stop()
}
)

testthat::test_that("Snapshot test for optionalSelectInput", {
testthat::local_edition(3)
testthat::expect_snapshot(
as.character(optionalSelectInput("my_select_input", "my label", c("choice_1", "choice_2"), sep = " "))
)
})
5 changes: 5 additions & 0 deletions tests/testthat/test-optionalSliderInputValMinMax_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ testthat::test_that(
app_driver$stop()
}
)

testthat::test_that("snapshot test for optionalSliderInputValMinMax", {
testthat::local_edition(3)
testthat::expect_snapshot(as.character(optionalSliderInput("my slider", "my label", 0, 10, 2)))
})
24 changes: 24 additions & 0 deletions tests/testthat/test-standard_layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,27 @@ testthat::test_that("Input validation", {
post_output = 1
), regexp = "Assertion on 'post_output' failed")
})

describe("Tests for standard_layout options", {
mock_output <- shiny::plotOutput("test")
mock_form <- shiny::actionButton("test", "")

it("checks that the class is correct", {
# Given
expected_class <- "bslib_page"
mock_layout <- standard_layout(output = mock_output, encoding = NULL, forms = mock_form)

# Then
expect_true(any(expected_class %in% class(mock_layout)))
})

it("checks snapshot with encoding and null forms", {
# Given
expected_class <- "bslib_page"
mock_layout <- standard_layout(output = mock_output, encoding = mock_form, forms = NULL)

# Then
testthat::local_edition(3)
expect_snapshot(as.character(mock_layout))
})
})
Loading
Loading