From 478cd977060f47d6bbce233596e8358e4203f9dc Mon Sep 17 00:00:00 2001 From: Moritz Dieing <63721811+moritzdieing@users.noreply.github.com> Date: Sun, 11 Jul 2021 11:54:15 +0200 Subject: [PATCH] Update integration tests --- .../view/main/AssumptionExampleContent.java | 6 +- .../resources/language/general.properties | 18 +++--- .../edu/kit/typicalc/view/ScreenshotIT.java | 60 ++++++++----------- .../pageobjects/ExampleDialogElement.java | 10 +++- .../view/pageobjects/InputBarElement.java | 30 ++++++++-- .../TypeAssumptionFieldElement.java | 17 ------ .../TypeAssumptionsAreaElement.java | 29 --------- 7 files changed, 69 insertions(+), 101 deletions(-) delete mode 100644 src/test/java/edu/kit/typicalc/view/pageobjects/TypeAssumptionFieldElement.java delete mode 100644 src/test/java/edu/kit/typicalc/view/pageobjects/TypeAssumptionsAreaElement.java diff --git a/src/main/java/edu/kit/typicalc/view/main/AssumptionExampleContent.java b/src/main/java/edu/kit/typicalc/view/main/AssumptionExampleContent.java index a6bbcc8..e34eb5d 100644 --- a/src/main/java/edu/kit/typicalc/view/main/AssumptionExampleContent.java +++ b/src/main/java/edu/kit/typicalc/view/main/AssumptionExampleContent.java @@ -12,8 +12,9 @@ import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.component.textfield.TextField; /** - * - * + * Contains all the predefined type assumptions for the selected term as buttons. + * Clicking on a button starts the type inference algorithm with the selected term and the selected type + * assumptions. */ @CssImport("./styles/view/main/assumption-example-content.css") public class AssumptionExampleContent extends VerticalLayout { @@ -48,6 +49,7 @@ public class AssumptionExampleContent extends VerticalLayout { Button button = new Button(assumptions); button.addClickListener(click -> forwardCallback.accept(assumptions. replace(getTranslation("root.emptySet"), StringUtils.EMPTY))); + button.setId(assumptions); this.add(button); } } diff --git a/src/main/resources/language/general.properties b/src/main/resources/language/general.properties index e734e1a..b424ff7 100644 --- a/src/main/resources/language/general.properties +++ b/src/main/resources/language/general.properties @@ -16,15 +16,15 @@ root.exampleTerms=\ let f = λx. let g = λy. y in g x in f 3,\ let f = λx. let g = λy.5 5 in g x in f 3 -root.λx.x=∅; x: int; y: bool -root.λx.λy.yx=∅; x: int; y: bool -root.λx.λy.y(xx)=∅; x: int; y: bool -root.letfλx.gyyinf3=∅; g: a->b->a; g: int->int->bool; g: int->int->bool, y: bool; g: int->int->bool, y: τ₁ -root.letkλx.λy.xinka(kbc)=∅; a: τ₁, a: ∀τ₁.τ₁->int; b: a, a: int; b: bool; c: char -root.(λx.xx)(λx.xx)=∅; x: bool -root.(λx.λy.y(xy))(λz.λa.zga)=∅; g: bool; a: int, g: bool->int; g: ∀τ₂.τ₁->τ₂ -root.letfλx.letgλy.yingxinf3=∅; g: bool->int->bool -root.letfλx.letgλy.55ingxinf3=∅; f: bool->int->bool +root.λx.x=∅;x: int;y: bool +root.λx.λy.yx=∅;x: int;y: bool +root.λx.λy.y(xx)=∅;x: int;y: bool +root.letfλx.gyyinf3=∅;g: a->b->a;g: int->int->bool;g: int->int->bool, y: bool;g: int->int->bool, y: τ₁ +root.letkλx.λy.xinka(kbc)=∅;a: τ₁;a: ∀τ₁.τ₁->int, b: a;a: int, b: bool, c: char +root.(λx.xx)(λx.xx)=∅;x: bool +root.(λx.λy.y(xy))(λz.λa.zga)=∅;g: bool;a: int, g: bool->int;g: ∀τ₂.τ₁->τ₂ +root.letfλx.letgλy.yingxinf3=∅;g: bool->int->bool +root.letfλx.letgλy.55ingxinf3=∅;f: bool->int->bool root.termGrammar=\u2329Term\u232A ::= (\u2329Term\u232A) | \u2329App\u232A | \u2329Abs\u232A | \ \u2329Let\u232A | \u2329Var\u232A | \u2329Const\u232A
\ diff --git a/src/test/java/edu/kit/typicalc/view/ScreenshotIT.java b/src/test/java/edu/kit/typicalc/view/ScreenshotIT.java index 9cbdcb6..73d4f04 100644 --- a/src/test/java/edu/kit/typicalc/view/ScreenshotIT.java +++ b/src/test/java/edu/kit/typicalc/view/ScreenshotIT.java @@ -1,7 +1,5 @@ package edu.kit.typicalc.view; -import com.vaadin.flow.component.button.testbench.ButtonElement; -import com.vaadin.flow.component.orderedlayout.testbench.HorizontalLayoutElement; import com.vaadin.testbench.Parameters; import com.vaadin.testbench.commands.TestBenchCommandExecutor; import edu.kit.typicalc.view.pageobjects.*; @@ -72,9 +70,9 @@ public class ScreenshotIT extends AbstractIT { @Test public void basicExecution() throws Exception { InputBarElement inputBar = $(InputBarElement.class).first(); - inputBar.setCurrentValue(IDENTITY_TERM); + inputBar.setTerm(IDENTITY_TERM); - assertEquals(IDENTITY_TERM, inputBar.getCurrentValue()); + assertEquals(IDENTITY_TERM, inputBar.getTerm()); inputBar.typeInfer(); TestBenchCommandExecutor executer = getCommandExecutor(); @@ -89,9 +87,9 @@ public class ScreenshotIT extends AbstractIT { @Test public void createPermalink() throws IOException { InputBarElement inputBar = $(InputBarElement.class).first(); - inputBar.setCurrentValue(LET_TERM); + inputBar.setTerm(LET_TERM); - assertEquals(LET_TERM, inputBar.getCurrentValue()); + assertEquals(LET_TERM, inputBar.getTerm()); inputBar.typeInfer(); TestBenchCommandExecutor executor = getCommandExecutor(); @@ -114,23 +112,26 @@ public class ScreenshotIT extends AbstractIT { @Test public void chooseExample() throws IOException { + TestBenchCommandExecutor executor = getCommandExecutor(); + InputBarElement inputBar = $(InputBarElement.class).first(); inputBar.openExampleDialog(); ExampleDialogElement exampleDialog = $(ExampleDialogElement.class).waitForFirst(); String term = "λx.x"; exampleDialog.insertExample(term); - - matches.add(term.equals(inputBar.getCurrentValue())); - - TestBenchCommandExecutor executor = getCommandExecutor(); + executor.waitForVaadin(); + + String typeAssumptions = "x: int"; + exampleDialog.insertAssumptions(typeAssumptions); executor.waitForVaadin(); + matches.add(term.equals(inputBar.getTerm())); + matches.add(typeAssumptions.equals(inputBar.getTypeAssumptions())); + // check that the example is copied to the input bar matches.add(testBench().compareScreen("chooseExample1")); - inputBar.typeInfer(); - executor.waitForVaadin(); ControlPanelElement control = $(ControlPanelElement.class).waitForFirst(); control.lastStep(); executor.waitForVaadin(); @@ -150,27 +151,16 @@ public class ScreenshotIT extends AbstractIT { InputBarElement inputBar = $(InputBarElement.class).first(); String term = "λx. f x"; - inputBar.setCurrentValue(term); + inputBar.setTerm(term); // check if the correct term is entered - matches.add(term.equals(inputBar.getCurrentValue())); - - inputBar.openTypeAssumptionsArea(); - TypeAssumptionsAreaElement assumptionsArea = $(TypeAssumptionsAreaElement.class).waitForFirst(); - assumptionsArea.addTypeAssumption(); - executor.waitForVaadin(); - TypeAssumptionFieldElement assumptionField = assumptionsArea.getLastTypeAssumption(); - - String variable = "f"; - String type = "int -> y"; - assumptionField.setVariable(variable); - assumptionField.setType(type); - assumptionsArea.$(HorizontalLayoutElement.class).first().$(ButtonElement.class).last().focus(); - - executor.waitForVaadin(); - // check if type assumption is added correctly - matches.add(testBench().compareScreen("exportLatexWithAssumptions1")); - assumptionsArea.closeDialog(); + matches.add(term.equals(inputBar.getTerm())); + + String typeAssumptions = "f: int -> y"; + inputBar.setTypeAssumptions(typeAssumptions); + + // check if the correct type assumptions are entered + matches.add(typeAssumptions.equals(inputBar.getTypeAssumptions())); inputBar.typeInfer(); executor.waitForVaadin(); @@ -193,10 +183,10 @@ public class ScreenshotIT extends AbstractIT { InputBarElement inputBar = $(InputBarElement.class).first(); String term = "λx. f x"; - inputBar.setCurrentValue(term); + inputBar.setTerm(term); // check if the correct term is entered - Assert.assertEquals(term, inputBar.getCurrentValue()); + Assert.assertEquals(term, inputBar.getTerm()); inputBar.typeInfer(); ControlPanelElement controlPanelElement = $(ControlPanelElement.class).first(); @@ -252,8 +242,8 @@ public class ScreenshotIT extends AbstractIT { InputBarElement inputBar = $(InputBarElement.class).first(); String term = "λ5.x"; - inputBar.setCurrentValue(term); - assertEquals(term, inputBar.getCurrentValue()); + inputBar.setTerm(term); + assertEquals(term, inputBar.getTerm()); inputBar.typeInfer(); executor.waitForVaadin(); diff --git a/src/test/java/edu/kit/typicalc/view/pageobjects/ExampleDialogElement.java b/src/test/java/edu/kit/typicalc/view/pageobjects/ExampleDialogElement.java index 3f05c9d..ec6c361 100644 --- a/src/test/java/edu/kit/typicalc/view/pageobjects/ExampleDialogElement.java +++ b/src/test/java/edu/kit/typicalc/view/pageobjects/ExampleDialogElement.java @@ -14,9 +14,13 @@ public class ExampleDialogElement extends DialogElement { /** * Click on an example of the example dialog. * - * @param example the example + * @param exampleTerm the example */ - public void insertExample(String example) { - $(VerticalLayoutElement.class).first().$(ButtonElement.class).id(example).click(); + public void insertExample(String exampleTerm) { + $(VerticalLayoutElement.class).first().$(ButtonElement.class).id(exampleTerm).click(); + } + + public void insertAssumptions(String exampleAssumptions) { + $(VerticalLayoutElement.class).first().$(ButtonElement.class).id(exampleAssumptions).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 index d20e7ad..59827e3 100644 --- a/src/test/java/edu/kit/typicalc/view/pageobjects/InputBarElement.java +++ b/src/test/java/edu/kit/typicalc/view/pageobjects/InputBarElement.java @@ -19,21 +19,39 @@ public class InputBarElement extends HorizontalLayoutElement { } /** - * Set the current value of the inputField. + * Set the current value of the termInputField. * * @param value the value */ - public void setCurrentValue(String value) { - $(TextFieldElement.class).id("inputField").setValue(value); + public void setTerm(String value) { + $(TextFieldElement.class).id("term-input-field").setValue(value); } /** - * Get the current value of the inputField. + * Get the current value of the termInputField. * * @return the current value */ - public String getCurrentValue() { - return $(TextFieldElement.class).id("inputField").getValue(); + public String getTerm() { + return $(TextFieldElement.class).id("term-input-field").getValue(); + } + + /** + * Set the current value of the assumptionInputField. + * + * @param assumptions the value + */ + public void setTypeAssumptions(String assumptions) { + $(TextFieldElement.class).id("ass-input-field").setValue(assumptions); + } + + /** + * Get the current value of the assumptionInputField. + * + * @return the current value + */ + public String getTypeAssumptions() { + return $(TextFieldElement.class).id("ass-input-field").getValue(); } /** diff --git a/src/test/java/edu/kit/typicalc/view/pageobjects/TypeAssumptionFieldElement.java b/src/test/java/edu/kit/typicalc/view/pageobjects/TypeAssumptionFieldElement.java deleted file mode 100644 index 5558715..0000000 --- a/src/test/java/edu/kit/typicalc/view/pageobjects/TypeAssumptionFieldElement.java +++ /dev/null @@ -1,17 +0,0 @@ -package edu.kit.typicalc.view.pageobjects; - -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 = "typeAssumptionField") -public class TypeAssumptionFieldElement extends HorizontalLayoutElement { - - public void setVariable(String variable) { - $(TextFieldElement.class).first().setValue(variable); - } - - public void setType(String type) { - $(TextFieldElement.class).last().setValue(type); - } -} diff --git a/src/test/java/edu/kit/typicalc/view/pageobjects/TypeAssumptionsAreaElement.java b/src/test/java/edu/kit/typicalc/view/pageobjects/TypeAssumptionsAreaElement.java deleted file mode 100644 index 58059fa..0000000 --- a/src/test/java/edu/kit/typicalc/view/pageobjects/TypeAssumptionsAreaElement.java +++ /dev/null @@ -1,29 +0,0 @@ -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.orderedlayout.testbench.VerticalLayoutElement; -import com.vaadin.testbench.annotations.Attribute; - -/** - * Vaadin TestBench element for {@link edu.kit.typicalc.view.main.TypeAssumptionsArea}. - */ -@Attribute(name = "id", value = "assLayout") -public class TypeAssumptionsAreaElement extends VerticalLayoutElement { - - /** - * Adds a new TypeAssumption. - */ - public void addTypeAssumption() { - $(HorizontalLayoutElement.class).id("assButtons").$(ButtonElement.class).first().click(); - } - - public TypeAssumptionFieldElement getLastTypeAssumption() { - return $(VerticalLayoutElement.class).id("assContainer") - .$(TypeAssumptionFieldElement.class).last(); - } - - public void closeDialog() { - $(HorizontalLayoutElement.class).first().$(ButtonElement.class).last().click(); - } -}