Package with an initial set of functions added

NOTE: Not all tests have been written yet!
This commit is contained in:
2026-01-22 15:59:54 +00:00
parent c94ca1549a
commit 6d3843a92b
25 changed files with 711 additions and 4 deletions

12
tests/testthat.R Normal file
View File

@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html
library(testthat)
library(AVSDevR.HTMLUtils)
test_check("AVSDevR.HTMLUtils")

View File

@@ -0,0 +1,69 @@
## Tests for all inputs:
# shiny::checkboxInput
# shiny::checkboxGroupInput
# shiny::dateInput
# shiny::dateRangeInput
# shiny::fileInput
# shiny::numericInput
# X shiny::passwordInput
# shiny::radioButtons
# X shiny::selectInput
# X shiny::selectizeInput
# X shiny::sliderInput
# X shiny::snapshotPreprocessInput
# shiny::textInput
# X shiny::textAreaInput
# X shiny::varSelectizeInput
# X shiny::varSelectInput
test_that("required checkbox input", {
x <- shiny::checkboxInput("input_id", "Some checkbox input")
y <- "<div class=\"form-group shiny-input-container\">\n <div class=\"checkbox\">\n <label>\n <input id=\"input_id\" type=\"checkbox\" class=\"shiny-input-checkbox\" required=\"true\" aria-required=\"true\"/>\n <span>\n Some checkbox input\n <span class=\"text-danger required\">*</span>\n </span>\n </label>\n </div>\n</div>"
expect_equal(as.character(htmlMarkRequired(x)), y)
})
test_that("required checkbox group input", {
x <- shiny::checkboxGroupInput(
"input_id", "Some checkbox group", choices = c(`Choice 1` = 1, `Choice 2` = 2)
)
y <- "<div id=\"input_id\" class=\"form-group shiny-input-checkboxgroup shiny-input-container\" role=\"group\" aria-labelledby=\"input_id-label\" aria-required=\"true\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">\n Some checkbox group\n <span class=\"text-danger required\">*</span>\n </label>\n <div class=\"shiny-options-group\">\n <div class=\"checkbox\">\n <label>\n <input type=\"checkbox\" name=\"input_id\" value=\"1\"/>\n <span>Choice 1</span>\n </label>\n </div>\n <div class=\"checkbox\">\n <label>\n <input type=\"checkbox\" name=\"input_id\" value=\"2\"/>\n <span>Choice 2</span>\n </label>\n </div>\n </div>\n</div>"
expect_equal(as.character(htmlMarkRequired(x)), y)
})
test_that("required date input", {
x <- shiny::dateInput("input_id", "Some date input")
y <- "<div id=\"input_id\" class=\"shiny-date-input form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">\n Some date input\n <span class=\"text-danger required\">*</span>\n </label>\n <input type=\"text\" class=\"form-control\" aria-labelledby=\"input_id-label\" title=\"Date format: yyyy-mm-dd\" data-date-language=\"en\" data-date-week-start=\"0\" data-date-format=\"yyyy-mm-dd\" data-date-start-view=\"month\" data-date-autoclose=\"true\" data-date-dates-disabled=\"null\" data-date-days-of-week-disabled=\"null\" required=\"true\" aria-required=\"true\"/>\n</div>"
expect_equal(as.character(htmlMarkRequired(x)), y)
})
test_that("required date range input", {
x <- shiny::dateRangeInput("input_id", "Some date range input")
y <- "<div id=\"input_id\" class=\"shiny-date-range-input form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">\n Some date range input\n <span class=\"text-danger required\">*</span>\n </label>\n <div class=\"input-daterange input-group input-group-sm\">\n <input class=\"form-control\" type=\"text\" aria-labelledby=\"input_id-label\" title=\"Date format: yyyy-mm-dd\" data-date-language=\"en\" data-date-week-start=\"0\" data-date-format=\"yyyy-mm-dd\" data-date-start-view=\"month\" data-date-autoclose=\"true\" required=\"true\" aria-required=\"true\"/>\n <span class=\"input-group-addon input-group-prepend input-group-append\">\n <span class=\"input-group-text\"> to </span>\n </span>\n <input class=\"form-control\" type=\"text\" aria-labelledby=\"input_id-label\" title=\"Date format: yyyy-mm-dd\" data-date-language=\"en\" data-date-week-start=\"0\" data-date-format=\"yyyy-mm-dd\" data-date-start-view=\"month\" data-date-autoclose=\"true\" required=\"true\" aria-required=\"true\"/>\n </div>\n</div>"
expect_equal(as.character(htmlMarkRequired(x)), y)
})
test_that("required file input", {
x <- shiny::fileInput("input_id", "Some file input")
y <- "<div class=\"form-group shiny-input-container\" aria-required=\"true\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">\n Some file input\n <span class=\"text-danger required\">*</span>\n </label>\n <div class=\"input-group\">\n <label class=\"input-group-btn input-group-prepend\">\n <span class=\"btn btn-default btn-file\">\n Browse...\n <input id=\"input_id\" class=\"shiny-input-file\" name=\"input_id\" type=\"file\" style=\"position: absolute !important; top: -99999px !important; left: -99999px !important;\" required=\"true\" aria-required=\"true\"/>\n </span>\n </label>\n <input type=\"text\" class=\"form-control\" placeholder=\"No file selected\" readonly=\"readonly\"/>\n </div>\n <div id=\"input_id_progress\" class=\"progress active shiny-file-input-progress\">\n <div class=\"progress-bar\"></div>\n </div>\n</div>"
expect_equal(as.character(htmlMarkRequired(x)), y)
})
test_that("required numeric input", {
x <- shiny::numericInput("input_id", "Some numeric input", 0)
y <- "<div class=\"form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">\n Some numeric input\n <span class=\"text-danger required\">*</span>\n </label>\n <input id=\"input_id\" type=\"number\" class=\"shiny-input-number form-control\" value=\"0\" data-update-on=\"change\" required=\"true\" aria-required=\"true\"/>\n</div>"
expect_equal(as.character(htmlMarkRequired(x)), y)
})
test_that("required radio buttons", {
x <- shiny::radioButtons(
"input_id", "Some radio buttons", choices = c(`Choice 1` = 1, `Choice 2` = 2)
)
y <- "<div id=\"input_id\" class=\"form-group shiny-input-radiogroup shiny-input-container\" role=\"radiogroup\" aria-labelledby=\"input_id-label\" aria-required=\"true\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">\n Some radio buttons\n <span class=\"text-danger required\">*</span>\n </label>\n <div class=\"shiny-options-group\">\n <div class=\"radio\">\n <label>\n <input type=\"radio\" name=\"input_id\" value=\"1\" checked=\"checked\" required=\"true\" aria-required=\"true\"/>\n <span>Choice 1</span>\n </label>\n </div>\n <div class=\"radio\">\n <label>\n <input type=\"radio\" name=\"input_id\" value=\"2\" required=\"true\" aria-required=\"true\"/>\n <span>Choice 2</span>\n </label>\n </div>\n </div>\n</div>"
expect_equal(as.character(htmlMarkRequired(x)), y)
})
test_that("required text input", {
x <- shiny::textInput("input_id", "Some text input")
y <- "<div class=\"form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">\n Some text input\n <span class=\"text-danger required\">*</span>\n </label>\n <input id=\"input_id\" type=\"text\" class=\"shiny-input-text form-control\" value=\"\" data-update-on=\"change\" required=\"true\" aria-required=\"true\"/>\n</div>"
expect_equal(as.character(htmlMarkRequired(x)), y)
})

