use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableToolbarNGTest method buttonChangeChecksOnToolbarUpdate.
/**
* Verifies that when the update tool bar method is called, the icons on the
* selected only button and element type buttons are changed. Also verifies
* the selected state of the selected only toggle button is changed.
*
* @param newSelectedOnlyState the new selected only state, true if it is
* on, false otherwise
* @param newElementType the new element type to be displayed in the table
* @param expectedSelectedOnlyIcon the icon expected to be on the selected
* only button once update is called
* @param expectedElementTypeIcon the icon expected to be on the element
* type button once the update it called
*/
private void buttonChangeChecksOnToolbarUpdate(final boolean newSelectedOnlyState, final GraphElementType newElementType, final Image expectedSelectedOnlyIcon, final Image expectedElementTypeIcon) throws InterruptedException {
final TableViewState state = new TableViewState();
final ArgumentCaptor<ImageView> selectedOnlyCaptor = ArgumentCaptor.forClass(ImageView.class);
final ArgumentCaptor<ImageView> elementTypeCaptor = ArgumentCaptor.forClass(ImageView.class);
final ToggleButton selectedOnlyButton = mock(ToggleButton.class);
final Button elementTypeButton = mock(Button.class);
when(tableToolbar.getSelectedOnlyButton()).thenReturn(selectedOnlyButton);
when(tableToolbar.getElementTypeButton()).thenReturn(elementTypeButton);
state.setSelectedOnly(newSelectedOnlyState);
state.setElementType(newElementType);
tableToolbar.updateToolbar(state);
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(() -> latch.countDown());
latch.await();
verify(selectedOnlyButton).setSelected(newSelectedOnlyState);
verify(selectedOnlyButton).setGraphic(selectedOnlyCaptor.capture());
assertTrue(isImageEqual(expectedSelectedOnlyIcon, selectedOnlyCaptor.getValue().getImage()));
verify(elementTypeButton).setGraphic(elementTypeCaptor.capture());
assertTrue(isImageEqual(expectedElementTypeIcon, elementTypeCaptor.getValue().getImage()));
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewPageFactoryNGTest method updateSelectionNotInSelectedOnlyMode.
@Test
public void updateSelectionNotInSelectedOnlyMode() throws InterruptedException, ExecutionException {
final TableViewState tableViewState = new TableViewState();
tableViewState.setSelectedOnly(false);
tableViewState.setElementType(GraphElementType.VERTEX);
doReturn(List.of(100, 102)).when(tableViewPageFactory).getSelectedIds(any(Graph.class), any(TableViewState.class));
final ObservableList<String> vertex1 = FXCollections.observableList(List.of("Vertex1Attr1", "Vertex1Attr2"));
final ObservableList<String> vertex2 = FXCollections.observableList(List.of("Vertex2Attr1", "Vertex2Attr2"));
final ObservableList<String> vertex3 = FXCollections.observableList(List.of("Vertex3Attr1", "Vertex3Attr2"));
final Map<Integer, ObservableList<String>> elementIdToRowIndex = Map.of(100, vertex1, 102, vertex2, 103, vertex3);
// Order is important here. Should match on vertex 1 and 2, so indicies 0 and 2.
when(tableView.getItems()).thenReturn(FXCollections.observableList(List.of(vertex1, vertex3, vertex2)));
try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(true);
tableViewPageFactory.restoreSelectionFromGraph(graph, tableViewState, elementIdToRowIndex);
}
verify(tableViewPageFactory).getSelectedIds(graph, tableViewState);
verify(selectionModel).clearSelection();
verify(selectionModel).selectIndices(0, 0, 2);
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewPageFactoryNGTest method updateSelectionInSelectedOnlyMode.
@Test
public void updateSelectionInSelectedOnlyMode() {
try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(true);
final TableViewState tableViewState = new TableViewState();
tableViewState.setSelectedOnly(true);
tableViewPageFactory.restoreSelectionFromGraph(graph, tableViewState, null);
verifyNoInteractions(table);
}
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableViewPageFactoryNGTest method callEnsureExternalCallsMade.
@Test
public void callEnsureExternalCallsMade() {
doNothing().when(tableViewPageFactory).restoreSelectionFromGraph(any(Graph.class), any(TableViewState.class), any(Map.class));
final ObservableList<String> row1 = FXCollections.observableArrayList(List.of("row1Column1", "row1Column2"));
final ObservableList<String> row2 = FXCollections.observableArrayList(List.of("row2Column1", "row2Column2"));
final ObservableList<String> row3 = FXCollections.observableArrayList(List.of("row3Column1", "row3Column2"));
final List<ObservableList<String>> newRowList = List.of(row1, row2, row3);
final Map<Integer, ObservableList<String>> elementIdToRowIndex = Map.of();
final int maxRowsPerPage = 2;
final int pageIndex = 0;
final TableColumn<ObservableList<String>, String> sortCol = mock(TableColumn.class);
final Pair<TableColumn<ObservableList<String>, ?>, TableColumn.SortType> currentSort = ImmutablePair.of(sortCol, TableColumn.SortType.DESCENDING);
doReturn(currentSort).when(tableViewPageFactory).getCurrentSort();
doNothing().when(tableViewPageFactory).restoreSort(any(Pair.class));
final TableViewState tableViewState = new TableViewState();
tableViewState.setSelectedOnly(false);
when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
when(activeTableReference.getElementIdToRowIndex()).thenReturn(elementIdToRowIndex);
selectedOnlySelectedRows.add(row1);
selectedOnlySelectedRows.add(row2);
// This is called after the page set up so just mocking it so that it is realistic
when(tableView.getItems()).thenReturn(FXCollections.observableList(List.of(row1, row2)));
tableViewPageFactory.update(newRowList, maxRowsPerPage);
assertEquals(tableView, tableViewPageFactory.call(pageIndex));
verify(tableViewPageFactory).removeListeners();
verify(tableViewPageFactory).getCurrentSort();
verify(sortedRowListComparator).unbind();
verify(tableView).setItems(FXCollections.observableList(List.of(row1, row2)));
verify(sortedRowListComparator).bind(tableViewComparator);
verify(tableViewPageFactory).restoreSort(currentSort);
verify(tableViewPageFactory).restoreSelectionFromGraph(graph, tableViewState, elementIdToRowIndex);
// This is the first call so selectedOnlySelectedRows will be cleared
// and the selection is not updated
verify(selectionModel, times(0)).selectIndices(0, 0, 1);
verify(tableViewPageFactory).restoreListeners();
}
use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.
the class TableNGTest method updateColumnsOnFxThread.
@Test(expectedExceptions = IllegalStateException.class)
public void updateColumnsOnFxThread() {
try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(true);
table.updateColumns(graph, new TableViewState());
}
}
Aggregations