use of elemental2.dom.Window 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.Window 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.Window 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);
}
use of elemental2.dom.Window 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();
}
use of elemental2.dom.Window in project kie-wb-common by kiegroup.
the class PrintHelper method print.
public void print(final HTMLElement element) {
final Window globalWindow = getGlobalWindow();
final Window printWindow = globalWindow.open("", "_blank");
final HTMLDocument printDocument = getWindowDocument(printWindow);
writeElementIntoDocument(element, printDocument);
changeMediaAttributesToAll(printDocument);
copyStylesFromWindow(printDocument, globalWindow);
setupPrintCommandOnPageLoad(printDocument, printWindow);
}
Aggregations