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

Fix option to "Search for unlinked local files" for new library #12738

Merged
merged 3 commits into from
Mar 19, 2025
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Loading