Search in sources :

Example 1 with EventTarget

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

the class DocumentUploadViewImpl method onDragEnd.

private void onDragEnd(Event event) {
    if (dropRegion.contains(dropHere)) {
        EventTarget relatedTarget = ((DragEvent) event).relatedTarget;
        if (relatedTarget.equals(dropHere) || dropHere.contains((Node) relatedTarget)) {
            return;
        }
        restore();
    }
}
Also used : DragEvent(elemental2.dom.DragEvent) Node(elemental2.dom.Node) EventTarget(elemental2.dom.EventTarget)

Example 2 with EventTarget

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

the class ContextMenuViewTest method testWhenGettingEventPathAndPathIsNull.

@Test
public void testWhenGettingEventPathAndPathIsNull() {
    final Event event = mock(Event.class);
    final Element element = mock(Element.class);
    final JsArray<EventTarget> composedPath = spy(new JsArray<>());
    final List<EventTarget> composedPathAsList = new ArrayList<>();
    final String value = "test-val";
    event.path = null;
    composedPathAsList.add(element);
    doReturn(composedPathAsList).when(composedPath).asList();
    when(event.composedPath()).thenReturn(composedPath);
    when(element.getAttribute(Mockito.<String>any())).thenReturn(value);
    final List<Element> eventPath = contextMenuView.getEventPath(event);
    assertThat(eventPath).isNotNull();
    assertThat(eventPath).isNotEmpty();
    assertThat(eventPath.size()).isEqualTo(1);
    assertThat(eventPath.get(0)).extracting(elem -> elem.getAttribute("test-attr")).isEqualTo(value);
}
Also used : Element(elemental2.dom.Element) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Event(elemental2.dom.Event) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.spy(org.mockito.Mockito.spy) ListSelector(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.ListSelector) ArrayList(java.util.ArrayList) EventTarget(elemental2.dom.EventTarget) HTMLDocument(elemental2.dom.HTMLDocument) Mockito.doReturn(org.mockito.Mockito.doReturn) Command(org.uberfire.mvp.Command) Before(org.junit.Before) DomGlobal(elemental2.dom.DomGlobal) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) JsArray(elemental2.core.JsArray) Mockito.verify(org.mockito.Mockito.verify) ListSelectorTextItem(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl.ListSelectorTextItem) Mockito(org.mockito.Mockito) List(java.util.List) Modifier(java.lang.reflect.Modifier) ListSelectorItem(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl.ListSelectorItem) Mockito.anyInt(org.mockito.Mockito.anyInt) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Element(elemental2.dom.Element) ArrayList(java.util.ArrayList) Event(elemental2.dom.Event) EventTarget(elemental2.dom.EventTarget) Test(org.junit.Test)

Example 3 with EventTarget

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

the class ContextMenuViewTest method testWhenGettingEventPath.

@Test
public void testWhenGettingEventPath() {
    final Event event = mock(Event.class);
    final Element element = mock(Element.class);
    final List<EventTarget> pathArray = new ArrayList<>();
    final String value = "test-val";
    event.path = spy(new JsArray<>());
    pathArray.add(element);
    doReturn(pathArray).when(event.path).asList();
    when(element.getAttribute(Mockito.<String>any())).thenReturn(value);
    final List<Element> eventPath = contextMenuView.getEventPath(event);
    assertThat(eventPath).isNotNull();
    assertThat(eventPath).isNotEmpty();
    assertThat(eventPath.size()).isEqualTo(1);
    assertThat(eventPath.get(0)).extracting(elem -> elem.getAttribute("test-attr")).isEqualTo(value);
}
Also used : Element(elemental2.dom.Element) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Event(elemental2.dom.Event) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.spy(org.mockito.Mockito.spy) ListSelector(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.ListSelector) ArrayList(java.util.ArrayList) EventTarget(elemental2.dom.EventTarget) HTMLDocument(elemental2.dom.HTMLDocument) Mockito.doReturn(org.mockito.Mockito.doReturn) Command(org.uberfire.mvp.Command) Before(org.junit.Before) DomGlobal(elemental2.dom.DomGlobal) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) JsArray(elemental2.core.JsArray) Mockito.verify(org.mockito.Mockito.verify) ListSelectorTextItem(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl.ListSelectorTextItem) Mockito(org.mockito.Mockito) List(java.util.List) Modifier(java.lang.reflect.Modifier) ListSelectorItem(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl.ListSelectorItem) Mockito.anyInt(org.mockito.Mockito.anyInt) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) JsArray(elemental2.core.JsArray) Element(elemental2.dom.Element) ArrayList(java.util.ArrayList) Event(elemental2.dom.Event) EventTarget(elemental2.dom.EventTarget) Test(org.junit.Test)

Aggregations

EventTarget (elemental2.dom.EventTarget)3 JsArray (elemental2.core.JsArray)2 DomGlobal (elemental2.dom.DomGlobal)2 Element (elemental2.dom.Element)2 Event (elemental2.dom.Event)2 HTMLDocument (elemental2.dom.HTMLDocument)2 Field (java.lang.reflect.Field)2 Modifier (java.lang.reflect.Modifier)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ListSelectorItem (org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl.ListSelectorItem)2 ListSelectorTextItem (org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl.ListSelectorTextItem)2 ListSelector (org.kie.workbench.common.dmn.client.widgets.grid.controls.list.ListSelector)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 Mockito (org.mockito.Mockito)2 Mockito.anyInt (org.mockito.Mockito.anyInt)2