Skip to content

Commit

Permalink
Merge pull request #87 from freshcabbage123/alan-listTask
Browse files Browse the repository at this point in the history
feat: Implement listTask command
  • Loading branch information
m1oojv authored Oct 18, 2023
2 parents fc8ba87 + ea455da commit 46ee0a8
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/main/java/seedu/address/logic/commands/ListTaskCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_TASKS;

import seedu.address.model.Model;

/**
* Lists all tasks in CoordiMate to the user.
*/
public class ListTaskCommand extends Command {
public static final String COMMAND_WORD = "listTask";

public static final String MESSAGE_SUCCESS = "Listed all tasks";


@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS);
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import seedu.address.logic.commands.FindTaskCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListPersonCommand;
import seedu.address.logic.commands.ListTaskCommand;
import seedu.address.logic.commands.MarkTaskCommand;
import seedu.address.logic.commands.UnmarkTaskCommand;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -75,6 +76,9 @@ public Command parseCommand(String userInput) throws ParseException {
case ListPersonCommand.COMMAND_WORD:
return new ListPersonCommand();

case ListTaskCommand.COMMAND_WORD:
return new ListTaskCommand();

case MarkTaskCommand.COMMAND_WORD:
return new MarkTaskCommandParser().parse(arguments);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Person;
import seedu.address.model.task.Task;
import seedu.address.model.task.TaskContainsKeywordsPredicate;
import seedu.address.model.task.TitleContainsKeywordsPredicate;
import seedu.address.testutil.EditPersonDescriptorBuilder;

Expand Down Expand Up @@ -150,8 +151,8 @@ public static void showTaskAtIndex(Model model, Index targetIndex) {

Task task = model.getFilteredTaskList().get(targetIndex.getZeroBased());
final String[] splitName = task.getTitle().value.split("\\s+");
model.updateFilteredTaskList(new TaskContainsKeywordsPredicate(Arrays.asList(splitName[1])));
model.updateFilteredTaskList(new TitleContainsKeywordsPredicate(Arrays.asList(splitName[1])));

assertEquals(1, model.getFilteredTaskList().size());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showTaskAtIndex;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST;
import static seedu.address.testutil.TypicalTasks.getTypicalAddressBook;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;

public class ListTaskCommandTest {
private Model model;
private Model expectedModel;

@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
}

@Test
public void execute_listIsNotFiltered_showsSameList() {
assertCommandSuccess(new ListTaskCommand(), model, ListTaskCommand.MESSAGE_SUCCESS, expectedModel);
}

@Test
public void execute_listIsFiltered_showsEverything() {
showTaskAtIndex(model, INDEX_FIRST);
assertCommandSuccess(new ListTaskCommand(), model, ListTaskCommand.MESSAGE_SUCCESS, expectedModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import seedu.address.logic.commands.FindTaskCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListPersonCommand;
import seedu.address.logic.commands.ListTaskCommand;
import seedu.address.logic.commands.MarkTaskCommand;
import seedu.address.logic.commands.UnmarkTaskCommand;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void parseCommand_help() throws Exception {
}

@Test
public void parseCommand_list() throws Exception {
public void parseCommand_listPerson() throws Exception {
assertTrue(parser.parseCommand(ListPersonCommand.COMMAND_WORD) instanceof ListPersonCommand);
assertTrue(parser.parseCommand(ListPersonCommand.COMMAND_WORD + " 3") instanceof ListPersonCommand);
}
Expand All @@ -102,6 +103,12 @@ public void parseCommand_addTask() throws Exception {
assertEquals(new AddTaskCommand(task), command);
}

@Test
public void parseCommand_listTask() throws Exception {
assertTrue(parser.parseCommand(ListTaskCommand.COMMAND_WORD) instanceof ListTaskCommand);
assertTrue(parser.parseCommand(ListTaskCommand.COMMAND_WORD + " 3") instanceof ListTaskCommand);
}

@Test
public void parseCommand_findTask() throws Exception {
List<String> keywords = Arrays.asList("foo", "bar", "baz");
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/seedu/address/testutil/TypicalIndexes.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* A utility class containing a list of {@code Index} objects to be used in tests.
*/
public class TypicalIndexes {

public static final Index INDEX_FIRST = Index.fromOneBased(1);
public static final Index INDEX_SECOND = Index.fromOneBased(2);
public static final Index INDEX_THIRD = Index.fromOneBased(3);

}

0 comments on commit 46ee0a8

Please sign in to comment.