Search in sources :

Example 26 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TableNGTest method updateSelectionGraphNull.

@Test
public void updateSelectionGraphNull() {
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        table.updateSelection(null, new TableViewState());
        platformMockedStatic.verifyNoInteractions();
    }
}
Also used : Platform(javafx.application.Platform) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Test(org.testng.annotations.Test)

Example 27 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TableNGTest method updateSelectionNotInSelectedOnlyModeAndNothingSelected.

@Test
public void updateSelectionNotInSelectedOnlyModeAndNothingSelected() throws InterruptedException {
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setSelectedOnly(false);
    tableViewState.setElementType(GraphElementType.VERTEX);
    final ChangeListener<ObservableList<String>> tableSelectionListener = mock(ChangeListener.class);
    final ListChangeListener selectedOnlySelectionListener = mock(ListChangeListener.class);
    doReturn(tableSelectionListener).when(table).getTableSelectionListener();
    doReturn(selectedOnlySelectionListener).when(table).getSelectedOnlySelectionListener();
    final TableView<ObservableList<String>> tableView = mock(TableView.class);
    when(table.getTableView()).thenReturn(tableView);
    final TableViewSelectionModel<ObservableList<String>> selectionModel = mock(TableViewSelectionModel.class);
    when(tableView.getSelectionModel()).thenReturn(selectionModel);
    final ObservableList<ObservableList<String>> selectedItems = mock(ObservableList.class);
    when(selectionModel.getSelectedItems()).thenReturn(selectedItems);
    final ReadOnlyObjectProperty<ObservableList<String>> selectedProperty = mock(ReadOnlyObjectProperty.class);
    when(table.getSelectedProperty()).thenReturn(selectedProperty);
    try (MockedStatic<TableViewUtilities> tableUtilsMockedStatic = Mockito.mockStatic(TableViewUtilities.class)) {
        tableUtilsMockedStatic.when(() -> TableViewUtilities.getSelectedIds(graph, tableViewState)).thenReturn(List.of());
        table.updateSelection(graph, tableViewState);
    }
    final CountDownLatch latch = new CountDownLatch(1);
    Platform.runLater(() -> latch.countDown());
    latch.await();
    verify(selectedProperty).removeListener(tableSelectionListener);
    verify(selectedItems).removeListener(selectedOnlySelectionListener);
    verify(selectionModel).clearSelection();
    verify(selectionModel, times(0)).selectIndices(anyInt(), any(int[].class));
    verify(selectedProperty).addListener(tableSelectionListener);
    verify(selectedItems).addListener(selectedOnlySelectionListener);
}
Also used : ObservableList(javafx.collections.ObservableList) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) TableViewUtilities(au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities) CountDownLatch(java.util.concurrent.CountDownLatch) ListChangeListener(javafx.collections.ListChangeListener) Test(org.testng.annotations.Test)

Example 28 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class UpdateColumnsTaskNGTest method run.

@Test
public void run() {
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setColumnAttributes(List.of(Tuple.create(columnType1, attribute1), Tuple.create(columnType4, attribute4), Tuple.create(columnType5, attribute5)));
    final Map<String, TableColumn<ObservableList<String>, String>> columnReferenceMap = new HashMap<>();
    columnReferenceMap.put("column header 1", column1);
    columnReferenceMap.put("column header 2", column3);
    updateColumnsTask.reset(columnReferenceMap, tableViewState);
    final List<TableColumn<ObservableList<String>, ?>> columnList = new ArrayList<>();
    columnList.add(mock(TableColumn.class));
    columnList.add(mock(TableColumn.class));
    final ObservableList<TableColumn<ObservableList<String>, ?>> columns = spy(FXCollections.observableList(columnList));
    when(tableView.getColumns()).thenReturn(columns);
    updateColumnsTask.run();
    // Verify that the listeners were removed
    verify(selectedItemProperty).removeListener(tableSelectionListener);
    verify(selectedItems).removeListener(selectedOnlySelectionListener);
    // Verify that only the columns in columnReferenceMap have their
    // graphic set to null
    verify(column1).setGraphic(isNull());
    verify(column2, times(0)).setGraphic(isNull());
    verify(column3).setGraphic(isNull());
    verify(column4, times(0)).setGraphic(isNull());
    verify(column5, times(0)).setGraphic(isNull());
    // Visibility set based on what columns are present in table view state
    verify(column1).setVisible(true);
    verify(column2).setVisible(false);
    verify(column3).setVisible(false);
    verify(column4).setVisible(true);
    verify(column5).setVisible(true);
    // Verify that the existing columns are cleared and replaced with what is in
    // the columnIndex
    assertEquals(List.of(column1, column2, column3, column4, column5), columns);
    final ArgumentCaptor<ListChangeListener<TableColumn<ObservableList<String>, ?>>> captor = ArgumentCaptor.forClass(ListChangeListener.class);
    verify(columns).addListener(captor.capture());
    assertNotNull(captor.getValue());
    verifyColumnChangeListenerAction(captor.getValue());
    verifyColumnChangeListenerAvoidsDuplicateActions(captor.getValue());
    // Verify that the listeners are added
    verify(selectedItemProperty).addListener(tableSelectionListener);
    verify(selectedItems).addListener(selectedOnlySelectionListener);
}
Also used : HashMap(java.util.HashMap) ObservableList(javafx.collections.ObservableList) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TableColumn(javafx.scene.control.TableColumn) ListChangeListener(javafx.collections.ListChangeListener) Test(org.testng.annotations.Test)

