use of elemental2.dom.Document 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.Document 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);
}
use of elemental2.dom.Document in project kie-wb-common by kiegroup.
the class DocumentUploadTest method testDrop.
@Test
public void testDrop() {
Document doc = mock(Document.class);
when(doc.getId()).thenReturn(DOC_1);
when(doc.getName()).thenReturn(DOC_1);
when(doc.getSize()).thenReturn(1024);
when(doc.getLastModified()).thenReturn((double) System.currentTimeMillis());
File file = mock(File.class);
documentUpload.doUpload(doc, file);
verify(instance).get();
verify(view).addDocument(any());
List<DocumentPreview> previews = (List<DocumentPreview>) documentUpload.getCurrentPreviews();
Assertions.assertThat(previews).isNotNull().hasSize(1);
ArgumentCaptor<DocumentData> documentDataArgumentCaptor = ArgumentCaptor.forClass(DocumentData.class);
DocumentPreview preview = previews.get(0);
verify(preview).init(documentDataArgumentCaptor.capture());
DocumentData documentData = documentDataArgumentCaptor.getValue();
Assertions.assertThat(documentData).isNotNull().hasFieldOrPropertyWithValue("contentId", DOC_1).hasFieldOrPropertyWithValue("fileName", DOC_1).hasFieldOrPropertyWithValue("size", Long.valueOf(1024));
ArgumentCaptor<DocumentPreviewStateActionsHandler> handlerCaptor = ArgumentCaptor.forClass(DocumentPreviewStateActionsHandler.class);
verify(preview).setStateHandler(handlerCaptor.capture());
DocumentPreviewStateActionsHandler handler = handlerCaptor.getValue();
ArgumentCaptor<Command> startUploadCaptor = ArgumentCaptor.forClass(Command.class);
ArgumentCaptor<ParameterizedCommand> uploadResultCaptor = ArgumentCaptor.forClass(ParameterizedCommand.class);
verify(uploader).upload(eq(DOC_1), any(), startUploadCaptor.capture(), uploadResultCaptor.capture());
startUploadCaptor.getValue().execute();
verify(preview).setState(DocumentPreviewState.UPLOADING);
uploadResultCaptor.getValue().execute(false);
verify(preview).setState(DocumentPreviewState.ERROR);
DocumentPreviewStateAction action = ((List<DocumentPreviewStateAction>) handler.getCurrentStateActions()).get(1);
action.execute();
verify(uploader).remove(eq(DOC_1), any());
uploadResultCaptor.getValue().execute(true);
verify(preview).setState(DocumentPreviewState.UPLOADED);
}
use of elemental2.dom.Document in project kie-wb-common by kiegroup.
the class ContextMenuViewTest method setUp.
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
presenter = mock(ContextMenu.class);
listSelector = mock(ListSelector.class);
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, mock(HTMLDocument.class));
contextMenuView = new ContextMenuView(listSelector);
contextMenuView.init(presenter);
}
use of elemental2.dom.Document 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();
}
Aggregations