Skip to content

Commit

Permalink
Merge branch 'master' into miljyy-UG
Browse files Browse the repository at this point in the history
  • Loading branch information
miljyy authored Nov 12, 2023
2 parents d5e9cf9 + 2ddd84f commit f09b67d
Show file tree
Hide file tree
Showing 19 changed files with 339 additions and 173 deletions.
198 changes: 107 additions & 91 deletions docs/DeveloperGuide.md

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions docs/diagrams/AddLeaveSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
Expand All @@ -14,10 +13,10 @@ box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
end box

[-> LogicManager : execute("addleave EID1234-5678 2023-11-11 2023-11-11")
[-> LogicManager : execute("addleave id/EID1234-5678 from/2023-11-11 to/2023-11-11")
activate LogicManager

LogicManager -> AddressBookParser : parseCommand("addleave EID1234-5678 2023-11-11 2023-11-11")
LogicManager -> AddressBookParser : parseCommand("addleave id/EID1234-5678 from/2023-11-11 to/2023-11-11")
activate AddressBookParser

create AddLeaveCommandParser
Expand All @@ -27,7 +26,7 @@ activate AddLeaveCommandParser
AddLeaveCommandParser --> AddressBookParser
deactivate AddLeaveCommandParser

AddressBookParser -> AddLeaveCommandParser : parse("EID1234-5678 2023-11-11 2023-11-11")
AddressBookParser -> AddLeaveCommandParser : parse("id/EID1234-5678 from/2023-11-11 to/2023-11-11")
activate AddLeaveCommandParser

create AddLeaveCommand
Expand All @@ -50,8 +49,13 @@ LogicManager -> AddLeaveCommand : execute()
activate AddLeaveCommand

AddLeaveCommand -> Model : updateFilteredEmployeeList()
activate Model

Model --> AddLeaveCommand

AddLeaveCommand -> Model : setEmployee(targetEmployee, editedEmployee)
Model --> AddLeaveCommand
deactivate Model

create CommandResult
AddLeaveCommand -> CommandResult
Expand Down
11 changes: 7 additions & 4 deletions docs/diagrams/ListLeaveSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
Expand All @@ -14,10 +13,10 @@ box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
end box

[-> LogicManager : execute("listleave 2023-11-11")
[-> LogicManager : execute("listleave on/2023-11-11")
activate LogicManager

LogicManager -> AddressBookParser : parseCommand("listleave 2023-11-11")
LogicManager -> AddressBookParser : parseCommand("listleave on/2023-11-11")
activate AddressBookParser

create ListLeaveCommandParser
Expand All @@ -27,7 +26,7 @@ activate ListLeaveCommandParser
ListLeaveCommandParser --> AddressBookParser
deactivate ListLeaveCommandParser

AddressBookParser -> ListLeaveCommandParser : parse("2023-11-11")
AddressBookParser -> ListLeaveCommandParser : parse("on/2023-11-11")
activate ListLeaveCommandParser

create ListLeaveCommand
Expand All @@ -50,6 +49,10 @@ LogicManager -> ListLeaveCommand : execute()
activate ListLeaveCommand

ListLeaveCommand -> Model : updateFilteredEmployeeList()
activate Model

Model --> ListLeaveCommand
deactivate Model

create CommandResult
ListLeaveCommand -> CommandResult
Expand Down
Binary file modified docs/images/uml-diagrams/AddLeaveSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/uml-diagrams/ListLeaveSequenceDiagram.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 docs/team/inezkok.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Given below are my contributions to the project.
* Added implementation guide for reset, editleave, addremark and deleteremark feature (including their UML diagrams)
* Added instructions for manual testing for reset, editleave, addremark and deleteremark feature
* Added and updated user stories
* Added efforts required and achievements of the project under the Appendix: Effort

* **Community**:

Expand Down
14 changes: 1 addition & 13 deletions src/main/java/seedu/address/model/employee/Leave.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Leave(LocalDate leaveDate) {
}

/**
* Returns true if the appointment date is in the valid format.
* Returns true if the leave date is in the valid format.
*
* @param test Date to be tested.
* @return True if the date is in the valid format.
Expand All @@ -44,18 +44,6 @@ public static boolean isValidLeaveDate(String test) {
return true;
}

/**
* Returns true if the date is the present date or in the future.
*
* @param test Date to be tested.
* @return True if date is not in the past.
*/
public static boolean isFutureDate(String test) {
LocalDate currDate = LocalDate.now();
LocalDate testDate = LocalDate.parse(test, VALID_DATE_FORMAT);
return !testDate.isBefore(currDate);
}

@Override
public String toString() {
return leaveDate == null ? "no leave scheduled!" : leaveDate.format(VALID_DATE_FORMAT);
Expand Down
33 changes: 1 addition & 32 deletions src/main/java/seedu/address/model/employee/LeaveList.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package seedu.address.model.employee;

import static seedu.address.model.employee.Employee.MAX_NUM_OF_LEAVES;

import java.time.LocalDate;
import java.util.ArrayList;

/**
* Represents a list of leaves taken by an employee.
* Guarantees: immutable; is valid as declared in {@link #isValidLeaveList(ArrayList)}
* Guarantees: immutable
*/
public class LeaveList {

Expand Down Expand Up @@ -48,15 +46,6 @@ public int getSize() {
return leaveList.size();
}

/**
* Returns true if the current size of the LeaveList is less than the maximum allowable size.
*
* @param maxLeaves The maximum number of leaves allowed in the LeaveList.
*/
public boolean isWithinLimit(int maxLeaves) {
return leaveList.size() < maxLeaves;
}

/**
* Adds a new leave of type Leave to this LeaveList.
*
Expand Down Expand Up @@ -109,26 +98,6 @@ public boolean getLeaveStatus(LocalDate date) {
}
}

/**
* Returns true if a given ArrayList is a valid LeaveList.
*
* @param test List to be tested
*/
public static boolean isValidLeaveList(ArrayList<Leave> test) {
if (test.isEmpty()) {
return true;
}
if (test.size() > MAX_NUM_OF_LEAVES) {
return false;
}
for (int i = 0; i < test.size(); i++) {
if (Leave.isValidLeaveDate(test.get(i).toString())) {
return true;
}
}
return false;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/seedu/address/model/remark/RemarkList.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ public Remark getRemark(int zeroBasedIndex) {
return remarkList.get(zeroBasedIndex);
}

public int getSize() {
return remarkList.size();
}

public void addRemark(Remark remark) {
remarkList.add(remark);
}
Expand Down Expand Up @@ -70,21 +66,4 @@ public String toString() {
}
return sb.toString();
}

/**
* Returns true if a given ArrayList is a valid RemarkList.
*
* @param test List to be tested
*/
public static boolean isValidRemarkList(ArrayList<Remark> test) {
if (test.isEmpty()) {
return true;
}
for (int i = 0; i < test.size(); i++) {
if (Remark.isValidRemark(test.get(i).toString())) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.VALID_DEPARTMENT_FINANCE;
import static seedu.address.logic.commands.CommandTestUtil.VALID_DEPARTMENT_IT;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ID_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_OVERTIME_HOURS_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_POSITION_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_REMARKLIST_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_SALARY_BOB;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.DeleteLeaveCommand.MESSAGE_NO_LEAVES_FOUND;
Expand Down Expand Up @@ -63,6 +71,36 @@ void execute_leavesExist_success() {
assertCommandSuccess(deleteLeaveCommand, model, expectedMessage, expectedModel);
}

@Test
void execute_atLeastOneLeaveExists_success() {
LocalDate startLeave = BOB.getLeaveList().getLeave(0).leaveDate;
LocalDate endLeave = startLeave.plusDays(14);
// leave period to delete exceeds maximum number of leaves
// means at least one date in leave period is not in employee's leave list
DeleteLeaveCommand command = new DeleteLeaveCommand(BOB.getId(), startLeave, endLeave);
LeaveList editedLeaveList = new LeaveList();
editedLeaveList.deleteLeave(new Leave(startLeave)); // since BOB only has one leave
Employee editedEmployee = new EmployeeBuilder().withName(VALID_NAME_BOB)
.withPosition(VALID_POSITION_BOB)
.withId(VALID_ID_BOB)
.withPhone(VALID_PHONE_BOB)
.withEmail(VALID_EMAIL_BOB)
.withDepartments(VALID_DEPARTMENT_FINANCE, VALID_DEPARTMENT_IT)
.withSalary(VALID_SALARY_BOB)
.withOvertimeHours(VALID_OVERTIME_HOURS_BOB)
.withLeaveList(editedLeaveList.leaveList)
.withRemarkList(VALID_REMARKLIST_BOB)
.build();

String expectedMessage = String.format(MESSAGE_SUCCESS, Messages.formatLeaves(editedEmployee));
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());

model.addEmployee(BOB);
expectedModel.addEmployee(editedEmployee);

assertCommandSuccess(command, model, expectedMessage, expectedModel);
}

@Test
void execute_leavesNotExist_failure() {
LocalDate leaveDate = BOB.getLeaveList().getLeave(0).leaveDate.plusDays(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_DEPARTMENT_IT;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ID_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_LEAVELIST_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_OVERTIME_HOURS_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
Expand All @@ -18,6 +19,7 @@
import static seedu.address.testutil.TypicalEmployees.getTypicalAddressBook;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -80,6 +82,16 @@ void execute_oldLeaveNotExist_failure() {
assertCommandFailure(editLeaveCommand, model, EditLeaveCommand.MESSAGE_NON_EXISTENT_LEAVE);
}

@Test
void execute_newLeaveExist_failure() {
VALID_LEAVELIST_BOB.add(new Leave(LocalDate.parse("2023-10-31", DateTimeFormatter.ISO_LOCAL_DATE)));
LocalDate oldLeaveDate = BOB.getLeaveList().getLeave(0).leaveDate;
LocalDate newLeaveDate = BOB.getLeaveList().getLeave(1).leaveDate;
EditLeaveCommand editLeaveCommand = new EditLeaveCommand(BOB.getId(), oldLeaveDate, newLeaveDate);
model.addEmployee(BOB);
assertCommandFailure(editLeaveCommand, model, EditLeaveCommand.MESSAGE_DUPLICATE_LEAVE);
}

@Test
void execute_oldLeaveNewLeaveSame_failure() {
// also tests for if new leave already exists (since to reach this stage, old leave has to exist)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void execute_decrementOvertimeHoursFilteredList_success() {
}

@Test
public void execute_incrementOvertimeHours_failure() {
public void execute_incrementOvertimeHoursExceedMaximum_failure() {
Index indexLastEmployee = Index.fromOneBased(model.getAddressBook().getEmployeeList().size());
Employee lastEmployee = model.getAddressBook().getEmployeeList().get(indexLastEmployee.getZeroBased());
OvertimeHours changeInOvertimeHours = new OvertimeHours(VALID_OVERTIME_HOURS_BOB);
Expand All @@ -118,7 +118,7 @@ public void execute_incrementOvertimeHours_failure() {
}

@Test
public void execute_decrementOvertimeHours_failure() {
public void execute_decrementOvertimeHoursExceedMinimum_failure() {
Employee employee = model.getAddressBook().getEmployeeList().get(INDEX_FIRST_EMPLOYEE.getZeroBased());
OvertimeHours changeInOvertimeHours = new OvertimeHours(VALID_OVERTIME_HOURS_BOB);
OvertimeCommand overtimeCommand = new OvertimeCommand(employee.getId(), changeInOvertimeHours, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ void isValidField_invalidField_throwsCommandException() {
ResetCommand resetCommand = new ResetCommand("overtime");

// empty field
assertThrows(CommandException.class, () -> resetCommand.isValidField(""));
assertThrows(CommandException.class, () -> resetCommand.isValidField(NO_FIELD));

// invalid field
assertThrows(CommandException.class, () -> resetCommand.isValidField("blah"));
assertThrows(CommandException.class, () -> resetCommand.isValidField(INVALID_FIELD));
}

@Test
void isValidField_validField_doesNotThrow() {
ResetCommand resetCommand = new ResetCommand("overtime");
assertAll(() -> {
// overtime
resetCommand.isValidField("overtime");
resetCommand.isValidField(OVERTIME_FIELD);

// leaves
resetCommand.isValidField("leaves");
resetCommand.isValidField(LEAVES_FIELD);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.junit.jupiter.api.Test;

import seedu.address.logic.Messages;
import seedu.address.logic.commands.AddRemarkCommand;
import seedu.address.model.employee.Id;
import seedu.address.model.remark.Remark;
Expand Down Expand Up @@ -44,6 +45,10 @@ void parse_invalidValue_failure() {
// empty id
userInput = " " + PREFIX_ID + " " + PREFIX_REMARK + "good worker";
assertParseFailure(parser, userInput, Id.MESSAGE_CONSTRAINTS);

// empty remark
userInput = " " + PREFIX_ID + VALID_ID_BOB + " " + PREFIX_REMARK;
assertParseFailure(parser, userInput, Messages.MESSAGE_MISSING_REMARK);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void parse_invalidValue_failure() {

// invalid date
assertParseFailure(parser, " on/2023-02-30", Messages.MESSAGE_INVALID_DATE);
assertParseFailure(parser, " on/2023-30-12", Messages.MESSAGE_INVALID_DATE);
assertParseFailure(parser, " on/2023-31-11", Messages.MESSAGE_INVALID_DATE);

// invalid format
assertParseFailure(parser, " on/30-12-2023", Messages.MESSAGE_INVALID_DATE);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/model/employee/IdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void constructor_invalidId_throwsIllegalArgumentException() {
}

@Test
public void isValidName() {
public void isValidId() {
// null id
assertThrows(NullPointerException.class, () -> Id.isValidId(null));

Expand Down
Loading

0 comments on commit f09b67d

Please sign in to comment.