-
Notifications
You must be signed in to change notification settings - Fork 33
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
BoardAutoCreator
should not prompt for save if there is no need to #1461
#1462
Changes from 9 commits
994c265
10d5df9
24dda4d
21b276d
fe54876
1b314c4
538394e
3b9abd9
6b2ab6c
1b4a581
21870ae
060bd77
000f197
a656b9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,30 +62,35 @@ public Menu generateBoardAutoCreateMenu() { | |
Menu autoCreate = new Menu("Auto-create"); | ||
MenuItem sample = new MenuItem(SAMPLE_BOARD); | ||
sample.setOnAction(e -> { | ||
saveBoardAfterUserConfirmation(SAMPLE_BOARD); | ||
saveBoardAfterUserConfirmationIfNeeded(SAMPLE_BOARD); | ||
createSampleBoard(true); | ||
}); | ||
autoCreate.getItems().add(sample); | ||
|
||
MenuItem milestone = new MenuItem(MILESTONES); | ||
milestone.setOnAction(e -> { | ||
saveBoardAfterUserConfirmation(MILESTONES); | ||
saveBoardAfterUserConfirmationIfNeeded(MILESTONES); | ||
createMilestoneBoard(); | ||
}); | ||
autoCreate.getItems().add(milestone); | ||
|
||
MenuItem workAllocation = new MenuItem(WORK_ALLOCATION); | ||
workAllocation.setOnAction(e -> { | ||
saveBoardAfterUserConfirmation(WORK_ALLOCATION); | ||
saveBoardAfterUserConfirmationIfNeeded(WORK_ALLOCATION); | ||
createWorkAllocationBoard(); | ||
}); | ||
autoCreate.getItems().add(workAllocation); | ||
|
||
return autoCreate; | ||
} | ||
|
||
private void saveBoardAfterUserConfirmation(String boardName) { | ||
if (isSaveBoardDialogResponsePositive(boardName)) ui.getMenuControl().saveBoardAs(); | ||
private void saveBoardAfterUserConfirmationIfNeeded(String boardName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The confusing name of this method might be a call to refactor some methods or maybe add a comment explaining the |
||
boolean isOpenBoardDifferentFromSavedBoard = !prefs.getLastOpenBoardPanelInfos().isPresent() | ||
|| !prefs.getLastOpenBoardPanelInfos().get().equals(panelControl.getCurrentPanelInfos()); | ||
|
||
if (isOpenBoardDifferentFromSavedBoard && isSaveBoardDialogResponsePositive(boardName)) { | ||
ui.getMenuControl().saveBoard(); | ||
} | ||
} | ||
|
||
private boolean isSaveBoardDialogResponsePositive(String boardName) { | ||
|
@@ -202,8 +207,10 @@ private void createBoard(List<PanelInfo> panelData, String boardName) { | |
} | ||
|
||
private void triggerBoardSaveEventSequence(String boardName) { | ||
prefs.addBoard(boardName, panelControl.getCurrentPanelInfos()); | ||
List<PanelInfo> currentPanelInfos = panelControl.getCurrentPanelInfos(); | ||
prefs.addBoard(boardName, currentPanelInfos); | ||
prefs.setLastOpenBoard(boardName); | ||
prefs.setLastOpenBoardPanelInfos(currentPanelInfos); | ||
TestController.getUI().triggerEvent(new BoardSavedEvent()); | ||
logger.info("Auto-created board, saved as \"" + boardName + "\""); | ||
TestController.getUI().updateTitle(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,19 +89,25 @@ private Menu createFileMenu() { | |
} | ||
|
||
/** | ||
* Creates an empty board. User will be prompted to | ||
* confirm the action if there are unclosed panels. | ||
* Called upon the Boards > New being clicked | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments should better explain what it does rather then how it's called. |
||
*/ | ||
private void onBoardNew() { | ||
logger.info("Menu: Boards > New"); | ||
newBoard(); | ||
} | ||
|
||
/** | ||
* Creates an empty board. User will be prompted to | ||
* confirm the action if there are unclosed panels | ||
*/ | ||
public final void newBoard() { | ||
if (!isNewBoardCreationDialogConfirmed()) { | ||
logger.info("New board creation cancelled"); | ||
return; | ||
} | ||
|
||
panels.closeAllPanels(); | ||
onBoardSaveAs(); | ||
saveBoardAs(); | ||
} | ||
|
||
/** | ||
|
@@ -126,11 +132,20 @@ private boolean isNewBoardCreationDialogConfirmed() { | |
response.get().getButtonData() == ButtonData.OK_DONE; | ||
} | ||
|
||
/** | ||
* Called upon the Boards > Save being clicked | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
private void onBoardSave() { | ||
logger.info("Menu: Boards > Save"); | ||
saveBoard(); | ||
} | ||
|
||
/** | ||
* Tries to save current board. If current board is dangling, it calls {@code saveBoardAs()} | ||
*/ | ||
public final void saveBoard() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not very clear what's |
||
if (!prefs.getLastOpenBoard().isPresent()) { | ||
onBoardSaveAs(); | ||
saveBoardAs(); | ||
return; | ||
} | ||
|
||
|
@@ -141,6 +156,7 @@ private void onBoardSave() { | |
} | ||
|
||
prefs.addBoard(prefs.getLastOpenBoard().get(), panelList); | ||
prefs.setLastOpenBoardPanelInfos(panelList); | ||
ui.triggerEvent(new BoardSavedEvent()); | ||
logger.info("Board " + prefs.getLastOpenBoard().get() + " saved"); | ||
} | ||
|
@@ -167,6 +183,7 @@ public final void saveBoardAs() { | |
String boardName = response.get().trim(); | ||
prefs.addBoard(boardName, panelList); | ||
prefs.setLastOpenBoard(boardName); | ||
prefs.setLastOpenBoardPanelInfos(panelList); | ||
ui.triggerEvent(new BoardSavedEvent()); | ||
logger.info("New board " + boardName + " saved"); | ||
ui.updateTitle(); | ||
|
@@ -176,13 +193,23 @@ public final void saveBoardAs() { | |
/** | ||
* Called upon the Boards > Open being clicked | ||
*/ | ||
private void onBoardOpen(String boardName, List<PanelInfo> panelInfo) { | ||
private void onBoardOpen(String boardName, List<PanelInfo> panelInfos) { | ||
logger.info("Menu: Boards > Open > " + boardName); | ||
openBoard(boardName, panelInfos); | ||
} | ||
|
||
/** | ||
* Opens the board named {@code boardName}. | ||
* | ||
* @param boardName name of the board | ||
* @param panelInfos list of panel infos of the board | ||
*/ | ||
public final void openBoard(String boardName, List<PanelInfo> panelInfos) { | ||
panels.closeAllPanels(); | ||
panels.openPanels(panelInfo); | ||
panels.openPanels(panelInfos); | ||
panels.selectFirstPanel(); | ||
prefs.setLastOpenBoard(boardName); | ||
prefs.setLastOpenBoardPanelInfos(panelInfos); | ||
ui.updateTitle(); | ||
|
||
ui.triggerEvent(new UsedReposChangedEvent()); | ||
|
@@ -193,7 +220,15 @@ private void onBoardOpen(String boardName, List<PanelInfo> panelInfo) { | |
*/ | ||
private void onBoardDelete(String boardName) { | ||
logger.info("Menu: Boards > Delete > " + boardName); | ||
deleteBoard(boardName); | ||
} | ||
|
||
/** | ||
* Delete the board named {@boardName} | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
* @param boardName name of the board to delete | ||
*/ | ||
public final void deleteBoard(String boardName) { | ||
Alert dlg = new Alert(AlertType.CONFIRMATION, ""); | ||
dlg.initModality(Modality.APPLICATION_MODAL); | ||
dlg.setTitle("Confirmation"); | ||
|
@@ -207,6 +242,7 @@ private void onBoardDelete(String boardName) { | |
prefs.getLastOpenBoard().get().equals(boardName)) { | ||
|
||
prefs.clearLastOpenBoard(); | ||
prefs.clearLastOpenBoardPanelInfos(); | ||
} | ||
ui.triggerEvent(new BoardSavedEvent()); | ||
logger.info(boardName + " was deleted"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ public void boardAutoCreator_clickYesInSavePrompt_currentBoardSaved() { | |
pushKeys(KeyboardShortcuts.CREATE_RIGHT_PANEL); | ||
pushKeys(KeyboardShortcuts.CREATE_RIGHT_PANEL); | ||
pushKeys(KeyboardShortcuts.CREATE_RIGHT_PANEL); | ||
PlatformEx.waitOnFxThread(); | ||
assertEquals(panelCount + 3, panelControl.getPanelCount()); | ||
|
||
// create milestones board | ||
|
@@ -58,13 +59,57 @@ public void boardAutoCreator_clickYesInSavePrompt_currentBoardSaved() { | |
// save as "New Board" | ||
clickOn("OK"); | ||
|
||
PlatformEx.waitOnFxThread(); | ||
assertNodeExists(hasText("Milestones board has been created and loaded.\n\n" | ||
+ "It is saved under the name \"Milestones\".")); | ||
clickOn("OK"); | ||
|
||
assertEquals(2, panelControl.getNumberOfSavedBoards()); | ||
assertEquals(5, panelControl.getPanelCount()); | ||
|
||
// check that "New Board" is saved correctly | ||
traverseMenu("Boards", "Open", "New Board"); | ||
PlatformEx.waitOnFxThread(); | ||
assertEquals(panelCount + 3, panelControl.getPanelCount()); | ||
|
||
traverseMenu("Boards", "Delete", "Milestones"); | ||
waitUntilNodeAppears("OK"); | ||
clickOn("OK"); | ||
traverseMenu("Boards", "Delete", "New Board"); | ||
waitUntilNodeAppears("OK"); | ||
clickOn("OK"); | ||
} | ||
|
||
@Test | ||
public void boardAutoCreator_clickNoInSavePrompt_currentBoardSaved() { | ||
int panelCount = panelControl.getPanelCount(); | ||
assertEquals(0, panelControl.getNumberOfSavedBoards()); | ||
|
||
// create 3 new panels | ||
pushKeys(KeyboardShortcuts.CREATE_RIGHT_PANEL); | ||
pushKeys(KeyboardShortcuts.CREATE_RIGHT_PANEL); | ||
pushKeys(KeyboardShortcuts.CREATE_RIGHT_PANEL); | ||
PlatformEx.waitOnFxThread(); | ||
assertEquals(panelCount + 3, panelControl.getPanelCount()); | ||
|
||
// create milestones board | ||
traverseMenu("Boards", "Auto-create", "Milestones"); | ||
PlatformEx.waitOnFxThread(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the docs in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we should wrap it in a method that states the high level intent. The current statement doesn't match the abstraction level of the code around it. But can be done as a separate issue. |
||
waitUntilNodeAppears(String.format(SAVE_MESSAGE, "Milestones")); | ||
// do not opt to save current board | ||
clickOn("No"); | ||
|
||
PlatformEx.waitOnFxThread(); | ||
assertNodeExists(hasText("Milestones board has been created and loaded.\n\n" | ||
+ "It is saved under the name \"Milestones\".")); | ||
clickOn("OK"); | ||
|
||
assertEquals(1, panelControl.getNumberOfSavedBoards()); | ||
assertEquals(5, panelControl.getPanelCount()); | ||
|
||
traverseMenu("Boards", "Delete", "Milestones"); | ||
waitUntilNodeAppears("OK"); | ||
clickOn("OK"); | ||
} | ||
|
||
@Test | ||
|
@@ -76,6 +121,8 @@ public void milestoneBoardAutoCreationTest() { | |
PlatformEx.waitOnFxThread(); | ||
waitUntilNodeAppears(String.format(SAVE_MESSAGE, "Milestones")); | ||
clickOn("No"); | ||
|
||
PlatformEx.waitOnFxThread(); | ||
assertNodeExists(hasText("Milestones board has been created and loaded.\n\n" | ||
+ "It is saved under the name \"Milestones\".")); | ||
clickOn("OK"); | ||
|
@@ -97,6 +144,10 @@ public void milestoneBoardAutoCreationTest() { | |
assertEquals("Next Milestone", panelInfos.get(2).getPanelName()); | ||
assertEquals("Next Next Milestone", panelInfos.get(3).getPanelName()); | ||
assertEquals("Next Next Next Milestone", panelInfos.get(4).getPanelName()); | ||
|
||
traverseMenu("Boards", "Delete", "Milestones"); | ||
waitUntilNodeAppears("OK"); | ||
clickOn("OK"); | ||
} | ||
|
||
@Test | ||
|
@@ -108,6 +159,8 @@ public void workAllocationBoardAutoCreationTest() { | |
PlatformEx.waitOnFxThread(); | ||
waitUntilNodeAppears(String.format(SAVE_MESSAGE, "Work Allocation")); | ||
clickOn("No"); | ||
|
||
PlatformEx.waitOnFxThread(); | ||
assertNodeExists(hasText("Work Allocation board has been created and loaded.\n\n" | ||
+ "It is saved under the name \"Work Allocation\".")); | ||
clickOn("OK"); | ||
|
@@ -129,6 +182,10 @@ public void workAllocationBoardAutoCreationTest() { | |
assertEquals("Work allocated to User 11", panelInfos.get(2).getPanelName()); | ||
assertEquals("Work allocated to User 12", panelInfos.get(3).getPanelName()); | ||
assertEquals("Work allocated to User 2", panelInfos.get(4).getPanelName()); | ||
|
||
traverseMenu("Boards", "Delete", "Work Allocation"); | ||
waitUntilNodeAppears("OK"); | ||
clickOn("OK"); | ||
} | ||
|
||
@Test | ||
|
@@ -141,6 +198,10 @@ public void sampleBoardAutoCreationTest() { | |
waitUntilNodeAppears(SAMPLE_BOARD_DIALOG); | ||
clickOn("OK"); | ||
verifyBoard(panelControl, BoardAutoCreator.getSamplePanelDetails()); | ||
|
||
traverseMenu("Boards", "Delete", SAMPLE_BOARD); | ||
waitUntilNodeAppears("OK"); | ||
clickOn("OK"); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a change in this PR, but can you help adding the header comment for this class?