-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added an option in preferences/groups to change the default the hierarchical context #9344
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.jabref.gui.groups; | ||
|
||
import java.util.Arrays; | ||
|
||
import javafx.beans.property.SimpleObjectProperty; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
import org.jabref.gui.StateManager; | ||
import org.jabref.gui.util.CurrentThreadTaskExecutor; | ||
import org.jabref.gui.util.CustomLocalDragboard; | ||
import org.jabref.gui.util.DroppingMouseLocation; | ||
import org.jabref.gui.util.TaskExecutor; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
import org.jabref.model.groups.AbstractGroup; | ||
import org.jabref.model.groups.AutomaticKeywordGroup; | ||
import org.jabref.model.groups.ExplicitGroup; | ||
import org.jabref.model.groups.GroupHierarchyType; | ||
import org.jabref.model.groups.GroupTreeNode; | ||
import org.jabref.model.groups.WordKeywordGroup; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class GroupCreateTest { | ||
|
||
private StateManager stateManager; | ||
private BibDatabaseContext databaseContext; | ||
private GroupNodeViewModel viewModel; | ||
private TaskExecutor taskExecutor; | ||
private PreferencesService preferencesService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
stateManager = mock(StateManager.class); | ||
when(stateManager.getSelectedEntries()).thenReturn(FXCollections.emptyObservableList()); | ||
databaseContext = new BibDatabaseContext(); | ||
taskExecutor = new CurrentThreadTaskExecutor(); | ||
preferencesService = mock(PreferencesService.class); | ||
when(preferencesService.getGroupsPreferences()).thenReturn(new GroupsPreferences( | ||
GroupViewMode.UNION, | ||
true, | ||
true, | ||
new SimpleObjectProperty<>(','), | ||
GroupHierarchyType.REFINING)); | ||
|
||
viewModel = getViewModelForGroup( | ||
new WordKeywordGroup("Test group", GroupHierarchyType.REFINING, StandardField.TITLE, "search", true, ',', false)); | ||
} | ||
|
||
@Test | ||
void groupContextCorrect() { | ||
String groupName = "group"; | ||
ExplicitGroup group = new ExplicitGroup(groupName, GroupHierarchyType.INDEPENDENT, ','); | ||
BibEntry entry = new BibEntry(); | ||
databaseContext.getDatabase().insertEntry(entry); | ||
GroupNodeViewModel model = new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, group, new CustomLocalDragboard(), preferencesService); | ||
model.addEntriesToGroup(databaseContext.getEntries()); | ||
// make sure group default hierarchy preference does not override new group | ||
assertEquals(model.getGroupNode().getGroup().getHierarchicalContext(),GroupHierarchyType.INDEPENDENT); | ||
} | ||
Comment on lines
+59
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't get what you want to test here? |
||
|
||
|
||
private GroupNodeViewModel getViewModelForGroup(AbstractGroup group) { | ||
return new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, group, new CustomLocalDragboard(), preferencesService); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be implemented as an constructor argument for the enum e.g.
INDEPENDENT("Independent")
and be localized. Open/closed design principle.