Skip to content

Commit

Permalink
Update test methods in GlobalSearchBarTest class
Browse files Browse the repository at this point in the history
  • Loading branch information
dkokkotas committed May 3, 2023
1 parent 2cd605b commit 664b015
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/test/java/org/jabref/gui/search/GlobalSearchBarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TextInputControl;
import javafx.scene.layout.HBox;
Expand All @@ -29,6 +28,7 @@
import org.testfx.framework.junit5.Start;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -51,10 +51,10 @@ public void onStart(Stage stage) {
when(prefs.getSearchPreferences()).thenReturn(searchPreferences);

stateManager = new StateManager();
// need for active database, otherwise the searchField will be disabled
// Need for active database, otherwise the searchField will be disabled
stateManager.setActiveDatabase(new BibDatabaseContext());

// instantiate GlobalSearchBar class, so the change listener is registered
// Instantiate GlobalSearchBar class, so the change listener is registered
searchBar = new GlobalSearchBar(
mock(JabRefFrame.class),
stateManager,
Expand All @@ -76,10 +76,10 @@ public void onStart(Stage stage) {
void recordingSearchQueriesOnFocusLostOnly(FxRobot robot) throws InterruptedException {
stateManager.clearSearchHistory();
String searchQuery = "Smith";
// track the node, that the search query will be typed into
// Track the node, that the search query will be typed into
TextInputControl searchField = robot.lookup("#searchField").queryTextInputControl();

// the focus is on searchField node, as we click on the search box
// The focus is on searchField node, as we click on the search box
var searchFieldRoboto = robot.clickOn(searchField);
for (char c : searchQuery.toCharArray()) {
searchFieldRoboto.write(String.valueOf(c));
Expand All @@ -88,11 +88,11 @@ void recordingSearchQueriesOnFocusLostOnly(FxRobot robot) throws InterruptedExce
}

// Set the focus to another node to trigger the listener and finally record the query.
DefaultTaskExecutor.runInJavaFXThread(() -> hBox.requestFocus());
ObservableList<String> lastSearchHistory = stateManager.getWholeSearchHistory();
ObservableList<String> expected = FXCollections.observableArrayList("Smith");
DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> hBox.requestFocus());
List<String> lastSearchHistory = stateManager.getWholeSearchHistory().stream().toList();

assertEquals(FXCollections.observableList(expected), FXCollections.observableList(lastSearchHistory));
assertFalse(lastSearchHistory.isEmpty());
assertEquals(FXCollections.observableArrayList("Smith"), lastSearchHistory);
}

@Test
Expand All @@ -104,9 +104,9 @@ void emptyQueryIsNotRecorded(FxRobot robot) {
var searchFieldRoboto = robot.clickOn(searchField);
searchFieldRoboto.write(searchQuery);

DefaultTaskExecutor.runInJavaFXThread(() -> hBox.requestFocus());
List<String> lastSearchHistory = stateManager.getWholeSearchHistory();
DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> hBox.requestFocus());
List<String> lastSearchHistory = stateManager.getWholeSearchHistory().stream().toList();

assertEquals(FXCollections.emptyObservableList(), lastSearchHistory);
assertTrue(lastSearchHistory.isEmpty());
}
}

0 comments on commit 664b015

Please sign in to comment.