Skip to content

Commit 4796a03

Browse files
FlyJoannelydia-yanyoasaaabrandon-lau0
authored
test: ensure search history is shared and ordered correctly across database contexts (#13119)
* test: add unit tests for StateManager's search history behavior * test: add unit test for search history across databases Co-authored-by: Lydia Yan <[email protected]> Co-authored-by: Yo Asaaa <[email protected]> Co-authored-by: Brandon Lau <[email protected]> --------- Co-authored-by: Lydia Yan <[email protected]> Co-authored-by: Yo Asaaa <[email protected]> Co-authored-by: Brandon Lau <[email protected]>
1 parent 5069894 commit 4796a03

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

jabgui/src/test/java/org/jabref/gui/search/GetLastSearchHistoryTest.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javafx.stage.Stage;
66

77
import org.jabref.gui.StateManager;
8+
import org.jabref.model.database.BibDatabaseContext;
89

910
import org.junit.jupiter.api.Test;
1011
import org.junit.jupiter.api.extension.ExtendWith;
@@ -15,6 +16,10 @@
1516

1617
@ExtendWith(ApplicationExtension.class)
1718
class GetLastSearchHistoryTest {
19+
private final StateManager stateManager = new StateManager();
20+
private final BibDatabaseContext dbContext1 = new BibDatabaseContext();
21+
private final BibDatabaseContext dbContext2 = new BibDatabaseContext();
22+
1823
@Start
1924
void onStart(Stage stage) {
2025
// Needed to init JavaFX thread
@@ -23,7 +28,7 @@ void onStart(Stage stage) {
2328

2429
@Test
2530
void getLastSearchHistory() {
26-
StateManager stateManager = new StateManager();
31+
stateManager.clearSearchHistory();
2732
stateManager.addSearchHistory("test1");
2833
stateManager.addSearchHistory("test2");
2934
stateManager.addSearchHistory("test3");
@@ -35,7 +40,7 @@ void getLastSearchHistory() {
3540

3641
@Test
3742
void duplicateSearchHistory() {
38-
StateManager stateManager = new StateManager();
43+
stateManager.clearSearchHistory();
3944
stateManager.addSearchHistory("test1");
4045
stateManager.addSearchHistory("test2");
4146
stateManager.addSearchHistory("test3");
@@ -48,7 +53,7 @@ void duplicateSearchHistory() {
4853

4954
@Test
5055
void clearSearchHistory() {
51-
StateManager stateManager = new StateManager();
56+
stateManager.clearSearchHistory();
5257
stateManager.addSearchHistory("test1");
5358
stateManager.addSearchHistory("test2");
5459
stateManager.addSearchHistory("test3");
@@ -60,4 +65,20 @@ void clearSearchHistory() {
6065
expected = List.of();
6166
assertEquals(expected, lastSearchHistory);
6267
}
68+
69+
@Test
70+
void searchHistory_isSharedAcrossMultipleDatabasesAndMaintainsCorrectOrder() {
71+
stateManager.clearSearchHistory();
72+
stateManager.setActiveDatabase(dbContext1);
73+
stateManager.addSearchHistory("queryA");
74+
75+
stateManager.setActiveDatabase(dbContext2);
76+
stateManager.addSearchHistory("queryB");
77+
78+
stateManager.setActiveDatabase(dbContext1);
79+
stateManager.addSearchHistory("queryC");
80+
81+
List<String> expected = List.of("queryA", "queryB", "queryC");
82+
assertEquals(expected, stateManager.getWholeSearchHistory());
83+
}
6384
}

0 commit comments

Comments
 (0)