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());
}
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");
}
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);
}
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);
}
}
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);
}
Aggregations