Skip to content
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

upload_file respects multiple argument in fileInput (unlike browsers) #370

Open
TymekDev opened this issue Dec 13, 2023 · 0 comments
Open

Comments

@TymekDev
Copy link

Context

Just recently I have learned that multiple = TRUE in fileInput is just a hint and is entirely enforced by the browser. For example, here is a short example of bypassing this limitation by dragging files:

CleanShot.2023-12-13.at.16.46.37.mp4

I have implemented a server-side validation to ensure that user uploads only a single file. If there is more than one file, then an error message is displayed. I want to write a test using {shinytest2} to check if a correct message is displayed.

Issue

Given a fileInput("f", multiple = FALSE) and the following {shinytest2} code only first file will make it to input$f during testing.

library(shinytest2)
app <- AppDriver$new()
app$upload_file(f = c("file1", "file2"))

However, if we provide multiple = TRUE, then both files will appear in input$f.

Reprex

tymek@maczek ~/w/r/reprex > Rscript test-shinytest2.R
Loading required package: testthat
   name size type datapath
1 file1    0             0

tymek@maczek ~/w/r/reprex > MULTIPLE=TRUE Rscript test-shinytest2.R
Loading required package: testthat
   name size type datapath
1 file1    0             0
2 file2    0             1

app.R

library(shiny)

shinyApp(
  tagList(
    fileInput("f", "", multiple = as.logical(Sys.getenv("MULTIPLE", FALSE))),
    verbatimTextOutput("t")
  ),
  function(input, output, session) {
    output$t <- renderPrint({
      print(input$f)
    })
  }
)

test-shinytest2.R

library(shinytest2)

app <- AppDriver$new(".")
app$upload_file(f = c("~/Documents/untitled folder/file1", "~/Documents/untitled folder/file2"))
print(app$get_value(input = "f"))
@TymekDev TymekDev changed the title upload_file respects multiple unlike browsers upload_file respects multiple argument in fileInput (unlike browsers) Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant