Skip to content

Commit

Permalink
Adding coverage: import data
Browse files Browse the repository at this point in the history
  • Loading branch information
thekangaroofactory committed Jan 31, 2024
1 parent eea37d2 commit c888c0f
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ date_slider_value <- c(19737, 19739)
# Declare helper functions
# --------------------------------------------------------------------------

# -- helper: build data model
# -- helper: create test data
create_testdata <- function(){

# -- create folder
Expand All @@ -133,6 +133,18 @@ create_testdata <- function(){
}


# -- helper: create data to import
create_data_to_import <- function(){

# -- create folder
dir.create(testdata_path)

# -- save items
item_save(items, file = "data_to_import.csv", path = testdata_path)

}


# -- helper: cleanup function
clean_all <- function(testdata_path){

Expand Down
84 changes: 84 additions & 0 deletions tests/testthat/test-kitemsManager_Server.R
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,90 @@ test_that("Delete works", {
})


# --------------------------------------------------------------------------
# Cleanup
# --------------------------------------------------------------------------

clean_all(testdata_path)


# --------------------------------------------------------------------------
# Scenario: import data
# --------------------------------------------------------------------------

# -- create test data
create_data_to_import()

test_that("Import works", {

cat("\n-------------------------------------------------------------------------- \n")
cat("Scenario: import data")
cat("\n-------------------------------------------------------------------------- \n")

# -- declare arguments
params <- list(id = module_id,
r = r,
file = "my_data.csv",
path = test_path,
data.model = NULL,
create = FALSE,
autosave = TRUE)

# -- module server call
testServer(kitemsManager_Server, args = params, {

# -- click
session$setInputs(import_data = 1)

# -- create input value
value <- data.frame(name = "data_to_import",
size = 12,
type = "dummy",
datapath = file.path(testdata_path, "data_to_import.csv"))

# -- set file input & click
session$setInputs(input_file = value)
session$setInputs(confirm_import_file = 1)

# -- click
session$setInputs(confirm_import_data = 1)
session$setInputs(confirm_data_model = 1)


# --------------------------------------------------------------------------
# Data model
# --------------------------------------------------------------------------

r_data_model <- dm_name(module_id)
x <- r[[r_data_model]]()

# -- test class
expect_s3_class(x, "data.frame")

# -- test dim
expect_equal(dim(x), dim(dm))


# --------------------------------------------------------------------------
# Items
# --------------------------------------------------------------------------


r_items <- items_name(module_id)
x <- r[[r_items]]()

# -- test class
expect_s3_class(x, "data.frame")

# -- test dim
expect_equal(dim(x), c(4, 6))


})

})


# --------------------------------------------------------------------------
# Cleanup
# --------------------------------------------------------------------------
Expand Down

0 comments on commit c888c0f

Please sign in to comment.