Search in sources :

Example 6 with UserTablePreferences

use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.

the class PreferenceMenuNGTest method verifyLoadPreferencesAction.

/**
 * Verifies that when the load preferences button is clicked, the load
 * preferences method is called and the tables pagination is updated with
 * any necessary changes. If the current active graph is null, then no
 * preferences will be loaded.
 *
 * @param loadPreferencesMenu the load userTablePreferences menu
 * @param isActiveGraphNull true if the active graph is null, false
 * otherwise
 * @throws InterruptedException if there is a an issue waiting for the
 * JavaFX thread work to complete
 */
private void verifyLoadPreferencesAction(final MenuItem loadPreferencesMenu, final boolean isActiveGraphNull) throws InterruptedException {
    clearInvocations(preferencesMenu, activeTableReference, tablePane);
    try (final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class)) {
        final GraphManager graphManager = mock(GraphManager.class);
        graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        final ActionEvent actionEvent = mock(ActionEvent.class);
        if (isActiveGraphNull) {
            when(graphManager.getActiveGraph()).thenReturn(null);
            loadPreferencesMenu.getOnAction().handle(actionEvent);
            verify(preferencesMenu, times(0)).loadPreferences();
        } else {
            final UserTablePreferences userTablePreferences = new UserTablePreferences();
            userTablePreferences.setMaxRowsPerPage(42);
            final Graph graph = mock(Graph.class);
            final Pagination pagination = mock(Pagination.class);
            when(graphManager.getActiveGraph()).thenReturn(graph);
            when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
            when(activeTableReference.getPagination()).thenReturn(pagination);
            doNothing().when(preferencesMenu).loadPreferences();
            loadPreferencesMenu.getOnAction().handle(actionEvent);
            final CountDownLatch latch = new CountDownLatch(1);
            Platform.runLater(() -> latch.countDown());
            latch.await();
            verify(activeTableReference).updatePagination(42, tablePane);
            verify(preferencesMenu).loadPreferences();
        }
        verify(actionEvent).consume();
    }
}
Also used : Pagination(javafx.scene.control.Pagination) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Graph(au.gov.asd.tac.constellation.graph.Graph) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ActionEvent(javafx.event.ActionEvent) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 7 with UserTablePreferences

use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.

the class TableNGTest method updateSortOrderPrefSortEmpty.

@Test
public void updateSortOrderPrefSortEmpty() {
    final UserTablePreferences userTablePreferences = new UserTablePreferences();
    userTablePreferences.setSortByColumn(ImmutablePair.of("", TableColumn.SortType.DESCENDING));
    when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
    final TableView<ObservableList<String>> tableView = mock(TableView.class);
    when(table.getTableView()).thenReturn(tableView);
    table.updateSortOrder();
    verifyNoInteractions(tableView);
}
Also used : UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ObservableList(javafx.collections.ObservableList) Test(org.testng.annotations.Test)

Example 8 with UserTablePreferences

use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.

the class TableNGTest method updateSortOrder.

@Test
public void updateSortOrder() {
    final UserTablePreferences userTablePreferences = new UserTablePreferences();
    userTablePreferences.setSortByColumn(ImmutablePair.of("COLUMN_B", TableColumn.SortType.DESCENDING));
    when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
    final TableView<ObservableList<String>> tableView = mock(TableView.class);
    when(table.getTableView()).thenReturn(tableView);
    final TableColumn<ObservableList<String>, String> column1 = mock(TableColumn.class);
    when(column1.getText()).thenReturn("COLUMN_A");
    final TableColumn<ObservableList<String>, String> column2 = mock(TableColumn.class);
    when(column2.getText()).thenReturn("COLUMN_B");
    when(tableView.getColumns()).thenReturn(FXCollections.observableList(List.of(column1, column2)));
    final ObservableList<TableColumn<ObservableList<String>, ?>> sortOrder = FXCollections.observableArrayList();
    when(tableView.getSortOrder()).thenReturn(sortOrder);
    table.updateSortOrder();
    verify(column2).setSortType(TableColumn.SortType.DESCENDING);
    assertEquals(FXCollections.observableArrayList(column2), sortOrder);
}
Also used : UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ObservableList(javafx.collections.ObservableList) TableColumn(javafx.scene.control.TableColumn) Test(org.testng.annotations.Test)

Example 9 with UserTablePreferences

use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.

the class TableNGTest method updateSortOrderPrefSortNull.

@Test
public void updateSortOrderPrefSortNull() {
    final UserTablePreferences userTablePreferences = new UserTablePreferences();
    userTablePreferences.setSortByColumn(null);
    when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
    final TableView<ObservableList<String>> tableView = mock(TableView.class);
    when(table.getTableView()).thenReturn(tableView);
    table.updateSortOrder();
    verifyNoInteractions(tableView);
}
Also used : UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ObservableList(javafx.collections.ObservableList) Test(org.testng.annotations.Test)

Example 10 with UserTablePreferences

use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.

the class TableViewPreferencesIoProviderNGTest method getPreferencesNullPrefs.

@Test
public void getPreferencesNullPrefs() throws IOException {
    jsonIOStaticMock.when(() -> JsonIO.loadJsonPreferences(eq(Optional.of("TableViewPreferences")), eq(Optional.of("vertex-")), any(TypeReference.class))).thenReturn(null);
    final UserTablePreferences tablepreferences = TableViewPreferencesIoProvider.getPreferences(GraphElementType.VERTEX);
    final UserTablePreferences expected = new UserTablePreferences();
    expected.setColumnOrder(Collections.emptyList());
    expected.setSortByColumn(ImmutablePair.of("", TableColumn.SortType.ASCENDING));
    expected.setMaxRowsPerPage(500);
    assertEquals(expected, tablepreferences);
}
Also used : UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.testng.annotations.Test)

Aggregations

UserTablePreferences (au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences)21 ObservableList (javafx.collections.ObservableList)15 Test (org.testng.annotations.Test)14 List (java.util.List)9 Pagination (javafx.scene.control.Pagination)6 Graph (au.gov.asd.tac.constellation.graph.Graph)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 ActionEvent (javafx.event.ActionEvent)5 TableViewPreferencesIoProvider (au.gov.asd.tac.constellation.views.tableview.io.TableViewPreferencesIoProvider)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 FileInputStream (java.io.FileInputStream)4 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)3 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 TableColumn (javafx.scene.control.TableColumn)3 Attribute (au.gov.asd.tac.constellation.graph.Attribute)2 ActiveTableReference (au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference)2 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)2 UpdateMethod (au.gov.asd.tac.constellation.views.tableview.api.UpdateMethod)2 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)2