Search in sources :

Example 6 with TableViewUtilities

use of au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities in project constellation by constellation-app.

the class RightClickContextMenuNGTest method verifyCopyAction.

/**
 * Verify that the passed event handler copies the correct table cells in
 * CSV form to the OS clipboard.
 *
 * @param eventHandler the handler to test
 * @param expectedClipboardText the expected CSV copied to the clipboard
 */
private void verifyCopyAction(final EventHandler<ActionEvent> eventHandler, final String expectedClipboardText) {
    try (MockedStatic<TableViewUtilities> tableViewUtilsMockedStatic = Mockito.mockStatic(TableViewUtilities.class)) {
        final ActionEvent actionEvent = mock(ActionEvent.class);
        eventHandler.handle(actionEvent);
        tableViewUtilsMockedStatic.verify(() -> TableViewUtilities.copyToClipboard(expectedClipboardText));
        verify(actionEvent).consume();
    }
}
Also used : ActionEvent(javafx.event.ActionEvent) TableViewUtilities(au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities)

Example 7 with TableViewUtilities

use of au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities in project constellation by constellation-app.

the class TableSelectionListenerNGTest method changedCurrentStateSelectedOnlyModeFalse.

@Test
public void changedCurrentStateSelectedOnlyModeFalse() {
    try (MockedStatic<TableViewUtilities> tableViewUtilitiesMockedStatic = Mockito.mockStatic(TableViewUtilities.class)) {
        final TableViewState currentState = new TableViewState();
        currentState.setSelectedOnly(false);
        currentState.setElementType(GraphElementType.META);
        final Graph graph = mock(Graph.class);
        when(tableViewTopComponent.getCurrentState()).thenReturn(currentState);
        when(tableViewTopComponent.getCurrentGraph()).thenReturn(graph);
        tableSelectionListener.changed(null, null, null);
        tableViewUtilitiesMockedStatic.verify(() -> TableViewUtilities.copySelectionToGraph(same(tableView), same(rowToElementIdIndex), eq(GraphElementType.META), same(graph)));
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) TableViewUtilities(au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities) Test(org.testng.annotations.Test)

Example 8 with TableViewUtilities

use of au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities in project constellation by constellation-app.

the class TableSelectionListenerNGTest method changedCurrentStateSelectedOnlyModeTrue.

@Test
public void changedCurrentStateSelectedOnlyModeTrue() {
    try (MockedStatic<TableViewUtilities> tableViewUtilitiesMockedStatic = Mockito.mockStatic(TableViewUtilities.class)) {
        final TableViewState currentState = new TableViewState();
        currentState.setSelectedOnly(true);
        when(tableViewTopComponent.getCurrentState()).thenReturn(currentState);
        tableSelectionListener.changed(null, null, null);
        tableViewUtilitiesMockedStatic.verifyNoInteractions();
    }
}
Also used : TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) TableViewUtilities(au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities) Test(org.testng.annotations.Test)

Example 9 with TableViewUtilities

use of au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities in project constellation by constellation-app.

the class CopyMenuNGTest method verifyCopyAction.

/**
 * Verify that the passed event handler copies to the clipboard either the
 * whole table or just the selected rows.
 *
 * @param eventHandler the handler to test
 * @param expectedCopyOnlySelectedRows true if only the selected rows are
 * expected to be copied, false otherwise
 */
private void verifyCopyAction(final EventHandler<ActionEvent> eventHandler, final boolean expectedCopyOnlySelectedRows) {
    try (MockedStatic<TableViewUtilities> tableViewUtilsMockedStatic = Mockito.mockStatic(TableViewUtilities.class)) {
        final ActionEvent actionEvent = mock(ActionEvent.class);
        final TableView<ObservableList<String>> tableView = mock(TableView.class);
        when(table.getTableView()).thenReturn(tableView);
        final String tableData = "Row1Column1,Row1Column2\nRow2Column2,Row2Column2";
        tableViewUtilsMockedStatic.when(() -> TableViewUtilities.getTableData(tableView, pagination, false, expectedCopyOnlySelectedRows)).thenReturn(tableData);
        eventHandler.handle(actionEvent);
        tableViewUtilsMockedStatic.verify(() -> TableViewUtilities.copyToClipboard(tableData));
        verify(actionEvent).consume();
    }
}
Also used : ObservableList(javafx.collections.ObservableList) ActionEvent(javafx.event.ActionEvent) TableViewUtilities(au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities)

Aggregations

TableViewUtilities (au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities)9 Test (org.testng.annotations.Test)7 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)5 ObservableList (javafx.collections.ObservableList)4 ActionEvent (javafx.event.ActionEvent)3 Graph (au.gov.asd.tac.constellation.graph.Graph)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ListChangeListener (javafx.collections.ListChangeListener)2 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Platform (javafx.application.Platform)1 Pagination (javafx.scene.control.Pagination)1 ImageView (javafx.scene.image.ImageView)1