Skip to content

Commit

Permalink
Merge pull request #137 from CS2103AUG2016-W10-C2/gui-tests
Browse files Browse the repository at this point in the history
Gui tests
  • Loading branch information
bertoia authored Nov 1, 2016
2 parents f30c16f + 137ad05 commit 72bc2f4
Show file tree
Hide file tree
Showing 26 changed files with 522 additions and 311 deletions.

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/task/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public final String markString() {

//@@author A0116603R
/**
* Formats the Entry as text, showing all contact details.
* Formats the Entry as text, showing all task details.
*/
public String getAsText() {
final StringBuilder builder = new StringBuilder();
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/seedu/address/ui/util/GuiUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.ui.util;

import com.google.common.annotations.VisibleForTesting;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import seedu.address.commons.core.EventsCenter;
Expand Down Expand Up @@ -29,9 +30,10 @@ public class GuiUtil {

public static final String EVENT_DESCRIPTION_STYLE_CLASS = "event";

private static String PAST_STYLE_CLASS = "past";
private static String ACTIVE_STYLE_CLASS = "present";
private static String OVERDUE_STYLE_CLASS = "overdue";
@VisibleForTesting
public static String PAST_STYLE_CLASS = "past";
public static String ACTIVE_STYLE_CLASS = "present";
public static String OVERDUE_STYLE_CLASS = "overdue";

public static ChangeListener<Boolean> getCheckBoxEventListener(int idx) {
return (ov, old_val, new_val) -> EventsCenter.getInstance().post(new MarkTaskEvent(idx, new_val));
Expand Down
34 changes: 19 additions & 15 deletions src/test/java/guitests/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,53 @@
import seedu.address.model.task.Entry;
import seedu.address.model.task.EntryViewComparator;
import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.testutil.TestEntry;
import seedu.address.testutil.TestUtil;

import static org.junit.Assert.assertTrue;

public class AddCommandTest extends AddressBookGuiTest {
public class AddCommandTest extends TaskManagerGuiTest {

//@@author A0116603R-reused
@Test
public void add() {
//add one task
TestEntry[] currentList = td.getTypicalSortedPersons();
TestEntry testEntry = td.homework;
assertAddSuccess(testEntry, currentList);
currentList = TestUtil.addPersonsToSortedList(currentList, testEntry);
TestEntry[] currentList = td.getTypicalSortedPersons(); // sample entries already present
TestEntry testEntry;

//add another task
testEntry = td.movie;
assertAddSuccess(testEntry, currentList);
currentList = TestUtil.addPersonsToSortedList(currentList, testEntry);
//add new entries
for (TestEntry entry : td.getNonSampleEntries()) {
testEntry = entry;
assertAddSuccess(testEntry, currentList);
currentList = TestUtil.addPersonsToList(currentList, testEntry);
}

assertTrue(currentList.length > 0);

//add duplicate task
commandBox.runCommand(td.homework.getAddCommand());
commandBox.runCommand(currentList[0].getAddCommand());
assertResultMessage(AddCommand.MESSAGE_DUPLICATE_ENTRY);
assertTrue(taskList.isListMatching(currentList));

//add to empty list
commandBox.runCommand("clear");
assertAddSuccess(td.apple);
commandBox.runCommand(ClearCommand.COMMAND_WORD);
assertAddSuccess(currentList[0]);

//invalid command
commandBox.runCommand("adds Johnny");
assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);

}

//@@author
private void assertAddSuccess(TestEntry testEntry, TestEntry... currentList) {
commandBox.runCommand(testEntry.getAddCommand());

//confirm the new card contains the right data
TaskCardHandle addedCard = taskList.navigateToPerson(testEntry.getTitle().fullTitle);
TaskCardHandle addedCard = taskList.navigateToEntry(testEntry.getTitle().fullTitle);
assertMatching(testEntry, addedCard);

Entry entry = taskList.getPerson(taskList.getPersonIndex(testEntry));
Entry entry = taskList.getEntry(taskList.getTaskIndex(testEntry));
testEntry.setLastModifiedTime(entry.getLastModifiedTime());

//confirm the list now contains all previous persons plus the new task
Expand Down
18 changes: 11 additions & 7 deletions src/test/java/guitests/ClearCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
package guitests;

import org.junit.Test;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.testutil.TestEntry;
import seedu.address.testutil.TypicalTestTasks;

import static org.junit.Assert.assertTrue;

public class ClearCommandTest extends AddressBookGuiTest {
public class ClearCommandTest extends TaskManagerGuiTest {

@Test
public void clear() {

//verify a non-empty list can be cleared
assertTrue(taskList.isListMatching(td.getTypicalSortedPersons()));
assertClearCommandSuccess();

//verify other commands can work after a clear command
commandBox.runCommand(td.homework.getAddCommand());
assertTrue(taskList.isListMatching(td.homework));
commandBox.runCommand("delete 1");
TestEntry testEntry = td.getTestEntry(TypicalTestTasks.BuyTasks.TASK_1);
commandBox.runCommand(testEntry.getAddCommand());
assertTrue(taskList.isListMatching(testEntry));
commandBox.runCommand(DeleteCommand.COMMAND_WORD + " 1");
assertListSize(0);

//verify clear command works when the list is empty
assertClearCommandSuccess();
}

private void assertClearCommandSuccess() {
commandBox.runCommand("clear");
commandBox.runCommand(ClearCommand.COMMAND_WORD);
assertListSize(0);
assertResultMessage("Todo list has been cleared!");
assertResultMessage(ClearCommand.MESSAGE_SUCCESS);
}
}
10 changes: 7 additions & 3 deletions src/test/java/guitests/CommandBoxTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package guitests;

import org.junit.Test;
import seedu.address.testutil.TestEntry;
import seedu.address.testutil.TypicalTestTasks;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class CommandBoxTest extends AddressBookGuiTest {
public class CommandBoxTest extends TaskManagerGuiTest {

@Test
public void commandBox_commandSucceeds_textCleared() {
commandBox.runCommand(td.banana.getAddCommand());
TestEntry testEntry = td.getTestEntry(TypicalTestTasks.BuyTasks.TASK_1);
commandBox.runCommand(testEntry.getAddCommand());
assertEquals(commandBox.getCommandInput(), "");
}

Expand All @@ -19,9 +22,10 @@ public void commandBox_commandFails_textStays(){
assertEquals(commandBox.getCommandInput(), "invalid command text remains");
}

//@@author A0116603R
@Test
public void commandBox_commandFails_redBorder() {
commandBox.runCommand("invalid command produces red glow");
commandBox.runCommand("invalid command produces error styling");
assertTrue(commandBox.hasErrorClass());
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/guitests/DeleteCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static org.junit.Assert.assertTrue;
import static seedu.address.logic.commands.DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS;

public class DeleteCommandTest extends AddressBookGuiTest {
public class DeleteCommandTest extends TaskManagerGuiTest {

@Test
public void delete() {
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/guitests/GuiUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package guitests;

import org.junit.Test;

import java.time.LocalDateTime;
import java.time.LocalTime;

import static org.junit.Assert.assertEquals;
import static seedu.address.ui.util.GuiUtil.*;

//@@author A0116603R
public class GuiUtilTest {

private LocalDateTime now = LocalDateTime.now();
private LocalDateTime midnight = LocalDateTime.of(now.toLocalDate().plusDays(1), LocalTime.MIDNIGHT);

@Test
public void taskStyling() {
assertEquals("Unmarked floating tasks have no styling", "", getTaskStyling(false));
assertEquals("Marked floating tasks have ." + PAST_STYLE_CLASS + " style class", PAST_STYLE_CLASS, getTaskStyling(true));
}

@Test
public void deadlineStyling_marked_havePastStyleRegardlessOfDeadline() {
String styleClass = getDeadlineStyling(true, now.minusWeeks(1));
assertEquals(PAST_STYLE_CLASS, styleClass);

styleClass = getDeadlineStyling(true, now.plusWeeks(1));
assertEquals(PAST_STYLE_CLASS, styleClass);
}

@Test
public void deadlineStyling_unmarked() {
assertEquals(OVERDUE_STYLE_CLASS, getDeadlineStyling(false, now.minusWeeks(1)));
assertEquals(ACTIVE_STYLE_CLASS, getDeadlineStyling(false, midnight.minusMinutes(1)));
assertEquals("", getDeadlineStyling(false, now.plusWeeks(1)));
}

@Test
public void eventStyling_past() {
assertEquals(PAST_STYLE_CLASS, getEventStyling(now.minusDays(5), now.minusDays(4)));
assertEquals(ACTIVE_STYLE_CLASS, getEventStyling(now.minusSeconds(1), now.plusHours(1)));
assertEquals("", getEventStyling(now.plusDays(1), now.plusDays(2)));
}

}
15 changes: 11 additions & 4 deletions src/test/java/guitests/HelpWindowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@

import static org.junit.Assert.assertTrue;

public class HelpWindowTest extends AddressBookGuiTest {
public class HelpWindowTest extends TaskManagerGuiTest {

//@@author A0116603R
@Test
public void openHelpWindow() {

public void openAndCloseHelpWindow() {
HelpWindowHandle helpWindowHandle = commandBox.runHelpCommand();
assertHelpWindowOpen(helpWindowHandle);

helpWindowHandle.pressEscape();
assertHelpWindowClosed();
}

private void assertHelpWindowClosed() {
assertTrue(taskList.isVisible());
}

// @@author
private void assertHelpWindowOpen(HelpWindowHandle helpWindowHandle) {
assertTrue(helpWindowHandle.isWindowOpen());
assertTrue(helpWindowHandle.isVisible());
}

}
37 changes: 28 additions & 9 deletions src/test/java/guitests/ListCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,41 @@
import java.util.Arrays;

import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.model.task.EntryViewComparator;
import seedu.address.testutil.TestEntry;
import seedu.address.testutil.TestTasks;
import seedu.address.testutil.TypicalTestTasks;

import java.util.List;

import static org.junit.Assert.assertTrue;

public class ListCommandTest extends AddressBookGuiTest {
public class ListCommandTest extends TaskManagerGuiTest {

//@@author A0116603R-reused
@Test
public void list_nonEmptyList() {
//TODO: Write better, less fragile tests
assertListResult("list nodoge"); //no results
assertListResult("list Buy", td.apple, td.banana, td.eggplant); //multiple results
// search miss
assertListResult(ListCommand.COMMAND_WORD + " 404 doge not found");

// search hits for BuyTasks
TestTasks generator = new TypicalTestTasks.BuyTasks();
assertListResult(ListCommand.COMMAND_WORD + " " + TypicalTestTasks.BuyTasks.VERB, generator.getSampleEntries());

//find after deleting one result
commandBox.runCommand("delete 1");
assertListResult("list doge",td.doge);
// search after deleting one result
commandBox.runCommand(DeleteCommand.COMMAND_WORD + " 1");
generator = new TypicalTestTasks.WatchTasks();
assertListResult(ListCommand.COMMAND_WORD + " " + TypicalTestTasks.WatchTasks.VERB, generator.getSampleEntries());
}

@Test
public void list_emptyList(){
commandBox.runCommand("clear");
assertListResult("list doge"); //no results
// clear the list and assert search miss
commandBox.runCommand(ClearCommand.COMMAND_WORD);
assertListResult(ListCommand.COMMAND_WORD + " " + TypicalTestTasks.BuyTasks.VERB);
}

@Test
Expand All @@ -41,4 +54,10 @@ private void assertListResult(String command, TestEntry... expectedHits ) {
assertResultMessage(expectedHits.length + " entries listed!");
assertTrue(taskList.isListMatching(expectedHits));
}

private void assertListResult(String command, List<TestEntry> expectedHits) {
TestEntry[] array = new TestEntry[expectedHits.size()];
expectedHits.toArray(array);
assertListResult(command, array);
}
}
Loading

0 comments on commit 72bc2f4

Please sign in to comment.