Search in sources :

Example 6 with HTMLDocument

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

the class PrintHelperTest method testPrint.

@Test
public void testPrint() {
    final HTMLElement element = mock(HTMLElement.class);
    final HTMLDocument printDocument = mock(HTMLDocument.class);
    final Window globalWindow = mock(Window.class);
    final Window printWindow = mock(Window.class);
    doReturn(globalWindow).when(helper).getGlobalWindow();
    doReturn(printDocument).when(helper).getWindowDocument(printWindow);
    doNothing().when(helper).writeElementIntoDocument(any(), any());
    doNothing().when(helper).changeMediaAttributesToAll(any());
    doNothing().when(helper).copyStylesFromWindow(any(), any());
    doNothing().when(helper).setupPrintCommandOnPageLoad(any(), any());
    when(globalWindow.open("", "_blank")).thenReturn(printWindow);
    helper.print(element);
    verify(helper).writeElementIntoDocument(element, printDocument);
    verify(helper).changeMediaAttributesToAll(printDocument);
    verify(helper).copyStylesFromWindow(printDocument, globalWindow);
    verify(helper).setupPrintCommandOnPageLoad(printDocument, printWindow);
}
Also used : Window(elemental2.dom.Window) HTMLElement(elemental2.dom.HTMLElement) HTMLDocument(elemental2.dom.HTMLDocument) Test(org.junit.Test)

Example 7 with HTMLDocument

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

Example 8 with HTMLDocument

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

the class PrintHelperTest method testWriteElementIntoDocument.

@Test
public void testWriteElementIntoDocument() {
    final HTMLElement element = mock(HTMLElement.class);
    final HTMLDocument document = mock(HTMLDocument.class);
    final HTMLBodyElement body = mock(HTMLBodyElement.class);
    final String elementHTML = "<html />";
    final DOMTokenList classList = mock(DOMTokenList.class);
    element.innerHTML = elementHTML;
    document.body = body;
    body.classList = classList;
    helper.writeElementIntoDocument(element, document);
    verify(document).open();
    verify(document).write(elementHTML);
    verify(document).close();
    verify(classList).add(PREVIEW_SCREEN_CSS_CLASS);
}
Also used : DOMTokenList(elemental2.dom.DOMTokenList) HTMLElement(elemental2.dom.HTMLElement) HTMLDocument(elemental2.dom.HTMLDocument) HTMLBodyElement(elemental2.dom.HTMLBodyElement) Test(org.junit.Test)

Example 9 with HTMLDocument

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

the class DNDListComponentViewTest method testCreateItem.

@Test
public void testCreateItem() {
    final HTMLDocument document = mock(HTMLDocument.class);
    final HTMLElement expectedItem = mock(HTMLElement.class);
    final HTMLElement htmlElement = mock(HTMLElement.class);
    final HTMLElement grip = mock(HTMLElement.class);
    final HTMLElement i0 = mock(HTMLElement.class);
    final HTMLElement i1 = mock(HTMLElement.class);
    DNDListDOMHelper.Factory.DOCUMENT = document;
    expectedItem.classList = mock(DOMTokenList.class);
    grip.classList = mock(DOMTokenList.class);
    i0.classList = mock(DOMTokenList.class);
    i1.classList = mock(DOMTokenList.class);
    when(document.createElement("div")).thenReturn(expectedItem, grip);
    when(document.createElement("i")).thenReturn(i0, i1);
    final HTMLElement actualItem = view.createItem(htmlElement);
    verify(actualItem).appendChild(grip);
    verify(actualItem).appendChild(htmlElement);
    verify(actualItem.classList).add(DRAGGABLE);
    assertEquals(expectedItem, actualItem);
}
Also used : DOMTokenList(elemental2.dom.DOMTokenList) HTMLElement(elemental2.dom.HTMLElement) HTMLDocument(elemental2.dom.HTMLDocument) Test(org.junit.Test)

Example 10 with HTMLDocument

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

the class DNDListDOMHelperTest method testCreateGripElement.

@Test
public void testCreateGripElement() {
    final HTMLDocument document = mock(HTMLDocument.class);
    final HTMLElement expectedGrip = mock(HTMLElement.class);
    final HTMLElement firstI = mock(HTMLElement.class);
    final HTMLElement secondI = mock(HTMLElement.class);
    final String div = "div";
    final String i = "i";
    DNDListDOMHelper.Factory.DOCUMENT = document;
    expectedGrip.classList = mock(DOMTokenList.class);
    firstI.classList = mock(DOMTokenList.class);
    secondI.classList = mock(DOMTokenList.class);
    when(document.createElement(div)).thenReturn(expectedGrip);
    when(document.createElement(i)).thenReturn(firstI, secondI);
    final HTMLElement actualGrip = createGripElement();
    verify(expectedGrip).appendChild(firstI);
    verify(expectedGrip).appendChild(secondI);
    verify(expectedGrip.classList).add(GRIP);
    verify(firstI.classList).add(ICON_CLASS);
    verify(secondI.classList).add(ICON_CLASS);
    verify(firstI.classList).add(ELLIPSIS_CLASS);
    verify(secondI.classList).add(ELLIPSIS_CLASS);
    assertEquals(expectedGrip, actualGrip);
}
Also used : DOMTokenList(elemental2.dom.DOMTokenList) HTMLElement(elemental2.dom.HTMLElement) HTMLDocument(elemental2.dom.HTMLDocument) Test(org.junit.Test)

Aggregations

HTMLDocument (elemental2.dom.HTMLDocument)11 HTMLElement (elemental2.dom.HTMLElement)10 Test (org.junit.Test)9 HTMLBodyElement (elemental2.dom.HTMLBodyElement)5 Element (elemental2.dom.Element)4 Window (elemental2.dom.Window)4 DOMTokenList (elemental2.dom.DOMTokenList)3 CSSStyleDeclaration (elemental2.dom.CSSStyleDeclaration)1 Event (elemental2.dom.Event)1 Field (java.lang.reflect.Field)1