Skip to content

Commit

Permalink
IT test for hidden attribute and visibility feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Anisimov committed Jan 30, 2018
1 parent 09f095e commit a9d673b
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<TemplateModel> {

@Id("child")
private Div div;

@EventHandler
private void updateVisibility() {
div.setVisible(!div.isVisible());
}

}
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit a9d673b

Please sign in to comment.