diff --git a/docs/UserGuide.md b/docs/UserGuide.md index cc8bfecae98..2e5a8615449 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -586,6 +586,12 @@ This feature involves only 1 command: `find`, which list contacts whose fields m Format: `find FIND_EXPRESSION` + + +The contact list will be filtered until you perform another `find` command or use the [`list` command](#list-all-contacts-list). +This includes commands that add, delete, or edit contacts — newly-added more edited contacts will be shown only if they match the criteria. + + Find expressions have a low barrier to entry that allows for simple filtering by field. This basic filtering for contacts is likely sufficient for most of your use cases. We recommend that you first read the [basic filtering](#basic-filtering) section to learn how to perform simple filtering by a single field. If you then find that the basic filtering is insufficient for your use case, you can read the [advanced filtering](#advanced-filtering) section to learn how to perform more complex filtering. diff --git a/src/main/java/seedu/address/logic/commands/AddAltCommand.java b/src/main/java/seedu/address/logic/commands/AddAltCommand.java index 9a3dbdfb67b..4228cf2ee3a 100644 --- a/src/main/java/seedu/address/logic/commands/AddAltCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddAltCommand.java @@ -5,7 +5,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_LINKEDIN; import static seedu.address.logic.parser.CliSyntax.PREFIX_SECONDARY_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.util.ArrayList; import java.util.List; @@ -80,7 +79,6 @@ public CommandResult execute(Model model) throws CommandException { Person editedPerson = createAddAltPerson(personToEdit, addAltPersonDescriptor); model.setPerson(personToEdit, editedPerson); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); return new CommandResult(String.format(MESSAGE_ADDALT_SUCCESS, Messages.format(editedPerson))); } diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 158981edea7..0854fbec0bc 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -10,7 +10,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_SECONDARY_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.util.ArrayList; import java.util.Collections; @@ -104,7 +103,6 @@ public CommandResult execute(Model model) throws CommandException { } model.setPerson(personToEdit, editedPerson); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); } diff --git a/src/main/java/seedu/address/logic/commands/UpdatePhotoCommand.java b/src/main/java/seedu/address/logic/commands/UpdatePhotoCommand.java index d6957d5f66f..9ff345ac0e2 100644 --- a/src/main/java/seedu/address/logic/commands/UpdatePhotoCommand.java +++ b/src/main/java/seedu/address/logic/commands/UpdatePhotoCommand.java @@ -2,7 +2,6 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_AVATAR; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.io.FileNotFoundException; import java.io.IOException; @@ -80,7 +79,6 @@ public CommandResult execute(Model model) throws CommandException { Person editedPerson = createPersonWithAvatar(personToEdit, avatar); model.setPerson(personToEdit, editedPerson); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); return new CommandResult(MESSAGE_SUCCESS); } diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index b08b62dd21c..1c31eed9153 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -15,9 +15,12 @@ import org.junit.jupiter.api.Test; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; +import seedu.address.model.person.Balance; import seedu.address.model.person.NameContainsKeywordsPredicate; /** @@ -82,6 +85,44 @@ public void toStringMethod() { assertEquals(expected, findCommand.toString()); } + // Integration tests for reactive commands + + @Test + public void execute_payAfterFiltered_reactive() throws CommandException { + Model tempModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + assert tempModel.hasPerson(CARL); + + FindCommand command = new FindCommand(person -> person.getBalance().value < 50); + command.execute(tempModel); + + int originalSize = tempModel.getFilteredPersonList().size(); + + assert tempModel.getFilteredPersonList().get(1) == CARL; + + PayCommand payCommand = new PayCommand(Index.fromZeroBased(1), new Balance(50000)); + payCommand.execute(tempModel); + + assert CARL.getBalance().value >= 50; + + assertEquals(originalSize - 1, tempModel.getFilteredPersonList().size()); + } + + @Test + public void execute_deleteAfterFiltered_reactive() { + Model tempModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + assert tempModel.hasPerson(CARL); + + FindCommand command = new FindCommand(person -> true); + command.execute(tempModel); + + int originalSize = tempModel.getFilteredPersonList().size(); + + tempModel.deletePerson(CARL); + + assertEquals(originalSize - 1, tempModel.getFilteredPersonList().size()); + } + + /** * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. */