Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Total person count in status bar #4

Merged
merged 3 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/seedu/address/ui/StatusBarFooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class StatusBarFooter extends UiPart<Region> {
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.
*
Expand All @@ -33,13 +35,17 @@ public class StatusBarFooter extends UiPart<Region> {
@FXML
private Label syncStatus;
@FXML
private Label totalPersonsStatus;
@FXML
private Label saveLocationStatus;


public StatusBarFooter(Path saveLocation, ReadOnlyAddressBook addressBook) {
super(FXML);
addressBook.addListener(observable -> updateSyncStatus());
addressBook.addListener(observable -> updateTotalPersonsStatus((ReadOnlyAddressBook) observable));
syncStatus.setText(SYNC_STATUS_INITIAL);
updateTotalPersonsStatus(addressBook);
saveLocationStatus.setText(Paths.get(".").resolve(saveLocation).toString());
}

Expand All @@ -66,4 +72,12 @@ private void updateSyncStatus() {
syncStatus.setText(String.format(SYNC_STATUS_UPDATED, lastUpdated));
}

/**
* Updates person count in the status bar to the actual count.
*/
private void updateTotalPersonsStatus(ReadOnlyAddressBook addressBook) {
int personsCount = addressBook.getPersonList().size();
totalPersonsStatus.setText(String.format(TOTAL_PERSONS_STATUS, personsCount));
}

}
3 changes: 2 additions & 1 deletion src/main/resources/view/StatusBarFooter.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" halignment="RIGHT" />
</columnConstraints>
<Label fx:id="syncStatus" />
<Label fx:id="saveLocationStatus" GridPane.columnIndex="1" />
<Label fx:id="totalPersonsStatus" GridPane.columnIndex="1" />
<Label fx:id="saveLocationStatus" GridPane.columnIndex="2" />
</GridPane>
26 changes: 26 additions & 0 deletions src/test/java/guitests/guihandles/StatusBarFooterHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ public class StatusBarFooterHandle extends NodeHandle<Node> {
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 Labeled syncStatusNode;
private final Labeled totalPersonsStatusNode;
private final Labeled 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);
}

Expand All @@ -32,6 +36,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.
*/
Expand All @@ -54,6 +65,21 @@ 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.
*/
Expand Down
18 changes: 13 additions & 5 deletions src/test/java/seedu/address/ui/StatusBarFooterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -25,6 +26,8 @@ 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 int INITIAL_TOTAL_PERSONS = 0;

private static final Clock originalClock = StatusBarFooter.getClock();
private static final Clock injectedClock = Clock.fixed(Instant.now(), ZoneId.systemDefault());

Expand Down Expand Up @@ -54,21 +57,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
guiRobot.interact(() -> addressBook.addPerson(ALICE));
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, addressBook.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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/systemtests/AddCommandSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private void assertCommandSuccess(String command, Model expectedModel, String ex
assertApplicationDisplaysExpected("", expectedResultMessage, expectedModel);
assertSelectedCardUnchanged();
assertCommandBoxShowsDefaultStyle();
assertStatusBarUnchangedExceptSyncStatus();
assertStatusBarChangedExceptSaveLocation();
}

/**
Expand Down
27 changes: 26 additions & 1 deletion src/test/java/systemtests/AddressBookSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.junit.Assert.assertTrue;
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.testutil.GuiTestAssert.assertListMatching;

import java.net.MalformedURLException;
Expand Down Expand Up @@ -186,6 +187,7 @@ private void rememberStates() {
StatusBarFooterHandle statusBarFooterHandle = getStatusBarFooter();
getBrowserPanel().rememberUrl();
statusBarFooterHandle.rememberSaveLocation();
statusBarFooterHandle.rememberTotalPersonsStatus();
statusBarFooterHandle.rememberSyncStatus();
getPersonListPanel().rememberSelectedPersonCard();
}
Expand Down Expand Up @@ -250,19 +252,40 @@ 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();
String timestamp = new Date(clockRule.getInjectedClock().millis()).toString();
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());
}

/**
Expand All @@ -276,6 +299,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());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/systemtests/ClearCommandSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void assertCommandSuccess(String command, String expectedResultMessage,
executeCommand(command);
assertApplicationDisplaysExpected("", expectedResultMessage, expectedModel);
assertCommandBoxShowsDefaultStyle();
assertStatusBarUnchangedExceptSyncStatus();
assertStatusBarChangedExceptSaveLocation();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/systemtests/DeleteCommandSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void assertCommandSuccess(String command, Model expectedModel, String ex
}

assertCommandBoxShowsDefaultStyle();
assertStatusBarUnchangedExceptSyncStatus();
assertStatusBarChangedExceptSaveLocation();
}

/**
Expand Down