ScenarioContextMenuRegistry { public boolean manageRightClick(final ScenarioGrid scenarioGrid, final ContextMenuEvent event) { final int canvasX = CoordinateUtilities.getRelativeXOfEvent(event); final int canvasY = CoordinateUtilities.getRelativeYOfEvent(event); final Point2D gridClickPoint = CoordinateUtilities.convertDOMToGridCoordinate(scenarioGrid, new Point2D(canvasX, canvasY)); boolean isHeader = true; Integer uiRowIndex = CoordinateUtilities.getUiHeaderRowIndex(scenarioGrid, gridClickPoint); if (uiRowIndex == null) { uiRowIndex = CoordinateUtilities.getUiRowIndex(scenarioGrid, gridClickPoint.getY()); isHeader = false; } if (uiRowIndex == null) { return false; } final Integer uiColumnIndex = CoordinateUtilities.getUiColumnIndex(scenarioGrid, gridClickPoint.getX()); if (uiColumnIndex == null) { return false; } return manageRightClick(scenarioGrid, event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY(), uiRowIndex, uiColumnIndex, isHeader); } @Inject  ScenarioContextMenuRegistry(final OtherContextMenu otherContextMenu,
                                       final HeaderGivenContextMenu headerGivenContextMenu,
                                       final HeaderExpectedContextMenu headerExpectedContextMenu,
                                       final GivenContextMenu givenContextMenu,
                                       final ExpectedContextMenu expectedContextMenu,
                                       final GridContextMenu gridContextMenu); void setEventBus(final EventBus eventBus); void hideMenus(); boolean manageRightClick(final ScenarioGrid scenarioGrid,
                                    final ContextMenuEvent event); boolean manageRightClick(final ScenarioGrid scenarioGrid,
                                    final int clientXPosition,
                                    final int clientYPosition,
                                    final Integer uiRowIndex,
                                    final Integer uiColumnIndex,
                                    final boolean isHeader); void setErrorReportPopoverPresenter(ErrorReportPopoverPresenter errorReportPopoverPresenter); void hideErrorReportPopover();  }
@Test public void testManageHeaderRightClick_ClickOutsideHeader() { final int clickPointX = 5; final int clickPointY = 11; doReturn(clickPointX).when(contextNativeEventMock).getClientX(); doReturn(clickPointY).when(contextNativeEventMock).getClientY(); assertThat(scenarioContextMenuRegistry.manageRightClick(scenarioGridMock, contextMenuEventMock)) .as("Click point y more then header max y") .isFalse(); verifyZeroInteractions(expectedContextMenuMock); verifyZeroInteractions(headerExpectedContextMenuMock); }
@Test public void testManageHeaderRightClick_NoColumnGroup() { final int clickPointX = 5; final int clickPointY = 6; doReturn(clickPointX).when(contextNativeEventMock).getClientX(); doReturn(clickPointY).when(contextNativeEventMock).getClientY(); doReturn("").when(informationHeaderMetaDataMock).getColumnGroup(); doReturn("EXPECT").when(informationHeaderMetaDataMock).getTitle(); assertThat(scenarioContextMenuRegistry.manageRightClick(scenarioGridMock, contextMenuEventMock)) .as("Context menu according to column title") .isTrue(); verify(headerExpectedContextMenuMock).show(eq(GridWidget.SIMULATION), eq(clickPointX), eq(clickPointY)); verifyZeroInteractions(expectedContextMenuMock); }
@Test public void testManageBodyRightClick() { final int clickPointX = 5; final int clickPointY = 11; final double widgetHeight = 50.0; final double rowHeight = widgetHeight - HEADER_HEIGHT; doReturn(clickPointX).when(contextNativeEventMock).getClientX(); doReturn(clickPointY).when(contextNativeEventMock).getClientY(); doReturn(widgetHeight).when(scenarioGridMock).getHeight(); doReturn(1).when(scenarioGridModelMock).getRowCount(); final GridRow gridRowMock = mock(GridRow.class); doReturn(gridRowMock).when(scenarioGridModelMock).getRow(0); doReturn(rowHeight).when(gridRowMock).getHeight(); assertThat(scenarioContextMenuRegistry.manageRightClick(scenarioGridMock, contextMenuEventMock)) .as("Click to expect/given body cell") .isTrue(); verify(scenarioGridMock, times(1)).clearSelections(); verify(gridContextMenuMock).show(GridWidget.SIMULATION, clickPointX, clickPointY, 0); verify(scenarioGridMock, times(1)).setSelectedCell(eq(0), eq(0)); }