-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Test UI popup window with TestFX (ReplaceStringView.java) #7654
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/test/java/org/jabref/gui/edit/ReplaceStringViewTest.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,81 @@ | ||
package org.jabref.gui.edit; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import javafx.scene.control.*; | ||
import javafx.stage.Stage; | ||
|
||
import org.jabref.gui.LibraryTab; | ||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
import org.jabref.model.entry.types.StandardEntryType; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.testfx.framework.junit5.ApplicationTest; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ReplaceStringViewTest extends ApplicationTest { | ||
|
||
private ReplaceStringView replaceStringView; | ||
private LibraryTab libraryTab = mock(LibraryTab.class); | ||
private BibDatabaseContext databaseContext = mock(BibDatabaseContext.class); | ||
private DialogPane dialogPane; | ||
private BibEntry entry; | ||
|
||
@Override | ||
public void start (Stage stage) throws Exception { | ||
// Globals.prefs = JabRefPreferences.getInstance(); | ||
// Globals.startBackgroundTasks(); | ||
|
||
entry = new BibEntry(StandardEntryType.Misc) | ||
.withField(StandardField.AUTHOR, "Souti Chattopadhyay and Nicholas Nelson and Audrey Au and Natalia Morales and Christopher Sanchez and Rahul Pandita and Anita Sarma") | ||
.withField(StandardField.TITLE, "A tale from the trenches") | ||
.withField(StandardField.YEAR, "2020") | ||
.withField(StandardField.DOI, "10.1145/3377811.3380330") | ||
.withField(StandardField.SUBTITLE, "cognitive biases and software development") | ||
.withCitationKey("abc"); | ||
List<BibEntry> entries = new ArrayList<>(); | ||
entries.add(entry); | ||
|
||
when(libraryTab.getSelectedEntries()).thenReturn(entries); | ||
when(libraryTab.getDatabase()).thenReturn(new BibDatabase(entries)); | ||
replaceStringView = new ReplaceStringView(libraryTab); | ||
dialogPane = replaceStringView.getDialogPane(); | ||
stage.setScene(dialogPane.getScene()); | ||
stage.show(); | ||
} | ||
|
||
@Test | ||
public void testReplace() throws Exception { | ||
|
||
// verify that the Year field text is of the initial value (2020) | ||
assertEquals(Optional.of("2020"), entry.getField(StandardField.YEAR)); | ||
|
||
// enter find field | ||
clickOn("#findField"); | ||
write("2020"); | ||
|
||
// enter replace field | ||
clickOn("#replaceField"); | ||
write("2021"); | ||
|
||
// click on "Replace" button | ||
for (ButtonType buttonType : dialogPane.getButtonTypes()) { | ||
if (buttonType.getText().equals("Replace")) { | ||
Button replaceButton = (Button) dialogPane.lookupButton(buttonType); | ||
clickOn(replaceButton); | ||
} | ||
} | ||
|
||
// verify that the Year field text has been replaced by new value (2021) | ||
assertEquals(Optional.of("2021"), entry.getField(StandardField.YEAR)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These are the lines of code that helped my test to run, because it needs Globals.prefs and Globals.fileUpdateMonitor to not be null.
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.
Just an idea, can you try if Globals.prefs = mock(JabRefPreferences.class) works?
for Globals.fileUpdateMonitor you can try to use the DummyFileUpdateMonitor
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.
@Siedlerchr Yes it would work if we mock it up but I think the point is that we should not assign new value to Globals.prefs like this "Globals.prefs = ...." in the test. Because it's not like creating an instance of the object Globals and mock its prefs, for example,
Globals globals = mock(Globals.class); globals.prefs = mock(JabRefPreferences.class);
, but now we are directly setting the value of this global variable which is not ideal I think.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.
@JabRef/developers anyone an idea how to either extract the globals or how to test it?