Skip to content

Commit

Permalink
some wip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d-callan committed Dec 11, 2023
1 parent bd35ae9 commit 746418d
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 5 deletions.
4 changes: 2 additions & 2 deletions R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ server <- function(input, output, session) {
upload_state$file2 <- "reset"
})

listenForFileUPloads <- reactive({
listenForFileUploads <- reactive({
list(upload_state$file1, upload_state$file2)
})

shiny::observeEvent(listenForFileUPloads(), {
shiny::observeEvent(listenForFileUploads(), {
if (is.null(input$fileUpload) && is.null(input$fileUpload2)) {
return(NULL)
}
Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-functions.R

This file was deleted.

94 changes: 94 additions & 0 deletions tests/testthat/test-server.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

test_that("reactives and outputs update", {
# todo try setting data1 and data2 directly from already loaded data?
# the file reading doesnt seem to work in this context and idk why
# something like:
# data1$matrix <- utils::read.table("inst/extdata/mpg-cty-hwy.csv", header = TRUE, sep = '\t')
# data2$matrix <- utils::read.table("inst/extdata/mpg-year-cyl.csv", header = TRUE, sep = '\t')
# session$flushReact()
shiny::testServer(server, {
session$setInputs(fileUpload = "inst/extdata/mpg-cty-hwy.csv",
fileUpload2 = "inst/extdata/mpg-year-cyl.csv",
correlationMethod = "spearman",
correlationFilter = 0,
pValueFilter = 0.05)

# trying to make sure we rendered some stuff
#output$pValueHistogram
#output$correlationHistogram
#output$correlationMatrix
#output$correlationNetwork
#output$bipartiteNetwork

# checking reactiveValues have values
expect_equal(upload_state$file1, 'uploaded')
expect_equal(upload_state$file2, 'uploaded')
#expect_equal(is.null(data1$matrix), FALSE)
#expect_equal(is.null(data2$matrix), FALSE)
#expect_equal(is.null(correlationMatrix$corr_matrix), FALSE)
#expect_equal(is.null(pValuesMatrix$p_values), FALSE)

# checking edgeList
#expect_equal(class(edgeList()$value), "numeric")
#expect_equal(class(edgeList()$p_value), "numeric")
#expect_equal(class(edgeList()$source), "character")
#expect_equal(class(edgeList()$target), "character")
#expect_equal(nrow(edgeList()) > 0, TRUE)
#expect_equal(all(edgeList()$source %in% colnames(data1$matrix)), TRUE)
#expect_equal(all(edgeList()$target %in% colnames(data2$matrix)), TRUE)
#expect_equal(any(edgeList()$target %in% colnames(data2$matrix)), FALSE)
#expect_equal(any(edgeList()$source %in% colnames(data1$matrix)), FALSE)

# checking filteredEdgeList did work
#expect_equal(nrow(filteredEdgeList()) < nrow(edgeList()), TRUE)

# checking bipartiteNetwork
#expect_equal(class(bipartiteNetworkOutput()$data), "list")
#expect_equal(class(bipartiteNetworkOutput()$column1NodeIds), "character")
#expect_equal(class(bipartiteNetworkOutput()$column2NodeIds), "character")

# reset data and check
#session$click("resetData")
#expect_equal(upload_state$file1, "reset")
#expect_equal(upload_state$file2, "reset")
#expect_equal(is.null(data1$matrix), TRUE)
#expect_equal(is.null(data2$matrix), TRUE)
#expect_equal(is.null(correlationMatrix$corr_matrix), TRUE)
#expect_equal(is.null(pValuesMatrix$p_values), TRUE)
#expect_equal(is.null(edgeList()), TRUE)

# upload single file this time
#session$setInputs(fileUpload = "inst/extdata/mpg-all-continuous.tsv",
# fileUpload2 = NULL,
# correlationMethod = "spearman",
# correlationFilter = 0,
# pValueFilter = 0.05)

#expect_equal(upload_state$file1, 'uploaded')
#expect_equal(upload_state$file2, NULL)
#expect_equal(is.null(data1$matrix), FALSE)
#expect_equal(is.null(data2$matrix), TRUE)
#expect_equal(is.null(correlationMatrix$corr_matrix), FALSE)
#expect_equal(is.null(pValuesMatrix$p_values), FALSE)

# checking edgeList
#expect_equal(class(edgeList()$value), "numeric")
#expect_equal(class(edgeList()$p_value), "numeric")
#expect_equal(class(edgeList()$source), "character")
#expect_equal(class(edgeList()$target), "character")
#expect_equal(nrow(edgeList()) > 0, TRUE)
#expect_equal(all(edgeList()$source %in% colnames(data1$matrix)), TRUE)
#expect_equal(all(edgeList()$target %in% colnames(data2$matrix)), TRUE)
#expect_equal(any(edgeList()$target %in% colnames(data2$matrix)), FALSE)
#expect_equal(any(edgeList()$source %in% colnames(data1$matrix)), FALSE)

# checking filteredEdgeList did work
#expect_equal(nrow(filteredEdgeList()) < nrow(edgeList()), TRUE)

# checking unipartiteNetwork
#expect_equal(class(unipartiteNetworkOutput()$data), "list")
#expect_equal(class(unipartiteNetworkOutput()$column1NodeIds), "character")
#expect_equal(class(unipartiteNetworkOutput()$column2NodeIds), "character")

})
})

0 comments on commit 746418d

Please sign in to comment.