use of com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem in project tcMenu by davetcc.
the class MenuEditorTestCases method testPuttingUpSubMenuEditorPane.
@SuppressWarnings("unchecked")
@Test
void testPuttingUpSubMenuEditorPane(FxRobot robot) throws Exception {
// open the usual menu
openTheCompleteMenuTree(robot);
checkTheTreeMatchesMenuTree(robot, MenuTree.ROOT);
// get hold of the tree and the sub menu item
TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
SubMenuItem subItem = project.getMenuTree().getSubMenuById(100).orElseThrow();
ArgumentCaptor<BiConsumer> captor = ArgumentCaptor.forClass(BiConsumer.class);
// set up the editorUI to return a panel when the submenu is chosen.
VariableNameGenerator vng = new VariableNameGenerator(project.getMenuTree(), false);
UISubMenuItem panel = new UISubMenuItem(subItem, new MenuIdChooserImpl(project.getMenuTree()), vng, (item1, item2) -> {
});
Mockito.when(editorProjectUI.createPanelForMenuItem(eq(subItem), eq(project.getMenuTree()), any(), any())).thenReturn(Optional.of(panel));
recursiveSelectTreeItem(treeView, treeView.getRoot(), subItem);
// get the consumer that takes change from the UIMenuItem back to the main controller.
// and send a simulated update to it, ensure it is processed and the tree updated.
verify(editorProjectUI).createPanelForMenuItem(eq(subItem), eq(project.getMenuTree()), any(), captor.capture());
SubMenuItem adjustedItem = SubMenuItemBuilder.aSubMenuItemBuilder().withExisting(subItem).withName("AdjustedName").menuItem();
captor.getValue().accept(subItem, adjustedItem);
// check it's been processed
MenuItem readBackAdjusted = project.getMenuTree().getMenuById(100).orElseThrow();
assertEquals(readBackAdjusted, adjustedItem);
assertEquals("AdjustedName", readBackAdjusted.getName());
// check the tree is updated
checkTheTreeMatchesMenuTree(robot, adjustedItem);
}
Aggregations