Skip to content

Commit

Permalink
Merge e1ef01e into 7abc694
Browse files Browse the repository at this point in the history
  • Loading branch information
codemanmeet committed Apr 7, 2016
2 parents 7abc694 + e1ef01e commit 6164040
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ui/MenuControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public MenuControl(UI ui, PanelControl panels, ScrollPane panelsScrollPane, Pref
this.ui = ui;
this.mainStage = mainStage;
this.boardAutoCreator = new BoardAutoCreator(ui, panels, prefs);
this.panelMenuCreator = new PanelMenuCreator(panels, panelsScrollPane);
this.panelMenuCreator = new PanelMenuCreator(panels, panelsScrollPane, prefs.getLastLoginUsername());

createMenuItems();
}
Expand Down
43 changes: 27 additions & 16 deletions src/main/java/ui/PanelMenuCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,25 @@
import org.apache.logging.log4j.Logger;
import ui.issuepanel.PanelControl;

import java.util.ArrayList;
import java.util.List;
import java.util.*;

import static ui.components.KeyboardShortcuts.CLOSE_PANEL;
import static ui.components.KeyboardShortcuts.CREATE_LEFT_PANEL;
import static ui.components.KeyboardShortcuts.CREATE_RIGHT_PANEL;

public class PanelMenuCreator {

private static final Logger logger = LogManager.getLogger(MenuControl.class.getName());

public static final String MILESTONE_FILTER_NAME = "milestone:curr sort:status";
public static final String MILESTONE_PANEL_NAME = "Current Milestone";

public static final String ASSIGNEE_FILTER_NAME = "is:open ((is:issue assignee:me) OR (is:pr author:me))";
public static final String ASSIGNEE_PANEL_NAME = "Open issues and PR's";
private final String lastLoginUsername;

public static final String UPDATED_FILTER_NAME = "assignee:me updated:<48";
public static final String UPDATED_PANEL_NAME = "Recently Updated issues";
private static final Logger logger = LogManager.getLogger(MenuControl.class.getName());

private final PanelControl panelControl;
private final ScrollPane panelsScrollPane;

public PanelMenuCreator(PanelControl panelControl, ScrollPane panelsScrollPane) {
public PanelMenuCreator(PanelControl panelControl, ScrollPane panelsScrollPane, String lastLoginUsername) {
this.panelsScrollPane = panelsScrollPane;
this.panelControl = panelControl;
this.lastLoginUsername = lastLoginUsername;
}

public Menu generatePanelMenu() {
Expand All @@ -48,15 +41,33 @@ public Menu generatePanelMenu() {
items.add(createLeftPanelMenuItem());
items.add(createRightPanelMenuItem());
items.add(closePanelMenuItem());
autoCreateItems.add(createCustomizedPanelMenuItem(ASSIGNEE_PANEL_NAME, ASSIGNEE_FILTER_NAME));
autoCreateItems.add(createCustomizedPanelMenuItem(MILESTONE_PANEL_NAME, MILESTONE_FILTER_NAME));
autoCreateItems.add(createCustomizedPanelMenuItem(UPDATED_PANEL_NAME, UPDATED_FILTER_NAME));
for (Map.Entry<String, String> entry :
generatePanelDetails(lastLoginUsername).entrySet()) {
autoCreateItems.add(createPanelMenuItem(entry.getKey(), entry.getValue()));
}
autoCreatePanelMenu.getItems().addAll(autoCreateItems);
panelMenu.getItems().addAll(items);
panelMenu.getItems().add(autoCreatePanelMenu);
return panelMenu;
}

/**
* Returns a map of custom panels that can be created using the auto-create menu
* with the key of the map as the panel name and the value as the corresponding filter name.
* Uses the username as a parameter to construct the filter names.
* @param lastLoginUsername
*/
public static Map<String, String> generatePanelDetails(String lastLoginUsername){
Map<String, String> customPanel = new LinkedHashMap<>();
customPanel.put("Open issues and PR's",
String.format("is:open ((is:issue assignee:%1$s) OR (is:pr author:%2$s))", lastLoginUsername,
lastLoginUsername));
customPanel.put("Current Milestone", "milestone:curr sort:status");
customPanel.put("Recently Updated issues",
String.format("assignee:%s updated:<48", lastLoginUsername));
return Collections.unmodifiableMap(customPanel);
}

public MenuItem createLeftPanelMenuItem() {
MenuItem createLeft = new MenuItem("Create (Left)");
createLeft.setOnAction(e -> {
Expand Down Expand Up @@ -107,7 +118,7 @@ public MenuItem closePanelMenuItem() {
return closePanel;
}

public MenuItem createCustomizedPanelMenuItem(String panelName, String panelFilter) {
public MenuItem createPanelMenuItem(String panelName, String panelFilter) {
MenuItem customizedPanel = new MenuItem(panelName);
customizedPanel.setOnAction(e -> {
logger.info("Menu: Panels > Auto-create > " + panelName + "panel");
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ui/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public static Preferences loadApplicationPreferences() {
* from it if it already exists.
*/
public static Preferences loadTestPreferences() {
return Preferences.load(TEST_DIRECTORY, TEST_SESSION_CONFIG_FILENAME, TEST_USER_CONFIG_FILENAME);
Preferences prefs = Preferences.load(TEST_DIRECTORY, TEST_SESSION_CONFIG_FILENAME, TEST_USER_CONFIG_FILENAME);
prefs.setLastLoginCredentials("test", "test");
return prefs;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/guitests/LogoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void logoutFunctionTest() {
}

Preferences testPref = TestController.loadTestPreferences();
assertEquals("", testPref.getLastLoginUsername());
assertEquals("", testPref.getLastLoginPassword());
assertEquals("test", testPref.getLastLoginUsername());
assertEquals("test", testPref.getLastLoginPassword());
}

@After
Expand Down
37 changes: 16 additions & 21 deletions src/test/java/guitests/PanelMenuCreatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,39 @@
import static org.junit.Assert.assertEquals;

import prefs.PanelInfo;
import ui.TestController;
import ui.UI;
import ui.*;
import ui.issuepanel.PanelControl;
import util.PlatformEx;

import java.lang.reflect.Field;
import java.util.Map;
import java.util.Optional;

import static ui.PanelMenuCreator.ASSIGNEE_FILTER_NAME;
import static ui.PanelMenuCreator.ASSIGNEE_PANEL_NAME;
import static ui.PanelMenuCreator.MILESTONE_FILTER_NAME;
import static ui.PanelMenuCreator.MILESTONE_PANEL_NAME;
import static ui.PanelMenuCreator.UPDATED_FILTER_NAME;
import static ui.PanelMenuCreator.UPDATED_PANEL_NAME;

public class PanelMenuCreatorTest extends UITest {

private PanelControl panelControl;
private UI ui;

@Before
public void setupUIComponent() {
UI ui = TestController.getUI();
ui = TestController.getUI();
panelControl = ui.getPanelControl();
}

@Test
public void assigneePanelMenuItemTest() {
customizedPanelMenuItemTest(ASSIGNEE_PANEL_NAME, ASSIGNEE_FILTER_NAME);
}

@Test
public void milestonePanelMenuItemTest() {
customizedPanelMenuItemTest(MILESTONE_PANEL_NAME, MILESTONE_FILTER_NAME);
public void autoCreatePanels_createCustomPanelsFromMenu_panelsCreatedWithAppropriatePanelNameAndFilter()
throws NoSuchFieldException, IllegalAccessException {
PanelMenuCreator value = (PanelMenuCreator) getPanelMenuCreatorField().get(ui.getMenuControl());
for (Map.Entry<String, String> entry :
value.generatePanelDetails(ui.prefs.getLastLoginUsername()).entrySet()) {
customizedPanelMenuItemTest(entry.getKey(), entry.getValue());
}
}

@Test
public void recentlyUpdatedPanelMenuItemTest() {
customizedPanelMenuItemTest(UPDATED_PANEL_NAME, UPDATED_FILTER_NAME);
private Field getPanelMenuCreatorField() throws NoSuchFieldException, IllegalAccessException {
Field panelMenuCreatorField = MenuControl.class.getDeclaredField("panelMenuCreator");
panelMenuCreatorField.setAccessible(true);
return panelMenuCreatorField;
}

@Test
Expand Down Expand Up @@ -72,5 +68,4 @@ private void customizedPanelMenuItemTest(String panelName, String panelFilter) {
assertEquals(panelName, panelInfo.getPanelName());
traverseMenu("Panels", "Close");
}

}

0 comments on commit 6164040

Please sign in to comment.