Skip to content

Commit

Permalink
Fix GUI tests (#5781)
Browse files Browse the repository at this point in the history
* Fix GUI tests (and remove BasePanelTest)

* Add architecture test exception

* Fix visibility of class SourceTabTest

* Revert "Add architecture test exception"

This reverts commit 4a154a8.

* Have keyBindingRepository as parameter for SourceTab

* Localize hint on rule

* Fix import of Globals
  • Loading branch information
koppor authored and tobiasdiez committed Jan 8, 2020
1 parent 88b02e2 commit db13dc0
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 90 deletions.
18 changes: 15 additions & 3 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,47 @@

public class Globals {

// JabRef version info
/**
* JabRef version info
*/
public static final BuildInfo BUILD_INFO = new BuildInfo();

// Remote listener
public static final RemoteListenerServerLifecycle REMOTE_LISTENER = new RemoteListenerServerLifecycle();

public static final ImportFormatReader IMPORT_FORMAT_READER = new ImportFormatReader();
public static final TaskExecutor TASK_EXECUTOR = new DefaultTaskExecutor();
// In the main program, this field is initialized in JabRefMain.java
// Each test case initializes this field if required

/**
* Each test case initializes this field if required
*/
public static JabRefPreferences prefs;

/**
* This field is initialized upon startup.
* Only GUI code is allowed to access it, logic code should use dependency injection.
*/
public static JournalAbbreviationLoader journalAbbreviationLoader;

/**
* This field is initialized upon startup.
* Only GUI code is allowed to access it, logic code should use dependency injection.
*/
public static ProtectedTermsLoader protectedTermsLoader;

/**
* Manager for the state of the GUI.
*/
public static StateManager stateManager = new StateManager();

public static ExporterFactory exportFactory;
public static CountingUndoManager undoManager = new CountingUndoManager();
public static BibEntryTypesManager entryTypesManager = new BibEntryTypesManager();
public static ClipBoardManager clipboardManager = new ClipBoardManager();

// Key binding preferences
private static KeyBindingRepository keyBindingRepository;

private static DefaultFileUpdateMonitor fileUpdateMonitor;
private static ThemeLoader themeLoader;
private static TelemetryClient telemetryClient;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private List<EntryEditorTab> createTabs() {
// Source tab
sourceTab = new SourceTab(databaseContext, undoManager,
entryEditorPreferences.getLatexFieldFormatterPreferences(),
entryEditorPreferences.getImportFormatPreferences(), fileMonitor, dialogService, stateManager);
entryEditorPreferences.getImportFormatPreferences(), fileMonitor, dialogService, stateManager, Globals.getKeyPrefs());
entryEditorTabs.add(sourceTab);

// LaTeX citations tab
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableChangeType;
Expand Down Expand Up @@ -70,6 +71,7 @@ public class SourceTab extends EntryEditorTab {
private final StateManager stateManager;
private Optional<Pattern> searchHighlightPattern = Optional.empty();
private CodeArea codeArea;
private KeyBindingRepository keyBindingRepository;

private class EditAction extends SimpleCommand {

Expand Down Expand Up @@ -99,7 +101,7 @@ public void execute() {
}
}

public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, LatexFieldFormatterPreferences fieldFormatterPreferences, ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor, DialogService dialogService, StateManager stateManager) {
public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, LatexFieldFormatterPreferences fieldFormatterPreferences, ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor, DialogService dialogService, StateManager stateManager, KeyBindingRepository keyBindingRepository) {
this.mode = bibDatabaseContext.getMode();
this.setText(Localization.lang("%0 source", mode.getFormattedName()));
this.setTooltip(new Tooltip(Localization.lang("Show/edit %0 source", mode.getFormattedName())));
Expand All @@ -110,6 +112,7 @@ public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undo
this.fileMonitor = fileMonitor;
this.dialogService = dialogService;
this.stateManager = stateManager;
this.keyBindingRepository = keyBindingRepository;

stateManager.activeSearchQueryProperty().addListener((observable, oldValue, newValue) -> {
searchHighlightPattern = newValue.flatMap(SearchQuery::getPatternForWords);
Expand Down Expand Up @@ -176,7 +179,7 @@ private CodeArea createSourceEditor() {
});
codeArea.setId("bibtexSourceCodeArea");

ActionFactory factory = new ActionFactory(Globals.getKeyPrefs());
ActionFactory factory = new ActionFactory(keyBindingRepository);
ContextMenu contextMenu = new ContextMenu();
contextMenu.getItems().addAll(
factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT)),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/help/VersionWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class VersionWorker {
* The version which was previously ignored by the user
*/
private final Version toBeIgnored;

private final DialogService dialogService;
private final TaskExecutor taskExecutor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.push;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.jabref.Globals;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class PushToApplicationAction extends SimpleCommand {
private PushToApplication application;

public PushToApplicationAction(StateManager stateManager, PushToApplicationsManager pushToApplicationsManager, DialogService dialogService) {
this.application = Globals.prefs.getActivePushToApplication(pushToApplicationsManager);
this.application = Objects.requireNonNull(Globals.prefs.getActivePushToApplication(pushToApplicationsManager));
this.stateManager = stateManager;
this.dialogService = dialogService;

Expand All @@ -40,7 +41,7 @@ public PushToApplicationAction(StateManager stateManager, PushToApplicationsMana
}

public void updateApplication(PushToApplication application) {
this.application = application;
this.application = Objects.requireNonNull(application);
}

public Action getActionInformation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public TextFlow getDescription() {
}

textList.add(getCaseSensitiveDescription());
textList.add(TooltipTextUtil.createText("\n\n" +
Localization.lang("Hint: To search specific fields only, enter for example:")));
textList.add(TooltipTextUtil.createText(" author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));

TextFlow searchDescription = new TextFlow();
searchDescription.getChildren().setAll(textList);
return searchDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ public void putStringList(String key, List<String> value) {
public List<String> getStringList(String key) {
String names = get(key);
if (names == null) {
return new ArrayList<>();
return Collections.emptyList();
}

StringReader rd = new StringReader(names);
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,7 @@ plain\ text=plain text
This\ search\ contains\ entries\ in\ which\ any\ field\ contains\ the\ regular\ expression\ <b>%0</b>=This search contains entries in which any field contains the regular expression <b>%0</b>
This\ search\ contains\ entries\ in\ which\ any\ field\ contains\ the\ term\ <b>%0</b>=This search contains entries in which any field contains the term <b>%0</b>
This\ search\ contains\ entries\ in\ which=This search contains entries in which
Hint\:\ To\ search\ specific\ fields\ only,\ enter\ for\ example\:=Hint: To search specific fields only, enter for example:

Unable\ to\ autodetect\ OpenOffice/LibreOffice\ installation.\ Please\ choose\ the\ installation\ directory\ manually.=Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually.

Expand Down Expand Up @@ -2097,4 +2098,4 @@ Select\ all\ changes\ on\ the\ right=Select all changes on the right
Dismiss=Dismiss
Mark\ all\ changes\ as\ accepted=Mark all changes as accepted
Unmark\ all\ changes=Unmark all changes
Unmark\ all\ changes=Unmark all changes
71 changes: 0 additions & 71 deletions src/test/java/org/jabref/gui/BasePanelTest.java

This file was deleted.

17 changes: 15 additions & 2 deletions src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.entryeditor;

import java.util.Collections;

import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
Expand All @@ -8,7 +10,10 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.bibtex.FieldContentParserPreferences;
import org.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.model.database.BibDatabaseContext;
Expand All @@ -25,10 +30,11 @@
import org.testfx.framework.junit5.Start;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@GUITest
@ExtendWith(ApplicationExtension.class)
public class SourceTabTest {
class SourceTabTest {

private Stage stage;
private Scene scene;
Expand All @@ -40,7 +46,14 @@ public class SourceTabTest {
public void onStart(Stage stage) {
area = new CodeArea();
area.appendText("some example\n text to go here\n across a couple of \n lines....");
sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), mock(ImportFormatPreferences.class), new DummyFileUpdateMonitor(), mock(DialogService.class), mock(StateManager.class));
StateManager stateManager = mock(StateManager.class);
when(stateManager.activeSearchQueryProperty()).thenReturn(OptionalObjectProperty.empty());
KeyBindingRepository keyBindingRepository = new KeyBindingRepository(Collections.emptyList(), Collections.emptyList());
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class);
when(importFormatPreferences.getFieldContentParserPreferences())
.thenReturn(mock(FieldContentParserPreferences.class));

sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), importFormatPreferences, new DummyFileUpdateMonitor(), mock(DialogService.class), stateManager, keyBindingRepository);
pane = new TabPane(
new Tab("main area", area),
new Tab("other tab", new Label("some text")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ void testSimpleTerm() {
TooltipTextUtil.createText("This search contains entries in which any field contains the term "),
TooltipTextUtil.createText("test", TooltipTextUtil.TextType.BOLD),
TooltipTextUtil.createText(" (case insensitive). "),
TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:\n"),
TooltipTextUtil.createText("author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:"),
TooltipTextUtil.createText(" author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
TextFlow description = new ContainsAndRegexBasedSearchRuleDescriber(false, false, query).getDescription();

TextFlowEqualityHelper.assertEquals(expectedTexts, description);
Expand All @@ -49,8 +49,8 @@ void testNoAst() {
TooltipTextUtil.createText(" and "),
TooltipTextUtil.createText("b", TooltipTextUtil.TextType.BOLD),
TooltipTextUtil.createText(" (case insensitive). "),
TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:\n"),
TooltipTextUtil.createText("author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:"),
TooltipTextUtil.createText(" author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
TextFlow description = new ContainsAndRegexBasedSearchRuleDescriber(false, false, query).getDescription();

TextFlowEqualityHelper.assertEquals(expectedTexts, description);
Expand All @@ -61,7 +61,8 @@ void testNoAstRegex() {
String query = "a b";
List<Text> expectedTexts = Arrays.asList(TooltipTextUtil.createText("This search contains entries in which any field contains the regular expression "),
TooltipTextUtil.createText("a", TooltipTextUtil.TextType.BOLD), TooltipTextUtil.createText(" and "), TooltipTextUtil.createText("b", TooltipTextUtil.TextType.BOLD), TooltipTextUtil.createText(" (case insensitive). "),
TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:\n"), TooltipTextUtil.createText("author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:"),
TooltipTextUtil.createText(" author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
TextFlow description = new ContainsAndRegexBasedSearchRuleDescriber(false, true, query).getDescription();

TextFlowEqualityHelper.assertEquals(expectedTexts, description);
Expand All @@ -72,7 +73,8 @@ void testNoAstRegexCaseSensitive() {
String query = "a b";
List<Text> expectedTexts = Arrays.asList(TooltipTextUtil.createText("This search contains entries in which any field contains the regular expression "),
TooltipTextUtil.createText("a", TooltipTextUtil.TextType.BOLD), TooltipTextUtil.createText(" and "), TooltipTextUtil.createText("b", TooltipTextUtil.TextType.BOLD), TooltipTextUtil.createText(" (case sensitive). "),
TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:\n"), TooltipTextUtil.createText("author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:"),
TooltipTextUtil.createText(" author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
TextFlow description = new ContainsAndRegexBasedSearchRuleDescriber(true, true, query).getDescription();

TextFlowEqualityHelper.assertEquals(expectedTexts, description);
Expand All @@ -83,7 +85,8 @@ void testNoAstCaseSensitive() {
String query = "a b";
List<Text> expectedTexts = Arrays.asList(TooltipTextUtil.createText("This search contains entries in which any field contains the term "),
TooltipTextUtil.createText("a", TooltipTextUtil.TextType.BOLD), TooltipTextUtil.createText(" and "), TooltipTextUtil.createText("b", TooltipTextUtil.TextType.BOLD), TooltipTextUtil.createText(" (case sensitive). "),
TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:\n"), TooltipTextUtil.createText("author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:"),
TooltipTextUtil.createText(" author=smith and title=electrical", TooltipTextUtil.TextType.MONOSPACED));
TextFlow description = new ContainsAndRegexBasedSearchRuleDescriber(true, false, query).getDescription();

TextFlowEqualityHelper.assertEquals(expectedTexts, description);
Expand Down

0 comments on commit db13dc0

Please sign in to comment.