Skip to content

Commit

Permalink
Merge pull request #227 from chonguschonguschongus/branch-updateDocs
Browse files Browse the repository at this point in the history
Add test cases for DeleteAppointment and FindAppointment and changed Ui to allow for text wrapping
  • Loading branch information
kohkaijie committed Nov 12, 2023
2 parents ec3d7ef + 5a2f363 commit 8643499
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 35 deletions.
12 changes: 6 additions & 6 deletions src/main/resources/view/DoctorListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<Label fx:id="name" text="\$first" styleClass="cell_big_label" style="-fx-font-weight: bold;"/>
</HBox>
<FlowPane fx:id="tags"/>
<Label fx:id="gender" styleClass="cell_small_label" text="\$gender"/>
<Label fx:id="nric" styleClass="cell_small_label" text="\$nric"/>
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone"/>
<Label fx:id="address" styleClass="cell_small_label" text="\$address"/>
<Label fx:id="email" styleClass="cell_small_label" text="\$email"/>
<Label fx:id="remark" styleClass="cell_small_label" text="\$remark"/>
<Label fx:id="gender" styleClass="cell_small_label" text="\$gender" wrapText="true"/>
<Label fx:id="nric" styleClass="cell_small_label" text="\$nric" wrapText="true"/>
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" wrapText="true"/>
<Label fx:id="address" styleClass="cell_small_label" text="\$address" wrapText="true"/>
<Label fx:id="email" styleClass="cell_small_label" text="\$email" wrapText="true"/>
<Label fx:id="remark" styleClass="cell_small_label" text="\$remark" wrapText="true"/>
</VBox>
</GridPane>
</HBox>
16 changes: 8 additions & 8 deletions src/main/resources/view/PatientListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
<Label fx:id="name" text="\$first" styleClass="cell_big_label" style="-fx-font-weight: bold;"/>
</HBox>
<FlowPane fx:id="tags"/>
<Label fx:id="gender" styleClass="cell_small_label" text="\$gender"/>
<Label fx:id="nric" styleClass="cell_small_label" text="\$nric"/>
<Label fx:id="gender" styleClass="cell_small_label" text="\$gender" wrapText="true"/>
<Label fx:id="nric" styleClass="cell_small_label" text="\$nric" wrapText="true"/>
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone"/>
<Label fx:id="emergencyContact" styleClass="cell_small_label" text="\$emergencyContact"/>
<Label fx:id="address" styleClass="cell_small_label" text="\$address"/>
<Label fx:id="email" styleClass="cell_small_label" text="\$email"/>
<Label fx:id="bloodType" styleClass="cell_small_label" text="\$bloodType"/>
<Label fx:id="condition" styleClass="cell_small_label" text="\$condition"/>
<Label fx:id="remark" styleClass="cell_small_label" text="\$remark"/>
<Label fx:id="emergencyContact" styleClass="cell_small_label" text="\$emergencyContact" wrapText="true"/>
<Label fx:id="address" styleClass="cell_small_label" text="\$address" wrapText="true"/>
<Label fx:id="email" styleClass="cell_small_label" text="\$email" wrapText="true"/>
<Label fx:id="bloodType" styleClass="cell_small_label" text="\$bloodType" wrapText="true"/>
<Label fx:id="condition" styleClass="cell_small_label" text="\$condition" wrapText="true"/>
<Label fx:id="remark" styleClass="cell_small_label" text="\$remark" wrapText="true"/>
</VBox>
</GridPane>
</HBox>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalAddressBook.getTypicalAddressBook;
import static seedu.address.testutil.TypicalDoctor.CHERYL;
import static seedu.address.testutil.TypicalDoctor.DEREK;
import static seedu.address.testutil.TypicalDoctor.KENNY;
import static seedu.address.testutil.TypicalPatient.AMY;
import static seedu.address.testutil.TypicalPatient.BOB;

