Search in sources :

Example 1 with DocumentPreviewStateActionsHandler

use of org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateActionsHandler in project kie-wb-common by kiegroup.

the class DocumentUploadTest method testDrop.

@Test
public void testDrop() {
    Document doc = mock(Document.class);
    when(doc.getId()).thenReturn(DOC_1);
    when(doc.getName()).thenReturn(DOC_1);
    when(doc.getSize()).thenReturn(1024);
    when(doc.getLastModified()).thenReturn((double) System.currentTimeMillis());
    File file = mock(File.class);
    documentUpload.doUpload(doc, file);
    verify(instance).get();
    verify(view).addDocument(any());
    List<DocumentPreview> previews = (List<DocumentPreview>) documentUpload.getCurrentPreviews();
    Assertions.assertThat(previews).isNotNull().hasSize(1);
    ArgumentCaptor<DocumentData> documentDataArgumentCaptor = ArgumentCaptor.forClass(DocumentData.class);
    DocumentPreview preview = previews.get(0);
    verify(preview).init(documentDataArgumentCaptor.capture());
    DocumentData documentData = documentDataArgumentCaptor.getValue();
    Assertions.assertThat(documentData).isNotNull().hasFieldOrPropertyWithValue("contentId", DOC_1).hasFieldOrPropertyWithValue("fileName", DOC_1).hasFieldOrPropertyWithValue("size", Long.valueOf(1024));
    ArgumentCaptor<DocumentPreviewStateActionsHandler> handlerCaptor = ArgumentCaptor.forClass(DocumentPreviewStateActionsHandler.class);
    verify(preview).setStateHandler(handlerCaptor.capture());
    DocumentPreviewStateActionsHandler handler = handlerCaptor.getValue();
    ArgumentCaptor<Command> startUploadCaptor = ArgumentCaptor.forClass(Command.class);
    ArgumentCaptor<ParameterizedCommand> uploadResultCaptor = ArgumentCaptor.forClass(ParameterizedCommand.class);
    verify(uploader).upload(eq(DOC_1), any(), startUploadCaptor.capture(), uploadResultCaptor.capture());
    startUploadCaptor.getValue().execute();
    verify(preview).setState(DocumentPreviewState.UPLOADING);
    uploadResultCaptor.getValue().execute(false);
    verify(preview).setState(DocumentPreviewState.ERROR);
    DocumentPreviewStateAction action = ((List<DocumentPreviewStateAction>) handler.getCurrentStateActions()).get(1);
    action.execute();
    verify(uploader).remove(eq(DOC_1), any());
    uploadResultCaptor.getValue().execute(true);
    verify(preview).setState(DocumentPreviewState.UPLOADED);
}
Also used : Document(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.js.Document) DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) DocumentPreviewStateActionsHandler(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateActionsHandler) DocumentPreview(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview) DocumentPreviewStateAction(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateAction) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Command(org.uberfire.mvp.Command) List(java.util.List) File(elemental2.dom.File) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Test(org.junit.Test)

Aggregations

File (elemental2.dom.File)1 List (java.util.List)1 Test (org.junit.Test)1 Document (org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.js.Document)1 DocumentPreview (org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview)1 DocumentPreviewStateAction (org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateAction)1 DocumentPreviewStateActionsHandler (org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateActionsHandler)1 DocumentData (org.kie.workbench.common.forms.jbpm.model.document.DocumentData)1 Command (org.uberfire.mvp.Command)1 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)1