Skip to content

Commit e11ddd5

Browse files
committed
test: add integration tests
1 parent 4297702 commit e11ddd5

File tree

2 files changed

+204
-0
lines changed

2 files changed

+204
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*-
2+
* #%L
3+
* Commons Demo
4+
* %%
5+
* Copyright (C) 2020 - 2026 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.demo.it;
21+
22+
import com.flowingcode.vaadin.addons.GithubLink;
23+
import com.flowingcode.vaadin.addons.demo.AdHocDemo;
24+
import com.flowingcode.vaadin.addons.demo.DemoSource;
25+
import com.flowingcode.vaadin.addons.demo.TabbedDemo;
26+
import com.vaadin.flow.component.html.Div;
27+
import com.vaadin.flow.component.html.Span;
28+
import com.vaadin.flow.router.Route;
29+
30+
@SuppressWarnings("serial")
31+
@GithubLink("https://github.com/FlowingCode/CommonsDemo")
32+
public class TabbedDemoView extends TabbedDemo {
33+
34+
public TabbedDemoView() {
35+
addDemo(TabbedDemoViewNoSource.class);
36+
addDemo(TabbedDemoViewSingleSource.class);
37+
addDemo(TabbedDemoViewMultiSource.class);
38+
addDemo(TabbedDemoViewConditionalTrue.class);
39+
addDemo(TabbedDemoViewConditionalFalse.class);
40+
}
41+
42+
protected abstract static class AbstractDemoView extends Div {
43+
public AbstractDemoView() {
44+
add(new Span(this.getClass().getSimpleName()));
45+
}
46+
}
47+
48+
@Route(value = "it/tabbed-demo-no-source", layout = TabbedDemoView.class)
49+
public static class TabbedDemoViewNoSource extends AbstractDemoView { }
50+
51+
@DemoSource(clazz = TabbedDemoView.class)
52+
@Route(value = "it/tabbed-demo-single-source", layout = TabbedDemoView.class)
53+
public static class TabbedDemoViewSingleSource extends AbstractDemoView { }
54+
55+
@DemoSource(clazz = TabbedDemoView.class)
56+
@DemoSource(clazz = AdHocDemo.class)
57+
@Route(value = "it/tabbed-demo-multi-source", layout = TabbedDemoView.class)
58+
public static class TabbedDemoViewMultiSource extends AbstractDemoView { }
59+
60+
@DemoSource(clazz = TabbedDemoView.class, condition = "vaadin ge 14")
61+
@Route(value = "it/tabbed-demo-conditional-true", layout = TabbedDemoView.class)
62+
public static class TabbedDemoViewConditionalTrue extends AbstractDemoView { }
63+
64+
@DemoSource(clazz = TabbedDemoView.class, condition = "vaadin eq 0")
65+
@Route(value = "it/tabbed-demo-conditional-false", layout = TabbedDemoView.class)
66+
public static class TabbedDemoViewConditionalFalse extends AbstractDemoView { }
67+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*-
2+
* #%L
3+
* Commons Demo
4+
* %%
5+
* Copyright (C) 2020 - 2026 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.demo.it;
21+
22+
import static org.hamcrest.CoreMatchers.not;
23+
import com.flowingcode.vaadin.addons.demo.it.TabbedDemoView.TabbedDemoViewConditionalFalse;
24+
import com.flowingcode.vaadin.addons.demo.it.TabbedDemoView.TabbedDemoViewConditionalTrue;
25+
import com.flowingcode.vaadin.addons.demo.it.TabbedDemoView.TabbedDemoViewMultiSource;
26+
import com.flowingcode.vaadin.addons.demo.it.TabbedDemoView.TabbedDemoViewNoSource;
27+
import com.flowingcode.vaadin.addons.demo.it.TabbedDemoView.TabbedDemoViewSingleSource;
28+
import com.vaadin.flow.component.Component;
29+
import com.vaadin.flow.router.Route;
30+
import org.hamcrest.Description;
31+
import org.hamcrest.Matcher;
32+
import org.hamcrest.TypeSafeMatcher;
33+
import org.junit.Assert;
34+
import org.junit.Test;
35+
import org.openqa.selenium.By;
36+
import org.openqa.selenium.SearchContext;
37+
38+
public class TabbedDemoViewIT extends AbstractViewTest {
39+
40+
private SourceCodeViewerElement viewer;
41+
42+
protected void open(Class<? extends Component> clazz) {
43+
if (viewer != null) {
44+
throw new IllegalStateException();
45+
}
46+
getDriver().get(getURL(clazz.getAnnotation(Route.class).value()));
47+
getCommandExecutor().waitForVaadin();
48+
getDriver().findElement(By.id("content"));
49+
}
50+
51+
public static Matcher<SearchContext> hasElement(String cssSelector) {
52+
return new TypeSafeMatcher<>() {
53+
54+
@Override
55+
protected boolean matchesSafely(SearchContext container) {
56+
return !container.findElements(By.cssSelector(cssSelector)).isEmpty();
57+
}
58+
59+
@Override
60+
public void describeTo(Description description) {
61+
description.appendText("a page containing element: ").appendValue(cssSelector);
62+
}
63+
64+
@Override
65+
protected void describeMismatchSafely(SearchContext container,
66+
Description mismatchDescription) {
67+
mismatchDescription.appendText("no elements matched selector: ").appendValue(cssSelector);
68+
}
69+
};
70+
}
71+
72+
private Matcher<SearchContext> hasPrimaryCodeTabs() {
73+
return hasElement("[slot='primary'] vaadin-menu-bar");
74+
}
75+
76+
private Matcher<SearchContext> hasPrimaryCodeViewer() {
77+
return hasElement("[slot='primary'] code-viewer");
78+
}
79+
80+
private Matcher<SearchContext> hasSecondaryCodeTabs() {
81+
return hasElement("[slot='secondary'] vaadin-menu-bar");
82+
}
83+
84+
private Matcher<SearchContext> hasSecondaryCodeViewer() {
85+
return hasElement("[slot='secondary'] code-viewer");
86+
}
87+
88+
private void assertThat(Matcher<SearchContext> matcher) {
89+
Assert.assertThat(getDriver(), matcher);
90+
}
91+
92+
@Test
93+
public void testSimpleNoSource() {
94+
open(TabbedDemoViewNoSource.class);
95+
assertThat(not(hasPrimaryCodeTabs()));
96+
assertThat(not(hasPrimaryCodeViewer()));
97+
assertThat(not(hasSecondaryCodeTabs()));
98+
assertThat(not(hasSecondaryCodeViewer()));
99+
}
100+
101+
@Test
102+
public void testSimpleSingleSource() {
103+
open(TabbedDemoViewSingleSource.class);
104+
assertThat(not(hasPrimaryCodeTabs()));
105+
assertThat(not(hasPrimaryCodeViewer()));
106+
assertThat(not(hasSecondaryCodeTabs()));
107+
assertThat(hasSecondaryCodeViewer());
108+
}
109+
110+
@Test
111+
public void testSimpleMultiSource() {
112+
open(TabbedDemoViewMultiSource.class);
113+
assertThat(not(hasPrimaryCodeTabs()));
114+
assertThat(not(hasPrimaryCodeViewer()));
115+
assertThat(hasSecondaryCodeTabs());
116+
assertThat(hasSecondaryCodeViewer());
117+
}
118+
119+
@Test
120+
public void testSimpleConditionalTrue() {
121+
open(TabbedDemoViewConditionalTrue.class);
122+
assertThat(not(hasPrimaryCodeTabs()));
123+
assertThat(not(hasPrimaryCodeViewer()));
124+
assertThat(not(hasSecondaryCodeTabs()));
125+
assertThat(hasSecondaryCodeViewer());
126+
}
127+
128+
@Test
129+
public void testSimpleConditionalFalse() {
130+
open(TabbedDemoViewConditionalFalse.class);
131+
assertThat(not(hasPrimaryCodeTabs()));
132+
assertThat(not(hasPrimaryCodeViewer()));
133+
assertThat(not(hasSecondaryCodeTabs()));
134+
assertThat(not(hasSecondaryCodeViewer()));
135+
}
136+
137+
}

0 commit comments

Comments
 (0)