|
| 1 | +package com.flowingcode.addons.applayout.integration; |
| 2 | + |
| 3 | +import static org.hamcrest.Matchers.empty; |
| 4 | +import static org.hamcrest.Matchers.is; |
| 5 | +import static org.hamcrest.Matchers.not; |
| 6 | +import static org.junit.Assert.assertThat; |
| 7 | + |
| 8 | +import java.util.List; |
| 9 | + |
| 10 | +import org.hamcrest.Description; |
| 11 | +import org.hamcrest.Matcher; |
| 12 | +import org.hamcrest.TypeSafeDiagnosingMatcher; |
| 13 | +import org.junit.Test; |
| 14 | +import org.openqa.selenium.By; |
| 15 | +import org.openqa.selenium.WebElement; |
| 16 | + |
| 17 | +import com.vaadin.testbench.TestBenchElement; |
| 18 | + |
| 19 | +public class ViewIT extends AbstractViewTest { |
| 20 | + |
| 21 | + private Matcher<TestBenchElement> hasBeenUpgradedToCustomElement = new TypeSafeDiagnosingMatcher<TestBenchElement>() { |
| 22 | + |
| 23 | + @Override |
| 24 | + public void describeTo(Description description) { |
| 25 | + description.appendText("a custom element"); |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + protected boolean matchesSafely(TestBenchElement item, Description mismatchDescription) { |
| 30 | + String script = "let s=arguments[0].shadowRoot; return !!(s&&s.childElementCount)"; |
| 31 | + if ((Boolean)item.getCommandExecutor().executeScript(script, item)) |
| 32 | + return true; |
| 33 | + else { |
| 34 | + mismatchDescription.appendText(item.getTagName()+" "); |
| 35 | + mismatchDescription.appendDescriptionOf(is(not(this))); |
| 36 | + return false; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + }; |
| 41 | + |
| 42 | + @Test |
| 43 | + public void componentWorks() { |
| 44 | + TestBenchElement header = $("app-header").first(); |
| 45 | + TestBenchElement drawer = $("app-drawer").first(); |
| 46 | + |
| 47 | + assertThat(header, hasBeenUpgradedToCustomElement); |
| 48 | + assertThat(drawer, hasBeenUpgradedToCustomElement); |
| 49 | + |
| 50 | + TestBenchElement toolbar = header.findElement(By.tagName("app-toolbar")); |
| 51 | + assertThat(toolbar, hasBeenUpgradedToCustomElement); |
| 52 | + |
| 53 | + TestBenchElement menu = toolbar.findElement(By.cssSelector("paper-icon-button[icon='menu']")); |
| 54 | + toolbar.findElement(By.cssSelector("img.applogo")); |
| 55 | + toolbar.findElement(By.cssSelector("div[main-title]")); |
| 56 | + toolbar.findElement(By.cssSelector("paper-icon-button[role='button'][icon='settings']")); |
| 57 | + |
| 58 | + assertThat(menu, hasBeenUpgradedToCustomElement); |
| 59 | + |
| 60 | + TestBenchElement listbox = drawer.findElement(By.cssSelector("paper-listbox")); |
| 61 | + assertThat(listbox, hasBeenUpgradedToCustomElement); |
| 62 | + |
| 63 | + List<WebElement> items = listbox.findElements(By.cssSelector("*")); |
| 64 | + assertThat(items, is(not(empty()))); |
| 65 | + |
| 66 | + for (WebElement item : items) { |
| 67 | + assertThat((TestBenchElement)item, hasBeenUpgradedToCustomElement); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments