Skip to content

Add more unit tests #288

@donyunardi

Description

@donyunardi

Feature description

Please add unit tests for these functions:

  • requirement #0.01 'Add empty choice to choices selected' is not covered by
    any test

#' Add empty choice to choices selected
#'
#' @param x (`choices_selected`) object.
#' @param multiple (`logical(1)`) whether multiple selections are allowed or not.
#'
#' @return `choices_selected` object with an empty option added to the choices.
#'
#' @export
#'
add_no_selected_choices <- function(x, multiple = FALSE) {
if (is.null(x)) {
choices_selected(NULL)
} else {
stopifnot(is.choices_selected(x))
if (!multiple) {
x$choices <- c(no_select_keyword, x$choices)
if (is.null(x$selected)) x$selected <- no_select_keyword
}
x
}
}

  • requirement #0.10 'Help text with available datasets input' is not covered
    by any test

#' Help text with available datasets input
#'
#' @description
#'
#' Creates [shiny::helpText()] with the names of available datasets for the
#' current module.
#'
#' @param data_extracts (`list`) of data extracts for single variable.
#'
#' @return `shiny.tag` defining help-text element that can be added to a UI element.
#'
#' @export
#'
datanames_input <- function(data_extracts) {
datanames <- get_extract_datanames(data_extracts)
helpText(
paste0("Dataset", `if`(length(datanames) > 1, "s", ""), ":"),
tags$code(paste(datanames, collapse = ", "))
)
}

  • requirement #0.15 'Returns non-key column names from data' is not covered
    by any test

#' Returns non-key column names from data
#'
#' @description Returns non-key column names from data.
#'
#' @param data (`data.frame`) Data with attribute `filter_and_columns`. This can only be
#' created by [data_extract_srv()], which returns a shiny [shiny::reactive()].
#'
#' @return A named `character` vector with the non-key columns of the `data`.
#'
#' @references [data_extract_srv()]
#'
#' @export
#'
get_dataset_prefixed_col_names <- function(data) {
if (!is.null(attr(data, "filter_and_columns")$columns) && attr(data, "filter_and_columns")$columns != "") {
paste(attr(data, "dataname"), attr(data, "filter_and_columns")$columns, sep = ".")
} else {
NULL
}
}

  • requirement #0.19 'Verify uniform dataset source across data extract
    specification' is not covered by any test

#' Verify uniform dataset source across data extract specification
#'
#' @description
#'
#' Checks if the input `data_extract_spec` objects all come from the same dataset.
#'
#' @param ... either `data_extract_spec` objects or lists of `data_extract_spec`
#' objects that do not contain `NULL`
#'
#' @return `TRUE` if all `data_extract_spec` objects come from the same dataset,
#' `FALSE` otherwise.
#'
#' @export
#'
is_single_dataset <- function(...) {
data_extract_spec <- list(...)
dataset_names <- get_extract_datanames(data_extract_spec)
length(dataset_names) == 1
}

  • requirement #0.24 'Check select choices for no choice made' is not covered
    by any test

#' Check select choices for no choice made
#'
#' @param x (`character`) Word that shall be checked for `NULL`, empty, "--no-selection".
#'
#' @return The word or `NULL`.
#'
#' @export
#'
no_selected_as_NULL <- function(x) { # nolint: object_name_linter.
if (is.null(x) || identical(x, no_select_keyword) || x == "") {
NULL
} else {
x
}
}


Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions