-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: verifyInputMessage for mock-session
New manner for testing the contents of `message` when unit testing methods that use `sendInputMessage`. Similar methods should be implemented for session$sendCustomMessage and session$sendBinaryMessage.
- Loading branch information
Stefan McKinnon Edwards
committed
Mar 14, 2023
1 parent
4d05a56
commit 9485723
Showing
6 changed files
with
260 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 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
This file contains 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 |
---|---|---|
@@ -1,36 +1,19 @@ | ||
test_that("Radio buttons and checkboxes work with modules", { | ||
createModuleSession <- function(moduleId) { | ||
session <- as.environment(list( | ||
ns = NS(moduleId), | ||
sendInputMessage = function(inputId, message) { | ||
session$lastInputMessage = list(id = inputId, message = message) | ||
} | ||
)) | ||
class(session) <- "ShinySession" | ||
session | ||
} | ||
|
||
sessA <- createModuleSession("modA") | ||
|
||
updateRadioButtons(sessA, "test1", label = "Label", choices = letters[1:5]) | ||
resultA <- sessA$lastInputMessage | ||
|
||
expect_equal("test1", resultA$id) | ||
expect_equal("Label", resultA$message$label) | ||
expect_equal("a", resultA$message$value) | ||
expect_true(grepl('"modA-test1"', resultA$message$options)) | ||
expect_false(grepl('"test1"', resultA$message$options)) | ||
|
||
|
||
sessB <- createModuleSession("modB") | ||
|
||
updateCheckboxGroupInput(sessB, "test2", label = "Label", choices = LETTERS[1:5]) | ||
resultB <- sessB$lastInputMessage | ||
|
||
expect_equal("test2", resultB$id) | ||
expect_equal("Label", resultB$message$label) | ||
expect_null(resultB$message$value) | ||
expect_true(grepl('"modB-test2"', resultB$message$options)) | ||
expect_false(grepl('"test2"', resultB$message$options)) | ||
|
||
session <- MockShinySession$new() | ||
|
||
updateRadioButtons(session, "test1", label = "Label", choices = letters[1:5]) | ||
session$verifyInputMessage("test1", | ||
expect_equal(.$label, "Label"), | ||
expect_equal(.$value, "a"), | ||
expect_true(grepl('"mock-session-test1"', .$options)), | ||
!expect_false(grepl('"test1"', .$options)) ## negate returned FALSE from expect_false | ||
) | ||
|
||
updateCheckboxGroupInput(session, "test2", label = "Label", choices = LETTERS[1:5]) | ||
session$verifyInputMessage("test2", | ||
expect_equal(.$label, "Label"), | ||
expect_null(.$value), | ||
expect_true(grepl('"mock-session-test2"', .$options)), | ||
!expect_false(grepl('"test2"', .$options)) | ||
) | ||
}) |