Example 29 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class UpdateColumnsTaskNGTest method verifyColumnChangeListenerAction.

/**
 * Sets up mocks so that the change will be iterated 3 times. For only one
 * iteration (the final one) will the code be able to pass the conditional
 * that allows an update to occur.
 *
 * @param listener the listener to be tested
 */
private void verifyColumnChangeListenerAction(final ListChangeListener<TableColumn<ObservableList<String>, ?>> listener) {
    final ListChangeListener.Change<TableColumn<ObservableList<String>, String>> change = mock(ListChangeListener.Change.class);
    // It will iterate 3 times. But only get past the if statement once
    when(change.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
    when(change.wasReplaced()).thenReturn(true).thenReturn(false).thenReturn(true);
    when(change.getRemovedSize()).thenReturn(10).thenReturn(5).thenReturn(5);
    when(change.getAddedSize()).thenReturn(5).thenReturn(5).thenReturn(5);
    doNothing().when(updateColumnsTask).saveSortDetails();
    when(change.getAddedSubList()).thenReturn(List.of(column2, column3, column5));
    final Graph graph = mock(Graph.class);
    when(tableViewTopComponent.getCurrentGraph()).thenReturn(graph);
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setColumnAttributes(List.of(Tuple.create(columnType2, attribute2), Tuple.create(columnType4, attribute4), Tuple.create(columnType5, attribute5)));
    when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
    listener.onChanged(change);
    // This should only be called ONCE due to the conditionals on the other
    // two loops
    verify(activeTableReference).updateVisibleColumns(graph, tableViewState, List.of(Tuple.create(columnType2, attribute2), Tuple.create(columnType5, attribute5)), UpdateMethod.REPLACE);
    verify(updateColumnsTask).saveSortDetails();
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) TableColumn(javafx.scene.control.TableColumn) ListChangeListener(javafx.collections.ListChangeListener)

Example 30 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class UpdateTableDataTaskNGTest method updateDataTask.

@Test
public void updateDataTask() {
    final TablePane tablePane = mock(TablePane.class);
    final Graph graph = mock(Graph.class);
    final TableViewState tableViewState = new TableViewState();
    final Table table = mock(Table.class);
    final ProgressBar progressBar = mock(ProgressBar.class);
    when(tablePane.getTable()).thenReturn(table);
    when(tablePane.getProgressBar()).thenReturn(progressBar);
    final TriggerDataUpdateTask updateTableDataTask = new TriggerDataUpdateTask(tablePane, graph, tableViewState);
    updateTableDataTask.run();
    verify(table).updateData(graph, tableViewState, progressBar);
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) Table(au.gov.asd.tac.constellation.views.tableview.components.Table) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ProgressBar(au.gov.asd.tac.constellation.views.tableview.components.ProgressBar) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) Test(org.testng.annotations.Test)

Aggregations

TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)65 Test (org.testng.annotations.Test)50 Graph (au.gov.asd.tac.constellation.graph.Graph)24 Platform (javafx.application.Platform)19 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)14 ObservableList (javafx.collections.ObservableList)14 Attribute (au.gov.asd.tac.constellation.graph.Attribute)13 UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)12 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)10 TableColumn (javafx.scene.control.TableColumn)10 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)7 ListChangeListener (javafx.collections.ListChangeListener)7 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)6 TableViewUtilities (au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities)6 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)5 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)5 Table (au.gov.asd.tac.constellation.views.tableview.components.Table)5 ArrayList (java.util.ArrayList)5