Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2103-F13-2#80 from sheryew/Add_test_cases
Browse files Browse the repository at this point in the history
Add test cases
  • Loading branch information
nixonwidjaja authored Oct 19, 2023
2 parents 2a01fb2 + b2c5fd9 commit c55fd01
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ Examples:

Views employee(s)'s personal attribute.

Format: `view [n/INDEX] [a/INDEX] [e/INDEX] [e/INDEX] [s/INDEX] [b/INDEX] [d/INDEX] [dob/INDEX]`
Format: `view [n/INDEX] [a/INDEX] [e/INDEX] [p/INDEX] [s/INDEX] [b/INDEX] [d/INDEX] [dob/INDEX]`

- Gives an overview of employee(s)'s attributes.
- ViewCommand provides overview of employee(s)'s attributes.
- Maximum of one prefix is allowed. This means user can only view one attribute at a time.
- INDEX parameters can either be a single digit or digits separated by ",".

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/seedu/address/logic/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
public class ViewCommand extends Command {

public static final String COMMAND_WORD = "view";
public static final String WRONG_PREFIX = "Allowed Formats: n/, a/, e/, s/, b/, d/, dob/.\n"
+ "Example: view n/1,2";
public static final String WRONG_PREFIX = "ViewCommand provides "
+ "overview of employee(s)'s attributes.\n"
+ "Allowed Formats: n/, a/, e/, p/, s/, b/, d/, dob/.\n"
+ "Example: view n/1,2";
public static final String EXCESS_PREFIX = "Kindly input only one prefix.\n"
+ "Allowed Format: n/, a/, e/, s/, b/, dob/.\n"
+ "Allowed Format: n/, a/, e/, p/, s/, b/, d/, dob/.\n"
+ "Example: view n/1,2";

public final HashMap<String, List<Index>> references;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<?import javafx.scene.layout.VBox?>

<fx:root type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"
title="Address App" minWidth="450" minHeight="600" onCloseRequest="#handleExit">
title="HR Insight" minWidth="450" minHeight="600" onCloseRequest="#handleExit">
<icons>
<Image url="@/images/address_book_32.png" />
</icons>
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/seedu/address/logic/commands/ViewCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.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;
Expand All @@ -16,6 +17,7 @@
import static seedu.address.logic.parser.ViewCommandParser.PHONE_IDENTIFIER;
import static seedu.address.logic.parser.ViewCommandParser.SALARY_IDENTIFIER;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import java.util.HashMap;
Expand All @@ -26,6 +28,7 @@

import seedu.address.commons.core.index.Index;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.ParserUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
Expand Down Expand Up @@ -90,6 +93,41 @@ public void execute_validViewClaimBudgetDepartment_success() {
assertCommandSuccess(newViewCommand, model, expectedResponse, model);
}

@Test
public void execute_validMultiplePhone_failure() throws CommandException {
HashMap<String, List<Index>> mutiplePhonesMap = new HashMap<String, List<Index>>() {{
put("Phone", List.of(INDEX_FIRST_PERSON, INDEX_SECOND_PERSON));
}};
ViewCommand newViewCommand = new ViewCommand(mutiplePhonesMap);
Person firstPersonToView = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person secondPersonToView = model.getFilteredPersonList().get(INDEX_SECOND_PERSON.getZeroBased());
String wrongReponse = String.format("You are viewing Department:\n"
+ "1. %s's Department is %s.\n\n", firstPersonToView.getName(), firstPersonToView.getDepartment())
+ String.format("You are viewing Claim Budget:\n"
+ "1. %s's Claim Budget is %s.\n\n", secondPersonToView.getName(), secondPersonToView.getClaimBudget());
assertNotEquals(newViewCommand.execute(model).toString(), wrongReponse);
}

@Test
public void execute_validMultipleEmail_success() throws CommandException {
HashMap<String, List<Index>> mutiplePhonesMap = new HashMap<String, List<Index>>() {{
put("Email", List.of(INDEX_FIRST_PERSON, INDEX_SECOND_PERSON));
}};
ViewCommand newViewCommand = new ViewCommand(mutiplePhonesMap);
Person firstPersonToView = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person secondPersonToView = model.getFilteredPersonList().get(INDEX_SECOND_PERSON.getZeroBased());
String expectedResponse = String.format("You are viewing Email:\n"
+ "1. %s's Email is %s.\n", firstPersonToView.getName(), firstPersonToView.getEmail())
+ String.format("2. %s's Email is %s.\n\n", secondPersonToView.getName(),
secondPersonToView.getEmail());
assertCommandSuccess(newViewCommand, model, expectedResponse, model);
}

@Test
public void generate_assertionPrefix_success() {
assertDoesNotThrow(() -> viewCommand.massAssertionFn("Name"));
}

@Test
public void generate_assertionPrefix_failure() {
assertThrows(AssertionError.class, () -> viewCommand.massAssertionFn("INVALID_KEY"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;
import static seedu.address.logic.parser.ViewCommandParser.CLAIM_BUDGET;
import static seedu.address.logic.parser.ViewCommandParser.DEPARTMENT;
import static seedu.address.logic.parser.ViewCommandParser.SALARY_IDENTIFIER;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -21,7 +23,7 @@ public class ViewCommandParserTest {
private ViewCommandParser parser = new ViewCommandParser();

@Test
public void parse_withAllFields_presentreturnssuccess() throws ParseException {
public void parse_withClaim_presentReturnsSuccess() throws ParseException {
String userInput = " b/1";
Index index = ParserUtil.parseIndex("1");
List<Index> indexOne = new ArrayList<>(List.of(index));
Expand All @@ -31,6 +33,28 @@ public void parse_withAllFields_presentreturnssuccess() throws ParseException {
assertParseSuccess(parser, userInput, successCommand);
}

@Test
public void parse_withDepartment_presentReturnsSuccess() throws ParseException {
String userInput = " d/2";
Index index = ParserUtil.parseIndex("2");
List<Index> indexTwo = new ArrayList<>(List.of(index));
HashMap<String, List<Index>> successHashMap = new HashMap<>();
successHashMap.put(DEPARTMENT, indexTwo);
ViewCommand successCommand = new ViewCommand(successHashMap);
assertParseSuccess(parser, userInput, successCommand);
}

@Test
public void parse_withSalary_presentReturnsSuccess() throws ParseException {
String userInput = " s/4";
Index index = ParserUtil.parseIndex("4");
List<Index> indexTwo = new ArrayList<>(List.of(index));
HashMap<String, List<Index>> successHashMap = new HashMap<>();
successHashMap.put(SALARY_IDENTIFIER, indexTwo);
ViewCommand successCommand = new ViewCommand(successHashMap);
assertParseSuccess(parser, userInput, successCommand);
}

@Test
public void parse_delimiter_success() {
List<String> testInputArr = new ArrayList<>(List.of("A,B,C"));
Expand Down

0 comments on commit c55fd01

Please sign in to comment.