*/ public class ScreenshotIT extends AbstractIT { + private static final String IDENTITY_TERM = "λx.x"; + /** * We'll want to perform some additional setup functions, so we override the * setUp() method. @@ -52,7 +56,25 @@ public class ScreenshotIT extends AbstractIT { + " for error images", testBench().compareScreen("initialView")); } - + + @Test + public void basicExecution() throws Exception { + //TODO take screenshot and add to proper folder + InputBarElement inputBar = $(InputBarElement.class).first(); + inputBar.setCurrentValue(IDENTITY_TERM); + + assertEquals(IDENTITY_TERM, inputBar.getCurrentValue()); + + inputBar.typeInfer(); + TestBenchCommandExecutor executer = getCommandExecutor(); + executer.waitForVaadin(); + + assertTrue("Screenshot comparison for 'identityView' failed, see " + + Parameters.getScreenshotErrorDirectory() + + " for error images", + testBench().compareScreen("identityView")); + } + /** * Generates a reference screenshot if no reference exists. *
diff --git a/src/test/java/edu/kit/typicalc/view/ViewMainIT.java b/src/test/java/edu/kit/typicalc/view/ViewMainIT.java new file mode 100644 index 0000000..32d83fb --- /dev/null +++ b/src/test/java/edu/kit/typicalc/view/ViewMainIT.java @@ -0,0 +1,67 @@ +package edu.kit.typicalc.view; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Ignore; +import org.junit.Test; + +import edu.kit.typicalc.model.parser.ParseError; +import edu.kit.typicalc.view.pageobjects.ErrorNotificationElement; +import edu.kit.typicalc.view.pageobjects.ExampleDialogElement; +import edu.kit.typicalc.view.pageobjects.InputBarElement; + +public class ViewMainIT extends AbstractIT { + + //TODO change to real Value + private static final String EMPTY_INPUT_ERROR = "?[" + "root." + ParseError.TOO_FEW_TOKENS.toString() + "]?"; + private static final String OVERLONG_INPUT_ERROR = "Die maximale Länge der Eingabe beträgt 1000 Zeichen!"; + private static final String INPUT_EXAMPLE = "let f = λx. g y y in f 3"; + + @Test + public void emptyInput() { + InputBarElement inputBar = $(InputBarElement.class).first(); + inputBar.setCurrentValue(StringUtils.EMPTY); + + assertEquals(StringUtils.EMPTY, inputBar.getCurrentValue()); + inputBar.typeInfer(); + + ErrorNotificationElement errorNotification = $(ErrorNotificationElement.class).waitForFirst(); + assertTrue(errorNotification.isOpen()); + String errorMessage = errorNotification.getErrorSpan().getText(); + assertEquals(EMPTY_INPUT_ERROR, errorMessage); + + errorNotification.close(); + assertFalse(errorNotification.isOpen()); + } + + @Ignore + @Test + public void overlongInput() { + //TODO only works when executed separately, fix bug + InputBarElement inputBar = $(InputBarElement.class).first(); + inputBar.setCurrentValue(new String(new char[1000])); + inputBar.typeInfer(); + + ErrorNotificationElement errorNotification = $(ErrorNotificationElement.class).waitForFirst(); + assertTrue(errorNotification.isOpen()); + String errorMessage = errorNotification.getErrorSpan().getText(); + assertEquals(OVERLONG_INPUT_ERROR, errorMessage); + + errorNotification.close(); + assertFalse(errorNotification.isOpen()); + } + + @Test + public void chooseExample() { + InputBarElement inputBar = $(InputBarElement.class).first(); + inputBar.openExampleDialog(); + + ExampleDialogElement exampleDialog = $(ExampleDialogElement.class).waitForFirst(); + exampleDialog.insertExample(INPUT_EXAMPLE); + + assertEquals(INPUT_EXAMPLE, inputBar.getCurrentValue()); + } +} diff --git a/src/test/java/edu/kit/typicalc/view/pageobjects/ErrorNotificationElement.java b/src/test/java/edu/kit/typicalc/view/pageobjects/ErrorNotificationElement.java new file mode 100644 index 0000000..821b287 --- /dev/null +++ b/src/test/java/edu/kit/typicalc/view/pageobjects/ErrorNotificationElement.java @@ -0,0 +1,19 @@ +package edu.kit.typicalc.view.pageobjects; + +import com.vaadin.flow.component.button.testbench.ButtonElement; +import com.vaadin.flow.component.html.testbench.SpanElement; +import com.vaadin.flow.component.notification.testbench.NotificationElement; +import com.vaadin.flow.component.orderedlayout.testbench.VerticalLayoutElement; +import com.vaadin.testbench.annotations.Attribute; + +@Attribute(name = "id", value = "errorNotification") +public class ErrorNotificationElement extends NotificationElement { + + public void close() { + $(ButtonElement.class).first().click(); + } + + public SpanElement getErrorSpan() { + return $(VerticalLayoutElement.class).first().$(SpanElement.class).first(); + } +} diff --git a/src/test/java/edu/kit/typicalc/view/pageobjects/ExampleDialogElement.java b/src/test/java/edu/kit/typicalc/view/pageobjects/ExampleDialogElement.java new file mode 100644 index 0000000..44c7c18 --- /dev/null +++ b/src/test/java/edu/kit/typicalc/view/pageobjects/ExampleDialogElement.java @@ -0,0 +1,14 @@ +package edu.kit.typicalc.view.pageobjects; + +import com.vaadin.flow.component.button.testbench.ButtonElement; +import com.vaadin.flow.component.dialog.testbench.DialogElement; +import com.vaadin.flow.component.orderedlayout.testbench.VerticalLayoutElement; +import com.vaadin.testbench.annotations.Attribute; + +@Attribute(name = "id", value = "exampleDialog") +public class ExampleDialogElement extends DialogElement { + + public void insertExample(String example) { + $(VerticalLayoutElement.class).first().$(ButtonElement.class).id(example).click(); + } +} diff --git a/src/test/java/edu/kit/typicalc/view/pageobjects/InputBarElement.java b/src/test/java/edu/kit/typicalc/view/pageobjects/InputBarElement.java new file mode 100644 index 0000000..8aa13b3 --- /dev/null +++ b/src/test/java/edu/kit/typicalc/view/pageobjects/InputBarElement.java @@ -0,0 +1,26 @@ +package edu.kit.typicalc.view.pageobjects; + +import com.vaadin.flow.component.button.testbench.ButtonElement; +import com.vaadin.flow.component.orderedlayout.testbench.HorizontalLayoutElement; +import com.vaadin.flow.component.textfield.testbench.TextFieldElement; +import com.vaadin.testbench.annotations.Attribute; + +@Attribute(name = "id", value = "inputBar") // maybe make id constants public to use the here +public class InputBarElement extends HorizontalLayoutElement { + + public void typeInfer() { + $(ButtonElement.class).id("inferButton").click(); + } + + public void setCurrentValue(String value) { + $(TextFieldElement.class).id("inputField").setValue(value); + } + + public String getCurrentValue() { + return $(TextFieldElement.class).id("inputField").getValue(); + } + + public void openExampleDialog() { + $(ButtonElement.class).id("exampleButton").click(); + } +} diff --git a/src/test/resources/screenshots/initialView_windows_chrome_88.png b/src/test/resources/screenshots/initialView_windows_chrome_88.png new file mode 100644 index 0000000..f999854 Binary files /dev/null and b/src/test/resources/screenshots/initialView_windows_chrome_88.png differ