Search in sources :

Example 21 with Document

use of elemental2.dom.Document in project kie-wb-common by kiegroup.

the class PrintHelperTest method testCopyStylesFromWindow.

@Test
public void testCopyStylesFromWindow() {
    final HTMLDocument document = mock(HTMLDocument.class);
    final HTMLDocument topDocument = mock(HTMLDocument.class);
    final Window window = mock(Window.class);
    final Window topWindow = mock(Window.class);
    final Element element = mock(Element.class);
    final Element head = mock(Element.class);
    final NodeList<Element> parentStyles = spy(new NodeList<>());
    parentStyles.length = 1;
    window.top = topWindow;
    element.innerHTML = ".page { background: red }";
    doReturn(element).when(parentStyles).item(0);
    doReturn(topDocument).when(helper).getWindowDocument(topWindow);
    doReturn(element).when(helper).asElement(element);
    doReturn(head).when(helper).asElement(head);
    doReturn(mock(Element.class)).when(helper).createElement("style");
    when(document.querySelector("head")).thenReturn(head);
    when(topDocument.querySelectorAll("style")).thenReturn(parentStyles);
    helper.copyStylesFromWindow(document, window);
    verify(head).appendChild(elementArgumentCaptor.capture());
    final Element copiedStyle = elementArgumentCaptor.getValue();
    assertEquals(".page { background: red }", copiedStyle.innerHTML);
}
Also used : Window(elemental2.dom.Window) HTMLDocument(elemental2.dom.HTMLDocument) Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) HTMLBodyElement(elemental2.dom.HTMLBodyElement) Test(org.junit.Test)

Example 22 with Document

use of elemental2.dom.Document in project kie-wb-common by kiegroup.

the class DNDListDOMHelperTest method testCreateDiv.

// -- Factory
@Test
public void testCreateDiv() {
    final HTMLDocument document = mock(HTMLDocument.class);
    final HTMLElement expectedDiv = mock(HTMLElement.class);
    final String tagName = "div";
    DNDListDOMHelper.Factory.DOCUMENT = document;
    when(document.createElement(tagName)).thenReturn(expectedDiv);
    final HTMLElement actualDiv = createDiv();
    assertEquals(expectedDiv, actualDiv);
}
Also used : HTMLElement(elemental2.dom.HTMLElement) HTMLDocument(elemental2.dom.HTMLDocument) Test(org.junit.Test)

Example 23 with Document

use of elemental2.dom.Document 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)

Example 24 with Document

use of elemental2.dom.Document in project kie-wb-common by kiegroup.

the class ContextMenuViewTest method setUp.

@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
    presenter = mock(ContextMenu.class);
    listSelector = mock(ListSelector.class);
    final Field field = DomGlobal.class.getDeclaredField("document");
    field.setAccessible(true);
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
    field.set(DomGlobal.class, mock(HTMLDocument.class));
    contextMenuView = new ContextMenuView(listSelector);
    contextMenuView.init(presenter);
}
Also used : Field(java.lang.reflect.Field) HTMLDocument(elemental2.dom.HTMLDocument) ListSelector(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.ListSelector) Before(org.junit.Before)

Example 25 with Document

use of elemental2.dom.Document in project kie-wb-common by kiegroup.

the class PrintHelperTest method testSetupPrintCommandOnPageLoad.

@Test
public void testSetupPrintCommandOnPageLoad() {
    final HTMLDocument document = mock(HTMLDocument.class);
    final Window window = mock(Window.class);
    document.body = mock(HTMLBodyElement.class);
    doNothing().when(helper).setTimeout(any(), anyInt());
    helper.setupPrintCommandOnPageLoad(document, window);
    document.body.onload.onInvoke(mock(Event.class));
    verify(helper).setTimeout(commandArgumentCaptor.capture(), eq(10));
    commandArgumentCaptor.getValue().execute();
    verify(window).focus();
    verify(window).print();
    verify(window).close();
}
Also used : Window(elemental2.dom.Window) HTMLDocument(elemental2.dom.HTMLDocument) Event(elemental2.dom.Event) HTMLBodyElement(elemental2.dom.HTMLBodyElement) Test(org.junit.Test)

Aggregations

Document (org.apache.tapestry5.dom.Document)20 Test (org.testng.annotations.Test)17 PageTester (org.apache.tapestry5.test.PageTester)11 Test (org.junit.Test)10 HTMLDocument (elemental2.dom.HTMLDocument)9 HTMLElement (elemental2.dom.HTMLElement)9 HTMLIFrameElement (elemental2.dom.HTMLIFrameElement)9 HTMLBodyElement (elemental2.dom.HTMLBodyElement)5 Element (elemental2.dom.Element)4 Element (org.apache.tapestry5.dom.Element)4 DOMTokenList (elemental2.dom.DOMTokenList)3 JsPropertyMap (jsinterop.base.JsPropertyMap)3 Document (org.gwtproject.dom.client.Document)3 Element (org.gwtproject.dom.client.Element)3 InputElement (org.gwtproject.dom.client.InputElement)3 Document (elemental2.dom.Document)2 File (elemental2.dom.File)2 Window (elemental2.dom.Window)2 Field (java.lang.reflect.Field)2 List (java.util.List)2