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

Add Tests for Ui and other parts. #219

Merged
4 commits merged into from
Nov 7, 2019
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
89 changes: 57 additions & 32 deletions docs/diagrams/UiSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -1,54 +1,79 @@
@startuml
!include style.puml

box Logic LOGIC_COLOR_T1
participant ":UiManager" as UiManager LOGIC_COLOR
end box

box Ui UI_COLOR_T1
participant ":MainWindow" as MainWindow UI_COLOR
participant ":CalendarPanel" as CalendarPanel UI_COLOR
participant "ListPanel" as ListPanel UI_COLOR
participant "LogPanel" as LogPanel UI_COLOR
end box

box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
participant ":VersionedAddressBook" as VersionedAddressBook MODEL_COLOR
end box
[-> MainWindow : OnModelListChange(List)
activate LogicManager
'==== UiManager ===='
[-> UiManager : onModelListChange(lists)
activate UiManager
UiManager -> UiManager : sortDateEventList(events)
UiManager -> UiManager : sortDateTaskList(tasks)
UiManager -> UiManager : addEventIndex(events)
UiManager -> UiManager : addTaskIndex(tasks)

LogicManager -> AddressBookParser : parseCommand(undo)
activate AddressBookParser
'==== MainWindow ====
UiManager -> MainWindow : onModelListChange(events, tasks, eventHash, taskHash)
activate MainWindow

create UndoCommand
AddressBookParser -> UndoCommand
activate UndoCommand
'==== CalendarPanel ====
MainWindow -> CalendarPanel : onModelListChange(events, tasks, eventHash, taskHash)
activate CalendarPanel
CalendarPanel --> MainWindow
deactivate CalendarPanel
CalendarPanel -[hidden]--> CalendarPanel
'==== ListPanel ====
MainWindow -> ListPanel : onEventListChange(events, eventHash)
activate ListPanel
ListPanel --> MainWindow
deactivate ListPanel
ListPanel -[hidden]--> ListPanel

UndoCommand --> AddressBookParser
deactivate UndoCommand
MainWindow -> ListPanel : onTaskListChange(tasks, taskHash)
activate ListPanel
ListPanel --> MainWindow
deactivate ListPanel
ListPanel -[hidden]--> ListPanel

AddressBookParser --> LogicManager : u
deactivate AddressBookParser
'==== MainWindow ====
MainWindow --> UiManager
deactivate MainWindow
MainWindow -[hidden]--> MainWindow

LogicManager -> UndoCommand : execute()
activate UndoCommand
deactivate UiManager
UiManager -[hidden]--> UiManager

UndoCommand -> Model : undoAddressBook()
activate Model
'==== UiManager ===='
[-> UiManager : onUserOutput(output, colorTheme)
activate UiManager

Model -> VersionedAddressBook : undo()
activate VersionedAddressBook
'==== MainWindow ====
UiManager -> MainWindow : onUserOutput(output. colorTheme)
activate MainWindow
MainWindow -> MainWindow : getColor(colorTheme)

VersionedAddressBook -> VersionedAddressBook :resetData(ReadOnlyAddressBook)
VersionedAddressBook --> Model :
deactivate VersionedAddressBook
'==== LogPanel ====
MainWindow -> LogPanel : createLogBox(feedbackToUser, colorTheme)

Model --> UndoCommand
deactivate Model
activate LogPanel
LogPanel --> MainWindow
deactivate LogPanel
LogPanel -[hidden]--> LogPanel

UndoCommand --> LogicManager : result
deactivate UndoCommand
UndoCommand -[hidden]-> LogicManager : result
destroy UndoCommand
'==== MainWindow ====
MainWindow -> MainWindow : createPopUpBox
MainWindow -[hidden]> MainWindow
MainWindow --> UiManager
deactivate MainWindow

[<--LogicManager
deactivate LogicManager
deactivate UiManager
UiManager -[hidden]--> UiManager
@enduml
41 changes: 0 additions & 41 deletions src/main/java/seedu/address/commons/stub/UiManagerStub.java

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/java/seedu/address/model/CalendarDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,6 @@ public CalendarDate nextDay() {
return new CalendarDate(previousLocalDate);
}

/**
* Returns a new CalendarDate of the current day plus the given days.
*
* @param days The number of days to add.
* @return A new CalendarDate of the next days.
*/
public CalendarDate nextDays(Integer days) {
LocalDate previousLocalDate = localDate.plusDays(days);
return new CalendarDate(previousLocalDate);
}

/**
* Returns a new CalendarDate of the current day minus the given days.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ public void onModelListChange(List<EventSource> events,
List<TaskSource> tasks,
HashMap<EventSource, Integer> eventHash,
HashMap<TaskSource, Integer> taskHash) {
this.calendarPanel.onModelListChange(events, tasks, eventHash, taskHash);
this.listPanel.onEventListChange(events, eventHash);
this.listPanel.onTaskListChange(tasks, taskHash);
this.calendarPanel.onModelListChange(events, tasks, eventHash, taskHash);
}

/**
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/seedu/address/ui/stub/CalendarPanelStub.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package seedu.address.ui.stub;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import seedu.address.model.events.EventSource;
import seedu.address.model.tasks.TaskSource;
import seedu.address.ui.panel.calendar.CalendarPanel;

/**
* Represents a stub for CalendarPanel that is mainly used for testing purpose only.
*
* @see CalendarPanel
*/
class CalendarPanelStub {

/**
* Returns a combined copy of list for event list and task list into an Object list to be used.
* This is a version modified mainly for testing. The logic behind it is the exact same.
*
* @param events Represents the event list.
* @param tasks Represents the task list.
* @return A combined copy of list for event list and task list into an Object list to be used.
*/
public List<Object> combineList(List<EventSource> events, List<TaskSource> tasks) {
List<Object> eventTaskList = new ArrayList<>();
Queue<EventSource> tempEvents = new LinkedList<>();
tempEvents.addAll(events);
Queue<TaskSource> tempTasks = new LinkedList<>();
tempTasks.addAll(tasks);

// Events and Tasks are already sorted, so we need to zip them.
while (!tempEvents.isEmpty() || !tempTasks.isEmpty()) {
if (tempEvents.isEmpty()) {
eventTaskList.addAll(tempTasks);
break;
}

if (tempTasks.isEmpty()) {
eventTaskList.addAll(tempEvents);
break;
}

EventSource event = tempEvents.peek();
TaskSource task = tempTasks.peek();
if (task.isDone() || task.getDueDate() == null) {
tempTasks.poll();
continue;
}

int dateCompare = event.getStartDateTime().compareTo(task.getDueDate());
if (dateCompare == 0) {
if (event.getDescription().compareTo(task.getDescription()) <= 0) {
eventTaskList.add(tempEvents.poll());
} else {
eventTaskList.add(tempTasks.poll());
}
} else if (dateCompare < 0) {
eventTaskList.add(tempEvents.poll());
} else {
eventTaskList.add(tempTasks.poll());
}
}

return eventTaskList;
}
}
64 changes: 64 additions & 0 deletions src/main/java/seedu/address/ui/stub/TimelineWeekViewStub.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package seedu.address.ui.stub;

import java.text.DateFormatSymbols;

import seedu.address.model.CalendarDate;
import seedu.address.ui.panel.calendar.TimelineWeekView;


/**
* Represents a stub for testing purpose for TimelineWeekView.
*
* @see TimelineWeekView
*/
class TimelineWeekViewStub {

private CalendarDate calendarDate;

public TimelineWeekViewStub() {}

public TimelineWeekViewStub(CalendarDate calendarDate) {
this.calendarDate = calendarDate;
}

/**
* Returns the list of dates of the given week. Main purpose is for testing.
*
* @return A list of dates.
*/
public CalendarDate[] addWeek() {
CalendarDate[] calendarDates = new CalendarDate[7];
int weekIndex = calendarDate.getWeekIndex();
while (weekIndex > 1) {
calendarDate = calendarDate.previousDay();
weekIndex--;
}
for (int i = 0; i < calendarDates.length; i++) {
calendarDates[i] = calendarDate;
calendarDate = calendarDate.nextDay();
}
return calendarDates;
}

public Integer getWeek(CalendarDate calendarDate) {
CalendarDate currentDate = calendarDate.firstDayOfTheMonth();
Integer weekIndex = currentDate.getWeekIndex();
currentDate = currentDate.previousDays(weekIndex - 1);
for (int week = 0; week < 6; week++) {
for (int day = 0; day < 7; day++) {
if (calendarDate.equals(currentDate)) {
return week + 1;
}
currentDate = currentDate.nextDay();
}
}
// Not suppose to reach here.
return null;
}

public String getEnglishWeekDate(Integer week, Integer month, Integer year) {
String monthStr = new DateFormatSymbols().getMonths()[month - 1].toLowerCase();
monthStr = monthStr.substring(0, 1).toUpperCase() + monthStr.substring(1);
return "Week " + week + " of " + monthStr + " " + year;
}
}
Loading