Class UploadFileListTester<T extends com.vaadin.flow.component.upload.UploadFileList>

java.lang.Object
com.vaadin.browserless.ComponentTester<T>
com.vaadin.flow.component.upload.UploadFileListTester<T>
Type Parameters:
T - the component type.
All Implemented Interfaces:
Clickable<T>

public class UploadFileListTester<T extends com.vaadin.flow.component.upload.UploadFileList> extends ComponentTester<T>
Tester for UploadFileList components.

The file list shows the files of the UploadManager it is linked to: the files the user picked with an UploadButton or dropped on an UploadDropZone linked to the same manager. The tester reads that list and simulates the buttons on its entries. As in the browser, the file list is not usable while it is not linked to a manager or while the manager is disabled.

Entries are reached by file name or by position. As in the browser, nothing prevents the user from adding the same file, or another file with the same name, more than once: every one becomes an entry of its own, is uploaded on its own and counts towards UploadManager.setMaxFiles(int). When several entries share a name, removeFile(String) removes the most recently added one, which is the first one the list shows, and startUpload(String) starts the most recently added one that still waits to be started. To act on a specific entry, use removeFile(int) and startUpload(int) with its position in getFiles().

  • Constructor Details

    • UploadFileListTester

      public UploadFileListTester(T component)
      Wrap given component for testing.
      Parameters:
      component - target component
  • Method Details

    • getFiles

      public List<UploadTester.FileStatus> getFiles()
      Gets the files the file list shows, in the order the browser shows them: the most recently added file first.

      A file is UploadTester.UploadStatus.UPLOADED once the upload handler has consumed it, UploadTester.UploadStatus.FAILED or UploadTester.UploadStatus.REJECTED when its transfer failed or the server refused it, and UploadTester.UploadStatus.PENDING while it waits to be started because auto upload is turned off.

      Returns:
      the files in the file list, or an empty list if the file list is not linked to an upload manager
    • getLastUploadStatus

      public List<UploadTester.FileStatus> getLastUploadStatus()
      Returns what happened to each file the user last picked with an UploadButton, dropped on an UploadDropZone or started from this list, in the order the files were given.

      A file is UploadTester.UploadStatus.UPLOADED once the upload handler has consumed it, UploadTester.UploadStatus.FAILED when the handler threw, and UploadTester.UploadStatus.PENDING while it waits for startUpload(String) because auto upload is turned off.

      Unlike getFiles(), this also reports the files the manager refused, which never enter the list: they are UploadTester.UploadStatus.REJECTED with the client-side error code as the error message: tooManyFiles, fileIsTooBig or incorrectFileType. A file Flow's server-side accepted type validation refused is REJECTED as well.

      Returns:
      the outcome of the last upload, one entry per file, or an empty list if nothing has been uploaded yet or the file list is not linked to a manager
    • removeFile

      public void removeFile(String fileName)
      Simulates the user clicking the remove button of a file in the list.

      A UploadManager.FileRemovedEvent is fired and the file stops counting towards UploadManager.setMaxFiles(int).

      When several entries have the given name, the most recently added one is removed.

      Parameters:
      fileName - name of the file to remove, as given when it was uploaded
      Throws:
      IllegalArgumentException - if the file is not in the file list
      IllegalStateException - if the component is not usable
    • removeFile

      public void removeFile(File file)
      Simulates the user clicking the remove button of a file in the list.

      A UploadManager.FileRemovedEvent is fired and the file stops counting towards UploadManager.setMaxFiles(int).

      When several entries have the name of the given file, the most recently added one is removed.

      Parameters:
      file - the file to remove
      Throws:
      IllegalArgumentException - if the file is not in the file list
      IllegalStateException - if the component is not usable
    • removeFile

      public void removeFile(int index)
      Simulates the user clicking the remove button of the file at the given position of the list, which reaches one entry when several share a name.

      A UploadManager.FileRemovedEvent is fired and the file stops counting towards UploadManager.setMaxFiles(int).

      Parameters:
      index - the position of the file in the list, in the order getFiles() returns them: the most recently added file first
      Throws:
      IllegalArgumentException - if there is no file at the position
      IllegalStateException - if the component is not usable
    • startUpload

      public void startUpload(String fileName)
      Simulates the user clicking the start button of a file that waits in the list because auto upload is turned off, uploading it.

      When several waiting entries have the given name, the most recently added one is started.

      Parameters:
      fileName - name of the file to start, as given when it was added
      Throws:
      UncheckedIOException - if the upload handler fails to handle the file contents
      IllegalArgumentException - if no such file waits in the file list
      IllegalStateException - if the component is not usable
    • startUpload

      public void startUpload(File file)
      Simulates the user clicking the start button of a file that waits in the list because auto upload is turned off, uploading it.

      When several waiting entries have the name of the given file, the most recently added one is started.

      Parameters:
      file - the file to start
      Throws:
      UncheckedIOException - if the upload handler fails to handle the file contents
      IllegalArgumentException - if no such file waits in the file list
      IllegalStateException - if the component is not usable
    • startUpload

      public void startUpload(int index)
      Simulates the user clicking the start button of the file at the given position of the list, which waits because auto upload is turned off, uploading it. This reaches one entry when several share a name.
      Parameters:
      index - the position of the file in the list, in the order getFiles() returns them: the most recently added file first
      Throws:
      UncheckedIOException - if the upload handler fails to handle the file contents
      IllegalArgumentException - if there is no file at the position, or it does not wait to be uploaded
      IllegalStateException - if the component is not usable
    • isUsable

      public boolean isUsable()
      Description copied from class: ComponentTester
      Validate that component can be interacted with and should be visible in the UI. Subclasses overriding this method should also override ComponentTester.notUsableReasons(Consumer) to provide additional details to the potential exception thrown by ComponentTester.ensureComponentIsUsable().
      Overrides:
      isUsable in class ComponentTester<T extends com.vaadin.flow.component.upload.UploadFileList>
      Returns:
      true if component can be interacted with by the user
      See Also:
    • notUsableReasons

      protected void notUsableReasons(Consumer<String> collector)
      Description copied from class: ComponentTester
      Provides messages explaining why the component is actually not usable. Subclasses overriding ComponentTester.isUsable() should also override this method to provide additional details to the potential exception throw by ComponentTester.ensureComponentIsUsable().
      Overrides:
      notUsableReasons in class ComponentTester<T extends com.vaadin.flow.component.upload.UploadFileList>
      Parameters:
      collector - receives the components the tester walks over
      See Also: