diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 658acb38988..6f867937954 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -71,6 +71,7 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); List lastShownList = model.getFilteredPersonList(); Person toDelete = null; + boolean PersonDetailsDeleted = false; for (Person person : lastShownList) { if (person.getStudentId().equals(studentId)) { @@ -84,14 +85,41 @@ public CommandResult execute(Model model) throws CommandException { } if (module != null) { - if (!toDelete.hasModule(module)) { + Module moduleToDelete = null; + for (Module currModule : toDelete.getModules()) { + if (currModule.equals(module)) { + moduleToDelete = currModule; + break; + } + } + + if (moduleToDelete == null) { throw new CommandException(String.format(MESSAGE_MODULE_NOT_FOUND, toDelete.getStudentId())); } - model.deleteModule(toDelete, module); - return new CommandResult(String.format(MESSAGE_DELETE_MODULE_SUCCESS, module.toString())); + + model.deleteModule(toDelete, moduleToDelete); + if (toDelete.isSamePerson(model.getPersonToDisplay())) { + for (Person person : lastShownList) { + if (person.getStudentId().equals(studentId)) { + toDelete = person; + break; + } + } + model.setPersonToDisplay(toDelete); + return new CommandResult(String.format(MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete), true); + } + return new CommandResult(String.format(MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete)); + } + + if (toDelete.isSamePerson(model.getPersonToDisplay())) { + model.setPersonToDisplay(null); + PersonDetailsDeleted = true; } model.deletePerson(toDelete); + if (PersonDetailsDeleted) { + return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(toDelete)), true); + } return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(toDelete))); } diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 9da3fc29d6d..59f04668cab 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -93,8 +93,14 @@ public CommandResult execute(Model model) throws CommandException { throw new CommandException(MESSAGE_DUPLICATE_PERSON); } + model.setPerson(personToEdit, editedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + + if (personToEdit.isSamePerson(model.getPersonToDisplay())) { + model.setPersonToDisplay(editedPerson); + return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)), true); + } return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); } @@ -118,12 +124,12 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Module newModule = editPersonDescriptor.newModule; boolean isModuleRenamed = false; - if (updatedModules.stream().anyMatch(m -> m.value.equals(newModule.value))) { + if (updatedModules.stream().anyMatch(m -> m.value.toUpperCase().equals(newModule.value.toUpperCase()))) { throw new CommandException(EditCommand.MESSAGE_DUPLICATE_MODULE); } for (int i = 0; i < updatedModules.size(); i++) { - if (updatedModules.get(i).value.equals(oldModule.value)) { + if (updatedModules.get(i).value.toUpperCase().equals(oldModule.value.toUpperCase())) { Module updatedModule = new Module(newModule.value); if (updatedModules.get(i).hasGrade()) { updatedModule.setGrade(updatedModules.get(i).getGrade()); diff --git a/src/main/java/seedu/address/logic/commands/GradeCommand.java b/src/main/java/seedu/address/logic/commands/GradeCommand.java index f6e33391fd7..227406ee750 100644 --- a/src/main/java/seedu/address/logic/commands/GradeCommand.java +++ b/src/main/java/seedu/address/logic/commands/GradeCommand.java @@ -81,6 +81,10 @@ public CommandResult execute(Model model) throws CommandException { Person updatedPerson = person.setModuleGrade(module, grade); model.setPerson(person, updatedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + if (updatedPerson.isSamePerson(model.getPersonToDisplay())) { + model.setPersonToDisplay(updatedPerson); + return new CommandResult(String.format(MESSAGE_SUCCESS, module), true); + } return new CommandResult(String.format(MESSAGE_SUCCESS, module)); } diff --git a/src/main/java/seedu/address/logic/commands/ModuleCommand.java b/src/main/java/seedu/address/logic/commands/ModuleCommand.java index 2562fba5f05..4cb2b01ae33 100644 --- a/src/main/java/seedu/address/logic/commands/ModuleCommand.java +++ b/src/main/java/seedu/address/logic/commands/ModuleCommand.java @@ -75,6 +75,10 @@ public CommandResult execute(Model model) throws CommandException { Person updatedPerson = person.addModule(module); model.setPerson(person, updatedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + if (updatedPerson.isSamePerson(model.getPersonToDisplay())) { + model.setPersonToDisplay(updatedPerson); + return new CommandResult(String.format(MESSAGE_SUCCESS, studentId), true); + } return new CommandResult(String.format(MESSAGE_SUCCESS, studentId)); } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 30135c38da0..85ddbc3a6c3 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -47,7 +47,8 @@ public EditCommand parse(String args) throws ParseException { if (modules.length != 2) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); } - editPersonDescriptor.setModuleChanges(new Module(modules[0].toUpperCase()), new Module(modules[1])); + editPersonDescriptor.setModuleChanges(new Module(modules[0].toUpperCase()), + new Module(modules[1].toUpperCase())); } else { if (argMultimap.getValue(PREFIX_NAME).isPresent()) { editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get() diff --git a/src/main/java/seedu/address/logic/parser/FindCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java index 634d211c2cf..06f2f7ce569 100644 --- a/src/main/java/seedu/address/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -18,7 +18,7 @@ public class FindCommandParser implements Parser { */ public FindCommand parse(String args) throws ParseException { String trimmedArg = args.trim(); - if (trimmedArg.contains(" ")) { + if (trimmedArg.isEmpty() || trimmedArg.contains(" ")) { throw new ParseException( String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); } diff --git a/src/main/java/seedu/address/logic/parser/ModuleCommandParser.java b/src/main/java/seedu/address/logic/parser/ModuleCommandParser.java index 3cfcb7f90fe..b339dfaa79f 100644 --- a/src/main/java/seedu/address/logic/parser/ModuleCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ModuleCommandParser.java @@ -32,7 +32,7 @@ public ModuleCommand parse(String args) throws ParseException { argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_MODULE); argMultimap.verifyNoDuplicateStudentId(args); StudentId studentId = ParserUtil.parseStudentId(preamble); - Module module = ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE).get().toUpperCase()); + Module module = ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE).get()); return new ModuleCommand(studentId, module); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 20d1f0e9e67..906f176e011 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -66,6 +66,7 @@ public static Name parseName(String name) throws ParseException { if (!Name.isValidName(trimmedName)) { throw new ParseException(Name.MESSAGE_CONSTRAINTS); } + trimmedName = makeCapitalise(trimmedName); return new Name(trimmedName); } @@ -96,6 +97,7 @@ public static Address parseAddress(String address) throws ParseException { if (!Address.isValidAddress(trimmedAddress)) { throw new ParseException(Address.MESSAGE_CONSTRAINTS); } + trimmedAddress = makeUppercase(trimmedAddress); return new Address(trimmedAddress); } @@ -111,6 +113,7 @@ public static Email parseEmail(String email) throws ParseException { if (!Email.isValidEmail(trimmedEmail)) { throw new ParseException(Email.MESSAGE_CONSTRAINTS); } + trimmedEmail = makeLowercase(trimmedEmail); return new Email(trimmedEmail); } @@ -126,6 +129,7 @@ public static Tag parseTag(String tag) throws ParseException { if (!Tag.isValidTag(trimmedTag)) { throw new ParseException(Tag.MESSAGE_CONSTRAINTS); } + trimmedTag = makeCapitalise(trimmedTag); return new Tag(trimmedTag); } @@ -153,6 +157,7 @@ public static Course parseCourse(String course) throws ParseException { if (!Course.isValidCourse(trimmedCourse)) { throw new ParseException(Course.MESSAGE_CONSTRAINTS); } + trimmedCourse = makeCapitalise(trimmedCourse); return new Course(trimmedCourse); } @@ -168,6 +173,7 @@ public static Module parseModule(String module) throws ParseException { if (!Module.isValidModule(trimmedModule)) { throw new ParseException(Module.MESSAGE_CONSTRAINTS); } + trimmedModule = makeUppercase(trimmedModule); return new Module(trimmedModule); } @@ -183,6 +189,43 @@ public static Grade parseGrade(String grade) throws ParseException { if (!Grade.isValidGrade(trimmedGrade)) { throw new ParseException(Grade.MESSAGE_CONSTRAINTS); } + trimmedGrade = makeUppercase(trimmedGrade); return new Grade(trimmedGrade); } + + /** + * Capitalizes the first letter of each word in the given input string + * and converts all other letters to lowercase. + * + * This method splits the input string by spaces, then processes each word + * to ensure that the first character is uppercase while the remaining characters + * are lowercase. The modified words are then joined back into a single string. + * + * @param input The input string to be capitalized. Each word's first letter will be capitalized, + * and the remaining letters will be in lowercase. + * @return A string with the first letter of each word capitalized and the rest in lowercase. + * Leading and trailing whitespace is removed. + */ + public static String makeCapitalise(String input) { + String[] words = input.split(" "); + StringBuilder capitalised = new StringBuilder(); + + for (String word : words) { + if (!word.isEmpty()) { + capitalised.append(Character.toUpperCase(word.charAt(0))) + .append(word.substring(1).toLowerCase()) + .append(" "); + } + } + + return capitalised.toString().trim(); + } + + public static String makeUppercase(String input) { + return input.toUpperCase(); + } + + public static String makeLowercase(String input) { + return input.toLowerCase(); + } } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index a8c36a9bc04..d86ddfccaef 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -144,7 +144,6 @@ public void setPerson(Person target, Person editedPerson) { requireAllNonNull(target, editedPerson); eduContacts.setPerson(target, editedPerson); - setPersonToDisplay(editedPerson); } //=========== Filtered Person List Accessors ============================================================= diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index 122faa9ddb0..e91ff206254 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -11,8 +11,8 @@ public class Phone { public static final String MESSAGE_CONSTRAINTS = - "Phone numbers should only contain numbers, and it should be at least 3 digits long"; - public static final String VALIDATION_REGEX = "\\d{3,}"; + "Phone numbers should only contain numbers, and it should be at least 8 digits long"; + public static final String VALIDATION_REGEX = "\\d{8,}"; public final String value; /** diff --git a/src/main/java/seedu/address/ui/PersonDetails.java b/src/main/java/seedu/address/ui/PersonDetails.java index c532e3b62f1..98342366608 100644 --- a/src/main/java/seedu/address/ui/PersonDetails.java +++ b/src/main/java/seedu/address/ui/PersonDetails.java @@ -93,6 +93,12 @@ public void updateDetails(Person person) { tag.setText(""); course.setText(""); module.setText(""); + profileImage.setVisible(false); + studentIdHeader.setVisible(false); + contactHeader.setVisible(false); + addressHeader.setVisible(false); + emailHeader.setVisible(false); + moduleHeader.setVisible(false); } } } diff --git a/src/main/java/seedu/address/ui/PersonListPanel.java b/src/main/java/seedu/address/ui/PersonListPanel.java index f4c501a897b..8d7e00329af 100644 --- a/src/main/java/seedu/address/ui/PersonListPanel.java +++ b/src/main/java/seedu/address/ui/PersonListPanel.java @@ -40,6 +40,7 @@ protected void updateItem(Person person, boolean empty) { if (empty || person == null) { setGraphic(null); setText(null); + setStyle("-fx-background-color: white;"); } else { setGraphic(new PersonCard(person, getIndex() + 1).getRoot()); } diff --git a/src/test/data/JsonSerializableEduContactsTest/typicalPersonsEduContacts.json b/src/test/data/JsonSerializableEduContactsTest/typicalPersonsEduContacts.json index 2c14094c707..fd79c572a7f 100644 --- a/src/test/data/JsonSerializableEduContactsTest/typicalPersonsEduContacts.json +++ b/src/test/data/JsonSerializableEduContactsTest/typicalPersonsEduContacts.json @@ -53,7 +53,7 @@ }, { "studentId": "25252525", "name" : "Elle Meyer", - "phone" : "9482224", + "phone" : "94822244", "email" : "werner@example.com", "address" : "michegan ave", "course": "biomedical engineering", @@ -68,7 +68,7 @@ }, { "studentId": "98989898", "name" : "Fiona Kunz", - "phone" : "9482427", + "phone" : "94824272", "email" : "lydia@example.com", "address" : "little tokyo", "course": "Data Science", @@ -76,7 +76,7 @@ }, { "studentId": "28184003", "name" : "George Best", - "phone" : "9482442", + "phone" : "94824422", "email" : "anna@example.com", "address" : "4th street", "course": "Dentistry", diff --git a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java index 8c93b162633..847d7b26c63 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GRADE_AMY; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; @@ -16,6 +17,7 @@ import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; +import seedu.address.model.person.Grade; import seedu.address.model.person.Module; import seedu.address.model.person.Person; import seedu.address.model.person.StudentId; @@ -185,4 +187,60 @@ public void execute_invalidStudentIdWithModule_throwsCommandException() { deleteCommand, model, String.format(DeleteCommand.MESSAGE_PERSON_NOT_FOUND, invalidStudentId)); } + @Test + public void execute_deleteModuleWhenPersonDisplayed_success() { + Person personToDisplay = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + model.setPersonToDisplay(personToDisplay); + + Module moduleToDelete = new Module("CS2103T"); + Person updatedPerson = personToDisplay.addModule(moduleToDelete); + model.setPerson(personToDisplay, updatedPerson); + + DeleteCommand deleteCommand = new DeleteCommand(personToDisplay.getStudentId(), moduleToDelete); + + String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete.toString()); + + ModelManager expectedModel = new ModelManager(model.getEduContacts(), new UserPrefs(), personToDisplay); + expectedModel.deleteModule(updatedPerson, moduleToDelete); + assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_deleteModuleWhenPersonNotDisplayed_success() { + Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + Person personToDisplay = model.getFilteredPersonList().get(INDEX_SECOND_PERSON.getZeroBased()); + + model.setPersonToDisplay(personToDisplay); + + Module moduleToDelete = new Module("CS2103T"); + Person updatedPerson = personToDelete.addModule(moduleToDelete); + model.setPerson(personToDelete, updatedPerson); + + DeleteCommand deleteCommand = new DeleteCommand(personToDelete.getStudentId(), moduleToDelete); + + String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete.toString()); + + ModelManager expectedModel = new ModelManager(model.getEduContacts(), new UserPrefs(), personToDisplay); + expectedModel.deleteModule(updatedPerson, moduleToDelete); + + assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_deleteGradedModule_success() { + Person personWithModule = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + StudentId studentIdToDelete = personWithModule.getStudentId(); + Module moduleToDelete = personWithModule.getModules().get(0); + moduleToDelete.setGrade(new Grade(VALID_GRADE_AMY)); + + DeleteCommand deleteCommand = new DeleteCommand(studentIdToDelete, moduleToDelete); + String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete); + + ModelManager expectedModel = new ModelManager(model.getEduContacts(), new UserPrefs()); + expectedModel.deleteModule(personWithModule, moduleToDelete); + + + assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel); + } + } diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 05d70be73f3..0936010489c 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -175,19 +175,6 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); } - @Test - public void execute_noFieldSpecifiedUnfilteredList_success() { - StudentId studentId = model.getFilteredPersonList().get(0).getStudentId(); - EditCommand editCommand = new EditCommand(studentId, new EditPersonDescriptor()); - Person editedPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - - String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); - - Model expectedModel = new ModelManager(new EduContacts(model.getEduContacts()), new UserPrefs(), editedPerson); - - assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); - } - @Test public void execute_filteredList_success() { showPersonAtIndex(model, INDEX_FIRST_PERSON); @@ -231,6 +218,35 @@ public void execute_invalidPersonIndexFilteredList_failure() { assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_STUDENTID); } + @Test + public void execute_personDisplayedEdited_success() throws CommandException { + + Person personToDisplay = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + model.setPersonToDisplay(personToDisplay); + + EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder() + .withName("Edited Name") + .withPhone("98765432") + .withEmail("edited@example.com") + .build(); + + EditCommand editCommand = new EditCommand(personToDisplay.getStudentId(), descriptor); + + Person editedPerson = new PersonBuilder(personToDisplay) + .withName("Edited Name") + .withPhone("98765432") + .withEmail("edited@example.com") + .build(); + + String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); + + Model expectedModel = new ModelManager(model.getEduContacts(), new UserPrefs()); + expectedModel.setPerson(personToDisplay, editedPerson); + expectedModel.setPersonToDisplay(editedPerson); + + assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); + } + @Test public void equals() { StudentId firstPersonId = model.getFilteredPersonList().get(0).getStudentId(); diff --git a/src/test/java/seedu/address/logic/commands/GradeCommandTest.java b/src/test/java/seedu/address/logic/commands/GradeCommandTest.java index fcf8b1c128c..527dbbef8ca 100644 --- a/src/test/java/seedu/address/logic/commands/GradeCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/GradeCommandTest.java @@ -11,6 +11,7 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_STUDENTID_BOB; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalPersons.getTypicalEduContacts; import org.junit.jupiter.api.Test; @@ -79,6 +80,28 @@ public void execute_moduleNotFound_throwsCommandException() { -> gradeCommand.execute(model)); } + @Test + public void execute_gradeAddedWhenPersonDisplayed_success() { + Person personToAddGrade = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + Person expectedStudent = new PersonBuilder(personToAddGrade).build(); + + Module validModule = new Module(VALID_MODULE_AMY); + Grade validGrade = new Grade(VALID_GRADE_AMY); + Person newPerson = personToAddGrade.addModule(validModule); + model.setPerson(model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()), newPerson); + expectedStudent = expectedStudent.addModule(validModule); + expectedStudent = expectedStudent.setModuleGrade(validModule, validGrade); + GradeCommand gradeCommand = new GradeCommand(personToAddGrade.getStudentId(), validModule, validGrade); + model.setPersonToDisplay(expectedStudent); + String expectedMessage = String.format(GradeCommand.MESSAGE_SUCCESS, validModule); + + Model expectedModel = new ModelManager(new EduContacts(model.getEduContacts()), + new UserPrefs(), expectedStudent); + expectedModel.setPerson(model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()), expectedStudent); + + assertCommandSuccess(gradeCommand, model, expectedMessage, expectedModel); + } + @Test public void equals() { StudentId amyId = new StudentId(VALID_STUDENTID_AMY); diff --git a/src/test/java/seedu/address/logic/commands/ModuleCommandTest.java b/src/test/java/seedu/address/logic/commands/ModuleCommandTest.java index 110758f51a2..16b00cc72f2 100644 --- a/src/test/java/seedu/address/logic/commands/ModuleCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ModuleCommandTest.java @@ -9,6 +9,7 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_STUDENTID_BOB; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalPersons.getTypicalEduContacts; import org.junit.jupiter.api.Test; @@ -72,6 +73,24 @@ public void execute_studentNotFound_throwsCommandException() { -> moduleCommand.execute(model)); } + @Test + public void execute_moduleAddedWhenPersonDisplayed_success() { + Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + Person expectedStudent = new PersonBuilder(personToDelete).build(); + model.setPersonToDisplay(expectedStudent); + Module validModule = new Module(VALID_MODULE_AMY); + expectedStudent = expectedStudent.addModule(validModule); + ModuleCommand moduleCommand = new ModuleCommand(personToDelete.getStudentId(), validModule); + + String expectedMessage = String.format(ModuleCommand.MESSAGE_SUCCESS, personToDelete.getStudentId()); + + Model expectedModel = new ModelManager(new EduContacts(model.getEduContacts()), + new UserPrefs(), expectedStudent); + expectedModel.setPerson(model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()), expectedStudent); + + assertCommandSuccess(moduleCommand, model, expectedMessage, expectedModel); + } + @Test public void equals() { StudentId amyId = new StudentId(VALID_STUDENTID_AMY); diff --git a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index 39d051d64f0..27715a3a62c 100644 --- a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -22,13 +22,17 @@ public class FindCommandParserTest { private FindCommandParser parser = new FindCommandParser(); @Test - public void parse_validArgs_returnsDeleteCommand() { + public void parse_validArgs_returnsFindCommand() { StudentId validStudentId = new StudentId(CommandTestUtil.VALID_STUDENTID_BOB); assertParseSuccess(parser, validStudentId.toString(), new FindCommand(validStudentId)); } @Test public void parse_invalidArgs_throwsParseException() { + // empty input + assertParseFailure(parser, "", + String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + // multiple arguments assertParseFailure(parser, "11111111 abc", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index 8de427470f2..3f01b92f364 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -21,7 +21,7 @@ public class ParserUtilTest { private static final String INVALID_TAG = "#friend"; private static final String VALID_NAME = "Rachel Walker"; - private static final String VALID_PHONE = "123456"; + private static final String VALID_PHONE = "12345678"; private static final String VALID_ADDRESS = "123 Main Street #0505"; private static final String VALID_EMAIL = "rachel@example.com"; private static final String VALID_TAG_1 = "Student"; diff --git a/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java b/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java index 7251d9c3d8a..dc1917faba9 100644 --- a/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java +++ b/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java @@ -63,7 +63,7 @@ public void test_nameDoesNotContainKeywords_returnsFalse() { assertFalse(predicate.test(new PersonBuilder().withName("Alice Bob").build())); predicate = new NameContainsKeywordsPredicate(Arrays.asList("12345", "alice@email.com", "Main", "Street")); - assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("12345") + assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("12345678") .withEmail("alice@email.com").withAddress("Main Street").build())); } diff --git a/src/test/java/seedu/address/model/person/PhoneTest.java b/src/test/java/seedu/address/model/person/PhoneTest.java index deaaa5ba190..859318534d4 100644 --- a/src/test/java/seedu/address/model/person/PhoneTest.java +++ b/src/test/java/seedu/address/model/person/PhoneTest.java @@ -27,23 +27,22 @@ public void isValidPhone() { // invalid phone numbers assertFalse(Phone.isValidPhone("")); // empty string assertFalse(Phone.isValidPhone(" ")); // spaces only - assertFalse(Phone.isValidPhone("91")); // less than 3 numbers + assertFalse(Phone.isValidPhone("911")); // less than 8 numbers assertFalse(Phone.isValidPhone("phone")); // non-numeric assertFalse(Phone.isValidPhone("9011p041")); // alphabets within digits assertFalse(Phone.isValidPhone("9312 1534")); // spaces within digits // valid phone numbers - assertTrue(Phone.isValidPhone("911")); // exactly 3 numbers - assertTrue(Phone.isValidPhone("93121534")); + assertTrue(Phone.isValidPhone("93121534")); // exactly 8 numbers assertTrue(Phone.isValidPhone("124293842033123")); // long phone numbers } @Test public void equals() { - Phone phone = new Phone("999"); + Phone phone = new Phone("99999999"); // same values -> returns true - assertTrue(phone.equals(new Phone("999"))); + assertTrue(phone.equals(new Phone("99999999"))); // same object -> returns true assertTrue(phone.equals(phone)); @@ -55,6 +54,6 @@ public void equals() { assertFalse(phone.equals(5.0f)); // different values -> returns false - assertFalse(phone.equals(new Phone("995"))); + assertFalse(phone.equals(new Phone("99599959"))); } } diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java index 6173842e7a2..314fd8fcba5 100644 --- a/src/test/java/seedu/address/testutil/TypicalPersons.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -75,7 +75,7 @@ public class TypicalPersons { public static final Person ELLE = new PersonBuilder() .withStudentId("25252525") .withName("Elle Meyer") - .withPhone("9482224") + .withPhone("94822244") .withEmail("werner@example.com") .withAddress("michegan ave") .withCourse("biomedical engineering") @@ -86,7 +86,7 @@ public class TypicalPersons { public static final Person FIONA = new PersonBuilder() .withStudentId("98989898") .withName("Fiona Kunz") - .withPhone("9482427") + .withPhone("94824272") .withEmail("lydia@example.com") .withAddress("little tokyo") .withCourse("Data Science") @@ -95,7 +95,7 @@ public class TypicalPersons { public static final Person GEORGE = new PersonBuilder() .withStudentId("28184003") .withName("George Best") - .withPhone("9482442") + .withPhone("94824422") .withEmail("anna@example.com") .withAddress("4th street") .withCourse("Dentistry") @@ -108,7 +108,7 @@ public class TypicalPersons { public static final Person HOON = new PersonBuilder() .withStudentId("15159888") .withName("Hoon Meier") - .withPhone("8482424") + .withPhone("84842424") .withEmail("stefan@example.com") .withAddress("little india") .withCourse("Mechanical engineering") @@ -117,7 +117,7 @@ public class TypicalPersons { public static final Person IDA = new PersonBuilder() .withStudentId("48883999") .withName("Ida Mueller") - .withPhone("8482131") + .withPhone("84842131") .withEmail("hans@example.com") .withAddress("chicago ave") .withCourse("Architecture")