-
Notifications
You must be signed in to change notification settings - Fork 0
Adding unit tests for tm_merge #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a0c17f
add unit tests for tm_merge
donyunardi 17117f8
remove ambiguity of outer and inner uid=501(unardid) gid=20(staff) gr…
donyunardi abb6d6b
Add value to selected
donyunardi fbe177e
[skip style] [skip vbump] Restyle files
github-actions[bot] ec8477b
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] fd73f34
Merge branch 'main' into add_unit_tests@main
donyunardi 3546fcf
update DESCRIPTION
donyunardi 9100b17
remove duplicate line
donyunardi 0200656
apply suggestions from @osenan
donyunardi 8bb0fb1
small update
donyunardi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| make_test_picks <- function() { | ||
| list( | ||
| a = picks( | ||
| datasets(choices = "iris", selected = "iris"), | ||
| variables(choices = "Sepal.Length", selected = "Sepal.Length") | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| call_ui <- function(module, id = "test") { | ||
| do.call(module$ui, c(list(id = id), module$ui_args)) | ||
| } | ||
|
|
||
| testthat::describe("tm_merge", { | ||
| it("returns a teal_module", { | ||
| result <- tm_merge(picks = make_test_picks()) | ||
| testthat::expect_s3_class(result, "teal_module") | ||
| }) | ||
|
|
||
| it("returns a module with the default label", { | ||
| result <- tm_merge(picks = make_test_picks()) | ||
| testthat::expect_identical(result$label, "merge-module") | ||
| }) | ||
|
|
||
| it("returns a module with a custom label", { | ||
| result <- tm_merge(label = "my-merge", picks = make_test_picks()) | ||
| testthat::expect_identical(result$label, "my-merge") | ||
| }) | ||
|
|
||
| it("returns a module with picks passed to ui_args", { | ||
| test_picks <- make_test_picks() | ||
| result <- tm_merge(picks = test_picks) | ||
| testthat::expect_identical(result$ui_args$picks, test_picks) | ||
| }) | ||
|
|
||
| it("returns a module with picks passed to server_args", { | ||
| test_picks <- make_test_picks() | ||
| result <- tm_merge(picks = test_picks) | ||
| testthat::expect_identical(result$server_args$picks, test_picks) | ||
| }) | ||
|
|
||
| it("returns a module with empty transformators by default", { | ||
| result <- tm_merge(picks = make_test_picks()) | ||
| testthat::expect_identical(result$transformators, list()) | ||
| }) | ||
|
|
||
| it("returns a module with custom transformators when provided", { | ||
| dummy_transformator <- list( | ||
| teal::teal_transform_module( | ||
| label = "t", | ||
| ui = function(id) NULL, | ||
| server = function(id, data) data | ||
| ) | ||
| ) | ||
| result <- tm_merge( | ||
| picks = make_test_picks(), | ||
| transformators = dummy_transformator | ||
| ) | ||
| testthat::expect_identical(result$transformators, dummy_transformator) | ||
| }) | ||
| }) | ||
|
|
||
| testthat::describe("tm_merge server", { | ||
| make_test_teal_data <- function() { | ||
| within(teal.data::teal_data(), iris <- iris) | ||
| } | ||
|
|
||
| it("initializes without error", { | ||
| test_picks <- make_test_picks() | ||
| data <- make_test_teal_data() | ||
| testthat::expect_no_error( | ||
| shiny::testServer( | ||
| tm_merge(picks = test_picks)$server, | ||
| args = list(data = shiny::reactive(data), picks = test_picks), | ||
| expr = {} | ||
| ) | ||
| ) | ||
| }) | ||
|
|
||
| it("output$join_keys renders without error", { | ||
| test_picks <- make_test_picks() | ||
| data <- make_test_teal_data() | ||
| shiny::testServer( | ||
| tm_merge(picks = test_picks)$server, | ||
| args = list(data = shiny::reactive(data), picks = test_picks), | ||
| expr = { | ||
| testthat::expect_no_error(session$output$join_keys) | ||
| } | ||
| ) | ||
| }) | ||
|
donyunardi marked this conversation as resolved.
Outdated
|
||
|
|
||
| it("output$mapped renders YAML containing the selected variable names", { | ||
| test_picks <- make_test_picks() | ||
| data <- make_test_teal_data() | ||
| shiny::testServer( | ||
| tm_merge(picks = test_picks)$server, | ||
| args = list(data = shiny::reactive(data), picks = test_picks), | ||
| expr = { | ||
| testthat::expect_true(grepl("Sepal.Length", session$output$mapped, fixed = TRUE)) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("output$src renders source code without error", { | ||
| test_picks <- make_test_picks() | ||
| data <- make_test_teal_data() | ||
| shiny::testServer( | ||
| tm_merge(picks = test_picks)$server, | ||
| args = list(data = shiny::reactive(data), picks = test_picks), | ||
| expr = { | ||
| testthat::expect_no_error(session$output$src) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("output$table_merged renders an HTML table containing selected variables", { | ||
| test_picks <- make_test_picks() | ||
| data <- make_test_teal_data() | ||
| shiny::testServer( | ||
| tm_merge(picks = test_picks)$server, | ||
| args = list(data = shiny::reactive(data), picks = test_picks), | ||
| expr = { | ||
| testthat::expect_true(grepl("Sepal.Length", session$output$table_merged, fixed = TRUE)) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| it("server handles multiple picks from separate datasets with join keys", { | ||
| data <- teal.data::teal_data() | ||
| data <- within(data, { | ||
| adsl <- data.frame(studyid = "A", usubjid = c("1", "2"), age = c(30, 40)) | ||
| adae <- data.frame(studyid = "A", usubjid = c("1", "2"), AVAL = c(1.5, 2.5)) | ||
| }) | ||
| teal.data::join_keys(data) <- teal.data::join_keys( | ||
| teal.data::join_key("adsl", "adsl", c("studyid", "usubjid")), | ||
| teal.data::join_key("adae", "adae", c("studyid", "usubjid")), | ||
| teal.data::join_key("adsl", "adae", c("studyid", "usubjid")) | ||
| ) | ||
| test_picks <- list( | ||
| a = picks(datasets("adsl", "adsl"), variables("age", "age")), | ||
| b = picks(datasets("adae", "adae"), variables("AVAL", "AVAL")) | ||
| ) | ||
| testthat::expect_no_error( | ||
| shiny::testServer( | ||
| tm_merge(picks = test_picks)$server, | ||
| args = list(data = shiny::reactive(data), picks = test_picks), | ||
| expr = {} | ||
| ) | ||
| ) | ||
|
donyunardi marked this conversation as resolved.
Outdated
|
||
| }) | ||
| }) | ||
|
|
||
| testthat::describe("tm_merge ui", { | ||
| it("returns a shiny tag", { | ||
| ui <- call_ui(tm_merge(picks = make_test_picks())) | ||
| checkmate::expect_multi_class(ui, c("shiny.tag", "shiny.tag.list")) | ||
| }) | ||
|
|
||
| it("renders one panel per pick", { | ||
| test_picks <- list( | ||
| a = picks( | ||
| datasets("iris", "iris"), | ||
| variables("Sepal.Length", "Sepal.Length") | ||
| ), | ||
| b = picks(datasets("iris", "iris"), variables("Species", "Species")) | ||
| ) | ||
| ui <- call_ui(tm_merge(picks = test_picks)) | ||
| page <- rvest::read_html(as.character(ui)) | ||
| testthat::expect_length(rvest::html_elements(page, ".col-auto"), 2L) | ||
| }) | ||
|
|
||
| it("labels each panel with the pick name", { | ||
| test_picks <- list( | ||
| alpha = picks( | ||
| datasets("iris", "iris"), | ||
| variables("Sepal.Length", "Sepal.Length") | ||
| ), | ||
| beta = picks(datasets("iris", "iris"), variables("Species", "Species")) | ||
| ) | ||
| ui <- call_ui(tm_merge(picks = test_picks)) | ||
| page <- rvest::read_html(as.character(ui)) | ||
| labels <- rvest::html_text(rvest::html_elements(page, "label")) | ||
| testthat::expect_true("alpha" %in% labels) | ||
| testthat::expect_true("beta" %in% labels) | ||
| }) | ||
|
|
||
| it("includes the join_keys output element", { | ||
| ui <- call_ui(tm_merge(picks = make_test_picks())) | ||
| page <- rvest::read_html(as.character(ui)) | ||
| testthat::expect_length(rvest::html_elements(page, "#test-join_keys"), 1L) | ||
| }) | ||
|
|
||
| it("includes the mapped output element", { | ||
| ui <- call_ui(tm_merge(picks = make_test_picks())) | ||
| page <- rvest::read_html(as.character(ui)) | ||
| testthat::expect_length(rvest::html_elements(page, "#test-mapped"), 1L) | ||
| }) | ||
|
|
||
| it("includes the src output element", { | ||
| ui <- call_ui(tm_merge(picks = make_test_picks())) | ||
| page <- rvest::read_html(as.character(ui)) | ||
| testthat::expect_length(rvest::html_elements(page, "#test-src"), 1L) | ||
| }) | ||
|
|
||
| it("includes the table_merged output element", { | ||
| ui <- call_ui(tm_merge(picks = make_test_picks())) | ||
| page <- rvest::read_html(as.character(ui)) | ||
| testthat::expect_length( | ||
| rvest::html_elements(page, "#test-table_merged"), 1L | ||
| ) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.