From a9d673b38e66abd46ccab0108041bdc25ce45484 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Tue, 30 Jan 2018 13:11:46 +0300 Subject: [PATCH] IT test for hidden attribute and visibility feature. --- .../ui/template/HiddenTemplateView.java | 41 ++++++++++++ .../uitest/ui/template/HiddenTemplateIT.java | 62 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/template/HiddenTemplateView.java create mode 100644 flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/template/HiddenTemplateIT.java diff --git a/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/template/HiddenTemplateView.java b/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/template/HiddenTemplateView.java new file mode 100644 index 00000000000..0f89c562645 --- /dev/null +++ b/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/template/HiddenTemplateView.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2017 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.flow.uitest.ui.template; + +import com.vaadin.flow.component.Tag; +import com.vaadin.flow.component.dependency.HtmlImport; +import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.polymertemplate.EventHandler; +import com.vaadin.flow.component.polymertemplate.Id; +import com.vaadin.flow.component.polymertemplate.PolymerTemplate; +import com.vaadin.flow.router.Route; +import com.vaadin.flow.templatemodel.TemplateModel; +import com.vaadin.flow.uitest.servlet.ViewTestLayout; + +@Route(value = "com.vaadin.flow.uitest.ui.template.HiddenTemplateView", layout = ViewTestLayout.class) +@Tag("hidden-template") +@HtmlImport("frontend://com/vaadin/flow/uitest/ui/template/HiddenTemplate.html") +public class HiddenTemplateView extends PolymerTemplate { + + @Id("child") + private Div div; + + @EventHandler + private void updateVisibility() { + div.setVisible(!div.isVisible()); + } + +} \ No newline at end of file diff --git a/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/template/HiddenTemplateIT.java b/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/template/HiddenTemplateIT.java new file mode 100644 index 00000000000..7bac0fc60c0 --- /dev/null +++ b/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/template/HiddenTemplateIT.java @@ -0,0 +1,62 @@ +/* + * Copyright 2000-2017 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.flow.uitest.ui.template; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.flow.testutil.ChromeBrowserTest; + +public class HiddenTemplateIT extends ChromeBrowserTest { + + @Test + public void initiallyHiddenElementStaysHidden() { + open(); + + WebElement template = findElement(By.tagName("hidden-template")); + WebElement child = getInShadowRoot(template, By.id("child")); + Assert.assertNotNull(child.getAttribute("hidden")); + + WebElement visibility = getInShadowRoot(template, By.id("visibility")); + visibility.click(); + Assert.assertNotNull(child.getAttribute("hidden")); + + visibility.click(); + Assert.assertNotNull(child.getAttribute("hidden")); + } + + @Test + public void initiallyNotHiddenElementChangesItsVisibility() { + open(); + + WebElement template = findElement(By.tagName("hidden-template")); + + WebElement hidden = getInShadowRoot(template, By.id("hidden")); + hidden.click(); + + WebElement child = getInShadowRoot(template, By.id("child")); + Assert.assertNull(child.getAttribute("hidden")); + + WebElement visibility = getInShadowRoot(template, By.id("visibility")); + visibility.click(); + Assert.assertNotNull(child.getAttribute("hidden")); + + visibility.click(); + Assert.assertNull(child.getAttribute("hidden")); + } +}