forked from nus-cs2103-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 3
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 tests in TaskListPanel and ToDoListEevntCard #78
Merged
SleepySanjinLi
merged 21 commits into
CS2103-AY1819S1-T10-1:master
from
SleepySanjinLi:master
Nov 7, 2018
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
036ca7f
fix tests in TaskListPanel and ToDoListEevntCard
SleepySanjinLi e503c37
Merge branch 'master' of https://github.com/CS2103-AY1819S1-T10-1/main
SleepySanjinLi c1a0971
Merge branch 'master' of https://github.com/CS2103-AY1819S1-T10-1/main
SleepySanjinLi b9aa74d
UI for description
SleepySanjinLi 323797a
Merge branch 'master' of https://github.com/CS2103-AY1819S1-T10-1/main
SleepySanjinLi fe2f774
command for show description and tests
SleepySanjinLi 383569c
UI modify
SleepySanjinLi c854d6e
delete arrow
SleepySanjinLi fd4effa
checkStyle
SleepySanjinLi b4d09ac
checkStyle
SleepySanjinLi d6a156c
checkStyle
SleepySanjinLi 014aac7
checkStyle
SleepySanjinLi 015fd3e
checStyle
SleepySanjinLi 4a426fe
checkStyle
SleepySanjinLi 0da8775
checkStyle
SleepySanjinLi 989c254
checkStyle
SleepySanjinLi 0781394
Merge branch 'master' of https://github.com/CS2103-AY1819S1-T10-1/main
SleepySanjinLi 5e7f92c
change command word
SleepySanjinLi 0003174
add SchedulerParserTest for showDescription
SleepySanjinLi 91b437c
remove javadoc
SleepySanjinLi 918bfce
Merge branch 'master' into master
SleepySanjinLi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/main/java/seedu/address/logic/commands/ShowDescriptionCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import javafx.scene.Parent; | ||
import javafx.scene.Scene; | ||
import javafx.stage.Modality; | ||
import javafx.stage.Stage; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelToDo; | ||
import seedu.address.model.todolist.ToDoListEvent; | ||
import seedu.address.ui.DescriptionDisplay; | ||
|
||
/** | ||
* Shows description of a todolist event identified using its displayed index | ||
* from the calendar event list in the toDoList. | ||
*/ | ||
public class ShowDescriptionCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "show todo"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Shows description of the todo event identified by the index number used in the displayed event list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_SHOW_DESCRIPTION_TODO_SUCCESS = "Showed Event's Description: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public ShowDescriptionCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
super.isToDoCommand = true; | ||
} | ||
|
||
/** | ||
* display a descriptionDisplay UI component {@code DescriptionDisplay} | ||
* @param root | ||
*/ | ||
private void display (Parent root) { | ||
Scene scene = new Scene(root, 200, 150); | ||
Stage stage = new Stage(); | ||
stage.initModality(Modality.APPLICATION_MODAL); | ||
stage.setScene(scene); | ||
stage.showAndWait(); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
throw new CommandException(MESSAGE_INCORRECT_MODEL_TODO); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(ModelToDo modelToDo, CommandHistory history) throws CommandException { | ||
requireNonNull(modelToDo); | ||
|
||
List<ToDoListEvent> filteredToDoListEventList = modelToDo.getFilteredToDoListEventList(); | ||
|
||
if (targetIndex.getZeroBased() >= filteredToDoListEventList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_TODOLIST_EVENTS_DISPLAYED_INDEX); | ||
} | ||
|
||
DescriptionDisplay descriptionDisplay = | ||
new DescriptionDisplay(filteredToDoListEventList.get(targetIndex.getZeroBased()), | ||
targetIndex.getZeroBased()); | ||
display(descriptionDisplay.getRoot()); | ||
|
||
return new CommandResult(String.format(MESSAGE_SHOW_DESCRIPTION_TODO_SUCCESS, targetIndex.getOneBased())); | ||
|
||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ShowDescriptionCommand // instanceof handles nulls | ||
&& targetIndex.equals(((ShowDescriptionCommand) other).targetIndex)); // state check | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/seedu/address/logic/parser/ShowDescriptionCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.ShowDescriptionCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new ShowDescriptionCommand object | ||
*/ | ||
public class ShowDescriptionCommandParser implements Parser<ShowDescriptionCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the ShowDescriptionCommand | ||
* and returns an ShowDescriptionCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ShowDescriptionCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new ShowDescriptionCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException ( | ||
String.format (MESSAGE_INVALID_COMMAND_FORMAT, ShowDescriptionCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package seedu.address.ui; | ||
|
||
import java.util.logging.Logger; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.TextArea; | ||
import javafx.scene.layout.Region; | ||
|
||
import seedu.address.commons.core.LogsCenter; | ||
import seedu.address.model.todolist.ToDoListEvent; | ||
|
||
/** | ||
* An UI component that displays selected description of a {@code ToDoListEvent}. | ||
*/ | ||
public class DescriptionDisplay extends UiPart<Region> { | ||
|
||
private static final String FXML = "DescriptionDisplay.fxml"; | ||
public final ToDoListEvent toDoListEvent; | ||
private final Logger logger = LogsCenter.getLogger(CommandBox.class); | ||
private int selectedIndex; | ||
|
||
@FXML | ||
private TextArea description; | ||
|
||
@FXML | ||
private Label id; | ||
|
||
public DescriptionDisplay(ToDoListEvent toDoListEvent, int displayedIndex) { | ||
super(FXML); | ||
this.selectedIndex = displayedIndex; | ||
this.toDoListEvent = toDoListEvent; | ||
id.setText(displayedIndex + 1 + ": "); | ||
description.setText(toDoListEvent.getDescription().value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.TextArea?> | ||
<?import javafx.scene.layout.AnchorPane?> | ||
|
||
<AnchorPane prefHeight="109.0" prefWidth="175.0" xmlns="http://javafx.com/javafx/10.0.1" | ||
xmlns:fx="http://javafx.com/fxml/1"> | ||
<children> | ||
<TextArea fx:id="description" layoutY="31.0" prefHeight="169.0" prefWidth="200.0" /> | ||
<Label layoutX="2.0" layoutY="3.0" prefHeight="25.0" prefWidth="153.0" text="Description" /> | ||
<Label fx:id="id" layoutX="140.0" layoutY="3.0" prefHeight="25.0" prefWidth="31.0" text="" /> | ||
</children> | ||
</AnchorPane> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/test/java/seedu/address/logic/commands/ShowDescriptionCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandToDoFailure; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandToDoSuccess; | ||
import static seedu.address.logic.commands.CommandTestUtil.showToDoListEventAtIndex; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_ELEMENT; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_ELEMENT; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_THIRD_ELEMENT; | ||
import static seedu.address.testutil.TypicalTodoListEvents.getTypicalToDoList; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.model.ModelManagerToDo; | ||
import seedu.address.model.ModelToDo; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.ui.testutil.EventsCollectorRule; | ||
|
||
/** | ||
* Contains integration tests (interaction with the ModelToDo) for {@code ShowDescriptionCommand}. | ||
*/ | ||
public class ShowDescriptionCommandTest { | ||
|
||
@Rule | ||
public final EventsCollectorRule eventsCollectorRule = new EventsCollectorRule(); | ||
|
||
private ModelToDo modelToDo = new ModelManagerToDo(getTypicalToDoList(), new UserPrefs()); | ||
private ModelToDo expectedModelToDo = new ModelManagerToDo(getTypicalToDoList(), new UserPrefs()); | ||
private CommandHistory commandHistory = new CommandHistory(); | ||
|
||
//@Test | ||
/** | ||
* TODO pass it | ||
*/ | ||
public void execute_validIndexUnfilteredList_success() { | ||
Index lastPersonIndex = Index.fromOneBased(modelToDo.getFilteredToDoListEventList().size()); | ||
|
||
assertExecutionSuccess(INDEX_FIRST_ELEMENT); | ||
assertExecutionSuccess(INDEX_THIRD_ELEMENT); | ||
assertExecutionSuccess(lastPersonIndex); | ||
} | ||
|
||
@Test | ||
public void execute_invalidIndexUnfilteredList_failure() { | ||
Index outOfBoundsIndex = Index.fromOneBased(modelToDo.getFilteredToDoListEventList().size() + 1); | ||
|
||
assertExecutionFailure(outOfBoundsIndex, Messages.MESSAGE_INVALID_TODOLIST_EVENTS_DISPLAYED_INDEX); | ||
} | ||
|
||
//@Test | ||
/** | ||
* TODO pass it | ||
*/ | ||
public void execute_validIndexFilteredList_success() { | ||
showToDoListEventAtIndex(modelToDo, INDEX_FIRST_ELEMENT); | ||
showToDoListEventAtIndex(expectedModelToDo, INDEX_FIRST_ELEMENT); | ||
|
||
assertExecutionSuccess(INDEX_FIRST_ELEMENT); | ||
} | ||
|
||
@Test | ||
public void execute_invalidIndexFilteredList_failure() { | ||
showToDoListEventAtIndex(modelToDo, INDEX_FIRST_ELEMENT); | ||
showToDoListEventAtIndex(expectedModelToDo, INDEX_FIRST_ELEMENT); | ||
|
||
Index outOfBoundsIndex = INDEX_SECOND_ELEMENT; | ||
// ensures that outOfBoundIndex is still in bounds of to do list | ||
assertTrue(outOfBoundsIndex.getZeroBased() < modelToDo.getToDoList().getToDoList().size()); | ||
|
||
assertExecutionFailure(outOfBoundsIndex, Messages.MESSAGE_INVALID_TODOLIST_EVENTS_DISPLAYED_INDEX); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
ShowDescriptionCommand showFirstCommand = new ShowDescriptionCommand(INDEX_FIRST_ELEMENT); | ||
ShowDescriptionCommand showSecondCommand = new ShowDescriptionCommand(INDEX_SECOND_ELEMENT); | ||
|
||
// same object -> returns true | ||
assertTrue(showFirstCommand.equals(showFirstCommand)); | ||
|
||
// same values -> returns true | ||
ShowDescriptionCommand showFirstCommandCopy = new ShowDescriptionCommand(INDEX_FIRST_ELEMENT); | ||
assertTrue(showFirstCommand.equals(showFirstCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(showFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(showFirstCommand.equals(null)); | ||
|
||
// different todolistevent -> returns false | ||
assertFalse(showFirstCommand.equals(showSecondCommand)); | ||
} | ||
|
||
/** | ||
* Executes a {@code ShowDescriptionCommand} with the given {@code index}. | ||
*/ | ||
private void assertExecutionSuccess(Index index) { | ||
ShowDescriptionCommand showDescriptionCommand = new ShowDescriptionCommand(index); | ||
String expectedMessage = String.format(ShowDescriptionCommand.MESSAGE_SHOW_DESCRIPTION_TODO_SUCCESS, | ||
index.getOneBased()); | ||
|
||
assertCommandToDoSuccess(showDescriptionCommand, modelToDo, commandHistory, expectedMessage, expectedModelToDo); | ||
} | ||
|
||
/** | ||
* Executes a {@code ShowDescriptionCommand} with the given {@code index}, | ||
* and checks that a {@code CommandException} | ||
* is thrown with the {@code expectedMessage}. | ||
*/ | ||
private void assertExecutionFailure(Index index, String expectedMessage) { | ||
ShowDescriptionCommand showDescriptionCommand = new ShowDescriptionCommand(index); | ||
assertCommandToDoFailure(showDescriptionCommand, modelToDo, commandHistory, expectedMessage); | ||
assertTrue(eventsCollectorRule.eventsCollector.isEmpty()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/java/seedu/address/logic/parser/ShowDescriptionCommandParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CommandParserTestUtilToDo.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtilToDo.assertParseSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_ELEMENT; | ||
|
||
import org.junit.Test; | ||
|
||
import seedu.address.logic.commands.ShowDescriptionCommand; | ||
|
||
/** | ||
* Test scope: similar to {@code DeleteToDoCommandParserTest}. | ||
* | ||
* @see DeleteToDoCommandParserTest | ||
*/ | ||
public class ShowDescriptionCommandParserTest { | ||
|
||
private ShowDescriptionCommandParser parser = new ShowDescriptionCommandParser(); | ||
|
||
@Test | ||
public void parse_validArgs_returnsSelectCommand() { | ||
assertParseSuccess(parser, "1", new ShowDescriptionCommand(INDEX_FIRST_ELEMENT)); | ||
} | ||
|
||
@Test | ||
public void parse_invalidArgs_throwsParseException() { | ||
assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
ShowDescriptionCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this bug, I think we should probably refactor the Priority class instead.
I feel that it is more "correct" for the 'value' in the Priority class to be stored as "High", "Medium" or "Low" depending on the user input. This would probably cause a few other tests to fail also, but we need to properly refactor the code by week 13, so there's no other choice.
Ideally, we should use an enum to represent priority, but that would take even more work to modify everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one can change if have time when everything is done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think enum (vig's suggestion) is necessary since we only have 3 possibilities.