Skip to content
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

Add automated screenshots #6089

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v1
with:
depth: 1
submodules: false
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
Expand All @@ -42,10 +39,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v1
with:
depth: 1
submodules: false
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
Expand Down Expand Up @@ -89,10 +83,7 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout source
uses: actions/checkout@v1
with:
depth: 1
submodules: false
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
Expand Down Expand Up @@ -138,10 +129,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v1
with:
depth: 1
submodules: false
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
Expand All @@ -164,6 +152,11 @@ jobs:
run: xvfb-run --auto-servernum ./gradlew guiTest
env:
CI: "true"
- name: Upload screenshots to GitHub workflow artifacts store
uses: actions/upload-artifact@master
with:
name: screenshots
path: build/screenshots
codecoverage:
name: Code coverage
runs-on: ubuntu-latest
Expand All @@ -180,10 +173,7 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout source
uses: actions/checkout@v1
with:
depth: 1
submodules: false
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
Expand All @@ -203,7 +193,7 @@ jobs:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
- name: Update test coverage metrics
run: xvfb-run --auto-servernum ./gradlew jacocoTestReport && bash <(curl -s https://codecov.io/bash);
run: xvfb-run --server-args=":1 -screen 0 1024x768x24" --auto-servernum ./gradlew jacocoTestReport && bash <(curl -s https://codecov.io/bash);
env:
CI: "false" # we pretend to run locally - even if tests fail on the CI, they count towards test coverage
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static boolean handleMultipleAppInstances(String[] args) {
return true;
}

private static void applyPreferences(JabRefPreferences preferences) {
public static void applyPreferences(JabRefPreferences preferences) {
// Read list(s) of journal names and abbreviations
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader();

Expand Down
25 changes: 2 additions & 23 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -143,11 +142,10 @@
import org.slf4j.LoggerFactory;

/**
* The main window of the application.
* The main window of JabRef's UI
*/
public class JabRefFrame extends BorderPane {

// Frame titles.
public static final String FRAME_TITLE = "JabRef";

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefFrame.class);
Expand Down Expand Up @@ -276,7 +274,7 @@ public void run() {
}
}

private Void showTrackingNotification() {
private void showTrackingNotification() {
if (!Globals.prefs.shouldCollectTelemetry()) {
boolean shouldCollect = dialogService.showConfirmationDialogAndWait(
Localization.lang("Telemetry: Help make JabRef better"),
Expand All @@ -287,13 +285,10 @@ private Void showTrackingNotification() {
}

Globals.prefs.askedToCollectTelemetry();

return null;
}

public void refreshTitleAndTabs() {
DefaultTaskExecutor.runInJavaFXThread(() -> {

setWindowTitle();
updateAllTabTitles();
});
Expand Down Expand Up @@ -328,22 +323,6 @@ public void setWindowTitle() {
}
}

/**
* The MacAdapter calls this method when a "BIB" file has been double-clicked from the Finder.
*/
public void openAction(String filePath) {
Path file = Paths.get(filePath);
// all the logic is done in openIt. Even raising an existing panel
getOpenDatabaseAction().openFile(file, true);
}

/**
* The MacAdapter calls this method when "About" is selected from the application menu.
*/
public void about() {
HelpAction.getMainHelpPageCommand().execute();
}

public JabRefPreferences prefs() {
return prefs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public class ManageJournalAbbreviationsView extends BaseDialog<Void> {
public ManageJournalAbbreviationsView() {
this.setTitle(Localization.lang("Journal abbreviations"));

ViewLoader.view(this).load().setAsDialogPane(this);
ViewLoader.view(this)
.load()
.setAsDialogPane(this);

ControlHelper.setAction(saveButton, getDialogPane(), event -> saveAbbreviationsAndCloseDialog());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/util/BaseDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected BaseDialog() {

setDialogIcon(IconTheme.getJabRefImageFX());
setResizable(true);
Globals.getThemeLoader().installCss(getDialogPane().getScene(), Globals.prefs);
//Globals.getThemeLoader().installCss(getDialogPane().getScene(), Globals.prefs);
}

private Optional<Button> getDefaultButton() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/logic/util/buildTest.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version=100.0.0
year=2020
authors=1160300608, 1160300614, Aaron Chen, Abhishek Rai, Abraham Polk, Adam Rehn, Admir Obralija, Adrian Daerr, Akash Deep, Alain Vaucher, Aleksandrs Gusevs, Alessio Pollero, Alex Montgomery, Alex Tarrix, Alexis Gallagher, Alexsandro Lauber, Ali Ayan, Ali Zhagparov, Alick Zhao, Allison Sampaio, Aman Jain, Ambrogio Oliva, Amish Shah, Andreas Amann, Andreas Buhr, Andreas Rudert, Andrew Collins, Andrew Levit, Andrés Sánchez, Anh Nghia Tran, Anita Armbruster, Antonio Ribeiro, Arno Blouin, Arthur Fröhlich, Atul Kaushik, Ayachi Nene, Bartosz J. Kaczkowski, Bartłomiej Dach, Behrouz Javanmardi, Benjamin Köhler, Berk Gureken, Bernd Kalbfuss, Bernhard Tempel, Bharat Raghunathan, Bhargava Varadharajan, Bherwani Ayush, Bitor Tonixa Biriato Balença, Brian Quistorff, Brian Van Essen, captain123, Carl Christian Snethlage, carlg0ransson, Carlos Morales, Carlos Silla, Carlos Silva, Cerrianne Santos, Chamod Shehanka, Chelsey Ong, Chris Brown, Christian Bartsch, Christian Kopf, Christoph Braun, Christoph Hochreiner, Christoph Schwentker, Christopher Oezbek, Christopher S. Lester, conorfos, cs464osu, Cyrille d'Haese, Dale Visser, Daniel Bruehl, Daniel Mair, Daniel Rodrigues, Daniel Svärd, David Gleich, David Méndez, David Weitzman, Dawid Owoc, Deepak Kumar, Dennis Tschechlov, DevSiroukane, Dilan Coss, dima, Domenico Cufalo, Dominik Schrempf, Dominik Traczyk, Dominik Waßenhoven, Douglas Nassif Roma Junior, Eduard Braun, Eduardo Greco, Egon Willighagen, Eiswindyeti, Ellen Reitmayr, Erdem Derebasoglu, Erdem Derebaşoğlu, Erik Putrycz, Ervin Kolenovic, Escoul, Ethan Harris, Fabian Bauer, Fabian Bieker, Fabrice Dessaint, Fancy Zhang, Fedor Bezrukov, Felix Berger, Felix Langner, Felix Wilke, Fernando Santagata, ffffatgoose, Florian Beetz, Florian Straßer, Foivos Christoulakis, Francois Charette, Frank Steimle, frasca80, Fred Stevens, Frédéric Darboux, Galileo Sartor, Geoffrey Taerim Kim, Gert Renckens, Gregor Herrmann, Guillaume Gardey, Hakan Duran, Hannes Restel, Harinda Samarasekara, Igor Chernyavsky, Igor Steinmacher, Illes Solt, Ingvar Jackal, Jackson Ryan, Jan Frederik Maas, Jan Kubovy, Jan Schäfer, Janosch Kutscherauer, Jason Pickering, Javier Muñoz Ferrara, Jeff Kerr, Jeff Miller, Jeffrey Kuhn, Jeffrey Sander, Jens Döcke, Johannes Hupe, Johannes Manner, John David, John Relph, John Zedlewski, Jonathan Powell, Jong-Ho Shinn, Jorge Tornero, josephshin93, Joshua Ramon Enslin, José Jesús Sinohui Fernández, Julian Pfeifer, Jure Slak, József Pallagi, Jörg Lenhard, Jörg Wegner, Jörg Zieren, Jørgen Kvalsvik, Jürgen Lange, Kai Mindermann, Kai Takac, Kaique Komata, Karsten Hiekmann, Kelly Click, Koji Yokota, KOLANICH, Kolja Brix, Krunoslav Zubrinic, Krzysztof A. Kościuszkiewicz, Kyle Johnson, Laura Hernández Gómez, Lavabit, Le-wi, Lee Patton, Leonardo Haddad, Leonhard Wolz, Li Yiming, Li Zhilin, Ling Wang, Linus Dietz, Lorenzo Genta, Luciana de Melo e Abud, Luis Romero, Mairieli Wessel, Malik Atalla, Malte Deiseroth, Manuel Siebeneicher, Manuel Wtfjoke, Marco Konersmann, Mariana Prudencio, Marius Kleiner, Mark Schenk, Martin Kähmer, Martin Stolle, Martina Catizone, Mathias Walter, Matthias Geiger, Matthias Mueller, Mattia Bunel, Mattias Ulbrich, mcmoody, Meltem Demirköprü, Michael Beckmann, Michael Falkenthal, Michael Lass, Michael McCann, Michael Schwarmi, Michael Spiegel, Michael Wrighton, Michal Rican, Michel Baylac, Michel Krämer, Mihu, Mike Smoot, mohamean, Morgan Lovato, Moritz Ringler, Morten Alver, ms111ds, Mélanie Tremblay, Nadeem Mahmood, Nathan Dunn, Nathan Sheffield, Nick Mancuso, Nick S. Weatherley, Nico Schlömer, Nicolas Pavillon, Nikita Borovikov, nikmilpv, Niv Ierushalmi, Nivedha Sunderraj, Nizar N. Batada, noravanq, Olaf Lenz, Oliver Beckmann, Oliver Kopp, omer-rotem1, Oscar Gustafsson, Owen Huang, P4trice, Param Mittal, Patrick Lin, Patrick Scheibe, Paul Krappatsch, Paul Martin, pavlapp, Peter Ansell, Philip Johnson, Prasan Yapa, Predrag Milanovic, Quentin Fritz, Rachel Wu, Raik Nagel, razvan05, Renato Massao, Richard Schneeman, Robert Jäschke, Robin Lichtenthaeler, Rodrigo Paula da Silva, Rolf Starre, Ronak Lakhotia, Roy Storey, Rudolf Seemann, Rui Kang, Ruy Minoru Ito Takata, Ryo Igarashi, S M Mahbub Murshed, S. Krause, Saivert, Sam Robertson, Samin Muhammad Ridwanul Karim, Samiya Caur, Sascha Hunold, Sascha Zeller, Saulius Gražulis, Saverio Mori, Scott Pogatetz, Scott Townsend, Seb Wills, Serban Iordache, Shitikanth, shubhamatlani, Simon Harrer, Simon Rutishauser, Songyu Wang, speed9, Stanley Foerster, Stefan Feyer, Stefan Gerzmann, Stefan Kolb, Stefan Robert, Stefan Scheffel, Stefano Gariazzo, Steffin Stanly, Stephan Lau, Stephan Rave, Stephen Beitzel, Stéphane Curet, Super-Tang, Sven Jäger, systemoperator, Thiago Toledo, Thomas Arildsen, Thomas Ilsche, Thorsten Dahlheimer, Tim Kilian, Tim van Rossum, Tim Würtele, Tobias Boceck, Tobias Bouschen, Tobias Denkinger, Tobias Diez, Tony K, Toralf Senger, uid112001, Ulrich Stärk, Ulrik Stervbo, UltimaBGD, Uwe Kuehn, Valentin Pons, Victor Figueira, Victor Michelan, Vincent W. Yang, Vlad Topala, Waida Fan, Waluyo Adi Siswanto, Ward Poelmans, Wenbo Yang, wuw, Yang Zongze, Yara Grassi Gouffon, Yash Kothari, Yichen Sun, Yifan Peng, Yurick Honda, zacmks, Zeabin, Zgarbul Andrey, Zhang Liang
developers=Oliver Kopp (since 2011), Jörg Lenhard (since 2015), Stefan Kolb (since 2015), Matthias Geiger (since 2015), Tobias Diez (since 2015), Christoph Schwentker (since 2016), Linus Dietz (since 2017), Carl Christian Snethlage (since 2020)
azureInstrumentationKey=null
minRequiredJavaVersion=1.8.0_171
allowJava9=true
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.jabref.gui.DefaultInjector
org.jabref.gui.DefaultTestInjector
30 changes: 14 additions & 16 deletions src/test/java/org/jabref/architecture/TestArchitectureTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
Expand All @@ -27,32 +26,31 @@ public class TestArchitectureTests {
private static final String CLASS_ORG_JABREF_UPDATE_TIMESTAMP_LISTENER_TEST = "UpdateTimestampListenerTest";
private static final String CLASS_ORG_JABREF_ENTRY_EDITOR_TEST = "EntryEditorTest";
private static final String CLASS_ORG_JABREF_LINKED_FILE_VIEW_MODEL_TEST = "LinkedFileViewModelTest";
private static final String CLASS_ORG_JABREF_SCREENSHOTS_TEST = "Screenshots";
private static final String CLASS_ORG_JABREF_SCREENSHOT_DARK_THEME_TEST = "ScreenshotDarkTheme";

private final List<String> exceptions;

public TestArchitectureTests() {

// Add exceptions for the architectural test here
// Note that bending the architectural constraints should not be done inconsiderately
exceptions = new ArrayList<>();
exceptions.add(CLASS_ORG_JABREF_PREFERENCES_TEST);
exceptions.add(CLASS_ORG_JABREF_PREFERENCES_MIGRATIONS_TEST);
exceptions.add(CLASS_ORG_JABREF_SAVE_DATABASE_ACTION_TEST);
exceptions.add(CLASS_ORG_JABREF_UPDATE_TIMESTAMP_LISTENER_TEST);
exceptions.add(CLASS_ORG_JABREF_ENTRY_EDITOR_TEST);
exceptions.add(CLASS_ORG_JABREF_LINKED_FILE_VIEW_MODEL_TEST);
exceptions = List.of(
CLASS_ORG_JABREF_PREFERENCES_TEST,
CLASS_ORG_JABREF_PREFERENCES_MIGRATIONS_TEST,
CLASS_ORG_JABREF_SAVE_DATABASE_ACTION_TEST,
CLASS_ORG_JABREF_UPDATE_TIMESTAMP_LISTENER_TEST,
CLASS_ORG_JABREF_ENTRY_EDITOR_TEST,
CLASS_ORG_JABREF_LINKED_FILE_VIEW_MODEL_TEST,
CLASS_ORG_JABREF_SCREENSHOTS_TEST,
CLASS_ORG_JABREF_SCREENSHOT_DARK_THEME_TEST);
}

public static Stream<String[]> data() {
return Stream.of(
new String[][]{
{CLASS_ORG_JABREF_PREFERENCES},
{CLASS_ORG_JABREF_GLOBALS}
});
public static Stream<String> forbiddenPackages() {
return Stream.of(CLASS_ORG_JABREF_PREFERENCES, CLASS_ORG_JABREF_GLOBALS);
}

@ParameterizedTest
@MethodSource("data")
@MethodSource("forbiddenPackages")
public void testsAreIndependent(String forbiddenPackage) throws IOException {
Predicate<String> isForbiddenPackage = (s) -> s.startsWith("import " + forbiddenPackage);
Predicate<String> isExceptionClass = (s) -> exceptions.stream().anyMatch(exception -> s.startsWith("class " + exception));
Expand Down
84 changes: 84 additions & 0 deletions src/test/java/org/jabref/gui/DefaultTestInjector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.jabref.gui;

import java.util.function.Function;

import javax.swing.undo.UndoManager;

import org.jabref.Globals;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.util.BuildInfo;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;
import com.airhacks.afterburner.injection.PresenterFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.mockito.Mockito.mock;

public class DefaultTestInjector implements PresenterFactory {

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultTestInjector.class);

/**
* This method takes care of creating dependencies.
* By default, it just creates a new instance of the class.
* Dependencies without default constructor are constructed by hand.
*/
private static Object createDependency(Class<?> clazz) {
if (clazz == DialogService.class) {
return mock(DialogService.class);
} else if (clazz == BuildInfo.class) {
return new BuildInfo("buildTest.properties");
} else if (clazz == TaskExecutor.class) {
return Globals.TASK_EXECUTOR;
} else if (clazz == PreferencesService.class) {
return Globals.prefs;
} else if (clazz == KeyBindingRepository.class) {
return Globals.getKeyPrefs();
} else if (clazz == JournalAbbreviationLoader.class) {
return Globals.journalAbbreviationLoader;
} else if (clazz == StateManager.class) {
return Globals.stateManager;
} else if (clazz == FileUpdateMonitor.class) {
return Globals.getFileUpdateMonitor();
} else if (clazz == ProtectedTermsLoader.class) {
return Globals.protectedTermsLoader;
} else if (clazz == ClipBoardManager.class) {
return Globals.clipboardManager;
} else if (clazz == UndoManager.class) {
return Globals.undoManager;
} else {
try {
return clazz.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
LOGGER.error("Cannot instantiate dependency: " + clazz, ex);
return null;
}
}
}

@Override
public <T> T instantiatePresenter(Class<T> clazz, Function<String, Object> injectionContext) {
LOGGER.debug("Instantiate " + clazz.getName());

// Use our own method to construct dependencies
Injector.setInstanceSupplier(DefaultTestInjector::createDependency);

return Injector.instantiatePresenter(clazz, injectionContext);
}

@Override
public void injectMembers(Object instance, Function<String, Object> injectionContext) {
LOGGER.debug("Inject into " + instance.getClass().getName());

// Use our own method to construct dependencies
Injector.setInstanceSupplier(DefaultTestInjector::createDependency);

Injector.injectMembers(instance, injectionContext);
}
}
Loading