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();
}
}
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);
}
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);
}
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();
}
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);
}
Aggregations