Search in sources :

Example 51 with Event

use of elemental2.dom.Event 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)

Example 52 with Event

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

the class FlashMessagesViewTest method testTeardownDisableErrorHighlightCallbacks.

@Test
public void testTeardownDisableErrorHighlightCallbacks() {
    final Element element = mock(Element.class);
    final Event event = mock(Event.class);
    element.onkeypress = (e) -> false;
    element.onblur = (e) -> false;
    view.teardownDisableErrorHighlightCallbacks(element);
    assertTrue(Boolean.valueOf(element.onkeypress.onInvoke(event).toString()));
    assertTrue(Boolean.valueOf(element.onblur.onInvoke(event).toString()));
}
Also used : Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) HTMLDivElement(elemental2.dom.HTMLDivElement) HTMLButtonElement(elemental2.dom.HTMLButtonElement) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Event(elemental2.dom.Event) Test(org.junit.Test)

Example 53 with Event

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

the class FlashMessagesViewTest method testOnOkWarningButtonClick.

@Test
public void testOnOkWarningButtonClick() {
    final ClickEvent event = mock(ClickEvent.class);
    doNothing().when(view).disableWarningHighlight();
    warningContainer.classList = mock(DOMTokenList.class);
    view.onOkWarningButtonClick(event);
    verify(presenter).executeSuccessWarningCallback();
    verify(warningContainer.classList).remove(OPENED_CONTAINER_CSS_CLASS);
    verify(view).disableWarningHighlight();
}
Also used : DOMTokenList(elemental2.dom.DOMTokenList) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Test(org.junit.Test)

Example 54 with Event

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

the class DataTypeShortcutsTest method testClickListenerWhenDatatypeElementIsClicked.

@Test
public void testClickListenerWhenDatatypeElementIsClicked() {
    final Event target = mock(Event.class);
    final Element targetElement = mock(Element.class);
    final Element targetMenu = mock(Element.class);
    final Element dataTypeRowElement = mock(Element.class);
    final JQuery jQuery = mock(JQuery.class);
    JQuery.$ = jQuery;
    target.target = targetElement;
    doReturn(targetMenu).when(targetElement).closest(SELECT_DATATYPE_MENU);
    doReturn(false).when(shortcuts).tabContentContainsTarget(target);
    doReturn(dataTypeRowElement).when(targetElement).closest(".list-group-item");
    shortcuts.clickListener(target);
    verify(listShortcuts).focusIn();
    verify(listShortcuts).highlight(dataTypeRowElement);
    verify(listShortcuts, never()).reset();
}
Also used : Element(elemental2.dom.Element) HTMLInputElement(elemental2.dom.HTMLInputElement) HTMLDivElement(elemental2.dom.HTMLDivElement) Event(elemental2.dom.Event) KeyboardEvent(elemental2.dom.KeyboardEvent) JQuery(org.uberfire.client.views.pfly.selectpicker.JQuery) Test(org.junit.Test)

Example 55 with Event

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

the class DataTypeShortcutsTest method testIsSearchBarTargetWhenItReturnsTrue.

@Test
public void testIsSearchBarTargetWhenItReturnsTrue() {
    final HTMLInputElement element = mock(HTMLInputElement.class);
    event.target = element;
    when(element.getAttribute("data-field")).thenReturn("search-bar");
    assertTrue(shortcuts.isTargetElementAnInput(event));
}
Also used : HTMLInputElement(elemental2.dom.HTMLInputElement) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)50 HTMLElement (elemental2.dom.HTMLElement)27 Event (elemental2.dom.Event)26 KeyboardEvent (elemental2.dom.KeyboardEvent)19 Element (elemental2.dom.Element)18 MouseEvent (elemental2.dom.MouseEvent)16 HTMLDivElement (elemental2.dom.HTMLDivElement)15 HTMLInputElement (elemental2.dom.HTMLInputElement)13 HTMLButtonElement (elemental2.dom.HTMLButtonElement)12 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)10 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)7 CSSStyleDeclaration (elemental2.dom.CSSStyleDeclaration)7 JQuery (org.uberfire.client.views.pfly.selectpicker.JQuery)7 DOMRect (elemental2.dom.DOMRect)5 DOMTokenList (elemental2.dom.DOMTokenList)5 DomGlobal (elemental2.dom.DomGlobal)5 LazyReverseView (com.github.mvp4g.mvp4g2.core.ui.LazyReverseView)4 AbstractCell (com.google.gwt.cell.client.AbstractCell)4 Elements.button (org.jboss.gwt.elemento.core.Elements.button)4 Elements.div (org.jboss.gwt.elemento.core.Elements.div)4