use of com.thecoderscorner.menu.domain.MenuItem in project tcMenu by davetcc.
the class CurrentEditorProject method applyCommand.
public void applyCommand(EditedItemChange.Command command, MenuItem newItem, SubMenuItem parent) {
if (command == EditedItemChange.Command.NEW) {
uncommittedItems.add(newItem.getId());
} else if (command == EditedItemChange.Command.REMOVE) {
uncommittedItems.remove(newItem.getId());
}
MenuItem oldItem = changeHistory.stream().filter(item -> item.getItem() != null && item.getItem().getId() == newItem.getId()).reduce((first, second) -> second).map(MenuItemChange::getItem).orElse(newItem);
MenuItemChange change = new EditedItemChange(newItem, oldItem, parent, command);
applyCommand(change);
}
use of com.thecoderscorner.menu.domain.MenuItem in project tcMenu by davetcc.
the class MenuEditorTestCases method testAddingRemovingAndMovingOnOpenedProject.
@Test
public void testAddingRemovingAndMovingOnOpenedProject(FxRobot robot) throws Exception {
openTheCompleteMenuTree(robot);
checkTheTreeMatchesMenuTree(robot, MenuTree.ROOT);
// smoke test of the prototype area, there is a proper test of the text rendering elsewhere
assertTrue(((TextArea) robot.lookup("#prototypeTextArea").query()).getText().contains("FloatTest -12345.1235"));
// we stub out the new item dialog as it has its
MenuItem itemToAdd = aNewMenuItem();
Mockito.when(editorProjectUI.showNewItemDialog(project.getMenuTree())).thenReturn(Optional.ofNullable(itemToAdd));
// now we get hold of the sub menu and the items in the submenu
SubMenuItem subItem = project.getMenuTree().getSubMenuById(100).orElseThrow();
MenuItem childItem = project.getMenuTree().getMenuById(2).orElseThrow();
TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
// change selection in the tree to the submenu and press the add item button
assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), subItem));
robot.clickOn("#menuTreeAdd");
// make sure the item is in the tree and make sure it's been drawn properly
assertOnItemInTree(itemToAdd, true);
checkTheTreeMatchesMenuTree(robot, itemToAdd);
// now we are going to move the new item up then back down. Before this we will check
// the ordering to ensure it started off in the right order.
assertThat(project.getMenuTree().getMenuItems(subItem)).containsExactly(childItem, itemToAdd);
// move it up and see that the menu changes order and gets drawn properly
robot.clickOn("#menuTreeUp");
assertThat(project.getMenuTree().getMenuItems(subItem)).containsExactly(itemToAdd, childItem);
checkTheTreeMatchesMenuTree(robot, itemToAdd);
// and back again to the previous ordering.
robot.clickOn("#menuTreeDown");
assertThat(project.getMenuTree().getMenuItems(subItem)).containsExactly(childItem, itemToAdd);
checkTheTreeMatchesMenuTree(robot, itemToAdd);
// and then lastly lets get rid of the item we just added. Root should be selected afterwards.
robot.clickOn("#menuTreeRemove");
assertOnItemInTree(itemToAdd, false);
checkTheTreeMatchesMenuTree(robot, MenuTree.ROOT);
// at this point the project should be dirty
assertTrue(project.isDirty());
// save the project
pushCtrlAndKey(robot, KeyCode.S);
Mockito.verify(persistor, atLeastOnce()).save("fileName", "project desc", project.getMenuTree(), project.getGeneratorOptions());
// now project should be clean
assertFalse(project.isDirty());
}
use of com.thecoderscorner.menu.domain.MenuItem in project tcMenu by davetcc.
the class MenuEditorTestCases method assertOnItemInTree.
/**
* Assert if the item was (or was not) found anywhere in the tree
* @param itemToAdd item to check
* @param shouldBeThere if it should be expected to be there or not.
*/
private void assertOnItemInTree(MenuItem itemToAdd, boolean shouldBeThere) {
MenuTree tree = project.getMenuTree();
Set<MenuItem> items = tree.getAllSubMenus().stream().flatMap(sub -> tree.getMenuItems(sub).stream()).collect(Collectors.toSet());
assertEquals(shouldBeThere, items.contains(itemToAdd));
}
use of com.thecoderscorner.menu.domain.MenuItem in project tcMenu by davetcc.
the class MenuEditorTestCases method testCopyingSingleItemInTree.
@Test
void testCopyingSingleItemInTree(FxRobot robot) throws Exception {
// open the usual suspect.
openTheCompleteMenuTree(robot);
checkTheTreeMatchesMenuTree(robot, MenuTree.ROOT);
// select the item with ID 100 which is a submenu.
TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
SubMenuItem subItem = project.getMenuTree().getSubMenuById(100).orElseThrow();
assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), subItem));
Thread.sleep(500);
// sub menus can not be copied
verifyThat("#menuTreeCopy", node -> !node.isDisabled());
// now select the first sub item of the sub menu, which can be copied
MenuItem itemToCopy = project.getMenuTree().getMenuById(2).orElseThrow();
assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), itemToCopy));
// make sure there isn't an ID of 101 already in the tree and then copy it.
assertFalse(project.getMenuTree().getMenuById(101).isPresent());
when(persistor.itemsToCopyText(any(), any())).thenReturn("tcMenuCopy:[{\"parentId\":0,\"type\":\"analogItem\",\"item\":{\"maxValue\":255,\"offset\":0,\"divisor\":100,\"unitName\":\"A\",\"name\":\"Current\",\"id\":2,\"eepromAddress\":4,\"functionName\":\"onCurrentChange\",\"readOnly\":false,\"localOnly\":false,\"visible\":true}}]");
when(persistor.copyTextToItems(any())).thenReturn(List.of(new PersistedMenu(MenuTree.ROOT, itemToCopy)));
robot.clickOn("#menuTreeCopy");
// wait for copy to take effect first.
int i = 0;
while (i < 100 && robot.lookup("#menuTreePaste").queryButton().isDisable()) {
Thread.sleep(50);
i++;
}
Thread.sleep(250);
robot.clickOn("#menuTreePaste");
// now check that the new duplicate is created.
Optional<MenuItem> maybeItem = project.getMenuTree().getMenuById(101);
assertTrue(maybeItem.isPresent());
assertThat(itemToCopy).isExactlyInstanceOf(maybeItem.get().getClass());
checkTheTreeMatchesMenuTree(robot, itemToCopy);
}
use of com.thecoderscorner.menu.domain.MenuItem in project tcMenu by davetcc.
the class MenuEditorTestCases method testAreaInformationPanelNeedingUpdate.
@Test
void testAreaInformationPanelNeedingUpdate(FxRobot robot) throws Exception {
when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, false));
when(installer.getVersionOfLibrary("module.name", AVAILABLE_PLUGIN)).thenReturn(new VersionInfo("1.0.2"));
openTheCompleteMenuTree(robot);
SubMenuItem subItem = project.getMenuTree().getSubMenuById(100).orElseThrow();
TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), subItem));
assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), MenuTree.ROOT));
Thread.sleep(500);
verifyThat("#tcMenuStatusArea", LabeledMatchers.hasText("Libraries need updating, check in General Settings"));
}
Aggregations