Expand Down Expand Up @@ -38,12 +38,12 @@ public void setUp() {

@Test
public void execute_newAppointment_success() {
Doctor derek = new DoctorBuilder(DEREK).build();
Doctor kenny = new DoctorBuilder(KENNY).build();
Patient bob = new PatientBuilder(BOB).build();
model.addPerson(derek);
model.addPerson(kenny);
model.addPerson(bob);
Appointment validAppointment =
new AppointmentBuilder().withDoctorIc(derek.getIc()).withPatientIc(bob.getIc()).build();
new AppointmentBuilder().withDoctorIc(kenny.getIc()).withPatientIc(bob.getIc()).build();

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedModel.addAppointment(validAppointment);
Expand All @@ -54,46 +54,46 @@ public void execute_newAppointment_success() {

// check that the appointments have been added to all patients, doctors and appointment list
Set<Appointment> patientAppointments = bob.getAppointments();
Set<Appointment> doctorAppointments = derek.getAppointments();
Set<Appointment> doctorAppointments = kenny.getAppointments();
assertTrue(patientAppointments.contains(validAppointment));
assertTrue(doctorAppointments.contains(validAppointment));
assertTrue(model.getFilteredAppointmentList().contains(validAppointment));
}

@Test
public void execute_appointmentWithPatientNotInModel_throwsCommandException() {
Doctor derek = new DoctorBuilder(DEREK).build();
Doctor kenny = new DoctorBuilder(KENNY).build();
Patient bob = new PatientBuilder(BOB).build();
// only add doctor
model.addPerson(derek);
model.addPerson(kenny);
Appointment invalidAppointment =
new AppointmentBuilder().withDoctorIc(derek.getIc()).withPatientIc(bob.getIc()).build();
new AppointmentBuilder().withDoctorIc(kenny.getIc()).withPatientIc(bob.getIc()).build();

assertCommandFailure(new AddAppointmentCommand(invalidAppointment), model,
AddAppointmentCommand.MESSAGE_INVALID_PATIENT);
}

@Test
public void execute_appointmentWithDoctorNotInModel_throwsCommandException() {
Doctor derek = new DoctorBuilder(DEREK).build();
Doctor kenny = new DoctorBuilder(KENNY).build();
Patient bob = new PatientBuilder(BOB).build();
// only add patient
model.addPerson(bob);
Appointment invalidAppointment =
new AppointmentBuilder().withDoctorIc(derek.getIc()).withPatientIc(bob.getIc()).build();
new AppointmentBuilder().withDoctorIc(kenny.getIc()).withPatientIc(bob.getIc()).build();

assertCommandFailure(new AddAppointmentCommand(invalidAppointment), model,
AddAppointmentCommand.MESSAGE_INVALID_DOCTOR);
}

@Test
public void execute_appointmentWithDoctorHasAppointmentAtTheSameTime_throwsCommandException() {
Doctor derek = new DoctorBuilder(DEREK).build();
Doctor kenny = new DoctorBuilder(KENNY).build();
Patient bob = new PatientBuilder(BOB).build();
model.addPerson(derek);
model.addPerson(kenny);
model.addPerson(bob);
Appointment validAppointment =
new AppointmentBuilder().withDoctorIc(derek.getIc()).withPatientIc(bob.getIc()).build();
new AppointmentBuilder().withDoctorIc(kenny.getIc()).withPatientIc(bob.getIc()).build();

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedModel.addAppointment(validAppointment);
Expand All @@ -104,22 +104,22 @@ public void execute_appointmentWithDoctorHasAppointmentAtTheSameTime_throwsComma

Patient amy = new PatientBuilder(AMY).build();
model.addPerson(amy);
// create another appointment between Amy and Doctor Derek at the same time
// create another appointment between Amy and Doctor kenny at the same time
Appointment invalidAppointment =
new AppointmentBuilder().withDoctorIc(derek.getIc()).withPatientIc(amy.getIc()).build();
new AppointmentBuilder().withDoctorIc(kenny.getIc()).withPatientIc(amy.getIc()).build();

assertCommandFailure(new AddAppointmentCommand(invalidAppointment), model,
AddAppointmentCommand.MESSAGE_DUPLICATE_APPOINTMENT_DOCTOR);
}

@Test
public void execute_appointmentWithPatientHasAppointmentAtTheSameTime_throwsCommandException() {
Doctor derek = new DoctorBuilder(DEREK).build();
Doctor kenny = new DoctorBuilder(KENNY).build();
Patient bob = new PatientBuilder(BOB).build();
model.addPerson(derek);
model.addPerson(kenny);
model.addPerson(bob);
Appointment validAppointment =
new AppointmentBuilder().withDoctorIc(derek.getIc()).withPatientIc(bob.getIc()).build();
new AppointmentBuilder().withDoctorIc(kenny.getIc()).withPatientIc(bob.getIc()).build();

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedModel.addAppointment(validAppointment);
Expand All @@ -140,12 +140,12 @@ public void execute_appointmentWithPatientHasAppointmentAtTheSameTime_throwsComm

@Test
public void execute_duplicateAppointment_throwsCommandException() {
Doctor derek = new DoctorBuilder(DEREK).build();
Doctor kenny = new DoctorBuilder(KENNY).build();
Patient bob = new PatientBuilder(BOB).build();
model.addPerson(derek);
model.addPerson(kenny);
model.addPerson(bob);
Appointment validAppointment =
new AppointmentBuilder().withDoctorIc(derek.getIc()).withPatientIc(bob.getIc()).build();
new AppointmentBuilder().withDoctorIc(kenny.getIc()).withPatientIc(bob.getIc()).build();

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedModel.addAppointment(validAppointment);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package seedu.address.logic.commands;

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.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.model.util.SampleDataUtil.getSampleAddressBook;

import org.junit.jupiter.api.Test;

import seedu.address.logic.Messages;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.appointment.Appointment;

/**
* Contains integration tests (interaction with the Model) and unit tests for
* {@code DeleteAppointmentCommand}.
*/
public class DeleteAppointmentCommandTest {

private Model model = new ModelManager(getSampleAddressBook(), new UserPrefs());

@Test
public void execute_validIndexUnfilteredList_success() {
Appointment appointmentToDelete = model.getFilteredAppointmentList().get(0);
int appointmentToDeleteIndex = 1;
DeleteAppointmentCommand deleteAppointmentCommand = new DeleteAppointmentCommand(appointmentToDeleteIndex);

String expectedMessage = String.format(deleteAppointmentCommand.MESSAGE_DELETE_APPOINTMENT_SUCCESS,
Messages.format(appointmentToDelete));

ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedModel.deleteAppointment(appointmentToDelete);

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

@Test
public void execute_invalidIndexUnfilteredList_throwsCommandException() {
DeleteAppointmentCommand deleteAppointmentCommand = new DeleteAppointmentCommand(4);
DeleteAppointmentCommand deleteAppointmentCommand2 = new DeleteAppointmentCommand(-1);

assertCommandFailure(deleteAppointmentCommand, model, Messages.MESSAGE_APPOINTMENT_NOT_FOUND);
assertCommandFailure(deleteAppointmentCommand2, model, Messages.MESSAGE_APPOINTMENT_NOT_FOUND);
}

@Test
public void equals() {
DeleteAppointmentCommand deleteFirstCommand = new DeleteAppointmentCommand(1);
DeleteAppointmentCommand deleteSecondCommand = new DeleteAppointmentCommand(2);

// same object -> returns true
assertTrue(deleteFirstCommand.equals(deleteFirstCommand));

// same values -> returns true
DeleteAppointmentCommand deleteFirstCommandCopy = new DeleteAppointmentCommand(1);
assertTrue(deleteFirstCommand.equals(deleteFirstCommandCopy));

// different types -> returns false
assertFalse(deleteFirstCommand.equals(1));

// null -> returns false
assertFalse(deleteFirstCommand.equals(null));

// different Appointment -> returns false
assertFalse(deleteFirstCommand.equals(deleteSecondCommand));
}

@Test
public void toStringMethod() {
DeleteAppointmentCommand deleteAppointmentCommand = new DeleteAppointmentCommand(1);
String expected = DeleteAppointmentCommand.class.getCanonicalName() + "{targetIc=" + 1 + "}";
assertEquals(expected, deleteAppointmentCommand.toString());
}

/**
* Updates {@code model}'s filtered list to show no one.
*/
private void showNoAppointment(Model model) {
model.updateFilteredAppointmentList(p -> false);

assertTrue(model.getFilteredAppointmentList().isEmpty());
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package seedu.address.logic.commands;

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.Messages.MESSAGE_APPOINTMENTS_FOUND_OVERVIEW;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.model.util.SampleDataUtil.APPOINTMENT_1;
import static seedu.address.model.util.SampleDataUtil.APPOINTMENT_2;
import static seedu.address.model.util.SampleDataUtil.getSampleAddressBook;
import static seedu.address.testutil.Assert.assertThrows;

import java.util.Arrays;
import java.util.function.Predicate;

import org.junit.jupiter.api.Test;

import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.appointment.AppointmentIcPredicate;

/**
* Contains integration tests (interaction with the Model) for {@code FindAppointmentCommand}.
*/
public class FindAppointmentCommandTest {
private Model model = new ModelManager(getSampleAddressBook(), new UserPrefs());
private Model expectedModel = new ModelManager(getSampleAddressBook(), new UserPrefs());

@Test
public void constructor_nullField_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new FindAppointmentCommand(null));
}

@Test
public void equals() {
AppointmentIcPredicate icPredicate1 = new AppointmentIcPredicate("T1234567Z");
AppointmentIcPredicate icPredicate2 = new AppointmentIcPredicate("T7654321Z");

FindAppointmentCommand findFirstCommand = new FindAppointmentCommand(icPredicate1);
FindAppointmentCommand findSecondCommand = new FindAppointmentCommand(icPredicate2);

// same object -> returns true
assertTrue(findFirstCommand.equals(findFirstCommand));

// same values -> returns true
FindAppointmentCommand findFirstCommandCopy = new FindAppointmentCommand(icPredicate1);
assertTrue(findFirstCommand.equals(findFirstCommandCopy));

// different types -> returns false
assertFalse(findFirstCommand.equals(1));

// null -> returns false
assertFalse(findFirstCommand.equals(null));

// different person -> returns false
assertFalse(findFirstCommand.equals(findSecondCommand));
}


@Test
public void execute_findPatientNric_appointmentFound() throws ParseException {
String expectedMessage = String.format(MESSAGE_APPOINTMENTS_FOUND_OVERVIEW, 2);
Predicate<Appointment> predicate = preparePredicate("S1111111Z");
FindAppointmentCommand command = new FindAppointmentCommand(predicate);
expectedModel.updateFilteredAppointmentList(predicate);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Arrays.asList(APPOINTMENT_1, APPOINTMENT_2),
model.getFilteredAppointmentList());
}

@Test
public void execute_findDoctorNric_appointmentFound() throws ParseException {
String expectedMessage = String.format(MESSAGE_APPOINTMENTS_FOUND_OVERVIEW, 1);
Predicate<Appointment> predicate = preparePredicate("S8811111Z");
FindAppointmentCommand command = new FindAppointmentCommand(predicate);
expectedModel.updateFilteredAppointmentList(predicate);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Arrays.asList(APPOINTMENT_1),
model.getFilteredAppointmentList());
}


@Test
public void toStringMethod() {
AppointmentIcPredicate predicate = new AppointmentIcPredicate("keyword");
FindAppointmentCommand findAppointmentCommand = new FindAppointmentCommand(predicate);
String expected = FindAppointmentCommand.class.getCanonicalName() + "{predicate=" + predicate + "}";
assertEquals(expected, findAppointmentCommand.toString());
}

/**
* Parses {@code userInput} into a {@code Predicate<Person>}.
*/
private Predicate<Appointment> preparePredicate(String userInput) throws ParseException {
return new AppointmentIcPredicate(userInput);
}
}
5 changes: 5 additions & 0 deletions src/test/java/seedu/address/testutil/TypicalAddressBook.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.testutil;

import seedu.address.model.AddressBook;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.person.Doctor;
import seedu.address.model.person.Patient;

Expand All @@ -21,6 +22,10 @@ public static AddressBook getTypicalAddressBook() {
for (Doctor doctor : TypicalDoctor.getTypicalDoctors()) {
ab.addDoctor(doctor);
}

for (Appointment appointment : TypicalAppointment.getTypicalAppointments()) {
ab.addAppointment(appointment);
}
return ab;
}
}
4 changes: 4 additions & 0 deletions src/test/java/seedu/address/testutil/TypicalDoctor.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public class TypicalDoctor {
.withAddress(VALID_ADDRESS_DEREK).withIc(VALID_NRIC_DEREK).withGender(VALID_GENDER_MALE)
.build();

public static final Doctor KENNY = new DoctorBuilder().withName("Kenny Pickett").withPhone("98884444")
.withEmail("kenny@gmail.com").withAddress("Woodlands Dr 55").withIc("S4445555Q").withGender("M")
.build();

public static final String KEYWORD_MATCHING_DAVID = "Beckham"; // A keyword that matches MEIER

private TypicalDoctor() {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/seedu/address/testutil/TypicalPatient.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class TypicalPatient {
.withRemark(VALID_REMARK_BOB).withCondition(VALID_CONDITION_BOB).withBloodType(VALID_BLOODTYPE_BOB)
.withTags(VALID_TAG_MEDIUM).build();


public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER

private TypicalPatient() {
Expand Down

0 comments on commit 8643499

Please sign in to comment.