Skip to content

Commit b49a68b

Browse files
ngonzalezpazFCjavier-godoy
authored andcommitted
feat(demo): add DemoLayout and LayoutTest
1 parent e2c9b13 commit b49a68b

File tree

4 files changed

+129
-34
lines changed

4 files changed

+129
-34
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*-
2+
* #%L
3+
* TwinColGrid add-on
4+
* %%
5+
* Copyright (C) 2017 - 2020 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;
21+
22+
import com.vaadin.flow.component.html.Div;
23+
import com.vaadin.flow.router.RouterLayout;
24+
25+
@SuppressWarnings("serial")
26+
public class DemoLayout extends Div implements RouterLayout {
27+
28+
public DemoLayout() {
29+
setSizeFull();
30+
}
31+
32+
}

src/test/java/com/flowingcode/vaadin/addons/errorwindow/DemoView.java

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,18 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.errorwindow;
2121

22-
import com.vaadin.flow.component.button.Button;
23-
import com.vaadin.flow.component.notification.Notification;
2422
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
23+
import com.vaadin.flow.router.BeforeEnterEvent;
24+
import com.vaadin.flow.router.BeforeEnterObserver;
2525
import com.vaadin.flow.router.Route;
2626

27+
@SuppressWarnings("serial")
2728
@Route("")
28-
public class DemoView extends VerticalLayout {
29+
public class DemoView extends VerticalLayout implements BeforeEnterObserver {
2930

30-
public DemoView() {
31-
Button errorButton = new Button("Throw Error", event -> {
32-
Integer.parseInt("asdf");
33-
});
34-
35-
Button throwErrorWithoutErrorHandler = new Button("Throw Error without an error handler", ev->{
36-
try {
37-
Integer.parseInt("asdf");
38-
} catch (NumberFormatException e) {
39-
ErrorManager.showError(e);
40-
}
41-
});
42-
43-
Button throwErrorWithCustomMessage = new Button("Throw Error with custom message", ev->{
44-
try {
45-
Integer.parseInt("asdf");
46-
} catch (NumberFormatException e) {
47-
ErrorWindow w = new ErrorWindow(e, "CUSTOM ERROR MESSAGE");
48-
w.open();
49-
}
50-
});
51-
52-
Button toggleProductionMode = new Button("Toggle production mode");
53-
toggleProductionMode.addClickListener(ev->{
54-
System.setProperty("productionMode",""+("false".equals(System.getProperty("productionMode"))));
55-
Notification.show("Currently production mode is: " + System.getProperty("productionMode"));
56-
});
57-
58-
add(errorButton, throwErrorWithoutErrorHandler, throwErrorWithCustomMessage, toggleProductionMode);
59-
31+
@Override
32+
public void beforeEnter(BeforeEnterEvent event) {
33+
event.forwardTo(ErrorwindowDemoView.class);
6034
}
61-
35+
6236
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.flowingcode.vaadin.addons.errorwindow;
2+
3+
import com.flowingcode.vaadin.addons.DemoLayout;
4+
import com.vaadin.flow.component.button.Button;
5+
import com.vaadin.flow.component.button.ButtonVariant;
6+
import com.vaadin.flow.component.html.Label;
7+
import com.vaadin.flow.component.html.Paragraph;
8+
import com.vaadin.flow.component.notification.Notification;
9+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
10+
import com.vaadin.flow.router.Route;
11+
import java.awt.TextField;
12+
13+
@SuppressWarnings("serial")
14+
@Route(value = "errorwindow", layout = DemoLayout.class)
15+
public class ErrorwindowDemoView extends VerticalLayout {
16+
17+
public ErrorwindowDemoView() {
18+
Button errorButton = new Button("Throw Error", event -> {
19+
Integer.parseInt("asdf");
20+
});
21+
22+
Button throwErrorWithoutErrorHandler = new Button("Throw Error without an error handler", ev->{
23+
try {
24+
Integer.parseInt("asdf");
25+
} catch (NumberFormatException e) {
26+
ErrorManager.showError(e);
27+
}
28+
});
29+
30+
Button throwErrorWithCustomMessage = new Button("Throw Error with custom message", ev->{
31+
try {
32+
Integer.parseInt("asdf");
33+
} catch (NumberFormatException e) {
34+
ErrorWindow w = new ErrorWindow(e, "CUSTOM ERROR MESSAGE");
35+
w.open();
36+
}
37+
});
38+
39+
Button toggleProductionMode = new Button("Toggle production mode");
40+
toggleProductionMode.addClickListener(ev->{
41+
System.setProperty("productionMode",""+("false".equals(System.getProperty("productionMode"))));
42+
Notification.show("Currently production mode is: " + System.getProperty("productionMode"));
43+
});
44+
45+
setSizeFull();
46+
add(errorButton, throwErrorWithoutErrorHandler, throwErrorWithCustomMessage, toggleProductionMode);
47+
}
48+
49+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*-
2+
* #%L
3+
* TwinColGrid add-on
4+
* %%
5+
* Copyright (C) 2017 - 2020 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.errorwindow.test;
21+
22+
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertNotEquals;
24+
25+
import org.junit.Test;
26+
27+
import com.flowingcode.vaadin.addons.DemoLayout;
28+
import com.flowingcode.vaadin.addons.errorwindow.ErrorwindowDemoView;
29+
import com.vaadin.flow.router.Route;
30+
31+
public class LayoutTest {
32+
33+
@Test
34+
public void testDemoLayout() {
35+
Route route = ErrorwindowDemoView.class.getAnnotation(Route.class);
36+
assertEquals("com.flowingcode.vaadin.addons.DemoLayout",DemoLayout.class.getName());
37+
assertEquals(DemoLayout.class, route.layout());
38+
assertNotEquals("", route.value());
39+
}
40+
}

0 commit comments

Comments
 (0)