-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rstudio/test-5-apps
testthat/integration tests for 5 apps
- Loading branch information
Showing
12 changed files
with
113 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
library(testthat) | ||
library(shiny) | ||
|
||
testthat::test_file("testthat/tests.R") |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
library(testthat) | ||
library(shiny) | ||
|
||
test_that("reactives update", { | ||
testServer({ | ||
session$setInputs(bins = 5) | ||
expect_equal(bins(), seq(43, 96, length.out = 6)) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
library(testthat) | ||
library(shiny) | ||
|
||
testthat::test_file("testthat/tests.R") |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
library(testthat) | ||
library(shiny) | ||
|
||
test_that("inputs are stored", { | ||
testServer({ | ||
session$setInputs( | ||
integer = 593, | ||
decimal = 0.6, | ||
range = c(100,300), | ||
format = 5000, | ||
animation = 100 | ||
) | ||
|
||
# The data frame should have these properties | ||
df <- sliderValues() | ||
expect_equal(nrow(df), 5) | ||
expect_equal(ncol(df), 2) | ||
expect_is(df$Value, "character") | ||
|
||
# Updating an input should result in a new plot | ||
plot1 <- output$values | ||
session$setInputs(integer = 594) | ||
plot2 <- output$values | ||
expect_true(plot1 != plot2) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
library(testthat) | ||
library(shiny) | ||
|
||
testthat::test_file("testthat/tests.R") |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
library(testthat) | ||
library(shiny) | ||
|
||
testServer({ | ||
test_that("it works", { | ||
session$setInputs( | ||
xcol = "Sepal.Length", | ||
ycol = "Petal.Length", | ||
clusters = 4 | ||
) | ||
expect_equal(colnames(selectedData()), c("Sepal.Length", "Petal.Length")) | ||
expect_equal(nrow(clusters()$centers), 4) | ||
session$setInputs(clusters = 3) | ||
expect_equal(nrow(clusters()$centers), 3) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
library(testthat) | ||
library(shiny) | ||
|
||
testthat::test_file("testthat/tests.R") |
15 changes: 15 additions & 0 deletions
15
119-namespaced-conditionalpanel-demo/tests/testthat/tests.R
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
library(testthat) | ||
library(shiny) | ||
library(withr) | ||
|
||
# TODO Determine the ideal way for module-reliant test code to load an app | ||
with_dir(shiny:::findApp(), { | ||
local({ | ||
source("app.R") | ||
test_that("module works", { | ||
testModule(myPlot, { | ||
expect_true(TRUE) | ||
}) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
library(testthat) | ||
library(shiny) | ||
|
||
# We explicitly pass environment() here because shiny::runTests() has sourced | ||
# the files in R/, and the module we're testing was defined in those files. If | ||
# we don't specify env, testthat uses an environment that doesn't include the | ||
# module, and the tests fail. | ||
testthat::test_file("testthat/tests.R", env = environment()) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
library(testthat) | ||
library(shiny) | ||
|
||
test_that("counter works", { | ||
testModule(counter, { | ||
inc <- function(x) if (is.null(x)) 0 else x+1 | ||
expect_equal(count(), 0) | ||
session$setInputs(button = inc(input$button)) | ||
expect_equal(count(), 1) | ||
expect_equal(output$out, "1") | ||
expect_equal(session$returned(), 1) | ||
}) | ||
}) |