From 11da7d0308fd38d029e30b35fa412b105dae5c76 Mon Sep 17 00:00:00 2001 From: ZheSun88 Date: Thu, 19 Jul 2018 13:21:26 +0300 Subject: [PATCH 1/5] Enable the test to check the added variant --- .../java/com/vaadin/flow/demo/ComponentDemoTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java b/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java index 5360d280b69..8e6b84999d0 100644 --- a/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java +++ b/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java @@ -105,6 +105,7 @@ private void verifyThemeIsToggled(List updatedThemes, previousButtonText, updatedButtonText); boolean shouldAddTheme = previousButtonText.startsWith("Add"); + String[] variant = updatedButtonText.split("'"); if (shouldAddTheme) { Assert.assertTrue( "When a theme variant got added, toggle button text should start with 'Remove' word", @@ -115,6 +116,11 @@ private void verifyThemeIsToggled(List updatedThemes, Assert.assertTrue( "When a theme variant got added, component 'theme' attribute should contain all previous theme variants", updatedThemes.containsAll(previousThemes)); + + Assert.assertTrue( + "The selected theme variant:" + variant[1] + + " should be added to the component 'theme' attribute.", + updatedThemes.contains(variant[1])); } else { Assert.assertTrue( "When a theme variant got removed, toggle button text should start with 'Add' word", @@ -125,6 +131,10 @@ private void verifyThemeIsToggled(List updatedThemes, Assert.assertTrue( "When a theme variant got removed, previous theme variants should contain all theme variants from component 'theme' attribute", previousThemes.containsAll(updatedThemes)); + Assert.assertFalse( + "The selected theme variant:" + variant[1] + + " should be removed from the component 'theme' attribute.", + updatedThemes.contains(variant[1])); } } From ca4ec0bb64dbf71dea905513ca50e307a5020829 Mon Sep 17 00:00:00 2001 From: ZheSun88 Date: Fri, 20 Jul 2018 16:28:05 +0300 Subject: [PATCH 2/5] Adding one more method to the test class --- .../vaadin/flow/demo/ComponentDemoTest.java | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java b/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java index 8e6b84999d0..5936864f8a1 100644 --- a/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java +++ b/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java @@ -56,13 +56,32 @@ public void openDemoPageAndCheckForErrors() { } /** - * Verifies variants functionality for the current layout. + * Verifies variants functionality for the current layout with default implementation. * * The test will fail if a specific variant demo is not added first with * {@link DemoView#addVariantsDemo(Supplier, BiConsumer, BiConsumer, Function, Enum[])} * method. */ protected void verifyThemeVariantsBeingToggled() { + verifyThemeVariantsBeingToggled(defaultProducer); + } + + /** + * With current design, the theme variant can be obtained from the button + * attached to the demo + */ + private Function defaultProducer = ( + WebElement button) -> { + String[] variant = button.getText().split("'"); + return variant[1]; + }; + + /** + * Verifies variants functionality for the current layout with customized + * implementation. + */ + protected void verifyThemeVariantsBeingToggled( + Function variantProducer) { List toggleThemeButtons = layout .findElement(By.id(VARIANT_TOGGLE_BUTTONS_DIV_ID)) .findElements(By.tagName("button")); @@ -70,17 +89,19 @@ protected void verifyThemeVariantsBeingToggled() { "Expected at least one toggle theme button in 'buttonDiv', but got none", toggleThemeButtons.isEmpty()); toggleThemeButtons.forEach(button -> toggleVariantAndCheck( - layout.findElement(By.id(COMPONENT_WITH_VARIANTS_ID)), button)); + layout.findElement(By.id(COMPONENT_WITH_VARIANTS_ID)), button, + variantProducer)); } private void toggleVariantAndCheck(WebElement component, - WebElement button) { + WebElement button, Function variantProducer) { List initialButtonThemes = getComponentThemes(component); String initialButtonText = button.getText(); button.click(); verifyThemeIsToggled(getComponentThemes(component), button.getText(), - initialButtonThemes, initialButtonText); + initialButtonThemes, initialButtonText, + variantProducer.apply(button)); button.click(); Assert.assertEquals( @@ -100,12 +121,12 @@ private void toggleVariantAndCheck(WebElement component, private void verifyThemeIsToggled(List updatedThemes, String updatedButtonText, List previousThemes, - String previousButtonText) { + String previousButtonText, + String variantName) { Assert.assertNotEquals("Button should change its text after toggling", previousButtonText, updatedButtonText); boolean shouldAddTheme = previousButtonText.startsWith("Add"); - String[] variant = updatedButtonText.split("'"); if (shouldAddTheme) { Assert.assertTrue( "When a theme variant got added, toggle button text should start with 'Remove' word", @@ -118,9 +139,10 @@ private void verifyThemeIsToggled(List updatedThemes, updatedThemes.containsAll(previousThemes)); Assert.assertTrue( - "The selected theme variant:" + variant[1] + "The selected theme variant:" + + variantName + " should be added to the component 'theme' attribute.", - updatedThemes.contains(variant[1])); + updatedThemes.contains(variantName)); } else { Assert.assertTrue( "When a theme variant got removed, toggle button text should start with 'Add' word", @@ -132,9 +154,9 @@ private void verifyThemeIsToggled(List updatedThemes, "When a theme variant got removed, previous theme variants should contain all theme variants from component 'theme' attribute", previousThemes.containsAll(updatedThemes)); Assert.assertFalse( - "The selected theme variant:" + variant[1] + "The selected theme variant:" + variantName + " should be removed from the component 'theme' attribute.", - updatedThemes.contains(variant[1])); + updatedThemes.contains(variantName)); } } From a16e17fcb6baf79207196cfd2df64600b6c18c1d Mon Sep 17 00:00:00 2001 From: ZheSun88 Date: Fri, 20 Jul 2018 17:26:24 +0300 Subject: [PATCH 3/5] Improve --- .../vaadin/flow/demo/ComponentDemoTest.java | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java b/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java index 5936864f8a1..1031269d64e 100644 --- a/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java +++ b/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java @@ -39,6 +39,22 @@ public abstract class ComponentDemoTest extends ChromeBrowserTest { protected WebElement layout; + /** + * Default variant producer + *

+ * With current design, the theme variant can be obtained from the button + * attached to the demo + */ + public static class DefaultProducer + implements Function { + + @Override + public String apply(WebElement button) { + String[] variant = button.getText().split("'"); + return variant[1]; + } + } + @Override protected int getDeploymentPort() { return 9998; @@ -56,25 +72,22 @@ public void openDemoPageAndCheckForErrors() { } /** - * Verifies variants functionality for the current layout with default implementation. - * + * Verifies variants functionality for the current layout with the + * implementation of {@link DefaultProducer}. + *

* The test will fail if a specific variant demo is not added first with * {@link DemoView#addVariantsDemo(Supplier, BiConsumer, BiConsumer, Function, Enum[])} * method. */ protected void verifyThemeVariantsBeingToggled() { - verifyThemeVariantsBeingToggled(defaultProducer); + verifyThemeVariantsBeingToggled(DEFAULT_VARIANT_PRODUCER); } /** * With current design, the theme variant can be obtained from the button * attached to the demo */ - private Function defaultProducer = ( - WebElement button) -> { - String[] variant = button.getText().split("'"); - return variant[1]; - }; + private Function DEFAULT_VARIANT_PRODUCER = new DefaultProducer(); /** * Verifies variants functionality for the current layout with customized @@ -93,8 +106,8 @@ protected void verifyThemeVariantsBeingToggled( variantProducer)); } - private void toggleVariantAndCheck(WebElement component, - WebElement button, Function variantProducer) { + private void toggleVariantAndCheck(WebElement component, WebElement button, + Function variantProducer) { List initialButtonThemes = getComponentThemes(component); String initialButtonText = button.getText(); @@ -121,8 +134,7 @@ private void toggleVariantAndCheck(WebElement component, private void verifyThemeIsToggled(List updatedThemes, String updatedButtonText, List previousThemes, - String previousButtonText, - String variantName) { + String previousButtonText, String variantName) { Assert.assertNotEquals("Button should change its text after toggling", previousButtonText, updatedButtonText); @@ -138,10 +150,8 @@ private void verifyThemeIsToggled(List updatedThemes, "When a theme variant got added, component 'theme' attribute should contain all previous theme variants", updatedThemes.containsAll(previousThemes)); - Assert.assertTrue( - "The selected theme variant:" - + variantName - + " should be added to the component 'theme' attribute.", + Assert.assertTrue("The selected theme variant:" + variantName + + " should be added to the component 'theme' attribute.", updatedThemes.contains(variantName)); } else { Assert.assertTrue( @@ -153,9 +163,8 @@ private void verifyThemeIsToggled(List updatedThemes, Assert.assertTrue( "When a theme variant got removed, previous theme variants should contain all theme variants from component 'theme' attribute", previousThemes.containsAll(updatedThemes)); - Assert.assertFalse( - "The selected theme variant:" + variantName - + " should be removed from the component 'theme' attribute.", + Assert.assertFalse("The selected theme variant:" + variantName + + " should be removed from the component 'theme' attribute.", updatedThemes.contains(variantName)); } } From 1592379fa919e4811e92e484242856c068138fa2 Mon Sep 17 00:00:00 2001 From: ZheSun88 Date: Fri, 20 Jul 2018 17:29:57 +0300 Subject: [PATCH 4/5] formatting --- .../main/java/com/vaadin/flow/demo/ComponentDemoTest.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java b/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java index 1031269d64e..03913b2b736 100644 --- a/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java +++ b/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java @@ -55,6 +55,8 @@ public String apply(WebElement button) { } } + private Function DEFAULT_VARIANT_PRODUCER = new DefaultProducer(); + @Override protected int getDeploymentPort() { return 9998; @@ -83,11 +85,6 @@ protected void verifyThemeVariantsBeingToggled() { verifyThemeVariantsBeingToggled(DEFAULT_VARIANT_PRODUCER); } - /** - * With current design, the theme variant can be obtained from the button - * attached to the demo - */ - private Function DEFAULT_VARIANT_PRODUCER = new DefaultProducer(); /** * Verifies variants functionality for the current layout with customized From 21a6d8fb7a0434e1aa22c2e47dbdac3bf517af1b Mon Sep 17 00:00:00 2001 From: ZheSun88 Date: Fri, 20 Jul 2018 17:32:04 +0300 Subject: [PATCH 5/5] Javadoc improves --- .../main/java/com/vaadin/flow/demo/ComponentDemoTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java b/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java index 03913b2b736..f0674635ff1 100644 --- a/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java +++ b/flow-components-parent/flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/ComponentDemoTest.java @@ -74,8 +74,8 @@ public void openDemoPageAndCheckForErrors() { } /** - * Verifies variants functionality for the current layout with the - * implementation of {@link DefaultProducer}. + * Verifies variants functionality for the current layout with using the + * {@link DefaultProducer}. *

* The test will fail if a specific variant demo is not added first with * {@link DemoView#addVariantsDemo(Supplier, BiConsumer, BiConsumer, Function, Enum[])} @@ -85,10 +85,9 @@ protected void verifyThemeVariantsBeingToggled() { verifyThemeVariantsBeingToggled(DEFAULT_VARIANT_PRODUCER); } - /** * Verifies variants functionality for the current layout with customized - * implementation. + * variant producer implementation. */ protected void verifyThemeVariantsBeingToggled( Function variantProducer) {