diff --git a/CHANGELOG.md b/CHANGELOG.md index edcf9fdd3cc..34a89efc32a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where month values 21–24 (ISO 8601-2019 season codes) in Biblatex date fields were not recognized as seasons during parsing. [#12437](https://github.com/JabRef/jabref/issues/12437) - We fixed an issue where migration of "Search groups" would fail with an exception when the search query is invalid. [#12555](https://github.com/JabRef/jabref/issues/12555) - We fixed an issue where not all linked files from BibDesk in the field `bdsk-file-...` were parsed. [#12555](https://github.com/JabRef/jabref/issues/12555) +- We fixed an issue where it was possible to select "Search for unlinked local files" for a new (unsaved) library. [#12558](https://github.com/JabRef/jabref/issues/12558) - We fixed an issue where user-defined keyword separator does not apply to Merge Groups. [#12535](https://github.com/JabRef/jabref/issues/12535) - We fixed an issue where duplicate items cannot be removed correctly when merging groups or keywords. [#12585](https://github.com/JabRef/jabref/issues/12585) - We fixed an issue where JabRef displayed an incorrect deletion notification when canceling entry deletion [#12645](https://github.com/JabRef/jabref/issues/12645) diff --git a/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesAction.java b/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesAction.java index 7c5cb7bf644..e31c5fd1a2f 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesAction.java @@ -4,7 +4,7 @@ import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; -import static org.jabref.gui.actions.ActionHelper.needsDatabase; +import static org.jabref.gui.actions.ActionHelper.needsSavedLocalDatabase; public class FindUnlinkedFilesAction extends SimpleCommand { @@ -15,7 +15,7 @@ public FindUnlinkedFilesAction(DialogService dialogService, StateManager stateMa this.dialogService = dialogService; this.stateManager = stateManager; - this.executable.bind(needsDatabase(this.stateManager)); + this.executable.bind(needsSavedLocalDatabase(this.stateManager)); } @Override diff --git a/src/test/java/org/jabref/gui/externalfiles/FindUnlinkedFilesActionTest.java b/src/test/java/org/jabref/gui/externalfiles/FindUnlinkedFilesActionTest.java new file mode 100644 index 00000000000..7ee1562bf8c --- /dev/null +++ b/src/test/java/org/jabref/gui/externalfiles/FindUnlinkedFilesActionTest.java @@ -0,0 +1,67 @@ +package org.jabref.gui.externalfiles; + +import java.nio.file.Path; +import java.util.Optional; + +import org.jabref.gui.DialogService; +import org.jabref.gui.StateManager; +import org.jabref.logic.shared.DatabaseLocation; +import org.jabref.model.database.BibDatabaseContext; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; + +class FindUnlinkedFilesActionTest { + + @Mock + private DialogService dialogService; + + @Mock + private BibDatabaseContext databaseContext; + + private StateManager stateManager; + private FindUnlinkedFilesAction action; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + stateManager = new StateManager(); + action = new FindUnlinkedFilesAction(dialogService, stateManager); + } + + @Test + void isEnabledWhenNewDatabaseIsSavedTest() { + when(databaseContext.getDatabasePath()).thenReturn(Optional.of(Path.of("test.bib"))); + when(databaseContext.getLocation()).thenReturn(DatabaseLocation.LOCAL); + + stateManager.activeDatabaseProperty().setValue(Optional.of(databaseContext)); + + assertTrue(action.executableProperty().get()); + } + + @Test + void isDisabledWhenNewDatabasePathIsEmptyTest() { + when(databaseContext.getDatabasePath()).thenReturn(Optional.empty()); + when(databaseContext.getLocation()).thenReturn(DatabaseLocation.LOCAL); + + stateManager.activeDatabaseProperty().setValue(Optional.of(databaseContext)); + + assertFalse(action.executableProperty().get()); + } + + @Test + void isDisabledWhenNewDatabaseIsNotLocalTest() { + when(databaseContext.getDatabasePath()).thenReturn(Optional.of(Path.of("test.bib"))); + when(databaseContext.getLocation()).thenReturn(DatabaseLocation.SHARED); + + stateManager.activeDatabaseProperty().setValue(Optional.of(databaseContext)); + + assertFalse(action.executableProperty().get()); + } +}