Skip to content

Commit

Permalink
Merge pull request #108 from jamz903/jamie-week10
Browse files Browse the repository at this point in the history
Update DG with UI Section & Add assertions
  • Loading branch information
jamz903 authored Oct 27, 2023
2 parents a9d3b16 + 9b70dd3 commit b212db7
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,51 @@ This emulates the iterative deletion of all transactions in the `TransactionList

### Feature Group 4 - User Interface Features

UniCa$h is a Graphical User Interface (GUI) application, built using JavaFX. The following section describes the
implementation of the various UI components in UniCa$h.

#### UI Components
UniCa$sh consists of the following UI components:
1. Main Window
2. Help Window
3. Statistics / Budget Window

<img src="images/unicash/UiClassDiagram.png" width="404" />

In this section, we will be going through the implementation of the main window.

#### 1a. Main Window Design
The main window consists of three components: the command input box, as well as two panes,
the transaction list pane and the command results pane.

For the command input box, we have a custom `CommandBox` class that extends `TextField` to provide
the user with the ability to type their commands into the application.

For the transaction list pane, we have a custom `TransactionListPanel` class that is a `ListView` to
provide the user with a scrollable list of transactions. This view is updated whenever the user executes
commands that modify the transaction list. (i.e. `add`, `delete`, `edit`, `clear`)

For the command results pane, we have a custom `ResultDisplay` class. This pane displays the results of the
user's command execution. This view is updated whenever the user executes commands that modify the transaction.
Error messages are also displayed here, such as when the user enters an invalid command.

#### 1b. Main Window Implementation
The main window for UniCa$h is implemented using the `MainWindow` class. This class is made up of:
1. `CommandBox`: The command input box
2. `TransactionListPanel`: The transaction list pane
3. `ResultDisplay`: The command results pane

All these components, including the `MainWindow`, inherit from the abstract `UiPart` class which provides
the basic functionality of a UI component, such as the ability to set the root node of the component.

The `UI` component uses the JavaFx UI framework to render the UI components. The layout of these parts are defined
in the matching .fxml files that are located in `src/main/resources/view` folder. (e.g. The layout of the
TransactionCard is specified in`TransactionCard.fxml`)

The `UI` component is also responsible for:
- executing commands using the `Logic` component, through the `executeCommand` method
- listening for changes to the `Model` component, through the `listenToModelChanges` method

## Continuous Integration (CI)

Continuous integration consists of the following:
Expand Down
61 changes: 61 additions & 0 deletions docs/diagrams/unicash/UiClassDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@startuml
!include ../style.puml
!include ../style.puml
skinparam arrowThickness 1.1
skinparam arrowColor MODEL_COLOR
skinparam classBackgroundColor MODEL_COLOR

package UI <<Rectangle>>{
Class "<<interface>>\nUi" as Ui
Class "{abstract}\nUiPart" as UiPart
Class UiManager
Class MainWindow
Class HelpWindow
Class ResultDisplay
Class TransactionListPanel
Class TransactionCard
Class StatusBarFooter
Class CommandBox
}

package Model <<Rectangle>> {
Class HiddenModel #FFFFFF
}

package Logic <<Rectangle>> {
Class HiddenLogic #FFFFFF
}

Class HiddenOutside #FFFFFF
HiddenOutside ..> Ui

UiManager .left.|> Ui
UiManager -down-> "1" MainWindow
MainWindow *-down-> "1" CommandBox
MainWindow *-down-> "1" ResultDisplay
MainWindow *-down-> "1" TransactionListPanel
MainWindow *-down-> "1" StatusBarFooter
MainWindow --> "0..1" HelpWindow

TransactionListPanel -down-> "*" TransactionCard

MainWindow -left-|> UiPart

ResultDisplay --|> UiPart
CommandBox --|> UiPart
TransactionListPanel --|> UiPart
TransactionCard --|> UiPart
StatusBarFooter --|> UiPart
HelpWindow --|> UiPart

TransactionCard ..> Model
UiManager -right-> Logic
MainWindow -left-> Logic

TransactionListPanel -[hidden]left- HelpWindow
HelpWindow -[hidden]left- CommandBox
CommandBox -[hidden]left- ResultDisplay
ResultDisplay -[hidden]left- StatusBarFooter

MainWindow -[hidden]-|> UiPart
@enduml
Binary file added docs/images/unicash/UiClassDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/java/unicash/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public FindCommand(TransactionContainsKeywordsPredicate predicate) {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
assert predicate != null : "predicate cannot be null";
model.updateFilteredTransactionList(predicate);
return new CommandResult(
String.format(UniCashMessages.MESSAGE_TRANSACTIONS_LISTED_OVERVIEW,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/unicash/logic/parser/ListCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ListCommandParser implements Parser<ListCommand> {
*/
@Override
public ListCommand parse(String userInput) throws ParseException {
assert userInput != null : "userInput cannot be null";
//list command must not have any additional arguments
if (!userInput.trim().isBlank()) {
throw new ParseException(ListCommand.MESSAGE_FAILURE);
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/unicash/logic/commands/FindCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package unicash.logic.commands;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static unicash.logic.UniCashMessages.MESSAGE_TRANSACTIONS_LISTED_OVERVIEW;
import static unicash.logic.commands.CommandTestUtil.assertCommandSuccess;
import static unicash.testutil.Assert.assertThrows;
import static unicash.testutil.TypicalTransactions.INTERN;
import static unicash.testutil.TypicalTransactions.NUS;
import static unicash.testutil.TypicalTransactions.getTypicalUniCash;
Expand Down Expand Up @@ -84,6 +86,21 @@ public void execute_oneKeyword_multipleTransactionsFound() {
assertEquals(filteredResult.get(2), INTERN);
}

@Test
public void execute_predicateNull_assertionFailure() {
String expectedMessage = String.format(MESSAGE_TRANSACTIONS_LISTED_OVERVIEW, 0);
TransactionContainsKeywordsPredicate predicate = preparePredicate(" ");
FindCommand command = new FindCommand(null);
expectedModel.updateFilteredTransactionList(predicate);

assertThrows(AssertionError.class, () -> command.execute(model));
}

@Test
public void execute_predicateNotNull_assertion() {
assertDoesNotThrow(() -> new FindCommand(preparePredicate(" ")).execute(model));
}

@Test
public void toStringMethod() {
TransactionContainsKeywordsPredicate predicate = new TransactionContainsKeywordsPredicate(
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/unicash/logic/parser/ListCommandParserTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package unicash.logic.parser;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static unicash.logic.parser.CommandParserTestUtil.assertParseFailure;
import static unicash.logic.parser.CommandParserTestUtil.assertParseSuccess;
import static unicash.testutil.Assert.assertThrows;

import org.junit.jupiter.api.Test;

Expand All @@ -27,4 +29,15 @@ public void parse_withExcessSpacing_throwsParseException() {
//list with number
assertParseSuccess(parser, " ", new ListCommand());
}

@Test
public void parse_withNullInput_assertionFailure() {
assertThrows(AssertionError.class, () -> parser.parse(null));

}

@Test
public void execute_predicateNotNull_assertion() {
assertDoesNotThrow(() -> new ListCommandParser().parse(" "));
}
}

0 comments on commit b212db7

Please sign in to comment.