Search in sources :

Example 1 with HTMLDocument

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

the class DMNEditDRDToolboxActionTest method testOnMouseClick.

@Test
public void testOnMouseClick() throws NoSuchFieldException, IllegalAccessException {
    final HTMLElement htmlElement = new HTMLElement();
    htmlElement.style = new CSSStyleDeclaration();
    final HTMLDocument htmlDocument = new HTMLDocument();
    htmlDocument.body = new HTMLBodyElement();
    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, htmlDocument);
    when(drdContextMenu.getElement()).thenReturn(htmlElement);
    dmnEditDRDToolboxAction.onMouseClick(canvasHandler, UUID, mouseClickEvent);
    verify(drdContextMenu, times(1)).show(Mockito.<Collection>any());
}
Also used : Field(java.lang.reflect.Field) HTMLElement(elemental2.dom.HTMLElement) HTMLDocument(elemental2.dom.HTMLDocument) HTMLBodyElement(elemental2.dom.HTMLBodyElement) CSSStyleDeclaration(elemental2.dom.CSSStyleDeclaration) Test(org.junit.Test)

Example 2 with HTMLDocument

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

the class PrintHelperTest method testChangeMediaAttributesToAll.

@Test
public void testChangeMediaAttributesToAll() {
    final HTMLDocument document = mock(HTMLDocument.class);
    final Element element = mock(Element.class);
    final NodeList<Element> links = spy(new NodeList<>());
    final String media = "media";
    links.length = 1;
    doReturn(element).when(links).item(0);
    doReturn(element).when(helper).asElement(element);
    when(document.querySelectorAll("link")).thenReturn(links);
    when(element.getAttribute(media)).thenReturn("print");
    helper.changeMediaAttributesToAll(document);
    verify(element).setAttribute(media, "all");
}
Also used : HTMLDocument(elemental2.dom.HTMLDocument) Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) HTMLBodyElement(elemental2.dom.HTMLBodyElement) Test(org.junit.Test)

Example 3 with HTMLDocument

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

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

the class PrintHelper method copyStylesFromWindow.

void copyStylesFromWindow(final HTMLDocument printDocument, final Window window) {
    final HTMLDocument topDocument = getWindowDocument(window.top);
    final NodeList<Element> parentStyles = topDocument.querySelectorAll("style");
    final Element documentHead = asElement(printDocument.querySelector("head"));
    for (int i = 0; i < parentStyles.length; i++) {
        final Element copiedStyle = createElement("style");
        copiedStyle.innerHTML = asElement(parentStyles.item(i)).innerHTML;
        documentHead.appendChild(copiedStyle);
    }
}
Also used : HTMLDocument(elemental2.dom.HTMLDocument) Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement)

Example 5 with HTMLDocument

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

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