Search in sources :

Example 6 with NodeList

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

the class DragAndDropHelperTest method testRefreshItemsPosition.

@Test
public void testRefreshItemsPosition() {
    final HTMLElement element1 = mock(HTMLElement.class);
    final HTMLElement element2 = mock(HTMLElement.class);
    final HTMLElement element3 = mock(HTMLElement.class);
    final CSSStyleDeclaration element1Style = mock(CSSStyleDeclaration.class);
    final CSSStyleDeclaration element2Style = mock(CSSStyleDeclaration.class);
    final CSSStyleDeclaration element3Style = mock(CSSStyleDeclaration.class);
    element1.style = element1Style;
    element2.style = element2Style;
    element3.style = element3Style;
    element1.offsetHeight = 50;
    final NodeList<Element> draggableItems = spy(new NodeList<>());
    doReturn(element1).when(draggableItems).getAt(0);
    doReturn(element2).when(draggableItems).getAt(1);
    doReturn(element3).when(draggableItems).getAt(2);
    when(element1.getAttribute(DATA_POSITION)).thenReturn("0");
    when(element2.getAttribute(DATA_POSITION)).thenReturn("1");
    when(element3.getAttribute(DATA_POSITION)).thenReturn("2");
    draggableItems.length = 3;
    when(dragArea.querySelectorAll(DragAndDropHelper.DRAGGABLE_ITEM_CLASS)).thenReturn(draggableItems);
    helper.refreshItemsPosition();
    verify(element1Style).setProperty(TOP, 0 + PX);
    verify(element2Style).setProperty(TOP, 50 + PX);
    verify(element3Style).setProperty(TOP, 100 + PX);
    verify(addButtonContainerStyle).setProperty(TOP, 150 + PX);
}
Also used : HTMLElement(elemental2.dom.HTMLElement) Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) CSSStyleDeclaration(elemental2.dom.CSSStyleDeclaration) Test(org.junit.Test)

Example 7 with NodeList

use of elemental2.dom.NodeList 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 8 with NodeList

use of elemental2.dom.NodeList 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 9 with NodeList

use of elemental2.dom.NodeList 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 10 with NodeList

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

the class DataTypeListViewTest method makeElement.

public Element makeElement(final String uuid) {
    final Element element = mock(Element.class);
    mockDOMElementsByParentUUID(uuid, new NodeList<>());
    when(element.getAttribute(UUID_ATTR)).thenReturn(uuid);
    return element;
}
Also used : Element(elemental2.dom.Element) HTMLAnchorElement(elemental2.dom.HTMLAnchorElement) HTMLElement(elemental2.dom.HTMLElement) HTMLDivElement(elemental2.dom.HTMLDivElement) HTMLButtonElement(elemental2.dom.HTMLButtonElement)

Aggregations

Element (elemental2.dom.Element)36 HTMLElement (elemental2.dom.HTMLElement)33 Test (org.junit.Test)24 HTMLDivElement (elemental2.dom.HTMLDivElement)18 HTMLButtonElement (elemental2.dom.HTMLButtonElement)16 DOMTokenList (elemental2.dom.DOMTokenList)15 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)9 HTMLInputElement (elemental2.dom.HTMLInputElement)8 HTMLAnchorElement (elemental2.dom.HTMLAnchorElement)7 NodeList (elemental2.dom.NodeList)4 Factory.createGripElement (org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListDOMHelper.Factory.createGripElement)4 DNDListDOMHelper.isDraggingElement (org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListDOMHelper.isDraggingElement)4 HTMLDocument (elemental2.dom.HTMLDocument)3 HTMLBodyElement (elemental2.dom.HTMLBodyElement)2 Node (elemental2.dom.Node)2 CSSStyleDeclaration (elemental2.dom.CSSStyleDeclaration)1 Window (elemental2.dom.Window)1 ArrayList (java.util.ArrayList)1 DataTypeConstraint (org.kie.workbench.common.dmn.client.editors.types.listview.constraint.DataTypeConstraint)1