Class UploadFileListTester

  • All Implemented Interfaces:
    com.vaadin.browserless.Clickable

    
    public class UploadFileListTester<T extends 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 setMaxFiles. When several entries share a name, removeFile removes the most recently added one, which is the first one the list shows, and startUpload starts the most recently added one that still waits to be started. To act on a specific entry, use removeFile and startUpload with its position in getFiles.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final T component
    • Constructor Summary

      Constructors 
      Constructor Description
      UploadFileListTester(T component) Wrap given component for testing.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      List<UploadTester.FileStatus> getFiles() Gets the files the file list shows, in the order the browser shows them: the most recently added file first.
      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.
      void removeFile(String fileName) Simulates the user clicking the remove button of a file in the list.
      void removeFile(File file) Simulates the user clicking the remove button of a file in the list.
      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.
      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.
      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.
      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.
      boolean isUsable() Validate that component can be interacted with and should be visible in the UI.
      • Methods inherited from class com.vaadin.browserless.ComponentTester

        blur, ensureComponentIsUsable, find, focus, getComponent, isFocused, setModal
      • Methods inherited from class com.vaadin.browserless.Clickable

        click, click, click, middleClick, middleClick, rightClick, rightClick
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UploadFileListTester

        UploadFileListTester(T component)

        Wrap given component for testing.

        Parameters:
        component - target component
    • Method Detail

      • getFiles

         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 UPLOADED once the upload handler has consumed it, FAILED or REJECTED when its transfer failed or the server refused it, and 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

         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 UPLOADED once the upload handler has consumed it, FAILED when the handler threw, and PENDING while it waits for startUpload because auto upload is turned off.

        Unlike getFiles, this also reports the files the manager refused, which never enter the list: they are 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

         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 setMaxFiles.

        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
      • removeFile

         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 setMaxFiles.

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

        Parameters:
        file - the file to remove
      • removeFile

         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 setMaxFiles.

        Parameters:
        index - the position of the file in the list, in the order getFiles returns them: the most recently added file first
      • startUpload

         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
      • startUpload

         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
      • startUpload

         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
      • isUsable

         boolean isUsable()

        Validate that component can be interacted with and should be visible in the UI. Subclasses overriding this method should also override notUsableReasons to provide additional details to the potential exception thrown by ensureComponentIsUsable.

        Returns:

        true if component can be interacted with by the user