From c1c35c7396999d2e7165d5e5866d622420c98ab9 Mon Sep 17 00:00:00 2001 From: Tan Wang Leng Date: Sun, 7 Jan 2018 19:15:52 +0800 Subject: [PATCH 1/2] StatusBarFooter: Show total persons In order to determine the total number of contacts in the address book, the user has to scroll the list all the way down to the last person, as the ID of the last person gives an indication of the total number of persons. This forces the user to use the graphical user interface to find such an information. Let's modify StatusBarFooter so that it shows the total number of persons in the current address book. --- .../java/seedu/address/ui/MainWindow.java | 3 ++- .../seedu/address/ui/StatusBarFooter.java | 13 +++++++-- src/main/resources/view/StatusBarFooter.fxml | 3 ++- .../guihandles/StatusBarFooterHandle.java | 27 +++++++++++++++++++ .../seedu/address/ui/StatusBarFooterTest.java | 26 ++++++++++++------ 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 0e361a4d7baf..75d5b3cbabb5 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -128,7 +128,8 @@ void fillInnerParts() { ResultDisplay resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); - StatusBarFooter statusBarFooter = new StatusBarFooter(prefs.getAddressBookFilePath()); + StatusBarFooter statusBarFooter = new StatusBarFooter(prefs.getAddressBookFilePath(), + logic.getFilteredPersonList().size()); statusbarPlaceholder.getChildren().add(statusBarFooter.getRoot()); CommandBox commandBox = new CommandBox(logic); diff --git a/src/main/java/seedu/address/ui/StatusBarFooter.java b/src/main/java/seedu/address/ui/StatusBarFooter.java index f6ba29502422..b01fd13c089b 100644 --- a/src/main/java/seedu/address/ui/StatusBarFooter.java +++ b/src/main/java/seedu/address/ui/StatusBarFooter.java @@ -24,6 +24,8 @@ public class StatusBarFooter extends UiPart { public static final String SYNC_STATUS_INITIAL = "Not updated yet in this session"; public static final String SYNC_STATUS_UPDATED = "Last Updated: %s"; + public static final String TOTAL_PERSONS_STATUS = "%d person(s) total"; + /** * Used to generate time stamps. * @@ -41,13 +43,15 @@ public class StatusBarFooter extends UiPart { @FXML private StatusBar syncStatus; @FXML + private StatusBar totalPersonsStatus; + @FXML private StatusBar saveLocationStatus; - - public StatusBarFooter(Path saveLocation) { + public StatusBarFooter(Path saveLocation, int totalPersons) { super(FXML); setSyncStatus(SYNC_STATUS_INITIAL); setSaveLocation(Paths.get(".").resolve(saveLocation).toString()); + setTotalPersons(totalPersons); registerAsAnEventHandler(this); } @@ -73,11 +77,16 @@ private void setSyncStatus(String status) { Platform.runLater(() -> syncStatus.setText(status)); } + private void setTotalPersons(int totalPersons) { + Platform.runLater(() -> totalPersonsStatus.setText(String.format(TOTAL_PERSONS_STATUS, totalPersons))); + } + @Subscribe public void handleAddressBookChangedEvent(AddressBookChangedEvent abce) { long now = clock.millis(); String lastUpdated = new Date(now).toString(); logger.info(LogsCenter.getEventHandlingLogMessage(abce, "Setting last updated status to " + lastUpdated)); setSyncStatus(String.format(SYNC_STATUS_UPDATED, lastUpdated)); + setTotalPersons(abce.data.getPersonList().size()); } } diff --git a/src/main/resources/view/StatusBarFooter.fxml b/src/main/resources/view/StatusBarFooter.fxml index 041e1ff9004f..a449715511e4 100644 --- a/src/main/resources/view/StatusBarFooter.fxml +++ b/src/main/resources/view/StatusBarFooter.fxml @@ -10,5 +10,6 @@ - + + diff --git a/src/test/java/guitests/guihandles/StatusBarFooterHandle.java b/src/test/java/guitests/guihandles/StatusBarFooterHandle.java index 33c5d1d788b8..0a744047a9c9 100644 --- a/src/test/java/guitests/guihandles/StatusBarFooterHandle.java +++ b/src/test/java/guitests/guihandles/StatusBarFooterHandle.java @@ -11,18 +11,22 @@ public class StatusBarFooterHandle extends NodeHandle { public static final String STATUS_BAR_PLACEHOLDER = "#statusbarPlaceholder"; private static final String SYNC_STATUS_ID = "#syncStatus"; + private static final String TOTAL_PERSONS_STATUS_ID = "#totalPersonsStatus"; private static final String SAVE_LOCATION_STATUS_ID = "#saveLocationStatus"; private final StatusBar syncStatusNode; + private final StatusBar totalPersonsStatusNode; private final StatusBar saveLocationNode; private String lastRememberedSyncStatus; + private String lastRememberedTotalPersonsStatus; private String lastRememberedSaveLocation; public StatusBarFooterHandle(Node statusBarFooterNode) { super(statusBarFooterNode); syncStatusNode = getChildNode(SYNC_STATUS_ID); + totalPersonsStatusNode = getChildNode(TOTAL_PERSONS_STATUS_ID); saveLocationNode = getChildNode(SAVE_LOCATION_STATUS_ID); } @@ -33,6 +37,13 @@ public String getSyncStatus() { return syncStatusNode.getText(); } + /** + * Returns the text of the 'total persons' portion of the status bar. + */ + public String getTotalPersonsStatus() { + return totalPersonsStatusNode.getText(); + } + /** * Returns the text of the 'save location' portion of the status bar. */ @@ -55,6 +66,22 @@ public boolean isSyncStatusChanged() { return !lastRememberedSyncStatus.equals(getSyncStatus()); } + + /** + * Remembers the content of the 'total persons' portion of the status bar. + */ + public void rememberTotalPersonsStatus() { + lastRememberedTotalPersonsStatus = getTotalPersonsStatus(); + } + + /** + * Returns true if the current content of the 'total persons' is different from the value remembered by the most + * recent {@code rememberTotalPersonsStatus()} call. + */ + public boolean isTotalPersonsStatusChanged() { + return !lastRememberedTotalPersonsStatus.equals(getTotalPersonsStatus()); + } + /** * Remembers the content of the 'save location' portion of the status bar. */ diff --git a/src/test/java/seedu/address/ui/StatusBarFooterTest.java b/src/test/java/seedu/address/ui/StatusBarFooterTest.java index c7d21684a472..f8f29b058d4b 100644 --- a/src/test/java/seedu/address/ui/StatusBarFooterTest.java +++ b/src/test/java/seedu/address/ui/StatusBarFooterTest.java @@ -2,8 +2,10 @@ import static org.junit.Assert.assertEquals; import static seedu.address.testutil.EventsUtil.postNow; +import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.ui.StatusBarFooter.SYNC_STATUS_INITIAL; import static seedu.address.ui.StatusBarFooter.SYNC_STATUS_UPDATED; +import static seedu.address.ui.StatusBarFooter.TOTAL_PERSONS_STATUS; import java.nio.file.Path; import java.nio.file.Paths; @@ -19,14 +21,17 @@ import guitests.guihandles.StatusBarFooterHandle; import seedu.address.commons.events.model.AddressBookChangedEvent; -import seedu.address.model.AddressBook; +import seedu.address.testutil.AddressBookBuilder; public class StatusBarFooterTest extends GuiUnitTest { private static final Path STUB_SAVE_LOCATION = Paths.get("Stub"); private static final Path RELATIVE_PATH = Paths.get("."); - private static final AddressBookChangedEvent EVENT_STUB = new AddressBookChangedEvent(new AddressBook()); + private static final AddressBookChangedEvent EVENT_STUB = new AddressBookChangedEvent( + new AddressBookBuilder().withPerson(ALICE).build()); + + private static final int INITIAL_TOTAL_PERSONS = 0; private static final Clock originalClock = StatusBarFooter.getClock(); private static final Clock injectedClock = Clock.fixed(Instant.now(), ZoneId.systemDefault()); @@ -47,7 +52,7 @@ public static void tearDownAfterClass() { @Before public void setUp() { - StatusBarFooter statusBarFooter = new StatusBarFooter(STUB_SAVE_LOCATION); + StatusBarFooter statusBarFooter = new StatusBarFooter(STUB_SAVE_LOCATION, INITIAL_TOTAL_PERSONS); uiPartRule.setUiPart(statusBarFooter); statusBarFooterHandle = new StatusBarFooterHandle(statusBarFooter.getRoot()); @@ -56,21 +61,26 @@ public void setUp() { @Test public void display() { // initial state - assertStatusBarContent(RELATIVE_PATH.resolve(STUB_SAVE_LOCATION).toString(), SYNC_STATUS_INITIAL); + assertStatusBarContent(RELATIVE_PATH.resolve(STUB_SAVE_LOCATION).toString(), SYNC_STATUS_INITIAL, + String.format(TOTAL_PERSONS_STATUS, INITIAL_TOTAL_PERSONS)); // after address book is updated postNow(EVENT_STUB); assertStatusBarContent(RELATIVE_PATH.resolve(STUB_SAVE_LOCATION).toString(), - String.format(SYNC_STATUS_UPDATED, new Date(injectedClock.millis()).toString())); + String.format(SYNC_STATUS_UPDATED, new Date(injectedClock.millis()).toString()), + String.format(TOTAL_PERSONS_STATUS, EVENT_STUB.data.getPersonList().size())); } /** - * Asserts that the save location matches that of {@code expectedSaveLocation}, and the - * sync status matches that of {@code expectedSyncStatus}. + * Asserts that the save location matches that of {@code expectedSaveLocation}, the + * sync status matches that of {@code expectedSyncStatus}, and the total persons matches that of + * {@code expectedTotalPersonsStatus}. */ - private void assertStatusBarContent(String expectedSaveLocation, String expectedSyncStatus) { + private void assertStatusBarContent(String expectedSaveLocation, String expectedSyncStatus, + String expectedTotalPersonsStatus) { assertEquals(expectedSaveLocation, statusBarFooterHandle.getSaveLocation()); assertEquals(expectedSyncStatus, statusBarFooterHandle.getSyncStatus()); + assertEquals(expectedTotalPersonsStatus, statusBarFooterHandle.getTotalPersonsStatus()); guiRobot.pauseForHuman(); } From c4ab24684eb8b724330949f68d9579181d568a49 Mon Sep 17 00:00:00 2001 From: Tan Wang Leng Date: Sun, 7 Jan 2018 19:18:26 +0800 Subject: [PATCH 2/2] AddressBookSystemTest: Verify that total person status is updated The application now shows the total number of persons in the address book on the status bar. Let's modify the system tests to verify the new behavior. --- .../systemtests/AddCommandSystemTest.java | 2 +- .../systemtests/AddressBookSystemTest.java | 27 ++++++++++++++++++- .../systemtests/ClearCommandSystemTest.java | 2 +- .../systemtests/DeleteCommandSystemTest.java | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/test/java/systemtests/AddCommandSystemTest.java b/src/test/java/systemtests/AddCommandSystemTest.java index c656bca6f0fd..b12735270fd6 100644 --- a/src/test/java/systemtests/AddCommandSystemTest.java +++ b/src/test/java/systemtests/AddCommandSystemTest.java @@ -222,7 +222,7 @@ private void assertCommandSuccess(String command, Model expectedModel, String ex assertApplicationDisplaysExpected("", expectedResultMessage, expectedModel); assertSelectedCardUnchanged(); assertCommandBoxShowsDefaultStyle(); - assertStatusBarUnchangedExceptSyncStatus(); + assertStatusBarChangedExceptSaveLocation(); } /** diff --git a/src/test/java/systemtests/AddressBookSystemTest.java b/src/test/java/systemtests/AddressBookSystemTest.java index bf1743e3d16e..0f6e46cfefe5 100644 --- a/src/test/java/systemtests/AddressBookSystemTest.java +++ b/src/test/java/systemtests/AddressBookSystemTest.java @@ -7,6 +7,7 @@ import static seedu.address.ui.BrowserPanel.DEFAULT_PAGE; import static seedu.address.ui.StatusBarFooter.SYNC_STATUS_INITIAL; import static seedu.address.ui.StatusBarFooter.SYNC_STATUS_UPDATED; +import static seedu.address.ui.StatusBarFooter.TOTAL_PERSONS_STATUS; import static seedu.address.ui.UiPart.FXML_FILE_FOLDER; import static seedu.address.ui.testutil.GuiTestAssert.assertListMatching; @@ -191,6 +192,7 @@ private void rememberStates() { StatusBarFooterHandle statusBarFooterHandle = getStatusBarFooter(); getBrowserPanel().rememberUrl(); statusBarFooterHandle.rememberSaveLocation(); + statusBarFooterHandle.rememberTotalPersonsStatus(); statusBarFooterHandle.rememberSyncStatus(); getPersonListPanel().rememberSelectedPersonCard(); } @@ -255,12 +257,14 @@ protected void assertCommandBoxShowsErrorStyle() { protected void assertStatusBarUnchanged() { StatusBarFooterHandle handle = getStatusBarFooter(); assertFalse(handle.isSaveLocationChanged()); + assertFalse(handle.isTotalPersonsStatusChanged()); assertFalse(handle.isSyncStatusChanged()); } /** * Asserts that only the sync status in the status bar was changed to the timing of - * {@code ClockRule#getInjectedClock()}, while the save location remains the same. + * {@code ClockRule#getInjectedClock()}, while the save location and the total person + * list remains the same. */ protected void assertStatusBarUnchangedExceptSyncStatus() { StatusBarFooterHandle handle = getStatusBarFooter(); @@ -268,6 +272,25 @@ protected void assertStatusBarUnchangedExceptSyncStatus() { String expectedSyncStatus = String.format(SYNC_STATUS_UPDATED, timestamp); assertEquals(expectedSyncStatus, handle.getSyncStatus()); assertFalse(handle.isSaveLocationChanged()); + assertFalse(handle.isTotalPersonsStatusChanged()); + } + + /** + * Asserts that the sync status in the status bar was changed to the timing of + * {@code ClockRule#getInjectedClock()}, and total persons was changed to match the total + * number of persons in the address book, while the save location remains the same. + */ + protected void assertStatusBarChangedExceptSaveLocation() { + StatusBarFooterHandle handle = getStatusBarFooter(); + + String timestamp = new Date(clockRule.getInjectedClock().millis()).toString(); + String expectedSyncStatus = String.format(SYNC_STATUS_UPDATED, timestamp); + assertEquals(expectedSyncStatus, handle.getSyncStatus()); + + final int totalPersons = testApp.getModel().getAddressBook().getPersonList().size(); + assertEquals(String.format(TOTAL_PERSONS_STATUS, totalPersons), handle.getTotalPersonsStatus()); + + assertFalse(handle.isSaveLocationChanged()); } /** @@ -281,6 +304,8 @@ private void assertApplicationStartingStateIsCorrect() { assertEquals(Paths.get(".").resolve(testApp.getStorageSaveLocation()).toString(), getStatusBarFooter().getSaveLocation()); assertEquals(SYNC_STATUS_INITIAL, getStatusBarFooter().getSyncStatus()); + assertEquals(String.format(TOTAL_PERSONS_STATUS, getModel().getAddressBook().getPersonList().size()), + getStatusBarFooter().getTotalPersonsStatus()); } /** diff --git a/src/test/java/systemtests/ClearCommandSystemTest.java b/src/test/java/systemtests/ClearCommandSystemTest.java index fb01059d9fe4..86b4c7112513 100644 --- a/src/test/java/systemtests/ClearCommandSystemTest.java +++ b/src/test/java/systemtests/ClearCommandSystemTest.java @@ -77,7 +77,7 @@ private void assertCommandSuccess(String command, String expectedResultMessage, executeCommand(command); assertApplicationDisplaysExpected("", expectedResultMessage, expectedModel); assertCommandBoxShowsDefaultStyle(); - assertStatusBarUnchangedExceptSyncStatus(); + assertStatusBarChangedExceptSaveLocation(); } /** diff --git a/src/test/java/systemtests/DeleteCommandSystemTest.java b/src/test/java/systemtests/DeleteCommandSystemTest.java index 29fbb5fc3930..4b12beb6d32d 100644 --- a/src/test/java/systemtests/DeleteCommandSystemTest.java +++ b/src/test/java/systemtests/DeleteCommandSystemTest.java @@ -168,7 +168,7 @@ private void assertCommandSuccess(String command, Model expectedModel, String ex } assertCommandBoxShowsDefaultStyle(); - assertStatusBarUnchangedExceptSyncStatus(); + assertStatusBarChangedExceptSaveLocation(); } /**