Search in sources :

Example 1 with VariableNameGenerator

use of com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator in project tcMenu by davetcc.

the class UIActionItemAndCoreTest method testEnteringBadValuesIntoBaseEditor.

@Test
void testEnteringBadValuesIntoBaseEditor(FxRobot robot) throws InterruptedException {
    MenuItem subItem = menuTree.getSubMenuById(100).orElseThrow();
    VariableNameGenerator vng = new VariableNameGenerator(menuTree, false);
    var uiSubItem = editorUI.createPanelForMenuItem(subItem, menuTree, vng, mockedConsumer);
    // open the sub menu item editor panel
    createMainPanel(uiSubItem);
    // firstly check that all the fields are populated properly
    performAllCommonChecks(subItem, false);
    tryToEnterBadValueIntoField(robot, "nameField", "variableField", "This#Is+Err", "Name - Text can only contain letters, numbers, spaces and '-_()*%'");
    tryToEnterBadValueIntoField(robot, "nameField", "variableField", "", "Name - field must not be blank and less than 19 characters");
    tryToEnterBadValueIntoField(robot, "functionNameTextField", "variableField", "name spaces", "Field must use only letters, digits, and '_'");
    tryToEnterBadValueIntoField(robot, "nameField", "variableField", "This name is too long for menuitem", "Name - field must not be blank and less than 19 characters");
    tryToEnterBadValueIntoField(robot, "functionNameTextField", "nameField", "19_Bad", "Field must use only letters, digits, and '_'");
    ArgumentCaptor<MenuItem> captor = ArgumentCaptor.forClass(MenuItem.class);
    verify(mockedConsumer, atLeastOnce()).accept(eq(subItem), captor.capture());
    assertEquals(-1, captor.getValue().getEepromAddress());
    MenuItem subItemCompare = menuTree.getSubMenuById(100).orElseThrow();
    assertEquals(-1, subItemCompare.getEepromAddress());
}
Also used : UIMenuItem(com.thecoderscorner.menu.editorui.uimodel.UIMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) Rgb32MenuItem(com.thecoderscorner.menu.domain.Rgb32MenuItem) ActionMenuItem(com.thecoderscorner.menu.domain.ActionMenuItem) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) Test(org.junit.jupiter.api.Test)

Example 2 with VariableNameGenerator

use of com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator in project tcMenu by davetcc.

the class UIAnalogMenuItemTest method testEnteringValidValuesIntoAnalogEditor.

@Test
void testEnteringValidValuesIntoAnalogEditor(FxRobot robot) throws InterruptedException {
    MenuItem analogItem = menuTree.getMenuById(1).orElseThrow();
    VariableNameGenerator vng = new VariableNameGenerator(menuTree, false);
    var uiSubItem = editorUI.createPanelForMenuItem(analogItem, menuTree, vng, mockedConsumer);
    // open the sub menu item editor panel
    createMainPanel(uiSubItem);
    // firstly check that all the fields are populated properly
    performAllCommonChecks(analogItem, true);
    robot.clickOn("#offsetField");
    robot.eraseText(5);
    robot.write("-180");
    robot.clickOn("#unitNameField");
    robot.eraseText(5);
    robot.write("dB");
    robot.clickOn("#divisorField");
    robot.eraseText(5);
    robot.write("2");
    robot.clickOn("#maxValueField");
    robot.eraseText(5);
    robot.write("255");
    verifyThatThereAreNoErrorsReported();
    ArgumentCaptor<MenuItem> captor = ArgumentCaptor.forClass(MenuItem.class);
    verify(mockedConsumer, atLeastOnce()).accept(any(), captor.capture());
    AnalogMenuItem item = (AnalogMenuItem) captor.getValue();
    assertEquals(-180, item.getOffset());
    assertEquals(255, item.getMaxValue());
    assertEquals(2, item.getDivisor());
    assertEquals("dB", item.getUnitName());
}
Also used : AnalogMenuItem(com.thecoderscorner.menu.domain.AnalogMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) AnalogMenuItem(com.thecoderscorner.menu.domain.AnalogMenuItem) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) Test(org.junit.jupiter.api.Test)

Example 3 with VariableNameGenerator

use of com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator in project tcMenu by davetcc.

the class UIEnumMenuItemTest method setup.

@Start
public void setup(Stage stage) {
    init(stage);
    enumItem = menuTree.getMenuById(20).get();
    VariableNameGenerator vng = new VariableNameGenerator(menuTree, false);
    uiSubItem = editorUI.createPanelForMenuItem(enumItem, menuTree, vng, mockedConsumer);
}
Also used : VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) Start(org.testfx.framework.junit5.Start)

Example 4 with VariableNameGenerator

use of com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator in project tcMenu by davetcc.

the class UILargeNumberItemTest method generateLargeNumDialog.

private UILargeNumberMenuItem generateLargeNumDialog() throws Exception {
    var largeNumItem = EditableLargeNumberMenuItemBuilder.aLargeNumberItemBuilder().withName("Large Num").withId(222).withEepromAddr(22).withDecimalPlaces(5).withTotalDigits(10).withNegativeAllowed(true).menuItem();
    menuTree.addMenuItem(MenuTree.ROOT, largeNumItem);
    VariableNameGenerator vng = new VariableNameGenerator(menuTree, false);
    var uiBoolItem = editorUI.createPanelForMenuItem(largeNumItem, menuTree, vng, mockedConsumer);
    if (uiBoolItem.isEmpty())
        throw new IllegalArgumentException("No menu item found");
    createMainPanel(uiBoolItem);
    return (UILargeNumberMenuItem) uiBoolItem.get();
}
Also used : UILargeNumberMenuItem(com.thecoderscorner.menu.editorui.uimodel.UILargeNumberMenuItem) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator)

Example 5 with VariableNameGenerator

use of com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator in project tcMenu by davetcc.

the class UIRemoteAndFloatMenuItemTest method testAuthenticationItem.

@Test
void testAuthenticationItem(FxRobot robot) throws InterruptedException {
    MenuItem authItem = new CustomBuilderMenuItemBuilder().withId(1001).withName("Auth test").withEepromAddr(-1).withMenuType(CustomBuilderMenuItem.CustomMenuType.AUTHENTICATION).withFunctionName("onAuth").menuItem();
    menuTree.addMenuItem(MenuTree.ROOT, authItem);
    VariableNameGenerator vng = new VariableNameGenerator(menuTree, false);
    var uiAuthPanel = editorUI.createPanelForMenuItem(authItem, menuTree, vng, mockedConsumer);
    // open the sub menu item editor panel
    createMainPanel(uiAuthPanel);
    // firstly check that all the fields are populated properly
    performAllCommonChecks(authItem, false);
    TestUtils.writeIntoField(robot, "#nameField", "new name", 10);
    ArgumentCaptor<MenuItem> captor = ArgumentCaptor.forClass(MenuItem.class);
    verify(mockedConsumer, atLeastOnce()).accept(any(), captor.capture());
    var item = (CustomBuilderMenuItem) captor.getValue();
    assertEquals("new name", item.getName());
    assertEquals(CustomBuilderMenuItem.CustomMenuType.AUTHENTICATION, item.getMenuType());
    FxAssert.verifyThat("#onlineDocsHyperlink", LabeledMatchers.hasText("Online documentation for AuthenticationItem"));
}
Also used : CustomBuilderMenuItem(com.thecoderscorner.menu.domain.CustomBuilderMenuItem) FloatMenuItem(com.thecoderscorner.menu.domain.FloatMenuItem) CustomBuilderMenuItem(com.thecoderscorner.menu.domain.CustomBuilderMenuItem) UIMenuItem(com.thecoderscorner.menu.editorui.uimodel.UIMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) CustomBuilderMenuItemBuilder(com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

VariableNameGenerator (com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator)20 MenuItem (com.thecoderscorner.menu.domain.MenuItem)13 Test (org.junit.jupiter.api.Test)13 UIMenuItem (com.thecoderscorner.menu.editorui.uimodel.UIMenuItem)8 ActionMenuItem (com.thecoderscorner.menu.domain.ActionMenuItem)4 Rgb32MenuItem (com.thecoderscorner.menu.domain.Rgb32MenuItem)4 AnalogMenuItem (com.thecoderscorner.menu.domain.AnalogMenuItem)3 CustomBuilderMenuItem (com.thecoderscorner.menu.domain.CustomBuilderMenuItem)3 FloatMenuItem (com.thecoderscorner.menu.domain.FloatMenuItem)3 HashSet (java.util.HashSet)3 BiConsumer (java.util.function.BiConsumer)3 CustomBuilderMenuItemBuilder (com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder)2 BooleanMenuItem (com.thecoderscorner.menu.domain.BooleanMenuItem)1 Rgb32MenuItemBuilder (com.thecoderscorner.menu.domain.Rgb32MenuItemBuilder)1 ScrollChoiceMenuItem (com.thecoderscorner.menu.domain.ScrollChoiceMenuItem)1 MenuTree (com.thecoderscorner.menu.domain.state.MenuTree)1 CodeGeneratorOptions (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions)1 CodeGeneratorOptionsBuilder (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder)1 IoExpanderDefinitionCollection (com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection)1 EepromAuthenticatorDefinition (com.thecoderscorner.menu.editorui.generator.parameters.auth.EepromAuthenticatorDefinition)1