Search in sources :

Example 6 with MouseEvent

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

the class DragAndDropHelperTest method testOnDragAreaMouseDown.

@Test
public void testOnDragAreaMouseDown() {
    final int clientY = 123;
    final int startYPosition = 1;
    final MouseEvent mouseEvent = mock(MouseEvent.class);
    final Element dragGrabber = mock(Element.class);
    final Element target = mock(Element.class);
    final HTMLElement draggable = mock(HTMLElement.class);
    mouseEvent.clientY = clientY;
    mouseEvent.target = target;
    when(target.closest(".drag-grabber")).thenReturn(dragGrabber);
    when(dragGrabber.closest(DragAndDropHelper.DRAGGABLE_ITEM_CLASS)).thenReturn(draggable);
    doReturn(startYPosition).when(helper).getTop(draggable);
    helper.onDragAreaMouseDown(mouseEvent);
    assertEquals(startYPosition, helper.getStartYPosition());
    assertEquals(clientY, helper.getClickedYPosition());
    assertEquals(draggable, helper.getDragging());
}
Also used : MouseEvent(elemental2.dom.MouseEvent) HTMLElement(elemental2.dom.HTMLElement) Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) Test(org.junit.Test)

Example 7 with MouseEvent

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

the class DNDListComponentViewTest method testUpdateDraggingElementXWhenNewDraggingXPositionIsGreaterThanMax.

@Test
public void testUpdateDraggingElementXWhenNewDraggingXPositionIsGreaterThanMax() {
    final MouseEvent event = mock(MouseEvent.class);
    final HTMLElement draggingElement = mock(HTMLElement.class);
    final DOMRect rect = mock(DOMRect.class);
    event.x = 1000;
    rect.left = 25;
    draggingElement.style = mock(CSSStyleDeclaration.class);
    dragArea.offsetWidth = 300;
    when(presenter.getIndentationSize()).thenReturn(50);
    when(dragArea.getBoundingClientRect()).thenReturn(rect);
    doReturn(draggingElement).when(view).getDragging();
    view.updateDraggingElementX(event);
    verify(draggingElement.style).setProperty("width", "calc(100% - 250px)");
}
Also used : MouseEvent(elemental2.dom.MouseEvent) HTMLElement(elemental2.dom.HTMLElement) DOMRect(elemental2.dom.DOMRect) CSSStyleDeclaration(elemental2.dom.CSSStyleDeclaration) Test(org.junit.Test)

Example 8 with MouseEvent

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

the class DragAndDropHelperTest method testGetDelta.

@Test
public void testGetDelta() {
    final int clickedYPosition = 20;
    final int mousePosition = 10;
    final int expected = mousePosition - clickedYPosition;
    final MouseEvent mouseEvent = mock(MouseEvent.class);
    mouseEvent.clientY = mousePosition;
    doReturn(clickedYPosition).when(helper).getClickedYPosition();
    final int actual = helper.getDelta(mouseEvent);
    assertEquals(expected, actual);
}
Also used : MouseEvent(elemental2.dom.MouseEvent) Test(org.junit.Test)

Example 9 with MouseEvent

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

the class DNDListComponentViewTest method testUpdateDraggingElementX.

@Test
public void testUpdateDraggingElementX() {
    final MouseEvent event = mock(MouseEvent.class);
    final HTMLElement draggingElement = mock(HTMLElement.class);
    final DOMRect rect = mock(DOMRect.class);
    event.x = 100;
    rect.left = 25;
    draggingElement.style = mock(CSSStyleDeclaration.class);
    dragArea.offsetWidth = 300;
    when(presenter.getIndentationSize()).thenReturn(50);
    when(dragArea.getBoundingClientRect()).thenReturn(rect);
    doReturn(draggingElement).when(view).getDragging();
    view.updateDraggingElementX(event);
    verify(draggingElement.style).setProperty("width", "calc(100% - 65px)");
}
Also used : MouseEvent(elemental2.dom.MouseEvent) HTMLElement(elemental2.dom.HTMLElement) DOMRect(elemental2.dom.DOMRect) CSSStyleDeclaration(elemental2.dom.CSSStyleDeclaration) Test(org.junit.Test)

Example 10 with MouseEvent

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

the class DNDListComponentViewTest method testUpdateDraggingElementXWhenNewDraggingXPositionIsLessThanZero.

@Test
public void testUpdateDraggingElementXWhenNewDraggingXPositionIsLessThanZero() {
    final MouseEvent event = mock(MouseEvent.class);
    final HTMLElement draggingElement = mock(HTMLElement.class);
    final DOMRect rect = mock(DOMRect.class);
    event.x = -1000;
    rect.left = 25;
    draggingElement.style = mock(CSSStyleDeclaration.class);
    dragArea.offsetWidth = 300;
    when(presenter.getIndentationSize()).thenReturn(50);
    when(dragArea.getBoundingClientRect()).thenReturn(rect);
    doReturn(draggingElement).when(view).getDragging();
    view.updateDraggingElementX(event);
    verify(draggingElement.style).setProperty("width", "calc(100% - 0px)");
}
Also used : MouseEvent(elemental2.dom.MouseEvent) HTMLElement(elemental2.dom.HTMLElement) DOMRect(elemental2.dom.DOMRect) CSSStyleDeclaration(elemental2.dom.CSSStyleDeclaration) Test(org.junit.Test)

Aggregations

MouseEvent (elemental2.dom.MouseEvent)10 HTMLElement (elemental2.dom.HTMLElement)8 Test (org.junit.Test)8 CSSStyleDeclaration (elemental2.dom.CSSStyleDeclaration)5 DOMRect (elemental2.dom.DOMRect)5 Element (elemental2.dom.Element)2