View File

@@ -0,0 +1,13 @@
test_that("remove existing attribute", {
x <- shiny::icon("wrench")
y <- "<i class=\"fas fa-wrench\" role=\"presentation\"></i>"
expect_equal(as.character(htmlRemoveAttributes(x, "aria-label")), y)
})
test_that("remove non-existing attribute does not fail", {
x <- shiny::icon("wrench")
expect_equal(
as.character(htmlRemoveAttributes(x, "aria-title")),
as.character(x)
)
})

View File

@@ -0,0 +1,47 @@
test_that("maximum length password input", {
x <- shiny::passwordInput("input_id", "Some password input")
y <- "<div class=\"form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">Some password input</label>\n <input id=\"input_id\" type=\"password\" class=\"shiny-input-password form-control\" value=\"\" data-update-on=\"change\" maxlength=\"50\"/>\n</div>"
expect_equal(as.character(htmlSetMaxLength(x, 50)), y)
})
test_that("minimum length password input", {
x <- shiny::passwordInput("input_id", "Some password input")
y <- "<div class=\"form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">Some password input</label>\n <input id=\"input_id\" type=\"password\" class=\"shiny-input-password form-control\" value=\"\" data-update-on=\"change\" minlength=\"3\"/>\n</div>"
expect_equal(as.character(htmlSetMinLength(x, 3)), y)
})
test_that("min/max length password input", {
x <- shiny::passwordInput("input_id", "Some password input")
y <- "<div class=\"form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">Some password input</label>\n <input id=\"input_id\" type=\"password\" class=\"shiny-input-password form-control\" value=\"\" data-update-on=\"change\" minlength=\"3\" maxlength=\"50\"/>\n</div>"
expect_equal(as.character(htmlSetMaxLength(htmlSetMinLength(x, 3), 50)), y)
})
test_that("maximum length text input", {
x <- shiny::textInput("input_id", "Some text input")
y <- "<div class=\"form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">Some text input</label>\n <input id=\"input_id\" type=\"text\" class=\"shiny-input-text form-control\" value=\"\" data-update-on=\"change\" maxlength=\"50\"/>\n</div>"
expect_equal(as.character(htmlSetMaxLength(x, 50)), y)
})
test_that("minimum length text input", {
x <- shiny::textInput("input_id", "Some text input")
y <- "<div class=\"form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">Some text input</label>\n <input id=\"input_id\" type=\"text\" class=\"shiny-input-text form-control\" value=\"\" data-update-on=\"change\" minlength=\"3\"/>\n</div>"
expect_equal(as.character(htmlSetMinLength(x, 3)), y)
})
test_that("min/max length text input", {
x <- shiny::textInput("input_id", "Some text input")
y <- "<div class=\"form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">Some text input</label>\n <input id=\"input_id\" type=\"text\" class=\"shiny-input-text form-control\" value=\"\" data-update-on=\"change\" minlength=\"3\" maxlength=\"50\"/>\n</div>"
expect_equal(as.character(htmlSetMaxLength(htmlSetMinLength(x, 3), 50)), y)
})
test_that("maximum length textarea input", {
x <- shiny::textAreaInput("input_id", "Some textarea input")
y <- "<div class=\"shiny-input-textarea form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">Some textarea input</label>\n <textarea id=\"input_id\" class=\"form-control\" data-update-on=\"change\" maxlength=\"500\"></textarea>\n</div>"
expect_equal(as.character(htmlSetMaxLength(x, 500)), y)
})
test_that("minimum length textarea input", {
x <- shiny::textAreaInput("input_id", "Some textarea input")
y <- "<div class=\"shiny-input-textarea form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">Some textarea input</label>\n <textarea id=\"input_id\" class=\"form-control\" data-update-on=\"change\" minlength=\"50\"></textarea>\n</div>"
expect_equal(as.character(htmlSetMinLength(x, 50)), y)
})
test_that("min/max length textarea input", {
x <- shiny::textAreaInput("input_id", "Some textarea input")
y <- "<div class=\"shiny-input-textarea form-group shiny-input-container\">\n <label class=\"control-label\" id=\"input_id-label\" for=\"input_id\">Some textarea input</label>\n <textarea id=\"input_id\" class=\"form-control\" data-update-on=\"change\" minlength=\"50\" maxlength=\"500\"></textarea>\n</div>"
expect_equal(as.character(htmlSetMaxLength(htmlSetMinLength(x, 50), 500)), y)
})