Skip to content

Commit a2e0ea5

Browse files
committed
#436 more UI automated testing
1 parent efd36cb commit a2e0ea5

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

.idea/runConfigurations/TcMenuDesigner_Single_Test.xml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tcMenuGenerator/src/test/java/com/thecoderscorner/menu/editorint/uitests/uimenuitem/UIActionItemAndCoreTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,5 @@ protected LocaleMappingHandler getTestLocaleHandler() {
225225
} catch (IOException e) {
226226
throw new RuntimeException(e);
227227
}
228-
229228
}
230229
}

tcMenuGenerator/src/test/java/com/thecoderscorner/menu/editorint/uitests/uimenuitem/UIAnalogMenuItemTest.java

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator;
1313
import com.thecoderscorner.menu.editorui.uimodel.UIAnalogMenuItem;
1414
import com.thecoderscorner.menu.editorui.util.TestUtils;
15+
import com.thecoderscorner.menu.persist.LocaleMappingHandler;
16+
import com.thecoderscorner.menu.persist.PropertiesLocaleEnabledHandler;
17+
import com.thecoderscorner.menu.persist.SafeBundleLoader;
1518
import javafx.application.Platform;
1619
import javafx.stage.Stage;
1720
import org.junit.jupiter.api.AfterEach;
@@ -24,6 +27,12 @@
2427
import org.testfx.matcher.control.LabeledMatchers;
2528
import org.testfx.matcher.control.TextInputControlMatchers;
2629

30+
import java.io.File;
31+
import java.io.IOException;
32+
import java.nio.file.Files;
33+
import java.nio.file.Path;
34+
import java.util.Comparator;
35+
2736
import static org.junit.jupiter.api.Assertions.assertEquals;
2837
import static org.mockito.ArgumentMatchers.any;
2938
import static org.mockito.Mockito.atLeastOnce;
@@ -32,15 +41,21 @@
3241

3342
@ExtendWith(ApplicationExtension.class)
3443
public class UIAnalogMenuItemTest extends UIMenuItemTestBase {
44+
private Path tempPath;
3545

3646
@Start
37-
public void setup(Stage stage) {
47+
public void setup(Stage stage) throws IOException {
48+
tempPath = Files.createTempDirectory("i18ntest");
3849
init(stage);
3950
}
4051

4152
@AfterEach
42-
protected void closeWindow() {
53+
protected void closeWindow() throws IOException {
4354
Platform.runLater(() -> stage.close());
55+
Files.walk(tempPath)
56+
.sorted(Comparator.reverseOrder())
57+
.map(Path::toFile)
58+
.forEach(File::delete);
4459
}
4560

4661
@Test
@@ -64,6 +79,9 @@ void testEnteringBadValuesIntoAnalogEditor(FxRobot robot) throws InterruptedExce
6479
tryToEnterBadValueIntoField(robot, "unitNameField", "nameField", "too long",
6580
"WARNING Unit name: default storage on device is 4 characters");
6681

82+
tryToEnterBadValueIntoField(robot, "unitNameField", "nameField", "%unknown",
83+
"WARNING Unit name: no locale entry in bundle");
84+
6785
tryToEnterBadValueIntoField(robot, "divisorField", "nameField", "100000",
6886
"ERROR Divisor: Value must be between 0 and 10000");
6987

@@ -126,7 +144,11 @@ void testEnteringValidValuesIntoAnalogEditor(FxRobot robot) throws InterruptedEx
126144
writeIntoField(robot, "unitNameField", "dB");
127145
writeIntoField(robot, "divisorField", "2");
128146

129-
verifyThat("#minMaxLabel", LabeledMatchers.hasText("Min value: -90.0dB. Max value -40.0dB."));
147+
writeIntoField(robot, "unitNameField", "%menu.item.unit");
148+
149+
verifyThat("#minMaxLabel", LabeledMatchers.hasText("Min value: -90.0VA. Max value -40.0VA."));
150+
151+
writeIntoField(robot, "unitNameField", "dB", 20);
130152

131153
writeIntoField(robot, "maxValueField", "255");
132154
verifyThat("#minMaxLabel", LabeledMatchers.hasText("Min value: -90.0dB. Max value 37.5dB."));
@@ -179,4 +201,18 @@ void testValidValuesNearLimits(FxRobot robot) throws InterruptedException {
179201
assertEquals(99, MenuItemHelper.getValueFor(item, menuTree, -1));
180202
}
181203

204+
@Override
205+
protected LocaleMappingHandler getTestLocaleHandler() {
206+
try {
207+
var coreFile = tempPath.resolve("temp.properties");
208+
Files.writeString(coreFile, """
209+
menu.item.name=hello world
210+
menu.item.unit=VA
211+
""");
212+
return new PropertiesLocaleEnabledHandler(new SafeBundleLoader(tempPath, "temp"));
213+
} catch (IOException e) {
214+
throw new RuntimeException(e);
215+
}
216+
}
217+
182218
}

tcMenuGenerator/src/test/java/com/thecoderscorner/menu/editorint/uitests/uimenuitem/UIMenuItemTestBase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ protected void writeIntoField(FxRobot robot, String idField, Object value) {
9292
TestUtils.writeIntoField(robot, "#" + idField, value, 12);
9393
}
9494

95+
protected void writeIntoField(FxRobot robot, String idField, Object value, int amountToErase) {
96+
TestUtils.writeIntoField(robot, "#" + idField, value, amountToErase);
97+
}
98+
9599
protected void verifyThatThereAreNoErrorsReported() {
96100
verifyThat("#uiItemErrors", node -> !node.isVisible());
97101
}

0 commit comments

Comments
 (0)