From abe89fe6abda4d6ba4afe2c87572a7d02f71c234 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Thu, 6 Sep 2012 18:16:21 +0300 Subject: TestBench test for Navigator --- .../com/vaadin/tests/navigator/NavigatorTest.html | 107 +++++++++++++++++ .../com/vaadin/tests/navigator/NavigatorTest.java | 129 +++++++++++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/navigator/NavigatorTest.html create mode 100644 uitest/src/com/vaadin/tests/navigator/NavigatorTest.java (limited to 'uitest') diff --git a/uitest/src/com/vaadin/tests/navigator/NavigatorTest.html b/uitest/src/com/vaadin/tests/navigator/NavigatorTest.html new file mode 100644 index 0000000000..8c4e8f657b --- /dev/null +++ b/uitest/src/com/vaadin/tests/navigator/NavigatorTest.html @@ -0,0 +1,107 @@ + + + + + + +NavigatorTest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NavigatorTest
open/run/com.vaadin.tests.navigator.NavigatorTest?restartApplication
clickvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]
assertTextvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLabel[0]1. Navigated to ListView with params
assertLocation*#!list
clickvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]
assertTextvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLabel[0]2. Navigated to EditView with params
assertLocation*#!edit
mouseClickvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VTextField[0]56,6
enterCharactervaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VTextField[0]param=value
clickvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]
assertTextvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLabel[0]3. Navigated to ListView with params param=value
assertLocation*#!list/param=value
clickvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]
assertTextvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLabel[0]4. Navigated to EditView with params param=value
assertLocation*#!edit/param=value
clickvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VButton[0]/domChild[0]/domChild[0]
assertTextvaadin=runcomvaadintestsnavigatorNavigatorTest::/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLabel[0]5. Prevent navigation to ForbiddenView
assertLocation*#!edit/param=value
+ + diff --git a/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java b/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java new file mode 100644 index 0000000000..bfb11f6b8c --- /dev/null +++ b/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java @@ -0,0 +1,129 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.navigator; + +import com.vaadin.navigator.Navigator; +import com.vaadin.navigator.View; +import com.vaadin.navigator.ViewChangeListener; +import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; +import com.vaadin.server.WrappedRequest; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.Layout; +import com.vaadin.ui.RichTextArea; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextField; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +public class NavigatorTest extends UI { + + private Log log = new Log(5); + private Layout naviLayout = new VerticalLayout(); + private TextField params = new TextField("Parameters"); + + private Navigator navi; + + class ListView extends Table implements View { + + public ListView() { + addContainerProperty("name", String.class, ""); + addContainerProperty("value", String.class, ""); + } + + @Override + public void enter(ViewChangeEvent event) { + String params = event.getParameters(); + log.log("Navigated to ListView with params " + params); + removeAllItems(); + for (String arg : params.split(",")) { + addItem(arg.split("=|$", 2), arg); + } + } + } + + class EditView extends RichTextArea implements View { + + @Override + public void enter(ViewChangeEvent event) { + log.log("Navigated to EditView with params " + + event.getParameters()); + setValue("Displaying edit view with parameters " + + event.getParameters()); + } + } + + class DefaultView extends Label implements View { + + @Override + public void enter(ViewChangeEvent event) { + log.log("Navigated to DefaultView with params " + + event.getParameters()); + setValue("Default view: " + event.getParameters()); + } + } + + class ForbiddenView implements View { + + @Override + public void enter(ViewChangeEvent event) { + log.log("Navigated to ForbiddenView - this should not happen"); + } + } + + class NaviListener implements ViewChangeListener { + + @Override + public boolean isViewChangeAllowed(ViewChangeEvent event) { + if (event.getNewView() instanceof ForbiddenView) { + log.log("Prevent navigation to ForbiddenView"); + return false; + } + return true; + } + + @Override + public void navigatorViewChanged(ViewChangeEvent event) { + } + }; + + class NaviButton extends Button { + public NaviButton(final String path) { + super("Navigate to " + path, new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + navi.navigateTo(path + "/" + params.getValue()); + } + }); + } + } + + @Override + protected void init(WrappedRequest req) { + try { + navi = new Navigator(naviLayout); + + navi.addView("", new DefaultView()); + + navi.addView("list", new ListView()); + navi.addView("edit", new EditView()); + navi.addView("forbidden", new ForbiddenView()); + + navi.addViewChangeListener(new NaviListener()); + // navi.navigate(); + + addComponent(new NaviButton("list")); + addComponent(new NaviButton("edit")); + addComponent(new NaviButton("forbidden")); + + addComponent(params); + addComponent(log); + addComponent(naviLayout); + } catch (Exception e) { + log.log("Exception: " + e.getMessage()); + } + } +} -- cgit v1.2.3