-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix order of string in editor (#10083)
* Fix order of string in editor The string defined in a BibTeX file were shown in random order in the respective GUI editor. While the code already sorts them, by storing the items into a set, it destroys the order again. Fix this behaviour by storing them as a list, which retains the order. * Apply suggestions from code review * Resort the strings table for new entry Adding a new entry should also preserve the sorting of the strings table, thus we need to resort the entries and take care that the focus in the table is still on the newly-created entry. * Add a test for the resorting * Cleanup code * Further cleanup for better reuse
- Loading branch information
1 parent
c8ce82c
commit bd03fbe
Showing
4 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...est/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.jabref.gui.libraryproperties.constants; | ||
|
||
import java.util.List; | ||
|
||
import javafx.beans.property.StringProperty; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.BibtexString; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class ConstantsPropertiesViewModelTest { | ||
|
||
@DisplayName("Check that the list of strings is sorted according to their keys") | ||
@Test | ||
void testStringsListPropertySorting() { | ||
BibtexString string1 = new BibtexString("TSE", "Transactions on Software Engineering"); | ||
BibtexString string2 = new BibtexString("ICSE", "International Conference on Software Engineering"); | ||
BibDatabase db = new BibDatabase(); | ||
db.setStrings(List.of(string1, string2)); | ||
BibDatabaseContext context = new BibDatabaseContext(db); | ||
DialogService service = mock(DialogService.class); | ||
List<String> expected = List.of(string2.getName(), string1.getName()); // ICSE before TSE | ||
|
||
ConstantsPropertiesViewModel model = new ConstantsPropertiesViewModel(context, service); | ||
model.setValues(); | ||
|
||
List<String> actual = model.stringsListProperty().stream() | ||
.map(ConstantsItemModel::labelProperty) | ||
.map(StringProperty::getValue) | ||
.toList(); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
@DisplayName("Check that the list of strings is sorted after resorting it") | ||
@Test | ||
void testStringsListPropertyResorting() { | ||
BibDatabase db = new BibDatabase(); | ||
BibDatabaseContext context = new BibDatabaseContext(db); | ||
DialogService service = mock(DialogService.class); | ||
List<String> expected = List.of("ICSE", "TSE"); | ||
|
||
ConstantsPropertiesViewModel model = new ConstantsPropertiesViewModel(context, service); | ||
var stringsList = model.stringsListProperty(); | ||
stringsList.add(new ConstantsItemModel("TSE", "Transactions on Software Engineering")); | ||
stringsList.add(new ConstantsItemModel("ICSE", "International Conference on Software Engineering")); | ||
|
||
model.resortStrings(); | ||
|
||
List<String> actual = model.stringsListProperty().stream() | ||
.map(ConstantsItemModel::labelProperty) | ||
.map(StringProperty::getValue) | ||
.toList(); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
} |