Class UploadDropZoneTester

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

    
    public class UploadDropZoneTester<T extends UploadDropZone>
    extends ComponentTester<T>
                        

    Tester for UploadDropZone components.

    Dropping files on the drop zone hands them to the UploadManager the drop zone is linked to, which checks them against its maxFiles, maxFileSize and accepted file types the same way the browser does: a file failing one of them fires a UploadManager.FileRejectedEvent and never reaches the upload handler. A refused file is no more of an error here than in the browser, so dropping does not throw for it. Use getLastUploadStatus to see what became of each file, or ensureUploaded to fail the test unless every file went through.

    The manager keeps the files in a file list shared by every component linked to it, and maxFiles is checked against that list. As in the browser, the drop zone is not usable while it is not linked to a manager, while the manager is disabled, or once the file list holds maxFiles files.

    When auto upload is turned off, accepted files wait in the file list until they are started with startUpload.

    • 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
      UploadDropZoneTester(T component) Wrap given component for testing.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      void drop(Array<File> files) Simulates the user dropping the given files on the drop zone.
      void drop(Collection<File> files) Simulates the user dropping the given files on the drop zone.
      void drop(String fileName, String contentType, Array<byte> contents) Simulates the user dropping a file with the given name, content type and contents on the drop zone.
      void uploadAborted(File file) Simulates the user dropping the given file on the drop zone and then aborting its upload.
      void uploadAborted(String fileName, String contentType) Simulates the user dropping a file with the given name and content type on the drop zone and then aborting its upload.
      void uploadFailed(File file) Simulates the user dropping the given file on the drop zone and its upload then failing.
      void uploadFailed(String fileName, String contentType) Simulates the user dropping a file with the given name and content type on the drop zone and its upload then failing.
      List<UploadTester.FileStatus> getLastUploadStatus() Returns what happened to each file the user last selected, dropped or started through the UploadManager the drop zone is linked to, in the order the files were given.
      void ensureUploaded() Checks that the last upload through the UploadManager the drop zone is linked to delivered every one of its files, and fails otherwise.
      void ensureUploadFailed() Checks that at least one file of the last upload through the UploadManager the drop zone is linked to failed or was rejected, and fails otherwise.
      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

      • UploadDropZoneTester

        UploadDropZoneTester(T component)

        Wrap given component for testing.

        Parameters:
        component - target component
    • Method Detail

      • drop

         void drop(Array<File> files)

        Simulates the user dropping the given files on the drop zone.

        The content types are detected from the file names.

        Parameters:
        files - the files to drop
      • drop

         void drop(Collection<File> files)

        Simulates the user dropping the given files on the drop zone.

        The content types are detected from the file names.

        Parameters:
        files - the files to drop
      • drop

         void drop(String fileName, String contentType, Array<byte> contents)

        Simulates the user dropping a file with the given name, content type and contents on the drop zone.

        Parameters:
        fileName - name of the file to drop
        contentType - content type of the file to drop
        contents - file contents as an array of bytes
      • uploadAborted

         void uploadAborted(File file)

        Simulates the user dropping the given file on the drop zone and then aborting its upload.

        As in the browser, the aborted file is dropped from the file list and a UploadManager.FileRemovedEvent is fired, freeing a slot when setMaxFiles is in use.

        The file is added and its transfer started in one go, whether or not auto upload is turned off. The content type is detected from the file name, and the file is not read.

        Parameters:
        file - the file to drop
      • uploadAborted

         void uploadAborted(String fileName, String contentType)

        Simulates the user dropping a file with the given name and content type on the drop zone and then aborting its upload.

        As in the browser, the aborted file is dropped from the file list and a UploadManager.FileRemovedEvent is fired, freeing a slot when setMaxFiles is in use.

        The file is added and its transfer started in one go, whether or not auto upload is turned off.

        Parameters:
        fileName - name of the file to drop
        contentType - content type of the file to drop
      • uploadFailed

         void uploadFailed(File file)

        Simulates the user dropping the given file on the drop zone and its upload then failing.

        As in the browser, a file whose upload failed stays in the file list.

        The file is added and its transfer started in one go, whether or not auto upload is turned off. The content type is detected from the file name, and the file is not read.

        Parameters:
        file - the file to drop
      • uploadFailed

         void uploadFailed(String fileName, String contentType)

        Simulates the user dropping a file with the given name and content type on the drop zone and its upload then failing.

        As in the browser, a file whose upload failed stays in the file list.

        The file is added and its transfer started in one go, whether or not auto upload is turned off.

        Parameters:
        fileName - name of the file to drop
        contentType - content type of the file to drop
      • getLastUploadStatus

         List<UploadTester.FileStatus> getLastUploadStatus()

        Returns what happened to each file the user last selected, dropped or started through the UploadManager the drop zone is linked to, in the order the files were given.

        Files are reported as UPLOADED once the upload handler has consumed them, as REJECTED when the manager or Flow's server-side accepted type validation refused them, as FAILED when the handler threw, and as PENDING while they wait in the file list for auto upload being turned off. The error message of a file the manager refused is the client-side error code: tooManyFiles, fileIsTooBig or incorrectFileType.

        Returns:

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

      • ensureUploaded

         void ensureUploaded()

        Checks that the last upload through the UploadManager the drop zone is linked to delivered every one of its files, and fails otherwise.

      • ensureUploadFailed

         void ensureUploadFailed()

        Checks that at least one file of the last upload through the UploadManager the drop zone is linked to failed or was rejected, and fails otherwise.

        Counterpart of ensureUploaded for a test about the failure case, such as an upload handler that throws or a file the manager refuses. Use getLastUploadStatus to check which file failed and why.

        A file left PENDING does not count as failed: it was neither delivered nor refused, such as a file waiting because auto upload is turned off.

      • 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