Change-Id: I6175398df4c3a07656a2682843615a0d7bd32a45tags/7.5.0.beta1
@@ -332,6 +332,8 @@ $v-grid-details-border-bottom-stripe: 1px solid darken($v-grid-row-background-co | |||
left: 0; | |||
right: 0; | |||
border: $v-grid-border; | |||
box-sizing: border-box; | |||
-moz-box-sizing: border-box; | |||
margin-top: nth($v-grid-border, 1) * -1; | |||
@include box-shadow(0 0 9px rgba(0,0,0,.2)); | |||
} |
@@ -137,6 +137,9 @@ $v-table-background-color: null !default; | |||
position: relative; | |||
background: $v-background-color; | |||
color: valo-font-color($v-background-color); | |||
// Hide row focus outline | |||
overflow: hidden; | |||
} | |||
.#{$primary-stylename}-header table, | |||
@@ -381,7 +384,7 @@ $v-table-background-color: null !default; | |||
.#{$primary-stylename}-focus-slot-right { | |||
border-right: $v-table-border-width + 2px solid $v-focus-color; | |||
right: -$v-table-border-width - 1px; | |||
margin-left: -$v-table-resizer-width - $v-table-border-width - 2px; | |||
margin-left: -$v-table-resizer-width - $v-table-border-width - 2px !important; | |||
} | |||
.#{$primary-stylename}-focus-slot-left { | |||
@@ -394,33 +397,34 @@ $v-table-background-color: null !default; | |||
} | |||
.#{$primary-stylename}-column-selector { | |||
@include valo-button-style; | |||
@include valo-button-style($shadow: null); | |||
position: absolute; | |||
z-index: 2; | |||
top: round($v-unit-size/-4); | |||
right: round($v-unit-size/-4); | |||
top: 0; | |||
right: 0; | |||
width: round($v-unit-size/2); | |||
height: round($v-unit-size/2); | |||
line-height: round($v-unit-size/2); | |||
width: round($v-unit-size/2); | |||
padding: 0; | |||
border-radius: 50%; | |||
border-top-width: 0; | |||
border-right-width: 0; | |||
border-radius: 0 0 0 $v-border-radius; | |||
cursor: pointer; | |||
text-align: center; | |||
@include opacity(0); | |||
@if $v-animations-enabled { | |||
@include transition(opacity 200ms 1s); | |||
@include transition(opacity 200ms 2s); | |||
} | |||
&:after { | |||
content: ""; | |||
position: absolute; | |||
$v-button-border-width: first-number($v-border); | |||
top: -$v-button-border-width; | |||
right: -$v-button-border-width; | |||
bottom: -$v-button-border-width; | |||
left: -$v-button-border-width; | |||
border-radius: inherit; | |||
border: none; | |||
top: 0; | |||
right: 0; | |||
bottom: 0; | |||
left: 0; | |||
} | |||
&:active:after { | |||
@include valo-button-active-style; | |||
@@ -430,22 +434,9 @@ $v-table-background-color: null !default; | |||
} | |||
} | |||
.v-scrollable > .#{$primary-stylename} .#{$primary-stylename}-column-selector { | |||
right: 0; | |||
top: 0; | |||
border-top: none; | |||
border-right: none; | |||
border-radius: 0 0 0 50%; | |||
&:after { | |||
top: 0; | |||
right: 0; | |||
} | |||
} | |||
.#{$primary-stylename}-header-wrap:hover .#{$primary-stylename}-column-selector { | |||
@include opacity(1); | |||
@include transition-delay(100ms); | |||
@include transition-delay(200ms); | |||
} | |||
.v-on, | |||
@@ -505,6 +496,11 @@ $v-table-background-color: null !default; | |||
// Drag'n'drop styles | |||
.#{$primary-stylename}-drag { | |||
// Show drag focus outline | |||
overflow: visible; | |||
} | |||
.#{$primary-stylename}-drag .#{$primary-stylename}-body { | |||
@include box-shadow(0 0 0 2px rgba($v-focus-color, .5)); | |||
@@ -912,12 +912,24 @@ public class VMenuBar extends SimpleFocusablePanel implements | |||
SUBMENU_CLASSNAME_PREFIX, ""); | |||
} | |||
String currentStyles = super.getStyleName(); | |||
List<String> customStyles = new ArrayList<String>(); | |||
for(String style : currentStyles.split(" ")) { | |||
if(!style.isEmpty() && !style.startsWith(primaryStyleName)) { | |||
customStyles.add(style); | |||
} | |||
} | |||
if (isSeparator) { | |||
super.setStyleName(primaryStyleName + "-separator"); | |||
} else { | |||
super.setStyleName(primaryStyleName + "-menuitem"); | |||
} | |||
for (String customStyle : customStyles) { | |||
super.addStyleName(customStyle); | |||
} | |||
if (styleName != null) { | |||
addStyleDependentName(styleName); | |||
} |
@@ -628,9 +628,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware | |||
} | |||
/** | |||
* Returns the index of the first visible tab | |||
* | |||
* @return | |||
* Returns the index of the first visible tab on the server | |||
*/ | |||
private int getFirstVisibleTab() { | |||
return getNextVisibleTab(-1); | |||
@@ -655,6 +653,23 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware | |||
} | |||
} | |||
/** | |||
* Returns the index of the first visible tab in browser. | |||
*/ | |||
private int getFirstVisibleTabClient() { | |||
int tabs = getTabCount(); | |||
int i = 0; | |||
while (i < tabs && !getTab(i).isVisible()) { | |||
i++; | |||
} | |||
if (i == tabs) { | |||
return -1; | |||
} else { | |||
return i; | |||
} | |||
} | |||
/** | |||
* Find the previous visible tab. Returns -1 if none is found. | |||
* | |||
@@ -1086,8 +1101,13 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware | |||
PREV_SCROLLER_DISABLED_CLASSNAME); | |||
} | |||
private boolean isScrollerHidden() { | |||
return scroller.getStyle().getDisplay().equals(Display.NONE.getCssName()); | |||
} | |||
private boolean isIndexSkippingHiddenTabs() { | |||
return isAllTabsBeforeIndexInvisible() && isScrollerPrevDisabled(); | |||
return isAllTabsBeforeIndexInvisible() | |||
&& (isScrollerPrevDisabled() || isScrollerHidden()); | |||
} | |||
@Override | |||
@@ -1105,12 +1125,21 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware | |||
// Should not set tabs visible if they are scrolled out of view | |||
tab.setVisible(false); | |||
} else { | |||
// reset the scroller index back to zero if tab is visible | |||
// again and tab is in view | |||
if (isIndexSkippingHiddenTabs() && tabState.visible) { | |||
scrollerIndex = 0; | |||
//When the tab was hidden and then turned visible again | |||
//and there is space for it, it should be in view (#17096) (#17333) | |||
if (isTabSetVisibleBeforeScroller(tabState, index, tab)) { | |||
scrollerIndex = index; | |||
tab.setVisible(true); | |||
tab.setStyleNames(false, true); | |||
//scroll to the currently selected tab if it got clipped | |||
//after making another tab visible | |||
if(isClippedTabs()) { | |||
scrollIntoView(getActiveTab()); | |||
} | |||
} else { | |||
tab.setVisible(tabState.visible); | |||
} | |||
tab.setVisible(tabState.visible); | |||
} | |||
/* | |||
@@ -1120,6 +1149,26 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware | |||
tab.recalculateCaptionWidth(); | |||
} | |||
/** | |||
* Checks whether the tab has been set to visible and the scroller is at the first visible tab. | |||
* That means that the scroller has to be adjusted so that the tab is visible again. | |||
*/ | |||
private boolean isTabSetVisibleBeforeScroller(TabState tabState, int index, Tab tab) { | |||
return isIndexSkippingHiddenTabs() && isScrollerAtFirstVisibleTab() | |||
&& hasTabChangedVisibility(tabState, tab) && scrolledOutOfView(index); | |||
} | |||
/** | |||
* Checks whether the tab is visible on server but is not visible on client yet. | |||
*/ | |||
private boolean hasTabChangedVisibility(TabState tabState, Tab tab) { | |||
return !tab.isVisible() && tabState.visible; | |||
} | |||
private boolean isScrollerAtFirstVisibleTab() { | |||
return tb.getFirstVisibleTabClient() == scrollerIndex; | |||
} | |||
/** | |||
* @deprecated as of 7.1, VTabsheet only keeps the active tab in the DOM | |||
* without any place holders. |
@@ -1526,10 +1526,8 @@ public class Grid<T> extends ResizeComposite implements | |||
} | |||
// Do not render over the vertical scrollbar | |||
int nativeScrollbarSize = WidgetUtil.getNativeScrollbarSize(); | |||
if (nativeScrollbarSize > 0) { | |||
editorOverlay.getStyle().setRight(nativeScrollbarSize, Unit.PX); | |||
} | |||
editorOverlay.getStyle().setWidth(grid.escalator.getInnerWidth(), | |||
Unit.PX); | |||
} | |||
private boolean buttonsShouldBeRenderedBelow(TableRowElement tr) { | |||
@@ -2268,8 +2266,7 @@ public class Grid<T> extends ResizeComposite implements | |||
// If selection cell already contains a widget do not | |||
// create a new CheckBox | |||
HeaderCell selectionCell = header.getDefaultRow().getCell(this); | |||
if (selectionCell.getType() | |||
.equals(GridStaticCellType.WIDGET) | |||
if (selectionCell.getType().equals(GridStaticCellType.WIDGET) | |||
&& selectionCell.getWidget() instanceof CheckBox) { | |||
return; | |||
} |
@@ -32,6 +32,7 @@ package com.vaadin.navigator; | |||
*/ | |||
import java.io.Serializable; | |||
import java.util.ArrayList; | |||
import java.util.Iterator; | |||
import java.util.LinkedList; | |||
import java.util.List; | |||
@@ -597,7 +598,10 @@ public class Navigator implements Serializable { | |||
* block the navigation operation | |||
*/ | |||
protected boolean fireBeforeViewChange(ViewChangeEvent event) { | |||
for (ViewChangeListener l : listeners) { | |||
// a copy of the listener list is needed to avoid | |||
// ConcurrentModificationException as a listener can add/remove | |||
// listeners | |||
for (ViewChangeListener l : new ArrayList<ViewChangeListener>(listeners)) { | |||
if (!l.beforeViewChange(event)) { | |||
return false; | |||
} | |||
@@ -647,7 +651,10 @@ public class Navigator implements Serializable { | |||
* view change event (not null) | |||
*/ | |||
protected void fireAfterViewChange(ViewChangeEvent event) { | |||
for (ViewChangeListener l : listeners) { | |||
// a copy of the listener list is needed to avoid | |||
// ConcurrentModificationException as a listener can add/remove | |||
// listeners | |||
for (ViewChangeListener l : new ArrayList<ViewChangeListener>(listeners)) { | |||
l.afterViewChange(event); | |||
} | |||
} |
@@ -336,11 +336,11 @@ public class VaadinServlet extends HttpServlet implements Constants { | |||
return; | |||
} | |||
if (isStaticResourceRequest(request)) { | |||
if (isStaticResourceRequest(vaadinRequest)) { | |||
// Define current servlet and service, but no request and response | |||
getService().setCurrentInstances(null, null); | |||
try { | |||
serveStaticResources(request, response); | |||
serveStaticResources(vaadinRequest, vaadinResponse); | |||
return; | |||
} finally { | |||
CurrentInstance.clearAll(); |
@@ -5985,10 +5985,6 @@ public class Grid extends AbstractComponent implements SelectionNotifier, | |||
setEditorEnabled(DesignAttributeHandler.readAttribute("editable", | |||
attrs, boolean.class)); | |||
} | |||
if (attrs.hasKey("frozen-columns")) { | |||
setFrozenColumnCount(DesignAttributeHandler.readAttribute( | |||
"frozen-columns", attrs, int.class)); | |||
} | |||
if (attrs.hasKey("rows")) { | |||
setHeightByRows(DesignAttributeHandler.readAttribute("rows", attrs, | |||
double.class)); | |||
@@ -6045,6 +6041,12 @@ public class Grid extends AbstractComponent implements SelectionNotifier, | |||
} | |||
} | |||
} | |||
// Read frozen columns after columns are read. | |||
if (attrs.hasKey("frozen-columns")) { | |||
setFrozenColumnCount(DesignAttributeHandler.readAttribute( | |||
"frozen-columns", attrs, int.class)); | |||
} | |||
} | |||
@Override |
@@ -15,11 +15,18 @@ | |||
*/ | |||
package com.vaadin.tests.server.component.abstractfield; | |||
import static org.junit.Assert.assertTrue; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.AbstractField; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests declarative support for implementations of {@link AbstractField}. | |||
@@ -31,23 +38,12 @@ public class AbstractFieldDeclarativeTest extends | |||
DeclarativeTestBase<AbstractField<?>> { | |||
@Test | |||
public void testPlainTextRead() { | |||
testRead(getDesign(), getExpected()); | |||
} | |||
@Test | |||
public void testPlainTextWrite() { | |||
testWrite(getDesign(), getExpected()); | |||
} | |||
protected String getDesign() { | |||
return "<v-text-field buffered='true' validation-visible='false' invalid-committed='true'" | |||
public void testPlainText() { | |||
String design = "<v-text-field buffered='true' validation-visible='false' invalid-committed='true'" | |||
+ " invalid-allowed='false' required='true' required-error='This is a required field'" | |||
+ " conversion-error='Input {0} cannot be parsed' tabindex=3 readonly='true'/>"; | |||
} | |||
protected AbstractField getExpected() { | |||
TextField tf = new TextField(); | |||
AbstractField tf = new TextField(); | |||
tf.setBuffered(true); | |||
tf.setBuffered(true); | |||
tf.setValidationVisible(false); | |||
tf.setInvalidCommitted(true); | |||
@@ -57,7 +53,40 @@ public class AbstractFieldDeclarativeTest extends | |||
tf.setConversionError("Input {0} cannot be parsed"); | |||
tf.setTabIndex(3); | |||
tf.setReadOnly(true); | |||
return tf; | |||
}; | |||
testRead(design, tf); | |||
testWrite(design, tf); | |||
// Test with readonly=false | |||
design = design.replace("readonly='true'", ""); | |||
tf.setReadOnly(false); | |||
testRead(design, tf); | |||
testWrite(design, tf); | |||
} | |||
@Test | |||
public void testWriteRemovesOldContent() { | |||
Attributes attr = new Attributes(); | |||
attr.put("should_be_removed", "foo"); | |||
Element design = new Element(Tag.valueOf("v-text-field"), "", attr); | |||
AbstractField component = new TextField(); | |||
component.setReadOnly(true); | |||
component.writeDesign(design, new DesignContext()); | |||
// we only changed one of the attributes, others are at default values | |||
assertEquals(1, design.attributes().size()); | |||
assertTrue("Design must contain readonly", design.hasAttr("readonly")); | |||
assertTrue("Readonly must be true", design.attr("readonly").equals("") | |||
|| design.attr("readonly").equals("true")); | |||
} | |||
@Test | |||
public void testModelReadOnly() { | |||
// Test that read only value coming from property data source is not | |||
// written to design. | |||
String design = "<v-text-field value=test></v-text-field>"; | |||
AbstractField component = new TextField(); | |||
ObjectProperty<String> property = new ObjectProperty<String>("test"); | |||
property.setReadOnly(true); | |||
component.setPropertyDataSource(property); | |||
testWrite(design, component); | |||
} | |||
} |
@@ -1,71 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstractfield; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.AbstractField; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* | |||
* Test case for reading the attributes of the AbstractField from design | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
public void testSynchronizeReadOnly() { | |||
Element design = createDesign("readonly", ""); | |||
AbstractField component = getComponent(); | |||
component.readDesign(design, ctx); | |||
assertEquals(true, component.isReadOnly()); | |||
design = createDesign("readonly", "false"); | |||
component.readDesign(design, ctx); | |||
assertEquals(false, component.isReadOnly()); | |||
} | |||
public void testSynchronizeTabIndex() { | |||
Element design = createDesign("tabindex", "2"); | |||
AbstractField component = getComponent(); | |||
component.readDesign(design, ctx); | |||
assertEquals("Tab index must be 2", 2, component.getTabIndex()); | |||
} | |||
private AbstractField getComponent() { | |||
return new TextField(); | |||
} | |||
private Element createDesign(String key, String value) { | |||
Attributes attributes = new Attributes(); | |||
attributes.put(key, value); | |||
Element node = new Element(Tag.valueOf("v-text-field"), "", attributes); | |||
return node; | |||
} | |||
} |
@@ -1,77 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstractfield; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.ui.AbstractField; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for writing the attributes of the AbstractField to design | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
public void testSynchronizeReadOnly() { | |||
Element design = createDesign(); | |||
AbstractField component = getComponent(); | |||
component.setReadOnly(true); | |||
component.writeDesign(design, ctx); | |||
// we only changed one of the attributes, others are at default values | |||
assertEquals(1, design.attributes().size()); | |||
assertTrue("Design must contain readonly", design.hasAttr("readonly")); | |||
assertTrue("Readonly must be true", design.attr("readonly").equals("") | |||
|| design.attr("readonly").equals("true")); | |||
} | |||
public void testSynchronizeModelReadOnly() { | |||
Element design = createDesign(); | |||
AbstractField component = getComponent(); | |||
ObjectProperty property = new ObjectProperty<String>("test"); | |||
property.setReadOnly(true); | |||
component.setPropertyDataSource(property); | |||
component.writeDesign(design, ctx); | |||
// make sure that property readonly is not written to design | |||
assertFalse("Design must not contain readonly", | |||
design.hasAttr("readonly")); | |||
} | |||
private AbstractField getComponent() { | |||
return new TextField(); | |||
} | |||
private Element createDesign() { | |||
Attributes attr = new Attributes(); | |||
attr.put("should_be_removed", "foo"); | |||
return new Element(Tag.valueOf("v-text-field"), "", attr); | |||
} | |||
} |
@@ -0,0 +1,178 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstractorderedlayout; | |||
import static org.junit.Assert.assertTrue; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.shared.ui.label.ContentMode; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.AbstractOrderedLayout; | |||
import com.vaadin.ui.Alignment; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests declarative support for AbstractOrderedLayout. | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class AbstractOrderedLayoutDeclarativeTest extends | |||
DeclarativeTestBase<AbstractOrderedLayout> { | |||
private List<String> defaultAlignments = Arrays.asList(new String[] { | |||
":top", ":left" }); | |||
@Test | |||
public void testMargin() { | |||
String design = getDesign(0, true); | |||
AbstractOrderedLayout layout = getLayout(0, true, null); | |||
testRead(design, layout); | |||
testWrite(design, layout); | |||
design = getDesign(0, false); | |||
layout = getLayout(0, false, null); | |||
testRead(design, layout); | |||
testWrite(design, layout); | |||
} | |||
@Test | |||
public void testExpandRatio() { | |||
String design = getDesign(1, false); | |||
AbstractOrderedLayout layout = getLayout(1, false, null); | |||
testRead(design, layout); | |||
testWrite(design, layout); | |||
design = getDesign(0.25f, false); | |||
layout = getLayout(0.25f, false, null); | |||
testRead(design, layout); | |||
testWrite(design, layout); | |||
} | |||
@Test | |||
public void testAlignment() { | |||
String design = getDesign(0, false, ":top", ":left"); | |||
AbstractOrderedLayout layout = getLayout(0, false, Alignment.TOP_LEFT); | |||
testRead(design, layout); | |||
testWrite(design, layout); | |||
design = getDesign(0, false, ":middle", ":center"); | |||
layout = getLayout(0, false, Alignment.MIDDLE_CENTER); | |||
testRead(design, layout); | |||
testWrite(design, layout); | |||
design = getDesign(0, false, ":bottom", ":right"); | |||
layout = getLayout(0, false, Alignment.BOTTOM_RIGHT); | |||
testRead(design, layout); | |||
testWrite(design, layout); | |||
} | |||
@Test | |||
public void testWriteRemovesOldElementContent() { | |||
// Create an element with some content | |||
Attributes rootAttributes = new Attributes(); | |||
rootAttributes.put("caption", "test-layout"); | |||
Element design = new Element(Tag.valueOf("v-vertical-layout"), "", | |||
rootAttributes); | |||
Attributes firstChildAttributes = new Attributes(); | |||
firstChildAttributes.put("caption", "test-label"); | |||
Element firstChild = new Element(Tag.valueOf("v-label"), "", | |||
firstChildAttributes); | |||
design.appendChild(firstChild); | |||
Attributes secondChildAttributes = new Attributes(); | |||
secondChildAttributes.put("caption", "test-button"); | |||
Element secondChild = new Element(Tag.valueOf("v-button"), "", | |||
secondChildAttributes); | |||
design.appendChild(secondChild); | |||
Attributes thirdChildAttributes = new Attributes(); | |||
thirdChildAttributes.put("caption", "test-button-2"); | |||
Element thirdChild = new Element(Tag.valueOf("v-button"), "", | |||
thirdChildAttributes); | |||
design.appendChild(thirdChild); | |||
// Create and write a layout and check the new contents of the element | |||
// node | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.addComponent(new Label("test-label")); | |||
layout.getComponent(0).setCaption("test-caption"); | |||
layout.setExpandRatio(layout.getComponent(0), 1.0f); | |||
layout.addComponent(new Label("test-label-2")); | |||
layout.writeDesign(design, new DesignContext()); | |||
assertEquals(2, design.childNodes().size()); | |||
assertEquals("v-label", ((Element) design.childNode(0)).tagName()); | |||
assertEquals("test-caption", design.childNode(0).attr("caption")); | |||
assertTrue(design.childNode(0).hasAttr(":expand")); | |||
assertEquals("", design.childNode(0).attr(":expand")); | |||
} | |||
private String getDesign(float expandRatio, boolean margin, | |||
String... alignments) { | |||
String result = "<v-vertical-layout caption=test-layout"; | |||
if (margin) { | |||
result += " margin=true"; | |||
} | |||
result += "><v-label caption=test-label "; | |||
String ratioString = expandRatio == 1.0f ? "\"\"" : String | |||
.valueOf(expandRatio); | |||
if (expandRatio != 0) { | |||
result += ":expand=" + ratioString; | |||
} | |||
for (String alignment : alignments) { | |||
if (!defaultAlignments.contains(alignment)) { | |||
result += " " + alignment + "=\"\""; | |||
} | |||
} | |||
result += "></v-label><v-button "; | |||
if (expandRatio != 0) { | |||
result += ":expand=" + ratioString; | |||
} | |||
for (String alignment : alignments) { | |||
if (!defaultAlignments.contains(alignment)) { | |||
result += " " + alignment + "=\"\""; | |||
} | |||
} | |||
result += "></v-button></v-vertical-layout>"; | |||
return result; | |||
} | |||
private AbstractOrderedLayout getLayout(float expandRatio, boolean margin, | |||
Alignment alignment) { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.setMargin(margin); | |||
layout.setCaption("test-layout"); | |||
Label l = new Label(); | |||
l.setCaption("test-label"); | |||
l.setContentMode(ContentMode.HTML); | |||
layout.addComponent(l); | |||
layout.setExpandRatio(l, expandRatio); | |||
Button b = new Button(); | |||
b.setCaptionAsHtml(true); | |||
layout.addComponent(b); | |||
layout.setExpandRatio(b, expandRatio); | |||
if (alignment != null) { | |||
layout.setComponentAlignment(l, alignment); | |||
layout.setComponentAlignment(b, alignment); | |||
} | |||
return layout; | |||
} | |||
} |
@@ -1,119 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstractorderedlayout; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.Alignment; | |||
import com.vaadin.ui.Component; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case from reading AbstractOrdered layouts from design | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
public void testChildCount() { | |||
VerticalLayout root = createLayout(0f, false); | |||
assertEquals(2, root.getComponentCount()); | |||
} | |||
public void testMargin() { | |||
VerticalLayout root = createLayout(0f, true); | |||
assertTrue(root.getMargin().getBitMask() != 0); | |||
root = createLayout(0f, false); | |||
assertTrue(root.getMargin().getBitMask() == 0); | |||
} | |||
public void testAttributes() { | |||
VerticalLayout root = createLayout(0f, false); | |||
assertEquals("test-layout", root.getCaption()); | |||
assertEquals("test-label", root.getComponent(0).getCaption()); | |||
assertEquals("test-button", root.getComponent(1).getCaption()); | |||
} | |||
public void testExpandRatio() { | |||
VerticalLayout root = createLayout(1f, false); | |||
assertEquals(1f, root.getExpandRatio(root.getComponent(0))); | |||
assertEquals(1f, root.getExpandRatio(root.getComponent(1))); | |||
root = createLayout(0f, false); | |||
assertEquals(0f, root.getExpandRatio(root.getComponent(0))); | |||
assertEquals(0f, root.getExpandRatio(root.getComponent(1))); | |||
} | |||
public void testAlignment() { | |||
VerticalLayout root = createLayout(0f, false, ":top", ":left"); | |||
assertEquals(Alignment.TOP_LEFT, | |||
root.getComponentAlignment(root.getComponent(0))); | |||
root = createLayout(0f, false, ":middle", ":center"); | |||
assertEquals(Alignment.MIDDLE_CENTER, | |||
root.getComponentAlignment(root.getComponent(0))); | |||
root = createLayout(0f, false, ":bottom", ":right"); | |||
assertEquals(Alignment.BOTTOM_RIGHT, | |||
root.getComponentAlignment(root.getComponent(0))); | |||
} | |||
private VerticalLayout createLayout(float expandRatio, boolean margin, | |||
String... alignments) { | |||
DesignContext ctx = new DesignContext(); | |||
Element design = createDesign(expandRatio, margin, alignments); | |||
Component child = ctx.readDesign(design); | |||
return (VerticalLayout) child; | |||
} | |||
private Element createDesign(float expandRatio, boolean margin, | |||
String... alignments) { | |||
Attributes rootAttributes = new Attributes(); | |||
rootAttributes.put("caption", "test-layout"); | |||
if (margin) { | |||
rootAttributes.put("margin", ""); | |||
} | |||
Element node = new Element(Tag.valueOf("v-vertical-layout"), "", | |||
rootAttributes); | |||
Attributes firstChildAttributes = new Attributes(); | |||
firstChildAttributes.put("caption", "test-label"); | |||
firstChildAttributes.put(":expand", String.valueOf(expandRatio)); | |||
for (String alignment : alignments) { | |||
firstChildAttributes.put(alignment, ""); | |||
} | |||
Element firstChild = new Element(Tag.valueOf("v-label"), "", | |||
firstChildAttributes); | |||
node.appendChild(firstChild); | |||
Attributes secondChildAttributes = new Attributes(); | |||
secondChildAttributes.put(":expand", String.valueOf(expandRatio)); | |||
for (String alignment : alignments) { | |||
secondChildAttributes.put(alignment, ""); | |||
} | |||
Element secondChild = new Element(Tag.valueOf("v-button"), "", | |||
secondChildAttributes); | |||
secondChild.html("test-button"); | |||
node.appendChild(secondChild); | |||
return node; | |||
} | |||
} |
@@ -1,148 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstractorderedlayout; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.Alignment; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for writing abstract ordered layout to design | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
public void testSynchronizeMargin() { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.setMargin(true); | |||
Element design = createDesign(); | |||
layout.writeDesign(design, createDesignContext()); | |||
assertTrue("The margin must be written", design.hasAttr("margin")); | |||
assertTrue("The margin must be empty or true", design.attr("margin") | |||
.equals("") || design.attr("margin").equalsIgnoreCase("true")); | |||
} | |||
public void testSynchronizeEmptyLayout() { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.setCaption("changed-caption"); | |||
Element design = createDesign(); | |||
layout.writeDesign(design, createDesignContext()); | |||
assertEquals(0, design.childNodes().size()); | |||
assertEquals("changed-caption", design.attr("caption")); | |||
} | |||
public void testSynchronizeLayoutWithChildren() { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.addComponent(new Label("test-label")); | |||
layout.getComponent(0).setCaption("test-caption"); | |||
layout.addComponent(new Label("test-label-2")); | |||
Element design = createDesign(); | |||
layout.writeDesign(design, createDesignContext()); | |||
assertEquals(2, design.childNodes().size()); | |||
assertEquals("v-label", ((Element) design.childNode(0)).tagName()); | |||
assertEquals("test-caption", design.childNode(0).attr("caption")); | |||
} | |||
public void testSynchronizeUnitExpandRatio() { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.addComponent(new Label("test-label")); | |||
layout.setExpandRatio(layout.getComponent(0), 1.0f); | |||
Element design = createDesign(); | |||
layout.writeDesign(design, createDesignContext()); | |||
assertTrue(design.childNode(0).hasAttr(":expand")); | |||
assertEquals("", design.childNode(0).attr(":expand")); | |||
} | |||
public void testSynchronizeArbitraryExpandRatio() { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.addComponent(new Label("test-label")); | |||
layout.setExpandRatio(layout.getComponent(0), 2.40f); | |||
Element design = createDesign(); | |||
layout.writeDesign(design, createDesignContext()); | |||
assertTrue(design.childNode(0).hasAttr(":expand")); | |||
assertEquals("2.4", design.childNode(0).attr(":expand")); | |||
} | |||
public void testSynchronizeDefaultAlignment() { | |||
Element design = createDesign(); | |||
VerticalLayout layout = createLayoutWithAlignment(design, null); | |||
layout.writeDesign(design, createDesignContext()); | |||
assertFalse(design.childNode(0).hasAttr(":top")); | |||
assertFalse(design.childNode(0).hasAttr(":left")); | |||
} | |||
public void testSynchronizeMiddleCenter() { | |||
Element design = createDesign(); | |||
VerticalLayout layout = createLayoutWithAlignment(design, | |||
Alignment.MIDDLE_CENTER); | |||
layout.writeDesign(design, createDesignContext()); | |||
assertTrue(design.childNode(0).hasAttr(":middle")); | |||
assertTrue(design.childNode(0).hasAttr(":center")); | |||
} | |||
public void testSynchronizeBottomRight() { | |||
Element design = createDesign(); | |||
VerticalLayout layout = createLayoutWithAlignment(design, | |||
Alignment.BOTTOM_RIGHT); | |||
layout.writeDesign(design, createDesignContext()); | |||
assertTrue(design.childNode(0).hasAttr(":bottom")); | |||
assertTrue(design.childNode(0).hasAttr(":right")); | |||
} | |||
private VerticalLayout createLayoutWithAlignment(Element design, | |||
Alignment alignment) { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.addComponent(new Label("test-label")); | |||
if (alignment != null) { | |||
layout.setComponentAlignment(layout.getComponent(0), alignment); | |||
} | |||
layout.writeDesign(design, createDesignContext()); | |||
return layout; | |||
} | |||
private Element createDesign() { | |||
// make sure that the design node has old content that should be removed | |||
Attributes rootAttributes = new Attributes(); | |||
rootAttributes.put("caption", "test-layout"); | |||
Element node = new Element(Tag.valueOf("v-vertical-layout"), "", | |||
rootAttributes); | |||
Attributes firstChildAttributes = new Attributes(); | |||
firstChildAttributes.put("caption", "test-label"); | |||
Element firstChild = new Element(Tag.valueOf("v-label"), "", | |||
firstChildAttributes); | |||
node.appendChild(firstChild); | |||
Attributes secondChildAttributes = new Attributes(); | |||
secondChildAttributes.put("caption", "test-button"); | |||
Element secondChild = new Element(Tag.valueOf("v-button"), "", | |||
secondChildAttributes); | |||
node.appendChild(secondChild); | |||
return node; | |||
} | |||
private DesignContext createDesignContext() { | |||
return new DesignContext(); | |||
} | |||
} |
@@ -0,0 +1,110 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstractsplitpanel; | |||
import static junit.framework.TestCase.assertTrue; | |||
import org.jsoup.nodes.Element; | |||
import org.junit.Test; | |||
import com.vaadin.server.Sizeable.Unit; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.AbstractSplitPanel; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.HorizontalSplitPanel; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.Table; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.VerticalSplitPanel; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests declarative support for AbstractSplitPanel. | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class AbstractSplitPanelDeclarativeTest extends | |||
DeclarativeTestBase<AbstractSplitPanel> { | |||
@Test | |||
public void testWithBothChildren() { | |||
String design = "<v-horizontal-split-panel split-position=20.5% " | |||
+ "min-split-position=20% max-split-position=50px locked=true " | |||
+ "reversed=\"\"> <v-table /> <v-vertical-layout />" | |||
+ "</v-horizontal-split-panel>"; | |||
AbstractSplitPanel sp = new HorizontalSplitPanel(); | |||
sp.setSplitPosition(20.5f, Unit.PERCENTAGE, true); | |||
sp.setMinSplitPosition(20, Unit.PERCENTAGE); | |||
sp.setMaxSplitPosition(50, Unit.PIXELS); | |||
sp.setLocked(true); | |||
sp.addComponent(new Table()); | |||
sp.addComponent(new VerticalLayout()); | |||
testRead(design, sp); | |||
testWrite(design, sp); | |||
} | |||
@Test | |||
public void testWithFirstChild() { | |||
String design = "<v-vertical-split-panel><v-table caption=\"First slot\"/>" | |||
+ "</v-vertical-split-panel>"; | |||
AbstractSplitPanel sp = new VerticalSplitPanel(); | |||
Table t = new Table(); | |||
t.setCaption("First slot"); | |||
sp.addComponent(t); | |||
testRead(design, sp); | |||
testWrite(design, sp); | |||
} | |||
@Test | |||
public void testWithSecondChild() { | |||
String design = "<v-horizontal-split-panel><v-button :second>Second slot</v-button>" | |||
+ "</v-vertical-split-panel>"; | |||
AbstractSplitPanel sp = new HorizontalSplitPanel(); | |||
Button b = new Button("Second slot"); | |||
b.setCaptionAsHtml(true); | |||
sp.setSecondComponent(b); | |||
testRead(design, sp); | |||
testWrite(design, sp); | |||
} | |||
@Test | |||
public void testEmpty() { | |||
String design = "<v-horizontal-split-panel/>"; | |||
AbstractSplitPanel sp = new HorizontalSplitPanel(); | |||
testRead(design, sp); | |||
testWrite(design, sp); | |||
} | |||
@Test | |||
public void testReSynchronize() { | |||
// Test that old children and attributes are removed when an element is | |||
// synchronized to a new component. | |||
DesignContext ctx = new DesignContext(); | |||
VerticalSplitPanel sp = new VerticalSplitPanel(); | |||
sp.setMinSplitPosition(5.5f, Unit.PERCENTAGE); | |||
sp.setMaxSplitPosition(95, Unit.PERCENTAGE); | |||
sp.setFirstComponent(new Button("First slot")); | |||
sp.setSecondComponent(new Label("Second slot")); | |||
Element e = ctx.createElement(sp); | |||
sp = new VerticalSplitPanel(); | |||
sp.writeDesign(e, ctx); | |||
assertTrue("There should be no attributes in the node.", e.attributes() | |||
.size() == 0); | |||
assertTrue("There should be no child elements.", | |||
e.children().size() == 0); | |||
} | |||
} |
@@ -1,158 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstractsplitpanel; | |||
import java.lang.reflect.Method; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.server.Sizeable.Unit; | |||
import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState.SplitterState; | |||
import com.vaadin.ui.AbstractSplitPanel; | |||
import com.vaadin.ui.HorizontalSplitPanel; | |||
import com.vaadin.ui.Table; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.VerticalSplitPanel; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests synchronizing the attributes and children of horizontal and vertical | |||
* split panels from a design. | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
DesignContext ctx; | |||
@Override | |||
protected void setUp() { | |||
ctx = new DesignContext(); | |||
} | |||
public void testAttributes() throws Exception { | |||
// Create a design with non-default attributes values. | |||
Element design = createDesign(true, false, true, true); | |||
HorizontalSplitPanel sp = new HorizontalSplitPanel(); | |||
sp.readDesign(design, ctx); | |||
// Check that the attributes are correctly parsed. | |||
assertEquals(20.5f, sp.getSplitPosition()); | |||
assertEquals(Unit.PERCENTAGE, sp.getSplitPositionUnit()); | |||
assertEquals(20f, sp.getMinSplitPosition()); | |||
assertEquals(Unit.PERCENTAGE, sp.getMinSplitPositionUnit()); | |||
assertEquals(50f, sp.getMaxSplitPosition()); | |||
assertEquals(Unit.PIXELS, sp.getMaxSplitPositionUnit()); | |||
assertEquals(true, sp.isLocked()); | |||
checkReversed(sp, true); | |||
} | |||
public void testWithNoChildren() { | |||
Element design = createDesign(true, false, false, false); | |||
HorizontalSplitPanel sp = new HorizontalSplitPanel(); | |||
sp.readDesign(design, ctx); | |||
assertEquals("Unexpected child count for the split panel.", 0, | |||
sp.getComponentCount()); | |||
} | |||
public void testWithFirstChild() { | |||
Element design = createDesign(false, false, true, false); | |||
VerticalSplitPanel sp = new VerticalSplitPanel(); | |||
sp.readDesign(design, ctx); | |||
assertEquals("Unexpected child count for the split panel.", 1, | |||
sp.getComponentCount()); | |||
Object obj = sp.getFirstComponent(); | |||
assertEquals("Wrong component in split panel.", Table.class, | |||
obj.getClass()); | |||
} | |||
public void testWithSecondChild() { | |||
Element design = createDesign(true, false, false, true); | |||
HorizontalSplitPanel sp = new HorizontalSplitPanel(); | |||
sp.readDesign(design, ctx); | |||
assertEquals("Unexpected child count for the split panel.", 1, | |||
sp.getComponentCount()); | |||
Object obj = sp.getSecondComponent(); | |||
assertEquals("Wrong component in split panel.", VerticalLayout.class, | |||
obj.getClass()); | |||
} | |||
public void testWithBothChildren() { | |||
Element design = createDesign(false, false, true, true); | |||
VerticalSplitPanel sp = new VerticalSplitPanel(); | |||
sp.readDesign(design, ctx); | |||
assertEquals("Unexpected child count for the split panel.", 2, | |||
sp.getComponentCount()); | |||
Object first = sp.getFirstComponent(); | |||
Object second = sp.getSecondComponent(); | |||
assertEquals("Wrong first component in split panel.", Table.class, | |||
first.getClass()); | |||
assertEquals("Wrong second component in split panel.", | |||
VerticalLayout.class, second.getClass()); | |||
} | |||
/* | |||
* Creates an html tree node structure representing a split panel and its | |||
* contents. The parameters are used for controlling whether the split panel | |||
* is horizontal or vertical, whether attributes are set for the design and | |||
* whether the split panel should have the first and the second child | |||
* component. | |||
*/ | |||
private Element createDesign(boolean horizontal, | |||
boolean useDefaultAttributes, boolean hasFirstChild, | |||
boolean hasSecondChild) { | |||
Attributes attributes = new Attributes(); | |||
if (!useDefaultAttributes) { | |||
attributes.put("split-position", "20.5%"); | |||
// The unitless number should correspond to 20% | |||
attributes.put("min-split-position", "20"); | |||
attributes.put("max-split-position", "50px"); | |||
attributes.put("locked", ""); | |||
attributes.put("reversed", ""); | |||
} | |||
String tagName = horizontal ? "v-horizontal-split-panel" | |||
: "v-vertical-split-panel"; | |||
Element element = new Element(Tag.valueOf(tagName), "", attributes); | |||
// Create the children | |||
if (hasFirstChild) { | |||
Element child = new Element(Tag.valueOf("v-table"), ""); | |||
element.appendChild(child); | |||
} | |||
if (hasSecondChild) { | |||
Element child = new Element(Tag.valueOf("v-vertical-layout"), ""); | |||
if (!hasFirstChild) { | |||
child.attr(":second", ""); | |||
} | |||
element.appendChild(child); | |||
} | |||
return element; | |||
} | |||
/* | |||
* Checks the reversed property of a split panel. | |||
*/ | |||
private void checkReversed(AbstractSplitPanel sp, boolean expected) | |||
throws Exception { | |||
Method getter = AbstractSplitPanel.class | |||
.getDeclaredMethod("getSplitterState"); | |||
getter.setAccessible(true); | |||
SplitterState state = (SplitterState) getter.invoke(sp); | |||
assertEquals("Wrong value for split panel property reversed.", | |||
expected, state.positionReversed); | |||
} | |||
} |
@@ -1,151 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstractsplitpanel; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Element; | |||
import com.vaadin.server.Sizeable.Unit; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.HorizontalSplitPanel; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.VerticalSplitPanel; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests synchronizing the properties and child components of split panels to a | |||
* design. | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
public void setUp() { | |||
ctx = new DesignContext(); | |||
} | |||
public void testHorizontalWithDefaultValues() { | |||
// no attributes or child elements should appear | |||
HorizontalSplitPanel sp = new HorizontalSplitPanel(); | |||
Element e = ctx.createElement(sp); | |||
assertEquals("Wrong tag name.", "v-horizontal-split-panel", | |||
e.nodeName()); | |||
assertEquals("The split panel should not have attributes.", 0, e | |||
.attributes().size()); | |||
assertEquals("The split panel should not have children.", 0, e | |||
.children().size()); | |||
} | |||
public void testVerticalWithAttributes() { | |||
// All defined attributes should be output in the tree node. No child | |||
// components are present in this test. | |||
VerticalSplitPanel sp = new VerticalSplitPanel(); | |||
sp.setSplitPosition(27f, Unit.PIXELS, true); | |||
sp.setMinSplitPosition(5.5f, Unit.PERCENTAGE); | |||
sp.setMaxSplitPosition(95, Unit.PERCENTAGE); | |||
sp.setLocked(true); | |||
Element e = ctx.createElement(sp); | |||
assertEquals("Wrong tag name.", "v-vertical-split-panel", e.nodeName()); | |||
assertEquals("Unexpected number of attributes.", 5, e.attributes() | |||
.size()); | |||
assertEquals("Wrong split position.", "27px", e.attr("split-position")); | |||
assertEquals("Wrong minimum split position.", "5.5%", | |||
e.attr("min-split-position")); | |||
assertEquals("Wrong maximum split position.", "95%", | |||
e.attr("max-split-position")); | |||
assertTrue("Unexpected value for locked: " + e.attr("locked"), | |||
"true".equals(e.attr("locked")) || "".equals(e.attr("locked"))); | |||
assertTrue( | |||
"Unexpected value for reversed: " + e.attr("reversed"), | |||
"true".equals(e.attr("reversed")) | |||
|| "".equals(e.attr("reversed"))); | |||
} | |||
public void testHorizontalWithFirstChild() { | |||
// The split panel contains only the first child. | |||
HorizontalSplitPanel sp = new HorizontalSplitPanel(); | |||
sp.setSplitPosition(25f); | |||
sp.setFirstComponent(new Button("First slot")); | |||
Element e = ctx.createElement(sp); | |||
assertEquals("Wrong split position.", "25%", e.attr("split-position")); | |||
assertEquals("Wrong number of child elements.", 1, e.children().size()); | |||
Element eb = e.children().get(0); | |||
assertEquals("Wrong tag name of first child element.", "v-button", | |||
eb.nodeName()); | |||
assertEquals("Wrong text in the button element.", "First slot", | |||
eb.html()); | |||
} | |||
public void testVerticalWithSecondChild() { | |||
// The split panel contains only the second child. | |||
VerticalSplitPanel sp = new VerticalSplitPanel(); | |||
sp.setMinSplitPosition(25f, Unit.PIXELS); | |||
sp.setSecondComponent(new Label("Second slot")); | |||
Element e = ctx.createElement(sp); | |||
assertEquals("Wrong minimum split position.", "25px", | |||
e.attr("min-split-position")); | |||
assertEquals("Wrong number of child elements.", 1, e.children().size()); | |||
Element el = e.children().get(0); | |||
assertEquals("Wrong tag name of child element.", "v-label", | |||
el.nodeName()); | |||
assertEquals("Wrong text in the label element.", "Second slot", | |||
el.html()); | |||
assertTrue("Missing attribute :second in the label element.", | |||
el.hasAttr(":second")); | |||
} | |||
public void testVerticalWithBothChildren() { | |||
// The split panel has both child components. | |||
VerticalSplitPanel sp = new VerticalSplitPanel(); | |||
sp.setFirstComponent(new Button("First slot")); | |||
sp.setSecondComponent(new Label("Second slot")); | |||
Element e = ctx.createElement(sp); | |||
assertEquals("Wrong number of child elements.", 2, e.children().size()); | |||
Element eb = e.children().get(0); | |||
assertEquals("Wrong tag name of first child element.", "v-button", | |||
eb.nodeName()); | |||
assertEquals("Wrong text in the button element.", "First slot", | |||
eb.html()); | |||
Element el = e.children().get(1); | |||
assertEquals("Wrong tag name of second child element.", "v-label", | |||
el.nodeName()); | |||
assertEquals("Wrong text in the label element.", "Second slot", | |||
el.html()); | |||
assertFalse( | |||
"There should be no :second attribute when a split panel has both children.", | |||
el.hasAttr(":second")); | |||
} | |||
public void testReSynchronize() { | |||
// Test that old children and attributes are removed when an element is | |||
// synchronized to a new component. | |||
VerticalSplitPanel sp = new VerticalSplitPanel(); | |||
sp.setMinSplitPosition(5.5f, Unit.PERCENTAGE); | |||
sp.setMaxSplitPosition(95, Unit.PERCENTAGE); | |||
sp.setFirstComponent(new Button("First slot")); | |||
sp.setSecondComponent(new Label("Second slot")); | |||
Element e = ctx.createElement(sp); | |||
sp = new VerticalSplitPanel(); | |||
sp.writeDesign(e, ctx); | |||
assertTrue("There should be no attributes in the node.", e.attributes() | |||
.size() == 0); | |||
assertTrue("There should be no child elements.", | |||
e.children().size() == 0); | |||
} | |||
} |
@@ -0,0 +1,52 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstracttextfield; | |||
import org.junit.Test; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.AbstractTextField; | |||
import com.vaadin.ui.AbstractTextField.TextChangeEventMode; | |||
import com.vaadin.ui.TextField; | |||
/** | |||
* Tests declarative support for AbstractTextField. | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class AbstractTextFieldDeclarativeTest extends | |||
DeclarativeTestBase<AbstractTextField> { | |||
@Test | |||
public void testAttributes() { | |||
String design = "<v-text-field null-representation=this-is-null " | |||
+ "null-setting-allowed=true maxlength=5 columns=3 " | |||
+ "input-prompt=input text-change-event-mode=eager " | |||
+ "text-change-timeout=100 />"; | |||
AbstractTextField tf = new TextField(); | |||
tf.setNullRepresentation("this-is-null"); | |||
tf.setNullSettingAllowed(true); | |||
tf.setMaxLength(5); | |||
tf.setColumns(3); | |||
tf.setInputPrompt("input"); | |||
tf.setTextChangeEventMode(TextChangeEventMode.EAGER); | |||
tf.setTextChangeTimeout(100); | |||
testRead(design, tf); | |||
testWrite(design, tf); | |||
} | |||
} |
@@ -1,73 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstracttextfield; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.AbstractTextField; | |||
import com.vaadin.ui.AbstractTextField.TextChangeEventMode; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for reading the attributes of the AbstractTextField from design | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
public void testAttributes() { | |||
Element design = createDesign(); | |||
AbstractTextField component = getComponent(); | |||
component.readDesign(design, ctx); | |||
assertEquals("this-is-null", component.getNullRepresentation()); | |||
assertEquals(true, component.isNullSettingAllowed()); | |||
assertEquals(5, component.getMaxLength()); | |||
assertEquals(3, component.getColumns()); | |||
assertEquals("input", component.getInputPrompt()); | |||
assertEquals(TextChangeEventMode.EAGER, | |||
component.getTextChangeEventMode()); | |||
assertEquals(100, component.getTextChangeTimeout()); | |||
} | |||
private AbstractTextField getComponent() { | |||
return new TextField(); | |||
} | |||
private Element createDesign() { | |||
Attributes attributes = new Attributes(); | |||
attributes.put("null-representation", "this-is-null"); | |||
attributes.put("null-setting-allowed", "true"); | |||
attributes.put("maxlength", "5"); | |||
attributes.put("columns", "3"); | |||
attributes.put("input-prompt", "input"); | |||
attributes.put("text-change-event-mode", "eager"); | |||
attributes.put("text-change-timeout", "100"); | |||
Element node = new Element(Tag.valueOf("v-text-field"), "", attributes); | |||
return node; | |||
} | |||
} |
@@ -1,73 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.abstracttextfield; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.AbstractTextField; | |||
import com.vaadin.ui.AbstractTextField.TextChangeEventMode; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for writing the attributes of the AbstractTextField to design | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
public void testSynchronizetestAttributes() { | |||
Element design = createDesign(); | |||
AbstractTextField component = getComponent(); | |||
component.setNullRepresentation("this-is-null"); | |||
component.setNullSettingAllowed(true); | |||
component.setMaxLength(5); | |||
component.setColumns(3); | |||
component.setInputPrompt("input"); | |||
component.setTextChangeEventMode(TextChangeEventMode.EAGER); | |||
component.setTextChangeTimeout(100); | |||
component.writeDesign(design, ctx); | |||
assertEquals("this-is-null", design.attr("null-representation")); | |||
assertEquals("true", design.attr("null-setting-allowed")); | |||
assertEquals("5", design.attr("maxlength")); | |||
assertEquals("3", design.attr("columns")); | |||
assertEquals("input", design.attr("input-prompt")); | |||
assertEquals("eager", design.attr("text-change-event-mode")); | |||
assertEquals("100", design.attr("text-change-timeout")); | |||
} | |||
private AbstractTextField getComponent() { | |||
return new TextField(); | |||
} | |||
private Element createDesign() { | |||
Attributes attr = new Attributes(); | |||
return new Element(Tag.valueOf("v-text-field"), "", attr); | |||
} | |||
} |
@@ -15,13 +15,23 @@ | |||
*/ | |||
package com.vaadin.tests.server.component.button; | |||
import static org.junit.Assert.assertTrue; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.event.ShortcutAction.KeyCode; | |||
import com.vaadin.event.ShortcutAction.ModifierKey; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.NativeButton; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests declarative support for implementations of {@link Button}. | |||
* Tests declarative support for implementations of {@link Button} and | |||
* {@link NativeButton}. | |||
* | |||
* @since 7.4 | |||
* @author Vaadin Ltd | |||
@@ -29,44 +39,90 @@ import com.vaadin.ui.Button; | |||
public class ButtonDeclarativeTest extends DeclarativeTestBase<Button> { | |||
@Test | |||
public void testPlainTextRead() { | |||
testRead(getDesignPlainText(), getExpectedPlainText()); | |||
public void testEmptyPlainText() { | |||
String design = "<v-button plain-text=''></v-button>"; | |||
testButtonAndNativeButton(design, false, ""); | |||
} | |||
@Test | |||
public void testPlainTextWrite() { | |||
testWrite(getDesignPlainText(), getExpectedPlainText()); | |||
public void testPlainTextCaption() { | |||
String design = "<v-button plain-text=''>Click</v-button>"; | |||
testButtonAndNativeButton(design, false, "Click"); | |||
} | |||
protected String getDesignPlainText() { | |||
return "<v-button plain-text=''></v-button>"; | |||
@Test | |||
public void testEmptyHtml() { | |||
String design = "<v-button />"; | |||
testButtonAndNativeButton(design, true, ""); | |||
} | |||
protected Button getExpectedPlainText() { | |||
Button c = new Button(); | |||
c.setCaption(""); | |||
return c; | |||
}; | |||
@Test | |||
public void testHtmlCaption() { | |||
String design = "<v-button><b>Click</b></v-button>"; | |||
testButtonAndNativeButton(design, true, "<b>Click</b>"); | |||
} | |||
@Test | |||
public void testHtmlRead() { | |||
testRead(getDesignHtml(), getExpectedHtml()); | |||
public void testWithCaptionAttribute() { | |||
// The caption attribute should be ignored | |||
String design = "<v-button caption=Caption>Click</v-button>"; | |||
String expectedWritten = "<v-button>Click</v-button>"; | |||
testButtonAndNativeButton(design, true, "Click", expectedWritten); | |||
} | |||
@Test | |||
public void testHtmlWrite() { | |||
testWrite(getDesignHtml(), getExpectedHtml()); | |||
public void testWithOnlyCaptionAttribute() { | |||
String design = "<v-button caption=Click/>"; | |||
String expectedWritten = "<v-button/>"; | |||
testButtonAndNativeButton(design, true, "", expectedWritten); | |||
} | |||
protected String getDesignHtml() { | |||
return "<v-button />"; | |||
public void testButtonAndNativeButton(String design, boolean html, | |||
String caption) { | |||
testButtonAndNativeButton(design, html, caption, design); | |||
} | |||
protected Button getExpectedHtml() { | |||
Button c = new Button(); | |||
c.setCaption(""); | |||
c.setCaptionAsHtml(true); | |||
return c; | |||
}; | |||
public void testButtonAndNativeButton(String design, boolean html, | |||
String caption, String expectedWritten) { | |||
// Test Button | |||
Button b = new Button(); | |||
b.setCaptionAsHtml(html); | |||
b.setCaption(caption); | |||
testRead(expectedWritten, b); | |||
testWrite(expectedWritten, b); | |||
// Test NativeButton | |||
design = design.replace("v-button", "v-native-button"); | |||
expectedWritten = expectedWritten | |||
.replace("v-button", "v-native-button"); | |||
NativeButton nb = new NativeButton(); | |||
nb.setCaptionAsHtml(html); | |||
nb.setCaption(caption); | |||
testRead(expectedWritten, nb); | |||
testWrite(expectedWritten, nb); | |||
} | |||
} | |||
@Test | |||
public void testAttributes() { | |||
String design = "<v-button tabindex=3 plain-text='' icon-alt=OK " | |||
+ "click-shortcut=ctrl-shift-o></v-button>"; | |||
Button b = new Button(""); | |||
b.setTabIndex(3); | |||
b.setIconAlternateText("OK"); | |||
b.setClickShortcut(KeyCode.O, ModifierKey.CTRL, ModifierKey.SHIFT); | |||
testRead(design, b); | |||
testWrite(design, b); | |||
} | |||
@Test | |||
public void testWriteUpdatesContentMode() { | |||
DesignContext ctx = new DesignContext(); | |||
Button button = new Button("OK"); | |||
Element e = new Element(Tag.valueOf("v-button"), "", new Attributes()); | |||
button.writeDesign(e, ctx); | |||
assertTrue("Button is plain text by default", e.hasAttr("plain-text")); | |||
button.setHtmlContentAllowed(true); | |||
button.writeDesign(e, ctx); | |||
assertTrue("Button is updated to HTML", !e.hasAttr("plain-text")); | |||
} | |||
} |
@@ -1,129 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.button; | |||
import java.lang.reflect.Field; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.event.ShortcutAction.KeyCode; | |||
import com.vaadin.event.ShortcutAction.ModifierKey; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickShortcut; | |||
import com.vaadin.ui.NativeButton; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* | |||
* Test cases for reading the contents of a Button and a NativeButton from a | |||
* design. | |||
* | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
@Test | |||
public void testWithContent() { | |||
createAndTestButtons("Click", null); | |||
} | |||
@Test | |||
public void testWithHtmlCaption() { | |||
createAndTestButtons("<b>Click me</b>", null); | |||
} | |||
@Test | |||
public void testWithContentAndCaption() { | |||
createAndTestButtons("Click me", "caption"); | |||
} | |||
@Test | |||
public void testWithCaption() { | |||
createAndTestButtons(null, "Click me"); | |||
} | |||
@Test | |||
public void testAttributes() throws IllegalArgumentException, | |||
SecurityException, IllegalAccessException, NoSuchFieldException { | |||
Attributes attributes = new Attributes(); | |||
attributes.put("tabindex", "3"); | |||
attributes.put("plain-text", ""); | |||
attributes.put("icon-alt", "OK"); | |||
attributes.put("click-shortcut", "ctrl-shift-o"); | |||
Button button = (Button) ctx | |||
.readDesign(createButtonWithAttributes(attributes)); | |||
assertEquals(3, button.getTabIndex()); | |||
assertEquals(false, button.isHtmlContentAllowed()); | |||
assertEquals("OK", button.getIconAlternateText()); | |||
Field field = Button.class.getDeclaredField("clickShortcut"); | |||
field.setAccessible(true); | |||
ClickShortcut value = (ClickShortcut) field.get(button); | |||
assertEquals(KeyCode.O, value.getKeyCode()); | |||
assertEquals(ModifierKey.CTRL, value.getModifiers()[0]); | |||
assertEquals(ModifierKey.SHIFT, value.getModifiers()[1]); | |||
} | |||
/* | |||
* Test both Button and NativeButton. Caption should always be ignored. If | |||
* content is null, the created button should have empty content. | |||
*/ | |||
private void createAndTestButtons(String content, String caption) { | |||
Element e1 = createElement("v-button", content, caption); | |||
Button b1 = (Button) ctx.readDesign(e1); | |||
Element e2 = createElement("v-native-button", content, caption); | |||
NativeButton b2 = (NativeButton) ctx.readDesign(e2); | |||
if (content != null) { | |||
assertEquals("The button has the wrong text content.", content, | |||
b1.getCaption()); | |||
assertEquals("The button has the wrong text content.", content, | |||
b2.getCaption()); | |||
} else { | |||
assertTrue("The button has the wrong content.", | |||
b1.getCaption() == null || "".equals(b1.getCaption())); | |||
assertTrue("The button has the wrong content.", | |||
b2.getCaption() == null || "".equals(b2.getCaption())); | |||
} | |||
} | |||
private Element createButtonWithAttributes(Attributes attributes) { | |||
return new Element(Tag.valueOf("v-button"), "", attributes); | |||
} | |||
private Element createElement(String elementName, String content, | |||
String caption) { | |||
Attributes attributes = new Attributes(); | |||
if (caption != null) { | |||
attributes.put("caption", caption); | |||
} | |||
Element node = new Element(Tag.valueOf(elementName), "", attributes); | |||
if (content != null) { | |||
node.html(content); | |||
} | |||
return node; | |||
} | |||
} |
@@ -1,103 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.button; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.event.ShortcutAction.KeyCode; | |||
import com.vaadin.event.ShortcutAction.ModifierKey; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.NativeButton; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests generating html tree nodes corresponding to the contents of a Button | |||
* and a NativeButton. | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
@Test | |||
public void testWithTextContent() { | |||
createAndTestButtons("Click me"); | |||
} | |||
@Test | |||
public void testWithHtmlContent() { | |||
createAndTestButtons("<b>Click</b>"); | |||
} | |||
@Test | |||
public void testAttributes() { | |||
Button button = new Button(); | |||
button.setTabIndex(3); | |||
button.setIconAlternateText("OK"); | |||
button.setClickShortcut(KeyCode.O, ModifierKey.CTRL, ModifierKey.SHIFT); | |||
Element e = new Element(Tag.valueOf("v-button"), "", new Attributes()); | |||
button.writeDesign(e, ctx); | |||
assertEquals("3", e.attr("tabindex")); | |||
assertTrue("Button is plain text by default", e.hasAttr("plain-text")); | |||
assertEquals("OK", e.attr("icon-alt")); | |||
assertEquals("ctrl-shift-o", e.attr("click-shortcut")); | |||
} | |||
@Test | |||
public void testUpdateContentMode() { | |||
Button button = new Button("OK"); | |||
Element e = new Element(Tag.valueOf("v-button"), "", new Attributes()); | |||
button.writeDesign(e, ctx); | |||
assertTrue("Button is plain text by default", e.hasAttr("plain-text")); | |||
button.setHtmlContentAllowed(true); | |||
button.writeDesign(e, ctx); | |||
assertTrue("Button is updated to HTML", !e.hasAttr("plain-text")); | |||
} | |||
private void createAndTestButtons(String content) { | |||
Button b1 = new Button(content); | |||
// we need to set this on, since the plain-text attribute will appear | |||
// otherwise | |||
b1.setHtmlContentAllowed(true); | |||
Element e1 = ctx.createElement(b1); | |||
assertEquals("Wrong tag name for button.", "v-button", e1.tagName()); | |||
assertEquals("Unexpected content in the v-button element.", content, | |||
e1.html()); | |||
assertTrue("The v-button element should not have attributes.", e1 | |||
.attributes().size() == 0); | |||
NativeButton b2 = new NativeButton(content); | |||
b2.setHtmlContentAllowed(true); | |||
Element e2 = ctx.createElement(b2); | |||
assertEquals("Wrong tag name for button.", "v-native-button", | |||
e2.tagName()); | |||
assertEquals("Unexpected content in the v-button element.", content, | |||
e2.html()); | |||
assertTrue("The v-button element should not have attributes.", e2 | |||
.attributes().size() == 0); | |||
} | |||
} |
@@ -28,29 +28,20 @@ import com.vaadin.ui.CheckBox; | |||
*/ | |||
public class CheckboxDeclarativeTest extends DeclarativeTestBase<CheckBox> { | |||
protected String getDesign() { | |||
return "<v-check-box checked='true' />"; | |||
} | |||
protected CheckBox getExpectedResult() { | |||
CheckBox c = new CheckBox(); | |||
c.setValue(true); | |||
return c; | |||
}; | |||
@Test | |||
public void read() { | |||
testRead(getDesign(), getExpectedResult()); | |||
public void testChecked() { | |||
String design = "<v-check-box />"; | |||
CheckBox checkBox = new CheckBox(); | |||
testRead(design, checkBox); | |||
testWrite(design, checkBox); | |||
} | |||
@Test | |||
public void write() { | |||
testWrite(getDesign(), getExpectedResult()); | |||
public void testUnchecked() { | |||
String design = "<v-check-box checked='true' />"; | |||
CheckBox checkBox = new CheckBox(); | |||
checkBox.setValue(true); | |||
testRead(design, checkBox); | |||
testWrite(design, checkBox); | |||
} | |||
@Test | |||
public void testEmpty() { | |||
testRead("<v-check-box>", new CheckBox()); | |||
} | |||
} |
@@ -1,67 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.checkbox; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.ui.CheckBox; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* | |||
* Test cases for reading the contents of a Checkbox from a design. | |||
* | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
@Test | |||
public void testChecked() { | |||
Element e = createElement(true); | |||
CheckBox box = (CheckBox) ctx.readDesign(e); | |||
assertEquals("The checkbox must be checked", Boolean.TRUE, | |||
box.getValue()); | |||
} | |||
@Test | |||
public void testUnchecked() { | |||
Element e = createElement(false); | |||
CheckBox box = (CheckBox) ctx.readDesign(e); | |||
assertEquals("The checkbox must be unchecked", Boolean.FALSE, | |||
box.getValue()); | |||
} | |||
private Element createElement(boolean checked) { | |||
Attributes attributes = new Attributes(); | |||
if (checked) { | |||
attributes.put("checked", ""); | |||
} | |||
Element node = new Element(Tag.valueOf("v-check-box"), "", attributes); | |||
return node; | |||
} | |||
} |
@@ -1,57 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.checkbox; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Element; | |||
import org.junit.Test; | |||
import com.vaadin.ui.CheckBox; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests generating html tree nodes corresponding to the contents of a Checkbox | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
@Test | |||
public void testChecked() { | |||
CheckBox box = new CheckBox(); | |||
box.setValue(true); | |||
Element e = ctx.createElement(box); | |||
assertTrue("element must have checked attribute", e.hasAttr("checked")); | |||
assertTrue("the checked attribute must be true", e.attr("checked") | |||
.equals("true") || e.attr("checked").equals("")); | |||
} | |||
@Test | |||
public void testUnchecked() { | |||
CheckBox box = new CheckBox(); | |||
box.setValue(false); | |||
Element e = ctx.createElement(box); | |||
assertFalse("the element must not have checked attribute", | |||
e.hasAttr("checked")); | |||
} | |||
} |
@@ -0,0 +1,96 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.csslayout; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.shared.ui.label.ContentMode; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.CssLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests declarative support for CssLayout. | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class CssLayoutDeclarativeTest extends DeclarativeTestBase<CssLayout> { | |||
@Test | |||
public void testNoChildren() { | |||
String design = "<v-css-layout />"; | |||
CssLayout layout = new CssLayout(); | |||
testRead(design, layout); | |||
testWrite(design, layout); | |||
design = "<v-css-layout caption=\"A caption\"/>"; | |||
layout = new CssLayout(); | |||
layout.setCaption("A caption"); | |||
testRead(design, layout); | |||
testWrite(design, layout); | |||
} | |||
@Test | |||
public void testFeatures() { | |||
String design = "<v-css-layout caption=test-layout><v-label caption=test-label />" | |||
+ "<v-button>test-button</v-button></v-css-layout>"; | |||
CssLayout layout = new CssLayout(); | |||
layout.setCaption("test-layout"); | |||
Label l = new Label(); | |||
l.setContentMode(ContentMode.HTML); | |||
l.setCaption("test-label"); | |||
layout.addComponent(l); | |||
Button b = new Button("test-button"); | |||
b.setCaptionAsHtml(true); | |||
layout.addComponent(b); | |||
testRead(design, layout); | |||
testWrite(design, layout); | |||
} | |||
@Test | |||
public void testWriteWithOldContents() { | |||
// Test that any old contents of an element are removed when | |||
// writing a design. | |||
Element design = createDesign(); | |||
CssLayout layout = new CssLayout(); | |||
layout.addComponent(new Label("test-label")); | |||
layout.getComponent(0).setCaption("test-caption"); | |||
layout.addComponent(new Label("test-label-2")); | |||
layout.writeDesign(design, new DesignContext()); | |||
assertEquals(2, design.childNodes().size()); | |||
assertEquals("v-label", ((Element) design.childNode(0)).tagName()); | |||
assertEquals("test-caption", design.childNode(0).attr("caption")); | |||
} | |||
private Element createDesign() { | |||
// create an element with some contents | |||
Attributes rootAttributes = new Attributes(); | |||
rootAttributes.put("caption", "test-layout"); | |||
Element node = new Element(Tag.valueOf("v-vertical-layout"), "", | |||
rootAttributes); | |||
Attributes childAttributes = new Attributes(); | |||
childAttributes.put("caption", "test-label"); | |||
Element child = new Element(Tag.valueOf("v-label"), "", childAttributes); | |||
node.appendChild(child); | |||
return node; | |||
} | |||
} |
@@ -1,74 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.csslayout; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.Component; | |||
import com.vaadin.ui.CssLayout; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for reading CssLayout from design | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
public void testChildCount() { | |||
CssLayout root = createLayout(); | |||
assertEquals(2, root.getComponentCount()); | |||
} | |||
public void testAttributes() { | |||
CssLayout root = createLayout(); | |||
assertEquals("test-layout", root.getCaption()); | |||
assertEquals("test-label", root.getComponent(0).getCaption()); | |||
assertEquals("test-button", root.getComponent(1).getCaption()); | |||
} | |||
private CssLayout createLayout() { | |||
DesignContext ctx = new DesignContext(); | |||
Element design = createDesign(); | |||
Component child = ctx.readDesign(design); | |||
return (CssLayout) child; | |||
} | |||
private Element createDesign() { | |||
Attributes rootAttributes = new Attributes(); | |||
rootAttributes.put("caption", "test-layout"); | |||
Element node = new Element(Tag.valueOf("v-css-layout"), "", | |||
rootAttributes); | |||
Attributes firstChildAttributes = new Attributes(); | |||
firstChildAttributes.put("caption", "test-label"); | |||
Element firstChild = new Element(Tag.valueOf("v-label"), "", | |||
firstChildAttributes); | |||
node.appendChild(firstChild); | |||
Attributes secondChildAttributes = new Attributes(); | |||
Element secondChild = new Element(Tag.valueOf("v-button"), "", | |||
secondChildAttributes); | |||
secondChild.html("test-button"); | |||
node.appendChild(secondChild); | |||
return node; | |||
} | |||
} |
@@ -1,78 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.csslayout; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.CssLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for writing CssLayout to design | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
public void testSynchronizeEmptyLayout() { | |||
CssLayout layout = new CssLayout(); | |||
layout.setCaption("changed-caption"); | |||
Element design = createDesign(); | |||
layout.writeDesign(design, createDesignContext()); | |||
assertEquals(0, design.childNodes().size()); | |||
assertEquals("changed-caption", design.attr("caption")); | |||
} | |||
public void testSynchronizeLayoutWithChildren() { | |||
CssLayout layout = new CssLayout(); | |||
layout.addComponent(new Label("test-label")); | |||
layout.getComponent(0).setCaption("test-caption"); | |||
layout.addComponent(new Label("test-label-2")); | |||
Element design = createDesign(); | |||
layout.writeDesign(design, createDesignContext()); | |||
assertEquals(2, design.childNodes().size()); | |||
assertEquals("v-label", ((Element) design.childNode(0)).tagName()); | |||
assertEquals("test-caption", design.childNode(0).attr("caption")); | |||
} | |||
private Element createDesign() { | |||
// make sure that the design node has old content that should be removed | |||
Attributes rootAttributes = new Attributes(); | |||
rootAttributes.put("caption", "test-layout"); | |||
Element node = new Element(Tag.valueOf("v-vertical-layout"), "", | |||
rootAttributes); | |||
Attributes firstChildAttributes = new Attributes(); | |||
firstChildAttributes.put("caption", "test-label"); | |||
Element firstChild = new Element(Tag.valueOf("v-label"), "", | |||
firstChildAttributes); | |||
node.appendChild(firstChild); | |||
Element secondChild = new Element(Tag.valueOf("v-button"), "", | |||
new Attributes()); | |||
secondChild.html("test-button"); | |||
node.appendChild(secondChild); | |||
return node; | |||
} | |||
private DesignContext createDesignContext() { | |||
return new DesignContext(); | |||
} | |||
} |
@@ -53,6 +53,20 @@ public class GridDeclarativeAttributeTest extends DeclarativeTestBase<Grid> { | |||
testWrite(design, grid); | |||
} | |||
@Test | |||
public void testFrozenColumnsAttributes() { | |||
String design = "<v-grid frozen-columns='2'><table>" // | |||
+ "<colgroup><col><col><col></colgroup></table></v-grid>"; | |||
Grid grid = new Grid(); | |||
grid.addColumn("property-0", String.class); | |||
grid.addColumn("property-1", String.class); | |||
grid.addColumn("property-2", String.class); | |||
grid.setFrozenColumnCount(2); | |||
testRead(design, grid); | |||
} | |||
@Test | |||
public void testSelectionMode() { | |||
String design = "<v-grid selection-mode='none'>"; |
@@ -15,11 +15,18 @@ | |||
*/ | |||
package com.vaadin.tests.server.component.label; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.shared.ui.label.ContentMode; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests declarative support for implementations of {@link Label}. | |||
@@ -30,66 +37,85 @@ import com.vaadin.ui.Label; | |||
public class LabelDeclarativeTest extends DeclarativeTestBase<Label> { | |||
@Test | |||
public void testDefaultRead() { | |||
testRead(getDefaultDesign(), getDefaultExpected()); | |||
public void testEmpty() { | |||
String design = "<v-label />"; | |||
Label l = new Label(); | |||
l.setContentMode(ContentMode.HTML); | |||
testRead(design, l); | |||
testWrite(design, l); | |||
} | |||
@Test | |||
public void testDefaultWrite() { | |||
testWrite(getDefaultDesign(), getDefaultExpected()); | |||
} | |||
protected String getDefaultDesign() { | |||
return "<v-label>Hello world!</v-label>"; | |||
public void testDefault() { | |||
String design = "<v-label>Hello world!</v-label>"; | |||
Label l = createLabel("Hello world!", null, true); | |||
testRead(design, l); | |||
testWrite(design, l); | |||
} | |||
protected Label getDefaultExpected() { | |||
Label tf = new Label(); | |||
tf.setContentMode(ContentMode.HTML); | |||
tf.setValue("Hello world!"); | |||
return tf; | |||
}; | |||
@Test | |||
public void testRichRead() { | |||
testRead(getRichDesign(), getRichExpected()); | |||
public void testRich() { | |||
String design = "<v-label>This is <b><u>Rich</u></b> content!</v-label>"; | |||
Label l = createLabel("This is \n<b><u>Rich</u></b> content!", null, | |||
true); | |||
testRead(design, l); | |||
testWrite(design, l); | |||
} | |||
@Test | |||
public void testRichWrite() { | |||
testWrite(getRichDesign(), getRichExpected()); | |||
public void testPlainText() { | |||
String design = "<v-label plain-text>This is only <b>text</b>" | |||
+ " and will contain visible tags</v-label>"; | |||
Label l = createLabel( | |||
"This is only \n<b>text</b> and will contain visible tags", | |||
null, false); | |||
testRead(design, l); | |||
testWrite(design, l); | |||
} | |||
protected String getRichDesign() { | |||
return "<v-label>This is <b><u>Rich</u></b> content!</v-label>"; | |||
@Test | |||
public void testContentAndCaption() { | |||
String design = "<v-label caption='This is a label'>This is <b><u>Rich</u></b> " | |||
+ "content!</v-label>"; | |||
Label l = createLabel("This is \n<b><u>Rich</u></b> content!", | |||
"This is a label", true); | |||
testRead(design, l); | |||
testWrite(design, l); | |||
} | |||
protected Label getRichExpected() { | |||
Label tf = new Label(); | |||
tf.setContentMode(ContentMode.HTML); | |||
tf.setValue("This is \n<b><u>Rich</u></b> content!"); | |||
return tf; | |||
}; | |||
@Test | |||
public void testPlainTextRead() { | |||
testRead(getPlainTextDesign(), getPlainTextExpected()); | |||
public void testCaption() { | |||
String design = "<v-label caption='This is a label' />"; | |||
Label l = createLabel(null, "This is a label", true); | |||
testRead(design, l); | |||
testWrite(design, l); | |||
} | |||
@Test | |||
public void testPlainTextWrite() { | |||
testWrite(getPlainTextDesign(), getPlainTextExpected()); | |||
public void testWriteContentMode() { | |||
// test that the plain-text attribute is overwritten by writeDesign | |||
DesignContext ctx = new DesignContext(); | |||
Label l = new Label("label"); | |||
l.setContentMode(ContentMode.TEXT); | |||
Element e = new Element(Tag.valueOf("v-label"), "", new Attributes()); | |||
l.writeDesign(e, ctx); | |||
assertTrue("Label should be marked as plain text", | |||
e.hasAttr("plain-text")); | |||
l.setContentMode(ContentMode.HTML); | |||
l.writeDesign(e, ctx); | |||
assertFalse("Label should not be marked as plain text", | |||
e.hasAttr("plain-text")); | |||
} | |||
protected String getPlainTextDesign() { | |||
return "<v-label plain-text>This is only <b>text</b> and will contain visible tags</v-label>"; | |||
private Label createLabel(String content, String caption, boolean html) { | |||
Label label = new Label(); | |||
label.setContentMode(html ? ContentMode.HTML : ContentMode.TEXT); | |||
if (content != null) { | |||
label.setValue(content); | |||
} | |||
if (caption != null) { | |||
label.setCaption(caption); | |||
} | |||
return label; | |||
} | |||
protected Label getPlainTextExpected() { | |||
Label tf = new Label(); | |||
tf.setContentMode(ContentMode.TEXT); | |||
tf.setValue("This is only \n<b>text</b> and will contain visible tags"); | |||
return tf; | |||
}; | |||
} |
@@ -1,102 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.label; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* | |||
* Test case for reading the contents of a Label from a design. | |||
* | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
@Test | |||
public void testWithContent() { | |||
createAndTestLabel("A label", null); | |||
} | |||
@Test | |||
public void testWithHtmlContent() { | |||
createAndTestLabel("<b>A label</b>", null); | |||
} | |||
@Test | |||
public void testWithContentAndCaption() { | |||
createAndTestLabel("A label", "This is a label"); | |||
} | |||
@Test | |||
public void testWithCaption() { | |||
createAndTestLabel(null, "This is a label"); | |||
} | |||
@Test | |||
public void testWithoutContentAndCaption() { | |||
createAndTestLabel(null, null); | |||
} | |||
/* | |||
* Test creating a Label. A Label can have both caption and content. | |||
*/ | |||
private void createAndTestLabel(String content, String caption) { | |||
Element e = createElement("v-label", content, caption); | |||
Label l = (Label) ctx.readDesign(e); | |||
if (content != null) { | |||
assertEquals("The label has wrong text content.", content, | |||
l.getValue()); | |||
} else { | |||
assertTrue("The label has wrong text content.", | |||
l.getValue() == null || "".equals(l.getValue())); | |||
} | |||
if (caption != null) { | |||
assertEquals("The label has wrong caption.", caption, | |||
l.getCaption()); | |||
} else { | |||
assertTrue("The label has wrong caption.", l.getCaption() == null | |||
|| "".equals(l.getCaption())); | |||
} | |||
} | |||
private Element createElement(String elementName, String content, | |||
String caption) { | |||
Attributes attributes = new Attributes(); | |||
if (caption != null) { | |||
attributes.put("caption", caption); | |||
} | |||
Element node = new Element(Tag.valueOf(elementName), "", attributes); | |||
if (content != null) { | |||
node.html(content); | |||
} | |||
return node; | |||
} | |||
} |
@@ -1,126 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.label; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.shared.ui.label.ContentMode; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests generating an html tree node corresponding to a Label. | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
@Test | |||
public void testWithContent() { | |||
createAndTestLabel("A label", null); | |||
} | |||
@Test | |||
public void testWithHtmlContent() { | |||
createAndTestLabel("<b>A label</b>", null); | |||
} | |||
@Test | |||
public void testWithCaption() { | |||
createAndTestLabel(null, "Label caption"); | |||
} | |||
@Test | |||
public void testWithContentAndCaption() { | |||
createAndTestLabel("A label", "Label caption"); | |||
} | |||
@Test | |||
public void testContentModeText() { | |||
Label l = new Label("plain text label"); | |||
Element e = new Element(Tag.valueOf("v-label"), "", new Attributes()); | |||
l.writeDesign(e, ctx); | |||
assertTrue("Label should be marked as plain text", | |||
e.hasAttr("plain-text")); | |||
} | |||
@Test | |||
public void testContentModeHtml() { | |||
Label l = new Label("html label"); | |||
l.setContentMode(ContentMode.HTML); | |||
Element e = new Element(Tag.valueOf("v-label"), "", new Attributes()); | |||
l.writeDesign(e, ctx); | |||
assertFalse("Label should not be marked as plain text", | |||
e.hasAttr("plain-text")); | |||
} | |||
@Test | |||
public void testChangeContentMode() { | |||
Label l = new Label("html label"); | |||
l.setContentMode(ContentMode.HTML); | |||
Element e = new Element(Tag.valueOf("v-label"), "", new Attributes()); | |||
l.writeDesign(e, ctx); | |||
assertFalse("Label should not be marked as plain text", | |||
e.hasAttr("plain-text")); | |||
l.setContentMode(ContentMode.TEXT); | |||
l.writeDesign(e, ctx); | |||
assertTrue("Label should be marked as plain text", | |||
e.hasAttr("plain-text")); | |||
} | |||
@Test | |||
public void testWithoutContentAndCaption() { | |||
createAndTestLabel(null, null); | |||
} | |||
private void createAndTestLabel(String content, String caption) { | |||
Label l = new Label(content); | |||
if (caption != null) { | |||
l.setCaption(caption); | |||
} | |||
Element e = ctx.createElement(l); | |||
assertEquals("Wrong tag name for label.", "v-label", e.tagName()); | |||
if (content != null) { | |||
assertEquals("Unexpected content in the v-label element.", content, | |||
e.html()); | |||
} else { | |||
assertTrue("Unexpected content in the v-label element.", | |||
e.html() == null || "".equals(e.html())); | |||
} | |||
if (caption != null) { | |||
assertEquals("Wrong caption in the v-label element.", caption, | |||
e.attr("caption")); | |||
} else { | |||
assertTrue("Unexpected caption in the v-label element.", | |||
e.attr("caption") == null || "".equals(e.attr("caption"))); | |||
} | |||
} | |||
} |
@@ -0,0 +1,62 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.panel; | |||
import org.junit.Test; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.Panel; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.declarative.DesignException; | |||
/** | |||
* Tests declarative support for Panel. | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class PanelDeclarativeTest extends DeclarativeTestBase<Panel> { | |||
@Test | |||
public void testFeatures() { | |||
String design = "<v-panel id=panelId caption=\"A panel\" tabindex=2 scroll-left=10 " | |||
+ "scroll-top=20 width=200px height=150px> " | |||
+ "<v-vertical-layout width=300px height=400px /> " | |||
+ "</v-panel>"; | |||
Panel p = new Panel(); | |||
p.setId("panelId"); | |||
p.setCaption("A panel"); | |||
p.setTabIndex(2); | |||
p.setScrollLeft(10); | |||
p.setScrollTop(20); | |||
p.setWidth("200px"); | |||
p.setHeight("150px"); | |||
VerticalLayout vl = new VerticalLayout(); | |||
vl.setWidth("300px"); | |||
vl.setHeight("400px"); | |||
p.setContent(vl); | |||
testRead(design, p); | |||
testWrite(design, p); | |||
} | |||
@Test(expected = DesignException.class) | |||
public void testWithMoreThanOneChild() { | |||
// Check that attempting to have two components in a panel causes a | |||
// DesignException. | |||
String design = "<v-panel> <v-vertical-layout/> <v-horizontal-layout/> </v-panel>"; | |||
testRead(design, null); | |||
} | |||
} |
@@ -1,98 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.panel; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.Panel; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
import com.vaadin.ui.declarative.DesignException; | |||
/** | |||
* Test case for reading the attributes of a Panel from design. | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
DesignContext ctx; | |||
@Override | |||
public void setUp() { | |||
ctx = new DesignContext(); | |||
} | |||
public void testAttributes() { | |||
Element design = createDesign(); | |||
Panel panel = new Panel(); | |||
panel.readDesign(design, ctx); | |||
assertEquals("A panel", panel.getCaption()); | |||
assertEquals(2, panel.getTabIndex()); | |||
assertEquals(10, panel.getScrollLeft()); | |||
assertEquals(20, panel.getScrollTop()); | |||
assertEquals(200f, panel.getWidth()); | |||
assertEquals(150f, panel.getHeight()); | |||
} | |||
public void testChild() { | |||
Element design = createDesign(); | |||
Panel panel = new Panel(); | |||
panel.readDesign(design, ctx); | |||
VerticalLayout vLayout = (VerticalLayout) panel.getContent(); | |||
assertEquals(300f, vLayout.getWidth()); | |||
assertEquals(400f, vLayout.getHeight()); | |||
} | |||
public void testWithMoreThanOneChild() { | |||
Element design = createDesign(); | |||
// Add a new child to the panel element. An exception should be | |||
// thrown when parsing the design. | |||
Element newChild = new Element(Tag.valueOf("v-horizontal-layout"), ""); | |||
design.appendChild(newChild); | |||
Panel panel = new Panel(); | |||
try { | |||
panel.readDesign(design, ctx); | |||
fail("Parsing a design containing a Panel with more than one child component should have failed."); | |||
} catch (DesignException e) { | |||
// Nothing needs to be done, this is the expected case. | |||
} | |||
} | |||
/* | |||
* Creates an html document that can be parsed into a valid component | |||
* hierarchy. | |||
*/ | |||
private Element createDesign() { | |||
// Create a node defining a Panel | |||
Element panelElement = new Element(Tag.valueOf("v-panel"), ""); | |||
panelElement.attr("caption", "A panel"); | |||
panelElement.attr("tabindex", "2"); | |||
panelElement.attr("scroll-left", "10"); | |||
panelElement.attr("scroll-top", "20"); | |||
panelElement.attr("width", "200px"); | |||
panelElement.attr("height", "150px"); | |||
// Add some content to the panel | |||
Element layoutElement = new Element(Tag.valueOf("v-vertical-layout"), | |||
""); | |||
layoutElement.attr("width", "300px"); | |||
layoutElement.attr("height", "400px"); | |||
panelElement.appendChild(layoutElement); | |||
return panelElement; | |||
} | |||
} |
@@ -1,71 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.panel; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.Panel; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for writing the attributes and the child element of a Panel to a | |||
* design. | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
Element panelElement; | |||
@Override | |||
public void setUp() { | |||
// create a component hierarchy | |||
Panel panel = new Panel("A panel"); | |||
panel.setId("panelId"); | |||
panel.setHeight("250px"); | |||
panel.setScrollTop(50); | |||
panel.setTabIndex(4); | |||
VerticalLayout vLayout = new VerticalLayout(); | |||
vLayout.setWidth("500px"); | |||
panel.setContent(vLayout); | |||
// synchronize to design | |||
DesignContext ctx = new DesignContext(); | |||
panelElement = new Element(Tag.valueOf("div"), ""); | |||
panel.writeDesign(panelElement, ctx); | |||
} | |||
public void testAttributes() { | |||
// should have caption, id, height, scroll top and tab index | |||
assertEquals(5, panelElement.attributes().size()); | |||
// check the values of the attributes | |||
assertEquals("A panel", panelElement.attr("caption")); | |||
assertEquals("panelId", panelElement.attr("id")); | |||
assertEquals("250px", panelElement.attr("height")); | |||
assertEquals("50", panelElement.attr("scroll-top")); | |||
assertEquals("4", panelElement.attr("tabindex")); | |||
} | |||
public void testChild() { | |||
// the panel element should have exactly one child, a v-vertical-layout | |||
assertEquals(1, panelElement.childNodes().size()); | |||
Element vLayoutElement = panelElement.child(0); | |||
assertEquals("v-vertical-layout", vLayoutElement.nodeName()); | |||
assertEquals("500px", vLayoutElement.attr("width")); | |||
} | |||
} |
@@ -1,132 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.tabsheet; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.server.ExternalResource; | |||
import com.vaadin.ui.TabSheet; | |||
import com.vaadin.ui.TabSheet.Tab; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case from reading TabSheet from design | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
private TabSheet sheet; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
sheet = createTabSheet(); | |||
} | |||
public void testChildCount() { | |||
assertEquals(1, sheet.getComponentCount()); | |||
} | |||
public void testTabIndex() { | |||
assertEquals(5, sheet.getTabIndex()); | |||
} | |||
public void testTabAttributes() { | |||
Tab tab = sheet.getTab(0); | |||
assertEquals("test-caption", tab.getCaption()); | |||
assertEquals(false, tab.isVisible()); | |||
assertEquals(false, tab.isClosable()); | |||
assertEquals(false, tab.isEnabled()); | |||
assertEquals("http://www.vaadin.com/test.png", | |||
((ExternalResource) tab.getIcon()).getURL()); | |||
assertEquals("OK", tab.getIconAlternateText()); | |||
assertEquals("test-desc", tab.getDescription()); | |||
assertEquals("test-style", tab.getStyleName()); | |||
assertEquals("test-id", tab.getId()); | |||
} | |||
public void testSelectedComponent() { | |||
TabSheet tabSheet = new TabSheet(); | |||
tabSheet.readDesign(createFirstTabSelectedDesign(), new DesignContext()); | |||
assertEquals(tabSheet.getTab(0).getComponent(), | |||
tabSheet.getSelectedTab()); | |||
} | |||
public void testTabContent() { | |||
assertTrue("The child for the tabsheet should be textfield", sheet | |||
.getTab(0).getComponent() instanceof TextField); | |||
} | |||
private TabSheet createTabSheet() { | |||
TabSheet tabSheet = new TabSheet(); | |||
DesignContext ctx = new DesignContext(); | |||
Element design = createDesign(); | |||
tabSheet.readDesign(design, ctx); | |||
return tabSheet; | |||
} | |||
private Element createDesign() { | |||
// create root design | |||
Attributes rootAttributes = new Attributes(); | |||
rootAttributes.put("tabindex", "5"); | |||
Element node = new Element(Tag.valueOf("v-tab-sheet"), "", | |||
rootAttributes); | |||
// create tab design | |||
Attributes tabAttributes = new Attributes(); | |||
tabAttributes.put("caption", "test-caption"); | |||
tabAttributes.put("visible", "false"); | |||
tabAttributes.put("closable", "false"); | |||
tabAttributes.put("enabled", "false"); | |||
tabAttributes.put("icon", "http://www.vaadin.com/test.png"); | |||
tabAttributes.put("icon-alt", "OK"); | |||
tabAttributes.put("description", "test-desc"); | |||
tabAttributes.put("style-name", "test-style"); | |||
tabAttributes.put("id", "test-id"); | |||
Element tab = new Element(Tag.valueOf("tab"), "", tabAttributes); | |||
// add child component to tab | |||
tab.appendChild(new Element(Tag.valueOf("v-text-field"), "", | |||
new Attributes())); | |||
// add tab to root design | |||
node.appendChild(tab); | |||
return node; | |||
} | |||
private Element createFirstTabSelectedDesign() { | |||
// create root design | |||
Attributes rootAttributes = new Attributes(); | |||
Element node = new Element(Tag.valueOf("v-tab-sheet"), "", | |||
rootAttributes); | |||
// create tab design | |||
Attributes tabAttributes = new Attributes(); | |||
tabAttributes.put("selected", ""); | |||
tabAttributes.put("caption", "test-caption"); | |||
Element tab = new Element(Tag.valueOf("tab"), "", tabAttributes); | |||
// add child component to tab | |||
tab.appendChild(new Element(Tag.valueOf("v-text-field"), "", | |||
new Attributes())); | |||
// add tab to root design | |||
node.appendChild(tab); | |||
return node; | |||
} | |||
} |
@@ -0,0 +1,98 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.tabsheet; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import org.junit.Test; | |||
import com.vaadin.server.ExternalResource; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.TabSheet; | |||
import com.vaadin.ui.TabSheet.Tab; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Tests declarative support for TabSheet. | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class TabSheetDeclarativeTest extends DeclarativeTestBase<TabSheet> { | |||
@Test | |||
public void testFeatures() { | |||
String design = "<v-tab-sheet tabindex=5><tab caption=test-caption " | |||
+ "visible=false closable=true enabled=false icon=http://www.vaadin.com/test.png" | |||
+ " icon-alt=OK description=test-desc style-name=test-style " | |||
+ "id=test-id><v-text-field/></tab></v-tab-sheet>"; | |||
TabSheet ts = new TabSheet(); | |||
ts.setTabIndex(5); | |||
TextField tf = new TextField(); | |||
Tab tab = ts.addTab(tf); | |||
tab.setCaption("test-caption"); | |||
tab.setVisible(false); | |||
tab.setClosable(true); | |||
tab.setEnabled(false); | |||
tab.setIcon(new ExternalResource("http://www.vaadin.com/test.png")); | |||
tab.setIconAlternateText("OK"); | |||
tab.setDescription("test-desc"); | |||
tab.setStyleName("test-style"); | |||
tab.setId("test-id"); | |||
ts.setSelectedTab(tf); | |||
testRead(design, ts); | |||
testWrite(design, ts); | |||
} | |||
@Test | |||
public void testSelected() { | |||
String design = "<v-tab-sheet><tab selected=true><v-text-field/></tab></v-tab-sheet>"; | |||
TabSheet ts = new TabSheet(); | |||
TextField tf = new TextField(); | |||
ts.addTab(tf); | |||
ts.setSelectedTab(tf); | |||
testRead(design, ts); | |||
testWrite(design, ts); | |||
} | |||
@Test | |||
public void testWriteRemovesOldContent() { | |||
// create old content that should be removed when writing | |||
Element design = new Element(Tag.valueOf("v-tab-sheet"), "", | |||
new Attributes()); | |||
design.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); | |||
design.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); | |||
design.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); | |||
// create a new TabSheet with one tab | |||
TabSheet ts = new TabSheet(); | |||
ts.setTabIndex(5); | |||
ts.addTab(new TextField()); | |||
Tab tab = ts.getTab(0); | |||
tab.setVisible(false); | |||
tab.setClosable(true); | |||
tab.setEnabled(false); | |||
// write the design and check written contents | |||
ts.writeDesign(design, new DesignContext()); | |||
assertEquals("There should be only one child", 1, design.children() | |||
.size()); | |||
assertEquals("v-text-field", design.child(0).child(0).tagName()); | |||
assertEquals("5", design.attr("tabindex")); | |||
Element tabDesign = design.child(0); | |||
assertEquals("false", tabDesign.attr("visible")); | |||
} | |||
} |
@@ -1,109 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.tabsheet; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.server.ExternalResource; | |||
import com.vaadin.ui.TabSheet; | |||
import com.vaadin.ui.TabSheet.Tab; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for writing TabSheet to design | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
private TabSheet sheet; | |||
private Element design; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
sheet = createTabSheet(); | |||
design = createDesign(); | |||
sheet.writeDesign(design, createDesignContext()); | |||
} | |||
public void testOnlyOneTab() { | |||
assertEquals("There should be only one child", 1, design.children() | |||
.size()); | |||
} | |||
public void testAttributes() { | |||
Element tabDesign = design.child(0); | |||
assertEquals("5", design.attr("tabindex")); | |||
assertEquals("test-caption", tabDesign.attr("caption")); | |||
assertEquals("false", tabDesign.attr("visible")); | |||
assertTrue(tabDesign.hasAttr("closable")); | |||
assertTrue(tabDesign.attr("closable").equals("true") | |||
|| tabDesign.attr("closable").equals("")); | |||
assertEquals("false", tabDesign.attr("enabled")); | |||
assertEquals("http://www.vaadin.com/test.png", tabDesign.attr("icon")); | |||
assertEquals("OK", tabDesign.attr("icon-alt")); | |||
assertEquals("test-desc", tabDesign.attr("description")); | |||
assertEquals("test-style", tabDesign.attr("style-name")); | |||
assertEquals("test-id", tabDesign.attr("id")); | |||
} | |||
public void testContent() { | |||
Element tabDesign = design.child(0); | |||
Element content = tabDesign.child(0); | |||
assertEquals("Tab must have only one child", 1, tabDesign.children() | |||
.size()); | |||
assertEquals("v-text-field", content.tagName()); | |||
} | |||
private Element createDesign() { | |||
// make sure that the design node has old content that should be removed | |||
Element node = new Element(Tag.valueOf("v-tab-sheet"), "", | |||
new Attributes()); | |||
node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); | |||
node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); | |||
node.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes())); | |||
return node; | |||
} | |||
private DesignContext createDesignContext() { | |||
return new DesignContext(); | |||
} | |||
private TabSheet createTabSheet() { | |||
TabSheet sheet = new TabSheet(); | |||
sheet.setTabIndex(5); | |||
sheet.addTab(new TextField()); | |||
Tab tab = sheet.getTab(0); | |||
tab.setCaption("test-caption"); | |||
tab.setVisible(false); | |||
tab.setClosable(true); | |||
tab.setEnabled(false); | |||
tab.setIcon(new ExternalResource("http://www.vaadin.com/test.png")); | |||
tab.setIconAlternateText("OK"); | |||
tab.setDescription("test-desc"); | |||
tab.setStyleName("test-style"); | |||
tab.setId("test-id"); | |||
return sheet; | |||
} | |||
} |
@@ -1,59 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.textarea; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.AbstractTextField; | |||
import com.vaadin.ui.TextArea; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for reading the value of the TextField from design | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
public void testValue() { | |||
Element design = createDesign(); | |||
AbstractTextField component = getComponent(); | |||
component.readDesign(design, ctx); | |||
assertEquals("test value", component.getValue()); | |||
} | |||
private AbstractTextField getComponent() { | |||
return new TextArea(); | |||
} | |||
private Element createDesign() { | |||
Attributes attributes = new Attributes(); | |||
Element node = new Element(Tag.valueOf("v-text-area"), "", attributes); | |||
node.html("test value"); | |||
return node; | |||
} | |||
} |
@@ -29,25 +29,13 @@ import com.vaadin.ui.TextArea; | |||
public class TextAreaDeclarativeTest extends DeclarativeTestBase<TextArea> { | |||
@Test | |||
public void testRead() { | |||
testRead(getDesign(), getExpected()); | |||
public void testTextArea() { | |||
String design = "<v-text-area rows=6 wordwrap=false>Hello World!</v-text-area>"; | |||
TextArea ta = new TextArea(); | |||
ta.setRows(6); | |||
ta.setWordwrap(false); | |||
ta.setValue("Hello World!"); | |||
testRead(design, ta); | |||
testWrite(design, ta); | |||
} | |||
@Test | |||
public void testWrite() { | |||
testWrite(getDesign(), getExpected()); | |||
} | |||
protected String getDesign() { | |||
return "<v-text-area rows=6 wordwrap=false>Hello World!</v-text-area>"; | |||
} | |||
protected TextArea getExpected() { | |||
TextArea tf = new TextArea(); | |||
tf.setRows(6); | |||
tf.setWordwrap(false); | |||
tf.setValue("Hello World!"); | |||
return tf; | |||
}; | |||
} |
@@ -1,60 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.textarea; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.AbstractTextField; | |||
import com.vaadin.ui.TextArea; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for writing the value of the TextField to design | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
public void testSynchronizeValue() { | |||
Element design = createDesign(); | |||
AbstractTextField component = getComponent(); | |||
component.setValue("test value"); | |||
component.writeDesign(design, ctx); | |||
assertEquals("test value", design.html()); | |||
assertFalse(design.hasAttr("value")); | |||
} | |||
private AbstractTextField getComponent() { | |||
return new TextArea(); | |||
} | |||
private Element createDesign() { | |||
Attributes attr = new Attributes(); | |||
return new Element(Tag.valueOf("v-text-area"), "", attr); | |||
} | |||
} |
@@ -1,59 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.textfield; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.AbstractTextField; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for reading the value of the TextField from design | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class ReadDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
public void testValue() { | |||
Element design = createDesign(); | |||
AbstractTextField component = getComponent(); | |||
component.readDesign(design, ctx); | |||
assertEquals("test value", component.getValue()); | |||
} | |||
private AbstractTextField getComponent() { | |||
return new TextField(); | |||
} | |||
private Element createDesign() { | |||
Attributes attributes = new Attributes(); | |||
attributes.put("value", "test value"); | |||
Element node = new Element(Tag.valueOf("v-text-field"), "", attributes); | |||
return node; | |||
} | |||
} |
@@ -29,22 +29,19 @@ import com.vaadin.ui.TextField; | |||
public class TextFieldDeclarativeTest extends DeclarativeTestBase<TextField> { | |||
@Test | |||
public void testPlainTextRead() { | |||
testRead(getDesign(), getExpected()); | |||
public void testEmpty() { | |||
String design = "<v-text-field/>"; | |||
TextField tf = new TextField(); | |||
testRead(design, tf); | |||
testWrite(design, tf); | |||
} | |||
@Test | |||
public void testPlainTextWrite() { | |||
testWrite(getDesign(), getExpected()); | |||
} | |||
protected String getDesign() { | |||
return "<v-text-field/>"; | |||
} | |||
protected TextField getExpected() { | |||
public void testValue() { | |||
String design = "<v-text-field value=\"test value\"/>"; | |||
TextField tf = new TextField(); | |||
return tf; | |||
}; | |||
tf.setValue("test value"); | |||
testRead(design, tf); | |||
testWrite(design, tf); | |||
} | |||
} |
@@ -1,59 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.server.component.textfield; | |||
import junit.framework.TestCase; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import org.jsoup.parser.Tag; | |||
import com.vaadin.ui.AbstractTextField; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* Test case for writing the value of the TextField to design | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
public class WriteDesignTest extends TestCase { | |||
private DesignContext ctx; | |||
@Override | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
ctx = new DesignContext(); | |||
} | |||
public void testSynchronizeValue() { | |||
Element design = createDesign(); | |||
AbstractTextField component = getComponent(); | |||
component.setValue("test value"); | |||
component.writeDesign(design, ctx); | |||
assertEquals("test value", design.attr("value")); | |||
} | |||
private AbstractTextField getComponent() { | |||
return new TextField(); | |||
} | |||
private Element createDesign() { | |||
Attributes attr = new Attributes(); | |||
return new Element(Tag.valueOf("v-text-field"), "", attr); | |||
} | |||
} |
@@ -0,0 +1,175 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.components; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.lang.annotation.ElementType; | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.RetentionPolicy; | |||
import java.lang.annotation.Target; | |||
import java.lang.reflect.InvocationTargetException; | |||
import java.lang.reflect.Method; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.ui.Component; | |||
import com.vaadin.ui.declarative.Design; | |||
/** | |||
* Declarative test UI. Provides simple instantiation of HTML designs located | |||
* under {@code uitest/src}. Also provides {@link OnLoad} annotation that lets | |||
* you easily hook up methods to run after the UI has been created. Note: you | |||
* <i>must</i> add the {@link DeclarativeUI} annotation to your subclass; not | |||
* doing this will result in program failure. | |||
*/ | |||
@SuppressWarnings("serial") | |||
public class DeclarativeTestUI extends AbstractTestUI { | |||
private Logger logger; | |||
private Component component; | |||
/** | |||
* Class marker indicating the design .html file to load | |||
*/ | |||
@Retention(RetentionPolicy.RUNTIME) | |||
@Target(ElementType.TYPE) | |||
public static @interface DeclarativeUI { | |||
String value(); | |||
/** | |||
* Set this property to true if you provide an absolute path to your | |||
* design; otherwise, the DeclarativeTestUI logic will look for the HTML | |||
* design file under {@code vaadin_project/uitest/src/<package path>/}. | |||
*/ | |||
boolean absolutePath() default false; | |||
} | |||
/** | |||
* Method marker interface indicating that a method should be run after the | |||
* declarative UI has been created | |||
*/ | |||
@Retention(RetentionPolicy.RUNTIME) | |||
@Target(ElementType.METHOD) | |||
public static @interface OnLoad { | |||
} | |||
/** | |||
* Figure out the proper path for the HTML design file | |||
*/ | |||
private String getDesignPath() { | |||
Class<?> clazz = getClass(); | |||
String designFilePath = null; | |||
if (clazz.getAnnotation(DeclarativeUI.class).absolutePath()) { | |||
designFilePath = ""; | |||
} else { | |||
// This is rather nasty.. but it works well enough for now. | |||
String userDir = System.getProperty("user.dir"); | |||
designFilePath = userDir + "/uitest/src/" | |||
+ clazz.getPackage().getName().replace('.', '/') + "/"; | |||
} | |||
String designFileName = clazz.getAnnotation(DeclarativeUI.class) | |||
.value(); | |||
return designFilePath + designFileName; | |||
} | |||
private Component readDesign() throws Exception { | |||
String path = getDesignPath(); | |||
getLogger().log(Level.INFO, "Reading design from " + path); | |||
File file = new File(path); | |||
return Design.read(new FileInputStream(file)); | |||
} | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
Class<?> clazz = getClass(); | |||
if (clazz.isAnnotationPresent(DeclarativeUI.class)) { | |||
// Create component | |||
try { | |||
component = readDesign(); | |||
} catch (Exception e1) { | |||
getLogger().log(Level.SEVERE, "Error reading design", e1); | |||
return; | |||
} | |||
addComponent(component); | |||
// Call on-load methods (if applicable) | |||
Method[] methods = clazz.getMethods(); | |||
for (Method m : methods) { | |||
if (m.isAnnotationPresent(OnLoad.class)) { | |||
try { | |||
m.invoke(this, (Object[]) null); | |||
} catch (IllegalAccessException e) { | |||
getLogger().log(Level.SEVERE, | |||
"Error invoking @OnLoad method", e); | |||
return; | |||
} catch (IllegalArgumentException e) { | |||
getLogger().log(Level.SEVERE, | |||
"Error invoking @OnLoad method", e); | |||
return; | |||
} catch (InvocationTargetException e) { | |||
getLogger().log(Level.SEVERE, | |||
"Error invoking @OnLoad method", e); | |||
return; | |||
} | |||
} | |||
} | |||
} else { | |||
throw new IllegalStateException( | |||
"Cannot find declarative UI annotation"); | |||
} | |||
} | |||
/** | |||
* Get access to the declaratively created component. This method typecasts | |||
* the component to the receiving type; if there's a mismatch between what | |||
* you expect and what's written in the design, this will fail with a | |||
* ClassCastException. | |||
* | |||
* @return a Vaadin component | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
public <T extends Component> T getComponent() { | |||
try { | |||
return (T) component; | |||
} catch (ClassCastException ex) { | |||
getLogger().log(Level.SEVERE, | |||
"Component code/design type mismatch", ex); | |||
} | |||
return null; | |||
} | |||
/** | |||
* Get access to the logger of this class | |||
* | |||
* @return a Logger instance | |||
*/ | |||
protected Logger getLogger() { | |||
if (logger == null) { | |||
logger = Logger.getLogger(getClass().getName()); | |||
} | |||
return logger; | |||
} | |||
} |
@@ -0,0 +1,53 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.components.grid; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.ComboBox; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Grid.Column; | |||
import com.vaadin.ui.Grid.SelectionMode; | |||
public class GridEditingWithNoScrollBars extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
Grid grid = new Grid(); | |||
grid.addColumn("foo", String.class); | |||
grid.addColumn("bar", String.class); | |||
for (int i = 0; i < 10; ++i) { | |||
grid.addRow("foo", "" + (i % 3 + 1)); | |||
} | |||
ComboBox stCombo = new ComboBox(); | |||
stCombo.addItem("" + 1); | |||
stCombo.addItem("" + 2); | |||
stCombo.addItem("" + 3); | |||
stCombo.setNullSelectionAllowed(false); | |||
stCombo.setSizeFull(); | |||
Column stCol = grid.getColumn("bar"); | |||
stCol.setEditorField(stCombo); | |||
grid.setSelectionMode(SelectionMode.SINGLE); | |||
grid.setEditorEnabled(true); | |||
grid.setSizeFull(); | |||
addComponent(grid); | |||
} | |||
} |
@@ -0,0 +1,36 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.components.grid; | |||
import static org.junit.Assert.assertEquals; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.GridElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class GridEditingWithNoScrollBarsTest extends MultiBrowserTest { | |||
@Test | |||
public void testEditorWideEnough() { | |||
openTestURL(); | |||
GridElement grid = $(GridElement.class).first(); | |||
grid.getCell(1, 1).doubleClick(); | |||
assertEquals(grid.getEditor().getSize().width, grid.getTableWrapper() | |||
.getSize().width); | |||
} | |||
} |
@@ -0,0 +1,499 @@ | |||
<v-grid | |||
editor-save-caption='Save' | |||
editor-cancel-caption='Cancel' | |||
frozen-columns=1 | |||
style-name='grid-basics' | |||
width='750px' height='100%'> | |||
<table> | |||
<colgroup> | |||
<col min-width='150'/> | |||
<col width='115'/> | |||
<col width='115'/> | |||
<col width='115'/> | |||
<col width='115'/> | |||
<col width='115'/> | |||
<col width='115'/> | |||
<col width='115'/> | |||
<col width='115'/> | |||
</colgroup> | |||
<thead> | |||
<tr> | |||
<th /> | |||
<th colspan=2><b>2012</b></th> | |||
<th colspan=2><b>2013</b></th> | |||
<th colspan=2><b>2014</b></th> | |||
<th colspan=2><b>2015</b></th> | |||
</tr> | |||
<tr default=true> | |||
<th>Company</th> | |||
<th>H1</th> | |||
<th>H2</th> | |||
<th>H1</th> | |||
<th>H2</th> | |||
<th>H1</th> | |||
<th>H2</th> | |||
<th>H1</th> | |||
<th>H2</th> | |||
</tr> | |||
<tr> | |||
<th> | |||
<v-text-field width='100%' input-prompt='Filter'></v-textfield> | |||
<!-- | |||
--> | |||
</th> | |||
<th /> | |||
<th /> | |||
<th /> | |||
<th /> | |||
<th /> | |||
<th /> | |||
<th /> | |||
<th /> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$6,063.67</td> | |||
<td>$7,116.66</td> | |||
<td>$5,879.24</td> | |||
<td>$5,270.28</td> | |||
<td>$393.65</td> | |||
<td>$4,922.45</td> | |||
<td>$5,443.97</td> | |||
<td>$203.05</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$6,508.00</td> | |||
<td>$8,904.53</td> | |||
<td>$3,938.05</td> | |||
<td>$2,283.44</td> | |||
</tr> | |||
<tr> | |||
<td>Deomic</td> | |||
<td>$4,802.82</td> | |||
<td>$7,083.74</td> | |||
<td>$6,418.09</td> | |||
<td>$9,964.82</td> | |||
<td>$4,543.26</td> | |||
<td>$2,004.65</td> | |||
<td>$5,961.86</td> | |||
<td>$5,753.23</td> | |||
</tr> | |||
</tbody> | |||
<tfoot> | |||
<tr> | |||
<td /> | |||
<td>$$$</td> | |||
<td>$$$</td> | |||
<td>$$$</td> | |||
<td>$$$</td> | |||
<td>$$$</td> | |||
<td>$$$</td> | |||
<td>$$$</td> | |||
<td>$$$</td> | |||
</tr> | |||
</tfoot> | |||
</table> | |||
</v-grid> |
@@ -0,0 +1,27 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.components.grid.declarative; | |||
import com.vaadin.annotations.Theme; | |||
import com.vaadin.tests.components.DeclarativeTestUI; | |||
import com.vaadin.tests.components.DeclarativeTestUI.DeclarativeUI; | |||
@SuppressWarnings("serial") | |||
@Theme("valo") | |||
@DeclarativeUI("GridBasicFeatures.html") | |||
public class GridDeclarativeBasicFeatures extends DeclarativeTestUI { | |||
} |
@@ -0,0 +1,81 @@ | |||
<v-grid caption="Double click to edit" width="100%" height="100%" | |||
editable selection-mode="none"> | |||
<table> | |||
<colgroup> | |||
<col property-id="index" editable=false width="50" expand=0> | |||
<col property-id="name" expand=2> | |||
<col property-id="progress" expand=2> | |||
<col property-id="weight" editable=false expand=4> | |||
</colgroup> | |||
<thead> | |||
<tr> | |||
<th>## | |||
<th>Name | |||
<th>Progress | |||
<th>Weight | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<tr> | |||
<td>00 | |||
<td>Marc Addams | |||
<td>0.42 | |||
<td>[SparkLine] | |||
</tr> | |||
<tr> | |||
<td>01 | |||
<td>Kenny Black | |||
<td>0.72 | |||
<td>[SparkLine] | |||
</tr> | |||
<tr> | |||
<td>02 | |||
<td>Sarah McGoff | |||
<td>0.12 | |||
<td>[SparkLine] | |||
</tr> | |||
<tr> | |||
<td>03 | |||
<td>Jos Jones | |||
<td>0.62 | |||
<td>[SparkLine] | |||
</tr> | |||
<tr> | |||
<td>04 | |||
<td>Jane Fielding | |||
<td>0.92 | |||
<td>[SparkLine] | |||
</tr> | |||
<tr> | |||
<td>05 | |||
<td>Marc Einstein | |||
<td>0.05 | |||
<td>[SparkLine] | |||
</tr> | |||
<tr> | |||
<td>06 | |||
<td>Lenny McGoff | |||
<td>0.40 | |||
<td>[SparkLine] | |||
</tr> | |||
<tr> | |||
<td>07 | |||
<td>Peter Adams | |||
<td>0.85 | |||
<td>[SparkLine] | |||
</tr> | |||
<tr> | |||
<td>08 | |||
<td>Tony Stark | |||
<td>0.22 | |||
<td>[SparkLine] | |||
</tr> | |||
<tr> | |||
<td>09 | |||
<td>Nathan Fillion | |||
<td>0.15 | |||
<td>[SparkLine] | |||
</tr> | |||
</tbody> | |||
</table> | |||
</v-grid> |
@@ -0,0 +1,23 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.components.grid.declarative; | |||
import com.vaadin.tests.components.DeclarativeTestUI; | |||
import com.vaadin.tests.components.DeclarativeTestUI.DeclarativeUI; | |||
@DeclarativeUI("GridItemEditor.html") | |||
public class GridItemEditor extends DeclarativeTestUI { | |||
} |
@@ -0,0 +1,43 @@ | |||
package com.vaadin.tests.components.menubar; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.JavaScript; | |||
import com.vaadin.ui.MenuBar; | |||
public class MenuItemStyleRemoved extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
MenuBar menuBar = new MenuBar(); | |||
MenuBar.MenuItem first = menuBar.addItem("first", null, null); | |||
first.addItem("first sub-item 1", null, null); | |||
first.addItem("first sub-item 2", null, null); | |||
MenuBar.MenuItem second = menuBar.addItem("second", null, null); | |||
second.addItem("second sub-item 2", null, null); | |||
second.addItem("second sub-item 2", null, null); | |||
addComponent(menuBar); | |||
addButton("Add styles", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(Button.ClickEvent event) { | |||
JavaScript.getCurrent().execute( | |||
"var x=document.getElementsByClassName('v-menubar-menuitem');" + | |||
" var i; for(i=0; i < x.length; i++)" + | |||
" {x[i].className += ' custom-menu-item'};"); | |||
} | |||
}); | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 17242; | |||
} | |||
@Override | |||
public String getDescription() { | |||
return "MenuItem's custom class names removed when hovering"; | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.vaadin.tests.components.menubar; | |||
import com.vaadin.testbench.By; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.MenuBarElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.openqa.selenium.WebElement; | |||
import java.util.List; | |||
public class MenuItemStyleRemovedTest extends MultiBrowserTest { | |||
@Test | |||
public void testCustomStyleShouldStayAfterMenuSelect() { | |||
openTestURL(); | |||
$(ButtonElement.class).caption("Add styles").first().click(); | |||
MenuBarElement menu = $(MenuBarElement.class).first(); | |||
List<WebElement> elements = menu.findElements(By.className("custom-menu-item")); | |||
Assert.assertEquals(2, elements.size()); | |||
menu.clickItem("first"); | |||
menu.clickItem("second"); | |||
elements = menu.findElements(By.className("custom-menu-item")); | |||
Assert.assertEquals(2, elements.size()); | |||
} | |||
} |
@@ -0,0 +1,130 @@ | |||
package com.vaadin.tests.components.tabsheet; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.*; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
public class FirstTabNotVisibleWhenTabsheetNotClipped extends AbstractTestUI { | |||
private TabSheet.Tab firstNotClippedTab; | |||
private TabSheet.Tab firstClippedTab; | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
addButton("Toggle first not clipped tab", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(Button.ClickEvent event) { | |||
firstNotClippedTab.setVisible(!firstNotClippedTab.isVisible()); | |||
} | |||
}); | |||
addComponent(createNotClippedTabSheet()); | |||
addButton("Toggle first clipped tab", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(Button.ClickEvent event) { | |||
firstClippedTab.setVisible(!firstClippedTab.isVisible()); | |||
} | |||
}); | |||
addComponent(createClippedTabSheet()); | |||
addComponent(new Label("VerticalLayout:")); | |||
addBlock(new VerticalLayout()); | |||
addComponent(new Label("HorizontalLayout:")); | |||
addBlock(new HorizontalLayout()); | |||
} | |||
private TabSheet createNotClippedTabSheet() { | |||
TabSheet notClippedTabSheet = new TabSheet(); | |||
for (int i = 0; i < 2; i++) { | |||
notClippedTabSheet.addTab(createTabContent(i), "Tab " + i); | |||
} | |||
firstNotClippedTab = notClippedTabSheet.getTab(0); | |||
return notClippedTabSheet; | |||
} | |||
private TabSheet createClippedTabSheet() { | |||
TabSheet clippedTabSheet = new TabSheet(); | |||
for (int i = 0; i < 50; i++) { | |||
clippedTabSheet.addTab(createTabContent(i), "Tab " + i); | |||
} | |||
firstClippedTab = clippedTabSheet.getTab(0); | |||
return clippedTabSheet; | |||
} | |||
private VerticalLayout createTabContent(int index) { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.addComponent(new Label("Tab " + index + " Content")); | |||
return layout; | |||
} | |||
private void addBlock(Layout layout) { | |||
layout.setWidth("300px"); | |||
TabSheet tabsheet = new TabSheet(); | |||
String[] letters = { "A", "B", "C", "D" }; | |||
HashMap<String, TabSheet.Tab> tabMap = new HashMap<String, TabSheet.Tab>(); | |||
for (String letter : letters) { | |||
VerticalLayout vLayout = new VerticalLayout(); | |||
vLayout.addComponent(new Label(letter + 1)); | |||
vLayout.addComponent(new Label(letter + 2)); | |||
vLayout.addComponent(new Label(letter + 3)); | |||
tabsheet.addTab(vLayout); | |||
tabsheet.getTab(vLayout).setCaption("tab " + letter); | |||
tabMap.put("tab " + letter, tabsheet.getTab(vLayout)); | |||
} | |||
VerticalLayout vtabLayout = new VerticalLayout(); | |||
for (String letter : letters) { | |||
Button btntab = new Button("show tab " + letter); | |||
btntab.setId("tab " + letter); | |||
btntab.addClickListener(createTabListener(tabMap, tabsheet)); | |||
vtabLayout.addComponent(btntab); | |||
} | |||
layout.addComponent(vtabLayout); | |||
layout.addComponent(tabsheet); | |||
addComponent(layout); | |||
} | |||
private Button.ClickListener createTabListener(final HashMap<String, TabSheet.Tab> map, | |||
final TabSheet tabsheet) { | |||
Button.ClickListener clickListener = new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(Button.ClickEvent event) { | |||
// id of the button is the same as the tab's caption | |||
String tabName = event.getComponent().getId(); | |||
for (Map.Entry<String, TabSheet.Tab> entry : map.entrySet()) { | |||
TabSheet.Tab tab = entry.getValue(); | |||
if (entry.getKey().equals(tabName)) { | |||
tab.setVisible(true); | |||
tabsheet.setSelectedTab(tab.getComponent()); | |||
} else { | |||
tab.setVisible(false); | |||
} | |||
} | |||
} | |||
}; | |||
return clickListener; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 17096; | |||
} | |||
@Override | |||
public String getDescription() { | |||
return "TabSheet should display re-shown tab if there's room for it"; | |||
} | |||
} |
@@ -0,0 +1,56 @@ | |||
package com.vaadin.tests.components.tabsheet; | |||
import com.vaadin.testbench.By; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.TabSheetElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.openqa.selenium.WebElement; | |||
public class FirstTabNotVisibleWhenTabsheetNotClippedTest extends MultiBrowserTest { | |||
@Test | |||
public void testNotClippedTabIsVisible() throws InterruptedException { | |||
openTestURL(); | |||
ButtonElement toggleNotClipped = $(ButtonElement.class) | |||
.caption("Toggle first not clipped tab").first(); | |||
toggleNotClipped.click(); | |||
TabSheetElement notClippedTabSheet = $(TabSheetElement.class).get(0); | |||
WebElement firstTab = notClippedTabSheet.findElement( | |||
By.className("v-tabsheet-tabitemcell-first")); | |||
String caption = firstTab.findElement(By.className("v-captiontext")).getText(); | |||
Assert.assertEquals("Tab with -first style should be Tab 1", "Tab 1", caption); | |||
toggleNotClipped.click(); | |||
firstTab = notClippedTabSheet.findElement( | |||
By.className("v-tabsheet-tabitemcell-first")); | |||
caption = firstTab.findElement(By.className("v-captiontext")).getText(); | |||
Assert.assertEquals("Tab with -first style should be Tab 0", "Tab 0", caption); | |||
} | |||
@Test | |||
public void testShowPreviouslyHiddenTab() { | |||
openTestURL(); | |||
$(ButtonElement.class).caption("show tab D").get(0).click(); | |||
$(ButtonElement.class).caption("show tab C").get(0).click(); | |||
WebElement firstTab = $(TabSheetElement.class).get(2) | |||
.findElement(By.className("v-tabsheet-tabitemcell-first")); | |||
String firstCaption = firstTab.findElement(By.className("v-captiontext")).getText(); | |||
org.junit.Assert.assertEquals("tab C", firstCaption); | |||
$(ButtonElement.class).caption("show tab D").get(1).click(); | |||
$(ButtonElement.class).caption("show tab C").get(1).click(); | |||
WebElement secondTab = $(TabSheetElement.class).get(3) | |||
.findElement(By.className("v-tabsheet-tabitemcell-first")); | |||
String secondCaption = secondTab.findElement(By.className("v-captiontext")).getText(); | |||
org.junit.Assert.assertEquals("tab C", secondCaption); | |||
} | |||
} |
@@ -0,0 +1,24 @@ | |||
package com.vaadin.tests.components.ui; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class CurrentUiRetainedTest extends MultiBrowserTest { | |||
@Test | |||
public void testCurrentUiRetained() throws Exception { | |||
openTestURL(); | |||
$(ButtonElement.class).first().click(); | |||
assertLogText(3, "1. Correct UI.getCurrent before GC: true"); | |||
assertLogText(2, "2. Correct UI.getCurrent after GC: true"); | |||
assertLogText(1, "3. GC probe available before GC: true"); | |||
assertLogText(0, "4. GC probe available after GC: false"); | |||
} | |||
private void assertLogText(int index, String expected) { | |||
Assert.assertEquals("Unexpected log contents,", expected, | |||
getLogRow(index)); | |||
} | |||
} |
@@ -3,15 +3,13 @@ package com.vaadin.tests.components.ui; | |||
import com.vaadin.server.Page.UriFragmentChangedEvent; | |||
import com.vaadin.server.Page.UriFragmentChangedListener; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.tests.util.Log; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
public class InitialFragmentEvent extends AbstractTestUI { | |||
public class InitialFragmentEvent extends AbstractTestUIWithLog { | |||
private String lastKnownFragment = "\"no event received\""; | |||
private Log log = new Log(5); | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
@@ -22,28 +20,25 @@ public class InitialFragmentEvent extends AbstractTestUI { | |||
public void uriFragmentChanged( | |||
UriFragmentChangedEvent source) { | |||
String newFragment = source.getUriFragment(); | |||
log.log("Fragment changed from " + lastKnownFragment | |||
log("Fragment changed from " + lastKnownFragment | |||
+ " to " + newFragment); | |||
lastKnownFragment = newFragment; | |||
} | |||
}); | |||
addComponent(log); | |||
addComponent(new Button("Set fragment to 'foo'", | |||
new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
setFragment("foo"); | |||
} | |||
})); | |||
addComponent(new Button("Set fragment to 'bar'", | |||
new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
setFragment("bar"); | |||
} | |||
})); | |||
addButton("Set fragment to 'foo'", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
setFragment("foo"); | |||
} | |||
}); | |||
addButton("Set fragment to 'bar'", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
setFragment("bar"); | |||
} | |||
}); | |||
} | |||
protected void setFragment(String fragment) { | |||
@@ -52,14 +47,12 @@ public class InitialFragmentEvent extends AbstractTestUI { | |||
@Override | |||
protected Integer getTicketNumber() { | |||
// TODO Auto-generated method stub | |||
return null; | |||
return 9558; | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
// TODO Auto-generated method stub | |||
return null; | |||
return "URI fragment handling should fire for initial fragment change"; | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.vaadin.tests.components.ui; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class InitiallyEmptyFragmentTest extends MultiBrowserTest { | |||
@Override | |||
protected Class<?> getUIClass() { | |||
return InitialFragmentEvent.class; | |||
} | |||
@Test | |||
public void testNoFragmentChangeEventWhenInitiallyEmpty() throws Exception { | |||
openTestURL(); | |||
/* | |||
* There is no fragment change event when the fragment is initially | |||
* empty | |||
*/ | |||
assertLogText(" "); | |||
executeScript("window.location.hash='bar'"); | |||
assertLogText("1. Fragment changed from \"no event received\" to bar"); | |||
} | |||
private void assertLogText(String expected) { | |||
Assert.assertEquals("Unexpected log contents,", expected, getLogRow(0)); | |||
} | |||
} |
@@ -22,7 +22,7 @@ import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Label; | |||
public class PollListenerTest extends AbstractTestUI { | |||
public class PollListening extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { |
@@ -0,0 +1,32 @@ | |||
package com.vaadin.tests.components.ui; | |||
import org.junit.Test; | |||
import org.openqa.selenium.WebDriver; | |||
import org.openqa.selenium.support.ui.ExpectedCondition; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class PollListeningTest extends MultiBrowserTest { | |||
@Test | |||
public void testReceivePollEvent() { | |||
openTestURL(); | |||
waitUntilPollEventReceived(); | |||
} | |||
private void waitUntilPollEventReceived() { | |||
waitUntil(new ExpectedCondition<Boolean>() { | |||
private String expected = "PollEvent received"; | |||
@Override | |||
public Boolean apply(WebDriver arg0) { | |||
return driver.getPageSource().contains(expected); | |||
} | |||
@Override | |||
public String toString() { | |||
return String.format("page to contain text '%s'", expected); | |||
} | |||
}); | |||
} | |||
} |
@@ -17,48 +17,42 @@ package com.vaadin.tests.components.ui; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.shared.ui.ui.PageClientRpc; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.tests.util.Log; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
public class RpcInvocationHandlerToString extends AbstractTestUI { | |||
public class RpcInvocationHandlerToString extends AbstractTestUIWithLog { | |||
private Log log = new Log(5); | |||
PageClientRpc dummyProxy = getRpcProxy(PageClientRpc.class); | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
addComponent(log); | |||
Button b = new Button("Exec toString() for an invocation proxy", | |||
addButton("Exec toString() for an invocation proxy", | |||
new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
log.log("An invoation proxy: " + dummyProxy.toString()); | |||
log("An invoation proxy: " + dummyProxy.toString()); | |||
} | |||
}); | |||
addComponent(b); | |||
b = new Button("Exec hashCode() for an invocation proxy", | |||
addButton("Exec hashCode() for an invocation proxy", | |||
new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
log.log("Invocation proxy.hashCode(): " | |||
log("Invocation proxy.hashCode(): " | |||
+ dummyProxy.hashCode()); | |||
} | |||
}); | |||
addComponent(b); | |||
b = new Button("Exec equals(false) for an invocation proxy", | |||
addButton("Exec equals(false) for an invocation proxy", | |||
new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
log.log("Invocation proxy.equals(false): " | |||
log("Invocation proxy.equals(false): " | |||
+ dummyProxy.equals(false)); | |||
} | |||
}); | |||
addComponent(b); | |||
} | |||
@Override |
@@ -0,0 +1,27 @@ | |||
package com.vaadin.tests.components.ui; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.NotificationElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class RpcInvocationHandlerToStringTest extends MultiBrowserTest { | |||
@Test | |||
public void testMethodsOnInvocationProxy() throws Exception { | |||
openTestURL(); | |||
execMethodForProxy("toString()"); | |||
execMethodForProxy("hashCode()"); | |||
execMethodForProxy("equals(false)"); | |||
} | |||
private void execMethodForProxy(String method) { | |||
$(ButtonElement.class) | |||
.caption("Exec " + method + " for an invocation proxy").first() | |||
.click(); | |||
Assert.assertFalse(method | |||
+ " for invocation proxy caused a notification", | |||
$(NotificationElement.class).exists()); | |||
} | |||
} |
@@ -128,13 +128,22 @@ public class UIAccessExceptionHandling extends AbstractTestUIWithLog implements | |||
} catch (InterruptedException e) { | |||
e.printStackTrace(); | |||
} catch (ExecutionException e) { | |||
log("Exception catched on get: " + e.getClass().getName()); | |||
log("Exception caught on get: " + e.getClass().getName()); | |||
} finally { | |||
future = null; | |||
} | |||
} | |||
} | |||
@Override | |||
public void error(com.vaadin.server.ErrorEvent event) { | |||
log("Exception caught on execution with " | |||
+ event.getClass().getSimpleName() + " : " | |||
+ event.getThrowable().getClass().getName()); | |||
DefaultErrorHandler.doDefault(event); | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Test for handling exceptions in UI.access and Session.access"; | |||
@@ -145,13 +154,4 @@ public class UIAccessExceptionHandling extends AbstractTestUIWithLog implements | |||
return Integer.valueOf(12703); | |||
} | |||
@Override | |||
public void error(com.vaadin.server.ErrorEvent event) { | |||
log("Exception catched on execution with " | |||
+ event.getClass().getSimpleName() + " : " | |||
+ event.getThrowable().getClass().getName()); | |||
DefaultErrorHandler.doDefault(event); | |||
} | |||
} |
@@ -0,0 +1,39 @@ | |||
package com.vaadin.tests.components.ui; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class UIAccessExceptionHandlingTest extends MultiBrowserTest { | |||
@Test | |||
public void testExceptionHandlingOnUIAccess() throws Exception { | |||
openTestURL(); | |||
$(ButtonElement.class).first().click(); | |||
assertLogTexts( | |||
"1. Exception caught on get: java.util.concurrent.ExecutionException", | |||
"0. Exception caught on execution with ConnectorErrorEvent : java.util.concurrent.ExecutionException"); | |||
$(ButtonElement.class).get(1).click(); | |||
assertLogTexts( | |||
"1. Exception caught on get: java.util.concurrent.ExecutionException", | |||
"0. Exception caught on execution with ErrorEvent : java.util.concurrent.ExecutionException"); | |||
$(ButtonElement.class).get(2).click(); | |||
assertLogTexts( | |||
"1. Exception caught on get: java.util.concurrent.ExecutionException", | |||
"0. Exception caught on execution with ConnectorErrorEvent : java.util.concurrent.ExecutionException"); | |||
} | |||
private void assertLogTexts(String first, String second) { | |||
assertLogText(0, first); | |||
assertLogText(1, second); | |||
} | |||
private void assertLogText(int index, String expected) { | |||
Assert.assertEquals("Unexpected log contents,", expected, | |||
getLogRow(index)); | |||
} | |||
} |
@@ -39,6 +39,14 @@ public class UIInitBrowserDetails extends AbstractTestUI { | |||
addDetail("current date", "v-curdate", wb.getCurrentDate()); | |||
} | |||
private void addDetail(String name, String param, Object value) { | |||
Label requestLabel = new Label(r.getParameter(param)); | |||
requestLabel.setId(param); | |||
Label browserLabel = new Label("" + value); | |||
browserLabel.setId(name); | |||
l.addComponents(new Label(name), requestLabel, browserLabel); | |||
} | |||
@Override | |||
public String getTestDescription() { | |||
return "Browser details should be available in UI init"; | |||
@@ -48,9 +56,4 @@ public class UIInitBrowserDetails extends AbstractTestUI { | |||
protected Integer getTicketNumber() { | |||
return Integer.valueOf(9037); | |||
} | |||
private void addDetail(String name, String param, Object value) { | |||
l.addComponents(new Label(name), new Label(r.getParameter(param)), | |||
new Label("" + value)); | |||
} | |||
} |
@@ -0,0 +1,58 @@ | |||
package com.vaadin.tests.components.ui; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.LabelElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class UIInitBrowserDetailsTest extends MultiBrowserTest { | |||
@Test | |||
public void testBrowserDetails() throws Exception { | |||
openTestURL(); | |||
/* location */ | |||
compareRequestAndBrowserValue("v-loc", "location", "null"); | |||
/* browser window width */ | |||
compareRequestAndBrowserValue("v-cw", "browser window width", "-1"); | |||
/* browser window height */ | |||
compareRequestAndBrowserValue("v-ch", "browser window height", "-1"); | |||
/* screen width */ | |||
compareRequestAndBrowserValue("v-sw", "screen width", "-1"); | |||
/* screen height */ | |||
compareRequestAndBrowserValue("v-sh", "screen height", "-1"); | |||
/* timezone offset */ | |||
assertTextNotNull("timezone offset"); | |||
/* raw timezone offset */ | |||
assertTextNotNull("raw timezone offset"); | |||
/* dst saving */ | |||
assertTextNotNull("dst saving"); | |||
/* dst in effect */ | |||
assertTextNotNull("dst in effect"); | |||
/* current date */ | |||
assertTextNotNull("v-curdate"); | |||
assertTextNotNull("current date"); | |||
} | |||
private void compareRequestAndBrowserValue(String paramName, | |||
String browserName, String errorValue) { | |||
assertTextNotEquals(browserName, errorValue); | |||
Assert.assertEquals(String.format( | |||
"Browser and request values differ in '%s',", browserName), | |||
getLabelText(paramName), getLabelText(browserName)); | |||
} | |||
private String getLabelText(String id) { | |||
return $(LabelElement.class).id(id).getText(); | |||
} | |||
private void assertTextNotNull(String id) { | |||
assertTextNotEquals(id, "null"); | |||
} | |||
private void assertTextNotEquals(String id, String notExpected) { | |||
String actual = getLabelText(id); | |||
Assert.assertNotEquals(String.format("Unexpected value for '%s'", id), | |||
notExpected, actual); | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.vaadin.tests.components.ui; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class UIInitExceptionTest extends MultiBrowserTest { | |||
@Test | |||
public void testExceptionOnUIInit() throws Exception { | |||
openTestURL(); | |||
Assert.assertTrue("Page does not contain the given text", driver | |||
.getPageSource().contains("Catch me if you can")); | |||
} | |||
} |
@@ -0,0 +1,39 @@ | |||
package com.vaadin.tests.components.ui; | |||
import java.util.List; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.openqa.selenium.remote.DesiredCapabilities; | |||
import com.vaadin.testbench.elements.TextFieldElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class UIPollingTest extends MultiBrowserTest { | |||
@Override | |||
public List<DesiredCapabilities> getBrowsersToTest() { | |||
// Manually testing IE8 stops polling with -1, but with automated test | |||
// it seems to be highly unpredictable. | |||
return super.getBrowsersExcludingIE8(); | |||
} | |||
@Test | |||
public void testPolling() throws Exception { | |||
openTestURL(); | |||
getTextField().setValue("500"); | |||
sleep(2000); | |||
/* Ensure polling has taken place */ | |||
Assert.assertTrue("Page does not contain the given text", driver | |||
.getPageSource().contains("2. 1000ms has passed")); | |||
getTextField().setValue("-1"); | |||
sleep(2000); | |||
/* Ensure polling has stopped */ | |||
Assert.assertFalse("Page contains the given text", driver | |||
.getPageSource().contains("20. 10000ms has passed")); | |||
} | |||
public TextFieldElement getTextField() { | |||
return $(TextFieldElement.class).first(); | |||
} | |||
} |
@@ -2,7 +2,6 @@ package com.vaadin.tests.components.ui; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
@@ -10,32 +9,24 @@ public class UITabIndex extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
Button b; | |||
b = new Button("Set tabIndex to -1"); | |||
b.addClickListener(new ClickListener() { | |||
addButton("Set tabIndex to -1", new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
setTabIndex(-1); | |||
} | |||
}); | |||
addComponent(b); | |||
b = new Button("Set tabIndex to 0"); | |||
b.addClickListener(new ClickListener() { | |||
addButton("Set tabIndex to 0", new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
setTabIndex(0); | |||
} | |||
}); | |||
addComponent(b); | |||
b = new Button("Set tabIndex to 1"); | |||
b.addClickListener(new ClickListener() { | |||
addButton("Set tabIndex to 1", new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
setTabIndex(1); | |||
} | |||
}); | |||
addComponent(b); | |||
} | |||
@Override |
@@ -0,0 +1,28 @@ | |||
package com.vaadin.tests.components.ui; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.UIElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class UITabIndexTest extends MultiBrowserTest { | |||
@Test | |||
public void testTabIndexOnUIRoot() throws Exception { | |||
openTestURL(); | |||
assertTabIndex("1"); | |||
$(ButtonElement.class).first().click(); | |||
assertTabIndex("-1"); | |||
$(ButtonElement.class).get(1).click(); | |||
assertTabIndex("0"); | |||
$(ButtonElement.class).get(2).click(); | |||
assertTabIndex("1"); | |||
} | |||
private void assertTabIndex(String expected) { | |||
Assert.assertEquals("Unexpected tab index,", expected, | |||
$(UIElement.class).first().getAttribute("tabIndex")); | |||
} | |||
} |
@@ -0,0 +1,25 @@ | |||
package com.vaadin.tests.components.ui; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.LabelElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class UIsInMultipleTabsTest extends MultiBrowserTest { | |||
@Test | |||
public void testPageReloadChangesUI() throws Exception { | |||
openTestURL(); | |||
assertUI(1); | |||
openTestURL(); | |||
assertUI(2); | |||
openTestURL("restartApplication"); | |||
assertUI(1); | |||
} | |||
private void assertUI(int i) { | |||
Assert.assertEquals("Unexpected UI found,", "This is UI number " + i, | |||
$(LabelElement.class).first().getText()); | |||
} | |||
} |
@@ -1,7 +1,7 @@ | |||
package com.vaadin.tests.components.window; | |||
import com.vaadin.tests.components.TestBase; | |||
import com.vaadin.tests.util.Log; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
@@ -10,23 +10,20 @@ import com.vaadin.ui.Window; | |||
import com.vaadin.ui.Window.CloseEvent; | |||
import com.vaadin.ui.Window.CloseListener; | |||
public class CloseSubWindow extends TestBase { | |||
private Log log = new Log(5); | |||
public class CloseSubWindow extends AbstractTestUIWithLog { | |||
@Override | |||
protected void setup() { | |||
protected void setup(VaadinRequest request) { | |||
Button openWindowButton = new Button("Open sub-window"); | |||
openWindowButton.setId("opensub"); | |||
openWindowButton.addListener(new ClickListener() { | |||
openWindowButton.addClickListener(new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
Window sub = createClosableSubWindow("Sub-window"); | |||
getMainWindow().addWindow(sub); | |||
getUI().addWindow(sub); | |||
} | |||
}); | |||
addComponent(log); | |||
addComponent(openWindowButton); | |||
} | |||
@@ -39,7 +36,7 @@ public class CloseSubWindow extends TestBase { | |||
window.setClosable(true); | |||
Button closeButton = new Button("Close"); | |||
closeButton.addListener(new ClickListener() { | |||
closeButton.addClickListener(new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
event.getButton().findAncestor(Window.class).close(); | |||
@@ -47,19 +44,19 @@ public class CloseSubWindow extends TestBase { | |||
}); | |||
layout.addComponent(closeButton); | |||
Button removeButton = new Button("Remove from parent"); | |||
removeButton.addListener(new ClickListener() { | |||
Button removeButton = new Button("Remove from UI"); | |||
removeButton.addClickListener(new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
window.close(); | |||
getUI().removeWindow(window); | |||
} | |||
}); | |||
layout.addComponent(closeButton); | |||
layout.addComponent(removeButton); | |||
window.addListener(new CloseListener() { | |||
window.addCloseListener(new CloseListener() { | |||
@Override | |||
public void windowClose(CloseEvent e) { | |||
log.log("Window '" + title + "' closed"); | |||
log("Window '" + title + "' closed"); | |||
} | |||
}); | |||
@@ -67,7 +64,7 @@ public class CloseSubWindow extends TestBase { | |||
} | |||
@Override | |||
protected String getDescription() { | |||
protected String getTestDescription() { | |||
return "Close sub-windows both from code and with the close button in the window title bar, and check for close events. Contains an ugly workaround for the Opera bug (Opera does not send close events)"; | |||
} | |||
@@ -0,0 +1,47 @@ | |||
package com.vaadin.tests.components.window; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.openqa.selenium.By; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.WindowElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class CloseSubWindowTest extends MultiBrowserTest { | |||
@Override | |||
public void setup() throws Exception { | |||
super.setup(); | |||
openTestURL(); | |||
openSubWindow(); | |||
} | |||
@Test | |||
public void testClosingFromClickHandler() throws Exception { | |||
$(WindowElement.class).$(ButtonElement.class).first().click(); | |||
assertLogText(); | |||
} | |||
@Test | |||
public void testClosingFromTitleBar() throws Exception { | |||
$(WindowElement.class).first() | |||
.findElement(By.className("v-window-closebox")).click(); | |||
assertLogText(); | |||
} | |||
@Test | |||
public void testClosingByRemovingFromUI() throws Exception { | |||
$(WindowElement.class).$(ButtonElement.class).get(1).click(); | |||
assertLogText(); | |||
} | |||
private void openSubWindow() { | |||
$(ButtonElement.class).id("opensub").click(); | |||
} | |||
private void assertLogText() { | |||
Assert.assertEquals("Unexpected log contents,", | |||
"1. Window 'Sub-window' closed", getLogRow(0)); | |||
} | |||
} |
@@ -1,17 +1,18 @@ | |||
package com.vaadin.tests.components.window; | |||
import com.vaadin.server.ThemeResource; | |||
import com.vaadin.tests.components.TestBase; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Alignment; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.Window; | |||
public class ExtraWindowShown extends TestBase { | |||
public class ExtraWindowShown extends AbstractTestUI { | |||
@Override | |||
protected void setup() { | |||
protected void setup(VaadinRequest request) { | |||
Button b = new Button("Open window", new Button.ClickListener() { | |||
@Override | |||
@@ -37,21 +38,20 @@ public class ExtraWindowShown extends TestBase { | |||
} | |||
}); | |||
getLayout().setHeight("100%"); | |||
getLayout().getParent().setSizeFull(); | |||
getLayout().setSizeFull(); | |||
getLayout().addComponent(b); | |||
getLayout().setComponentAlignment(b, Alignment.MIDDLE_CENTER); | |||
} | |||
@Override | |||
protected String getDescription() { | |||
// TODO Auto-generated method stub | |||
return null; | |||
protected String getTestDescription() { | |||
return "Sub window shouldn't reappear after closing."; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
// TODO Auto-generated method stub | |||
return null; | |||
return 5987; | |||
} | |||
} |
@@ -0,0 +1,37 @@ | |||
package com.vaadin.tests.components.window; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.WindowElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class ExtraWindowShownTest extends MultiBrowserTest { | |||
@Test | |||
public void testNoExtraWindowAfterClosing() throws Exception { | |||
openTestURL(); | |||
openWindow(); | |||
closeWindow(); | |||
assertNoWindow(); | |||
openWindow(); | |||
closeWindow(); | |||
assertNoWindow(); | |||
} | |||
private void openWindow() { | |||
$(ButtonElement.class).first().click(); | |||
} | |||
private void closeWindow() { | |||
$(WindowElement.class).$(ButtonElement.class).first().click(); | |||
} | |||
private void assertNoWindow() { | |||
Assert.assertFalse("Window found when there should be none.", | |||
$(WindowElement.class).exists()); | |||
} | |||
} |
@@ -28,7 +28,7 @@ public class RepaintWindowContents extends AbstractTestUI { | |||
window.setContent(layout1); | |||
button1.addListener(new ClickListener() { | |||
button1.addClickListener(new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
@@ -36,7 +36,7 @@ public class RepaintWindowContents extends AbstractTestUI { | |||
} | |||
}); | |||
button2.addListener(new ClickListener() { | |||
button2.addClickListener(new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { |
@@ -0,0 +1,36 @@ | |||
package com.vaadin.tests.components.window; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.WindowElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class RepaintWindowContentsTest extends MultiBrowserTest { | |||
@Test | |||
public void testRepaintWindowContents() throws Exception { | |||
openTestURL(); | |||
assertWindowContents("Button 1"); | |||
toggleWindowContents(); | |||
assertWindowContents("Button 2"); | |||
toggleWindowContents(); | |||
assertWindowContents("Button 1"); | |||
toggleWindowContents(); | |||
assertWindowContents("Button 2"); | |||
} | |||
private void toggleWindowContents() { | |||
getWindowButton().click(); | |||
} | |||
private void assertWindowContents(String expected) { | |||
Assert.assertEquals("Unexpected window contents,", expected, | |||
getWindowButton().getText()); | |||
} | |||
private ButtonElement getWindowButton() { | |||
return $(WindowElement.class).$(ButtonElement.class).first(); | |||
} | |||
} |
@@ -7,15 +7,19 @@ import com.vaadin.event.Action; | |||
import com.vaadin.event.Action.Handler; | |||
import com.vaadin.event.ShortcutAction; | |||
import com.vaadin.event.ShortcutAction.ModifierKey; | |||
import com.vaadin.tests.components.TestBase; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.shared.ui.MarginInfo; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.Notification; | |||
import com.vaadin.ui.TextField; | |||
public class WindowShouldRemoveActionHandler extends TestBase { | |||
public class WindowShouldRemoveActionHandler extends AbstractTestUI { | |||
@Override | |||
protected String getDescription() { | |||
protected String getTestDescription() { | |||
return "Adding action handlers to the window should make them appear on the client side. Removing the action handlers should remove them also from the client side, also if all action handlers are removed."; | |||
} | |||
@@ -24,54 +28,49 @@ public class WindowShouldRemoveActionHandler extends TestBase { | |||
return 2941; | |||
} | |||
private Label state; | |||
@Override | |||
protected void setup() { | |||
addComponent(new TextField()); | |||
Button add = new Button("Add an action handler", | |||
new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
add(); | |||
} | |||
}); | |||
Button addAnother = new Button("Add another action handler", | |||
new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
addAnother(); | |||
} | |||
}); | |||
Button remove = new Button("Remove an action handler", | |||
new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
remove(); | |||
} | |||
}); | |||
addComponent(add); | |||
addComponent(addAnother); | |||
addComponent(remove); | |||
protected void setup(VaadinRequest request) { | |||
getLayout().setMargin(new MarginInfo(true, false, false, false)); | |||
state = new Label("An UI with no action handlers."); | |||
state.setId("state"); | |||
addComponents(state, new TextField()); | |||
addButton("Add an action handler", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
add(); | |||
} | |||
}); | |||
addButton("Add another action handler", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
addAnother(); | |||
} | |||
}); | |||
addButton("Remove an action handler", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
remove(); | |||
} | |||
}); | |||
} | |||
public void remove() { | |||
getMainWindow().setCaption( | |||
getMainWindow().getCaption() + " - Removed handler"); | |||
getMainWindow().removeActionHandler( | |||
actionHandlers.remove(actionHandlers.size() - 1)); | |||
state.setValue(state.getValue() + " - Removed handler"); | |||
removeActionHandler(actionHandlers.remove(actionHandlers.size() - 1)); | |||
} | |||
private List<Handler> actionHandlers = new ArrayList<Handler>(); | |||
public void add() { | |||
getMainWindow().setCaption( | |||
getMainWindow().getCaption() + " - Added handler"); | |||
Handler actionHandler = new Handler() { | |||
@Override | |||
@@ -83,8 +82,7 @@ public class WindowShouldRemoveActionHandler extends TestBase { | |||
@Override | |||
public void handleAction(Action action, Object sender, Object target) { | |||
getMainWindow().showNotification( | |||
"Handling action " + action.getCaption()); | |||
Notification.show("Handling action " + action.getCaption()); | |||
} | |||
}; | |||
@@ -104,8 +102,7 @@ public class WindowShouldRemoveActionHandler extends TestBase { | |||
@Override | |||
public void handleAction(Action action, Object sender, Object target) { | |||
getMainWindow().showNotification( | |||
"Handling action " + action.getCaption()); | |||
Notification.show("Handling action " + action.getCaption()); | |||
} | |||
}; | |||
@@ -115,9 +112,9 @@ public class WindowShouldRemoveActionHandler extends TestBase { | |||
private void addHandler(Handler actionHandler) { | |||
actionHandlers.add(actionHandler); | |||
getMainWindow().addActionHandler(actionHandler); | |||
getMainWindow().setCaption( | |||
"A panel with " + actionHandlers.size() + " action handlers"); | |||
addActionHandler(actionHandler); | |||
state.setValue("An UI with " + actionHandlers.size() | |||
+ " action handlers"); | |||
} | |||
} |
@@ -0,0 +1,50 @@ | |||
package com.vaadin.tests.components.window; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.LabelElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class WindowShouldRemoveActionHandlerTest extends MultiBrowserTest { | |||
@Test | |||
public void testRemovingActionHandlers() { | |||
openTestURL(); | |||
addActionHandler(); | |||
addAnotherActionHandler(); | |||
assertState("An UI with 2 action handlers"); | |||
addActionHandler(); | |||
assertState("An UI with 3 action handlers"); | |||
removeActionHandler(); | |||
removeActionHandler(); | |||
assertState("An UI with 3 action handlers - Removed handler - Removed handler"); | |||
addActionHandler(); | |||
assertState("An UI with 2 action handlers"); | |||
} | |||
private void removeActionHandler() { | |||
$(ButtonElement.class).caption("Remove an action handler").first() | |||
.click(); | |||
} | |||
private void addAnotherActionHandler() { | |||
$(ButtonElement.class).caption("Add another action handler").first() | |||
.click(); | |||
} | |||
private void addActionHandler() { | |||
$(ButtonElement.class).caption("Add an action handler").first().click(); | |||
} | |||
private void assertState(String expected) { | |||
Assert.assertEquals("Unexpected state,", expected, | |||
$(LabelElement.class).id("state").getText()); | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.vaadin.tests.components.window; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.openqa.selenium.By; | |||
import com.vaadin.testbench.elements.WindowElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class WindowWithInvalidCloseListenerTest extends MultiBrowserTest { | |||
@Test | |||
public void testWindowClosesCorrectly() throws Exception { | |||
openTestURL(); | |||
$(WindowElement.class).first() | |||
.findElement(By.className("v-window-closebox")).click(); | |||
Assert.assertFalse("Window found when there should be none.", | |||
$(WindowElement.class).exists()); | |||
} | |||
} |
@@ -12,17 +12,15 @@ import com.vaadin.data.util.sqlcontainer.SQLContainer; | |||
import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool; | |||
import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool; | |||
import com.vaadin.data.util.sqlcontainer.query.TableQuery; | |||
import com.vaadin.server.LegacyApplication; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.shared.ui.combobox.FilteringMode; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.ComboBox; | |||
import com.vaadin.ui.LegacyWindow; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class TableQueryWithNonUniqueFirstPrimaryKey extends LegacyApplication { | |||
public class TableQueryWithNonUniqueFirstPrimaryKey extends AbstractTestUI { | |||
@Override | |||
public void init() { | |||
LegacyWindow mainWindow = new LegacyWindow("Test Application"); | |||
setMainWindow(mainWindow); | |||
public void setup(VaadinRequest request) { | |||
try { | |||
JDBCConnectionPool connectionPool = new SimpleJDBCConnectionPool( | |||
@@ -41,9 +39,6 @@ public class TableQueryWithNonUniqueFirstPrimaryKey extends LegacyApplication { | |||
myContainer.removeAllContainerFilters(); | |||
myContainer.addContainerFilter(new Equal("PFX", "C")); | |||
VerticalLayout layout = new VerticalLayout(); | |||
mainWindow.setContent(layout); | |||
final ComboBox myCombo = new ComboBox("MyCaption"); | |||
myCombo.setDescription("Description"); | |||
myCombo.setContainerDataSource(myContainer); | |||
@@ -64,7 +59,7 @@ public class TableQueryWithNonUniqueFirstPrimaryKey extends LegacyApplication { | |||
} | |||
} | |||
}); | |||
layout.addComponent(myCombo); | |||
addComponent(myCombo); | |||
} catch (Exception ex) { | |||
ex.printStackTrace(); | |||
} | |||
@@ -122,4 +117,14 @@ public class TableQueryWithNonUniqueFirstPrimaryKey extends LegacyApplication { | |||
connectionPool.releaseConnection(conn); | |||
} | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Ensure unique ordering when using TableQuery with multiple primary key columns."; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 10878; | |||
} | |||
} |
@@ -0,0 +1,45 @@ | |||
package com.vaadin.tests.containers.sqlcontainer; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.openqa.selenium.Keys; | |||
import org.openqa.selenium.WebElement; | |||
import com.vaadin.testbench.By; | |||
import com.vaadin.testbench.elements.ComboBoxElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class TableQueryWithNonUniqueFirstPrimaryKeyTest extends | |||
MultiBrowserTest { | |||
private static final String[] DATA = { "TARUSCIO GIOVANNI", | |||
"RUSSO GAETANO AUTORICAMBI", "AMORUSO LUIGI SRL", "CARUSO ROCCO", | |||
"F.LLI RUSSO DI GAETANO RUSSO & C", "RUSSO GIUSEPPE", | |||
"TRUSCELLI ANTONIO", "CARUSO CALOGERO" }; | |||
@Test | |||
public void testComboBoxSuggestionsListedCorrectly() throws Exception { | |||
openTestURL(); | |||
$(ComboBoxElement.class).first().findElement(By.vaadin("#textbox")) | |||
.sendKeys("rus", Keys.ENTER); | |||
List<String> result = new ArrayList<String>(); | |||
// pick list items that are shown in suggestion popup | |||
List<WebElement> elems = findElements(By | |||
.cssSelector("td[role=\"listitem\"]")); | |||
Assert.assertEquals("not enough suggestions shown", DATA.length, | |||
elems.size()); | |||
for (WebElement elem : elems) { | |||
result.add(elem.getText()); | |||
} | |||
Assert.assertArrayEquals("popup items not what they should be", DATA, | |||
result.toArray()); | |||
} | |||
} |
@@ -4,24 +4,24 @@ import java.util.Locale; | |||
import com.vaadin.data.Property.ValueChangeEvent; | |||
import com.vaadin.data.Property.ValueChangeListener; | |||
import com.vaadin.tests.components.TestBase; | |||
import com.vaadin.tests.util.Log; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
import com.vaadin.ui.TextField; | |||
public class ConverterThatEnforcesAFormat extends TestBase { | |||
private Log log = new Log(5); | |||
public class ConverterThatEnforcesAFormat extends AbstractTestUIWithLog { | |||
@Override | |||
protected void setup() { | |||
protected void setup(VaadinRequest request) { | |||
final TextField tf = new TextField( | |||
"This field should always be formatted with 3 digits"); | |||
tf.setLocale(Locale.ENGLISH); | |||
// this is needed so that IE tests pass | |||
tf.setNullRepresentation(""); | |||
tf.setConverter(new StringToDoubleConverterWithThreeFractionDigits()); | |||
tf.addValueChangeListener(new ValueChangeListener() { | |||
@Override | |||
public void valueChange(ValueChangeEvent event) { | |||
log.log("Value changed to " | |||
log("Value changed to " | |||
+ event.getProperty().getValue() | |||
+ "(converted value is " | |||
+ tf.getConvertedValue() | |||
@@ -33,13 +33,12 @@ public class ConverterThatEnforcesAFormat extends TestBase { | |||
} | |||
}); | |||
tf.setImmediate(true); | |||
addComponent(log); | |||
addComponent(tf); | |||
tf.setConvertedValue(50.0); | |||
} | |||
@Override | |||
protected String getDescription() { | |||
protected String getTestDescription() { | |||
return "Entering a valid double in the field should always cause the field contents to be formatted to contain 3 digits after the decimal point"; | |||
} | |||
@@ -0,0 +1,90 @@ | |||
package com.vaadin.tests.converter; | |||
import org.junit.Test; | |||
import org.openqa.selenium.Keys; | |||
import org.openqa.selenium.WebDriver; | |||
import org.openqa.selenium.support.ui.ExpectedCondition; | |||
import com.vaadin.testbench.elements.TextFieldElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class ConverterThatEnforcesAFormatTest extends MultiBrowserTest { | |||
private TextFieldElement field; | |||
@Override | |||
public void setup() throws Exception { | |||
super.setup(); | |||
openTestURL(); | |||
field = $(TextFieldElement.class).first(); | |||
} | |||
@Test | |||
public void checkDefault() { | |||
waitUntilValueIs("50.000"); | |||
} | |||
@Test | |||
public void checkRounding() { | |||
setValue("50.0202", Keys.ENTER); | |||
waitUntilValueIs("50.020"); | |||
} | |||
@Test | |||
public void checkElaborating() { | |||
setValue("12"); | |||
waitUntilValueIs("12.000"); | |||
} | |||
@Test | |||
public void checkText() { | |||
setValue("abc", Keys.ENTER); | |||
waitUntilValueIs("abc"); | |||
waitUntilHasCssClass("v-textfield-error"); | |||
} | |||
private void setValue(String value, CharSequence... keysToSend) { | |||
field.setValue(value); | |||
if (keysToSend.length > 0) { | |||
field.sendKeys(keysToSend); | |||
} else { | |||
field.submit(); | |||
} | |||
} | |||
private void waitUntilValueIs(final String expected) { | |||
waitUntil(new ExpectedCondition<Boolean>() { | |||
private String actual; | |||
@Override | |||
public Boolean apply(WebDriver arg0) { | |||
actual = field.getValue(); | |||
return expected.equals(actual); | |||
} | |||
@Override | |||
public String toString() { | |||
return String.format( | |||
"the field to have value '%s' (was: '%s')", expected, | |||
actual); | |||
} | |||
}); | |||
} | |||
private void waitUntilHasCssClass(final String className) { | |||
waitUntil(new ExpectedCondition<Boolean>() { | |||
@Override | |||
public Boolean apply(WebDriver arg0) { | |||
return hasCssClass(field, className); | |||
} | |||
@Override | |||
public String toString() { | |||
return String.format("the field to have css class '%s'", | |||
className); | |||
} | |||
}); | |||
} | |||
} |
@@ -10,8 +10,9 @@ import com.vaadin.event.dd.DragAndDropEvent; | |||
import com.vaadin.event.dd.DropHandler; | |||
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; | |||
import com.vaadin.event.dd.acceptcriteria.Or; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.shared.ui.dd.VerticalDropLocation; | |||
import com.vaadin.tests.components.TestBase; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.AbstractSelect; | |||
import com.vaadin.ui.Tree; | |||
import com.vaadin.ui.Tree.TreeDragMode; | |||
@@ -20,36 +21,48 @@ import com.vaadin.ui.Tree.TreeTargetDetails; | |||
/** | |||
* DD playground. Better quality example/prototype codes in {@link DDTest2}. | |||
*/ | |||
public class DDTest8 extends TestBase { | |||
public class DDTest8 extends AbstractTestUI { | |||
@Override | |||
protected void setup() { | |||
final Tree t = new Tree( | |||
protected void setup(VaadinRequest request) { | |||
final Tree tree = new Tree( | |||
"Tree with criteria from AbstractSelect (OverItem, ContainsItem). Foo can be dragged anywhere, anything can be dropped on Foo or Bar. Bar5 subtree is also valid drop target."); | |||
final HierarchicalContainer idx = new HierarchicalContainer(); | |||
t.setContainerDataSource(idx); | |||
t.addItem("Foo"); | |||
t.addItem("Bar"); | |||
t.addItem("Bar1"); | |||
t.addItem("Bar2"); | |||
t.addItem("Bar3"); | |||
t.addItem("Bar4"); | |||
t.addItem("Bar5"); | |||
t.addItem("Child"); | |||
t.setParent("Child", "Foo"); | |||
t.setSizeFull(); | |||
t.setDragMode(TreeDragMode.NODE); | |||
/* | |||
* Moves items in tree (and could work in Table too). Also supports | |||
* "building" tree. | |||
* | |||
* TODO fix algorithm, broken in some cases. | |||
*/ | |||
DropHandler itemSorter = new DropHandler() { | |||
final HierarchicalContainer container = new HierarchicalContainer(); | |||
tree.setContainerDataSource(container); | |||
tree.addItem("Foo"); | |||
tree.addItem("Bar"); | |||
tree.addItem("Bar1"); | |||
tree.addItem("Bar2"); | |||
tree.addItem("Bar3"); | |||
tree.addItem("Bar4"); | |||
tree.addItem("Bar5"); | |||
tree.addItem("Child"); | |||
tree.setParent("Child", "Foo"); | |||
tree.setSizeFull(); | |||
tree.setDragMode(TreeDragMode.NODE); | |||
tree.setDropHandler(getDropHandler(tree, container)); | |||
@SuppressWarnings("unused") | |||
getLayout().setSizeFull(); | |||
getLayout().getParent().setSizeFull(); | |||
addComponent(tree); | |||
} | |||
/** | |||
* Moves items in tree (and could work in Table too). Also supports | |||
* "building" tree. | |||
* | |||
* TODO fix algorithm, broken in some cases. | |||
* | |||
* @param tree | |||
* @param container | |||
* @return drop handler | |||
*/ | |||
private DropHandler getDropHandler(final Tree tree, | |||
final HierarchicalContainer container) { | |||
return new DropHandler() { | |||
@SuppressWarnings({ "unused", "unchecked" }) | |||
private void populateSubTree(HierarchicalContainer idx, | |||
HierarchicalContainer subtree, Object itemId) { | |||
Collection<?> children = subtree.getChildren(itemId); | |||
@@ -91,6 +104,7 @@ public class DDTest8 extends TestBase { | |||
return hierarchicalContainer; | |||
} | |||
@SuppressWarnings("unchecked") | |||
private void copyChildren(HierarchicalContainer source, | |||
HierarchicalContainer target, Object itemId) { | |||
Collection<?> children = source.getChildren(itemId); | |||
@@ -135,16 +149,16 @@ public class DDTest8 extends TestBase { | |||
Object itemIdAfter = details.getItemIdAfter(); | |||
if (itemIdOver.equals(itemIdInto)) { // directly on a node | |||
t.setParent(itemId, itemIdOver); | |||
container.setParent(itemId, itemIdOver); | |||
return; | |||
} | |||
idx.setParent(itemId, itemIdInto); | |||
container.setParent(itemId, itemIdInto); | |||
if (dropLocation == null) { | |||
System.err.println("No detail of drop place available"); | |||
} | |||
idx.moveAfterSibling(itemId, itemIdAfter); | |||
container.moveAfterSibling(itemId, itemIdAfter); | |||
} | |||
return; | |||
@@ -152,23 +166,17 @@ public class DDTest8 extends TestBase { | |||
@Override | |||
public AcceptCriterion getAcceptCriterion() { | |||
return new Or(new AbstractSelect.TargetItemIs(t, "Foo", "Bar"), | |||
new AbstractSelect.AcceptItem(t, "Foo"), | |||
t.new TargetInSubtree("Bar5") // | |||
return new Or(new AbstractSelect.TargetItemIs(tree, "Foo", | |||
"Bar"), new AbstractSelect.AcceptItem(tree, "Foo"), | |||
tree.new TargetInSubtree("Bar5") // | |||
); | |||
} | |||
}; | |||
t.setDropHandler(itemSorter); | |||
getLayout().setSizeFull(); | |||
addComponent(t); | |||
} | |||
@Override | |||
protected String getDescription() { | |||
protected String getTestDescription() { | |||
return "Random DD tests"; | |||
} | |||
@@ -0,0 +1,52 @@ | |||
package com.vaadin.tests.dd; | |||
import org.junit.Test; | |||
import org.openqa.selenium.WebDriver; | |||
import org.openqa.selenium.WebElement; | |||
import org.openqa.selenium.interactions.Actions; | |||
import org.openqa.selenium.support.ui.ExpectedCondition; | |||
import com.vaadin.testbench.By; | |||
import com.vaadin.testbench.TestBenchElement; | |||
import com.vaadin.testbench.elements.TreeElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class DnDOnSubtreeTest extends MultiBrowserTest { | |||
@Override | |||
protected Class<?> getUIClass() { | |||
return DDTest8.class; | |||
} | |||
@Test | |||
public void testDragAndDropOnSubTrees() throws Exception { | |||
openTestURL(); | |||
TreeElement tree = $(TreeElement.class).first(); | |||
WebElement bar2 = tree.findElement(By.vaadin("#n[3]")); | |||
WebElement bar5 = tree.findElement(By.vaadin("#n[6]")); | |||
new Actions(driver).moveToElement(bar2, 11, 8).clickAndHold() | |||
.moveByOffset(10, 10).perform(); | |||
/* Drop on Bar5, which is a subtree target */ | |||
new Actions(driver).moveToElement(bar5, 34, 9).release().perform(); | |||
testBenchElement(tree.findElement(By.vaadin("#n[5]/expand"))).click(5, | |||
5); | |||
/* Assert that the dragged & dropped node is now a child of Bar5 */ | |||
waitUntilElementPresent(tree, "#n[5]/n[0]"); | |||
} | |||
private void waitUntilElementPresent(final TestBenchElement parent, | |||
final String vaadinSelector) { | |||
waitUntil(new ExpectedCondition<Boolean>() { | |||
@Override | |||
public Boolean apply(WebDriver arg0) { | |||
return parent.isElementPresent(By.vaadin(vaadinSelector)); | |||
} | |||
@Override | |||
public String toString() { | |||
return String.format("element to contain '%s'", vaadinSelector); | |||
} | |||
}); | |||
} | |||
} |
@@ -10,12 +10,12 @@ import com.vaadin.data.util.converter.StringToBooleanConverter; | |||
import com.vaadin.data.validator.EmailValidator; | |||
import com.vaadin.data.validator.IntegerRangeValidator; | |||
import com.vaadin.data.validator.StringLengthValidator; | |||
import com.vaadin.tests.components.TestBase; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
import com.vaadin.tests.data.bean.Address; | |||
import com.vaadin.tests.data.bean.Country; | |||
import com.vaadin.tests.data.bean.Person; | |||
import com.vaadin.tests.data.bean.Sex; | |||
import com.vaadin.tests.util.Log; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.ComponentContainer; | |||
@@ -26,9 +26,8 @@ import com.vaadin.ui.TextArea; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class BasicPersonForm extends TestBase { | |||
public class BasicPersonForm extends AbstractTestUIWithLog { | |||
private Log log = new Log(5); | |||
private TextField firstName; | |||
private TextArea lastName; | |||
private TextField email; | |||
@@ -80,7 +79,7 @@ public class BasicPersonForm extends TestBase { | |||
} | |||
@Override | |||
protected void setup() { | |||
protected void setup(VaadinRequest request) { | |||
addComponent(log); | |||
Panel confPanel = new ConfigurationPanel(); | |||
addComponent(confPanel); | |||
@@ -133,7 +132,7 @@ public class BasicPersonForm extends TestBase { | |||
msg = "Commit failed: " + e.getMessage(); | |||
} | |||
Notification.show(msg); | |||
log.log(msg); | |||
log(msg); | |||
} | |||
}); | |||
@@ -143,7 +142,7 @@ public class BasicPersonForm extends TestBase { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
fieldGroup.discard(); | |||
log.log("Discarded changes"); | |||
log("Discarded changes"); | |||
} | |||
}); | |||
@@ -152,7 +151,7 @@ public class BasicPersonForm extends TestBase { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
log.log(getPerson(fieldGroup).toString()); | |||
log(getPerson(fieldGroup).toString()); | |||
} | |||
}); | |||
@@ -182,20 +181,19 @@ public class BasicPersonForm extends TestBase { | |||
fieldGroup.setItemDataSource(new BeanItem<Person>(p)); | |||
} | |||
@SuppressWarnings("unchecked") | |||
public static Person getPerson(FieldGroup binder) { | |||
return ((BeanItem<Person>) binder.getItemDataSource()).getBean(); | |||
} | |||
@Override | |||
protected String getDescription() { | |||
// TODO Auto-generated method stub | |||
return null; | |||
public String getDescription() { | |||
return "Basic Person Form"; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
// TODO Auto-generated method stub | |||
return null; | |||
return 8094; | |||
} | |||
} |
@@ -0,0 +1,173 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.fieldgroup; | |||
import org.junit.Assert; | |||
import com.vaadin.testbench.TestBenchElement; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.CheckBoxElement; | |||
import com.vaadin.testbench.elements.NotificationElement; | |||
import com.vaadin.testbench.elements.TableElement; | |||
import com.vaadin.testbench.elements.TableRowElement; | |||
import com.vaadin.testbench.elements.TextAreaElement; | |||
import com.vaadin.testbench.elements.TextFieldElement; | |||
import com.vaadin.tests.data.bean.Sex; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public abstract class BasicPersonFormTest extends MultiBrowserTest { | |||
private static final String BEAN_VALUES = "Person [firstName=John, lastName=Doe, email=john@doe.com, age=64, sex=Male, address=Address [streetAddress=John street, postalCode=11223, city=John's town, country=USA], deceased=false, salary=null, salaryDouble=null, rent=null]"; | |||
private int logCounter = 0; | |||
@Override | |||
protected Class<?> getUIClass() { | |||
return BasicPersonForm.class; | |||
} | |||
protected TextFieldElement getFirstNameField() { | |||
return $(TextFieldElement.class).caption("First Name").first(); | |||
} | |||
protected TextAreaElement getLastNameArea() { | |||
return $(TextAreaElement.class).caption("Last Name").first(); | |||
} | |||
protected TextFieldElement getEmailField() { | |||
return $(TextFieldElement.class).caption("Email").first(); | |||
} | |||
protected TextFieldElement getAgeField() { | |||
return $(TextFieldElement.class).caption("Age").first(); | |||
} | |||
protected TableElement getGenderTable() { | |||
return $(TableElement.class).caption("Sex").first(); | |||
} | |||
protected TextFieldElement getDeceasedField() { | |||
return $(TextFieldElement.class).caption("Deceased").first(); | |||
} | |||
protected void showBeanValues() { | |||
$(ButtonElement.class).caption("Show bean values").first().click(); | |||
} | |||
protected CheckBoxElement getPreCommitFailsCheckBox() { | |||
return $(CheckBoxElement.class).get(1); | |||
} | |||
protected void commitChanges() { | |||
$(ButtonElement.class).caption("Commit").first().click(); | |||
} | |||
protected void closeNotification() { | |||
$(NotificationElement.class).first().close(); | |||
} | |||
protected CheckBoxElement getPostCommitFailsCheckBox() { | |||
return $(CheckBoxElement.class).get(0); | |||
} | |||
protected void discardChanges() { | |||
$(ButtonElement.class).caption("Discard").first().click(); | |||
} | |||
protected void assertFirstNameValue(String expected) { | |||
assertFieldValue("First Name", expected, getFirstNameField()); | |||
} | |||
protected void assertLastNameValue(String expected) { | |||
assertFieldValue("Last Name", expected, getLastNameArea()); | |||
} | |||
protected void assertEmailValue(String expected) { | |||
assertFieldValue("Email", expected, getEmailField()); | |||
} | |||
protected void assertAgeValue(String expected) { | |||
assertFieldValue("Age", expected, getAgeField()); | |||
} | |||
protected void assertDeceasedValue(String expected) { | |||
assertFieldValue("Deceased", expected, getDeceasedField()); | |||
} | |||
private void assertFieldValue(String caption, String expected, | |||
TestBenchElement field) { | |||
Assert.assertEquals( | |||
String.format("Unexpected value for field '%s',", caption), | |||
expected, field.getAttribute("value")); | |||
} | |||
protected void assertSelectedSex(Sex sex) { | |||
TableRowElement row = getGenderTable().getRow(getIndex(sex)); | |||
Assert.assertTrue( | |||
String.format("Given sex (%s) isn't selected.", | |||
sex.getStringRepresentation()), | |||
hasCssClass(row, "v-selected")); | |||
} | |||
private int getIndex(Sex sex) { | |||
switch (sex) { | |||
case MALE: | |||
return 0; | |||
case FEMALE: | |||
return 1; | |||
default: | |||
return 2; | |||
} | |||
} | |||
protected void assertBeanValuesUnchanged() { | |||
showBeanValues(); | |||
assertLogText(BEAN_VALUES); | |||
} | |||
protected void assertCommitFails() { | |||
commitChanges(); | |||
closeNotification(); | |||
assertLogText("Commit failed: Commit failed"); | |||
} | |||
protected void assertCommitSuccessful() { | |||
commitChanges(); | |||
closeNotification(); | |||
assertLogText("Commit succesful"); | |||
} | |||
protected void assertDiscardResetsFields() { | |||
discardChanges(); | |||
assertLogText("Discarded changes"); | |||
assertDefaults(); | |||
} | |||
protected void assertLogText(String expected) { | |||
++logCounter; | |||
Assert.assertEquals("Unexpected log contents,", logCounter + ". " | |||
+ expected, getLogRow(0)); | |||
} | |||
protected void assertDefaults() { | |||
assertFirstNameValue("John"); | |||
assertLastNameValue("Doe"); | |||
assertEmailValue("john@doe.com"); | |||
assertAgeValue("64"); | |||
assertSelectedSex(Sex.MALE); | |||
assertDeceasedValue("NAAAAAH"); | |||
} | |||
} |
@@ -0,0 +1,60 @@ | |||
package com.vaadin.tests.fieldgroup; | |||
import org.junit.Test; | |||
import org.openqa.selenium.Keys; | |||
public class CommitHandlerFailuresTest extends BasicPersonFormTest { | |||
@Override | |||
public void setup() throws Exception { | |||
super.setup(); | |||
openTestURL(); | |||
} | |||
@Test | |||
public void testDefaults() { | |||
assertDefaults(); | |||
assertBeanValuesUnchanged(); | |||
} | |||
@Test | |||
public void testUpdatingWithoutCommit() { | |||
updateFields(); | |||
assertBeanValuesUnchanged(); | |||
} | |||
@Test | |||
public void testPreCommitFails() { | |||
updateFields(); | |||
getPreCommitFailsCheckBox().click(); | |||
assertCommitFails(); | |||
assertBeanValuesUnchanged(); | |||
} | |||
@Test | |||
public void testPostCommitFails() { | |||
updateFields(); | |||
getPostCommitFailsCheckBox().click(); | |||
assertCommitFails(); | |||
assertBeanValuesUnchanged(); | |||
} | |||
@Test | |||
public void testDiscard() { | |||
updateFields(); | |||
assertDiscardResetsFields(); | |||
assertBeanValuesUnchanged(); | |||
} | |||
private void updateFields() { | |||
getLastNameArea().sendKeys("Doeve", Keys.ENTER); | |||
getFirstNameField().sendKeys("Mike", Keys.ENTER); | |||
getEmailField().sendKeys("me@me.com", Keys.ENTER); | |||
getAgeField().sendKeys("12", Keys.ENTER); | |||
getGenderTable().getCell(2, 0).click(); | |||
} | |||
} |
@@ -0,0 +1,74 @@ | |||
package com.vaadin.tests.fieldgroup; | |||
import org.junit.Test; | |||
public class CommitWithValidationOrConversionErrorTest extends | |||
BasicPersonFormTest { | |||
private static final String UPDATED_BEAN_VALUES = "Person [firstName=John, lastName=Doever, email=john@doe.com, age=123, sex=Male, address=Address [streetAddress=John street, postalCode=11223, city=John's town, country=USA], deceased=false, salary=null, salaryDouble=null, rent=null]"; | |||
private static final String UPDATED_NAME_BEAN_VALUES = "Person [firstName=John, lastName=Doever, email=john@doe.com, age=64, sex=Male, address=Address [streetAddress=John street, postalCode=11223, city=John's town, country=USA], deceased=false, salary=null, salaryDouble=null, rent=null]"; | |||
@Override | |||
public void setup() throws Exception { | |||
super.setup(); | |||
openTestURL(); | |||
} | |||
@Test | |||
public void testCommitInvalidName() { | |||
getLastNameArea().setValue("Doev"); | |||
assertCommitFails(); | |||
assertBeanValuesUnchanged(); | |||
} | |||
@Test | |||
public void testCommitInvalidAge() { | |||
// default name invalid, must be fixed or doesn't test the correct error | |||
getLastNameArea().setValue("Doever"); | |||
getAgeField().setValue("64,2"); | |||
assertCommitFails(); | |||
assertBeanValuesUnchanged(); | |||
} | |||
@Test | |||
public void testFixValidationError() { | |||
getLastNameArea().setValue("Doev"); | |||
assertCommitFails(); | |||
assertBeanValuesUnchanged(); | |||
getLastNameArea().setValue("Doever"); | |||
assertCommitSuccessful(); | |||
showBeanValues(); | |||
assertLogText(UPDATED_NAME_BEAN_VALUES); | |||
} | |||
@Test | |||
public void testFixConversionError() { | |||
// default name invalid, must be fixed as well | |||
getLastNameArea().setValue("Doever"); | |||
getAgeField().setValue("64,2"); | |||
assertCommitFails(); | |||
assertBeanValuesUnchanged(); | |||
getAgeField().setValue("123"); | |||
assertCommitSuccessful(); | |||
showBeanValues(); | |||
assertLogText(UPDATED_BEAN_VALUES); | |||
} | |||
@Test | |||
public void testDiscardAfterSuccessfulCommit() { | |||
getLastNameArea().setValue("Doever"); | |||
getAgeField().setValue("123"); | |||
assertCommitSuccessful(); | |||
discardChanges(); | |||
assertLogText("Discarded changes"); | |||
showBeanValues(); | |||
assertLogText(UPDATED_BEAN_VALUES); | |||
} | |||
} |
@@ -8,9 +8,9 @@ import com.vaadin.data.fieldgroup.FieldGroup; | |||
import com.vaadin.data.fieldgroup.FieldGroup.CommitException; | |||
import com.vaadin.data.fieldgroup.PropertyId; | |||
import com.vaadin.data.util.BeanItem; | |||
import com.vaadin.tests.components.TestBase; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
import com.vaadin.tests.data.bean.Person; | |||
import com.vaadin.tests.util.Log; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.DateField; | |||
@@ -19,9 +19,8 @@ import com.vaadin.ui.Notification; | |||
import com.vaadin.ui.PopupDateField; | |||
import com.vaadin.ui.TextField; | |||
public class DateForm extends TestBase { | |||
public class DateForm extends AbstractTestUIWithLog { | |||
private Log log = new Log(5); | |||
@PropertyId("date1") | |||
private DateField dateField; | |||
@PropertyId("date2") | |||
@@ -77,8 +76,8 @@ public class DateForm extends TestBase { | |||
} | |||
@Override | |||
protected void setup() { | |||
getMainWindow().setLocale(Locale.US); | |||
protected void setup(VaadinRequest request) { | |||
setLocale(Locale.US); | |||
addComponent(log); | |||
final FieldGroup fieldGroup = new BeanFieldGroup<DateObject>( | |||
DateObject.class); | |||
@@ -102,7 +101,7 @@ public class DateForm extends TestBase { | |||
msg = "Commit failed: " + e.getMessage(); | |||
} | |||
Notification.show(msg); | |||
log.log(msg); | |||
log(msg); | |||
} | |||
}); | |||
@@ -112,8 +111,7 @@ public class DateForm extends TestBase { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
fieldGroup.discard(); | |||
log.log("Discarded changes"); | |||
log("Discarded changes"); | |||
} | |||
}); | |||
Button showBean = new Button("Show bean values", | |||
@@ -121,7 +119,7 @@ public class DateForm extends TestBase { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
log.log(getPerson(fieldGroup).toString()); | |||
log(getPerson(fieldGroup).toString()); | |||
} | |||
}); | |||
@@ -135,12 +133,13 @@ public class DateForm extends TestBase { | |||
fieldGroup.setItemDataSource(new BeanItem<DateObject>(d)); | |||
} | |||
@SuppressWarnings("unchecked") | |||
public static Person getPerson(FieldGroup binder) { | |||
return ((BeanItem<Person>) binder.getItemDataSource()).getBean(); | |||
} | |||
@Override | |||
protected String getDescription() { | |||
public String getDescription() { | |||
return "Ensure FieldGroupFieldFactory supports Dates"; | |||
} | |||
@@ -0,0 +1,47 @@ | |||
package com.vaadin.tests.fieldgroup; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.openqa.selenium.WebElement; | |||
import com.vaadin.testbench.By; | |||
import com.vaadin.testbench.elements.DateFieldElement; | |||
import com.vaadin.testbench.elements.InlineDateFieldElement; | |||
import com.vaadin.testbench.elements.PopupDateFieldElement; | |||
import com.vaadin.testbench.elements.TextFieldElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class DateFormTest extends MultiBrowserTest { | |||
@Test | |||
public void testCorrectDateFormat() throws Exception { | |||
openTestURL(); | |||
Assert.assertEquals("Unexpected DateField value,", "1/20/84", | |||
getDateFieldValue()); | |||
Assert.assertEquals("Unexpected PopupDateField value,", "1/20/84", | |||
getPopupDateFieldValue()); | |||
WebElement day20 = getInlineDateFieldCalendarPanel().findElement( | |||
By.vaadin("#day20")); | |||
Assert.assertTrue( | |||
"Unexpected InlineDateField state, 20th not selected.", | |||
hasCssClass(day20, | |||
"v-inline-datefield-calendarpanel-day-selected")); | |||
Assert.assertEquals("Unexpected TextField contents,", | |||
"Jan 20, 1984 4:34:49 PM", $(TextFieldElement.class).first() | |||
.getValue()); | |||
} | |||
protected String getDateFieldValue() { | |||
return $(DateFieldElement.class).first().getValue(); | |||
} | |||
protected String getPopupDateFieldValue() { | |||
return $(PopupDateFieldElement.class).first().getValue(); | |||
} | |||
protected WebElement getInlineDateFieldCalendarPanel() { | |||
return $(InlineDateFieldElement.class).first().findElement( | |||
By.className("v-inline-datefield-calendarpanel")); | |||
} | |||
} |
@@ -0,0 +1,32 @@ | |||
package com.vaadin.tests.fieldgroup; | |||
import org.junit.Test; | |||
import org.openqa.selenium.Keys; | |||
public class FieldGroupDiscardTest extends BasicPersonFormTest { | |||
@Test | |||
public void testFieldGroupDiscard() throws Exception { | |||
openTestURL(); | |||
assertDefaults(); | |||
/* make some changes */ | |||
getFirstNameField().sendKeys("John123", Keys.ENTER); | |||
getLastNameArea().sendKeys("Doe123", Keys.ENTER); | |||
getEmailField().sendKeys("john@doe.com123", Keys.ENTER); | |||
getAgeField().sendKeys("64123", Keys.ENTER); | |||
getGenderTable().getCell(2, 0); | |||
getDeceasedField().click(); | |||
getDeceasedField().click(); | |||
getDeceasedField().sendKeys("YAY!", Keys.ENTER); | |||
assertBeanValuesUnchanged(); | |||
assertDiscardResetsFields(); | |||
assertBeanValuesUnchanged(); | |||
/* we should still be at the state we started from */ | |||
assertDefaults(); | |||
} | |||
} |
@@ -4,8 +4,7 @@ import java.util.ArrayList; | |||
import java.util.List; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.tests.util.Log; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
import com.vaadin.ui.AbstractField; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
@@ -30,14 +29,13 @@ import com.vaadin.ui.Tree; | |||
import com.vaadin.ui.TreeTable; | |||
import com.vaadin.ui.TwinColSelect; | |||
public class TabIndexes extends AbstractTestUI { | |||
@SuppressWarnings("rawtypes") | |||
public class TabIndexes extends AbstractTestUIWithLog { | |||
private List<AbstractField> fields; | |||
private Log log = new Log(5); | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
addComponent(log); | |||
HorizontalLayout buttonLayout = new HorizontalLayout(); | |||
addComponent(buttonLayout); | |||
Button clearTabIndexes = new Button("Set all tab indexes to 0"); | |||
@@ -45,7 +43,7 @@ public class TabIndexes extends AbstractTestUI { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
log.log("Setting tab indexes to 0"); | |||
log("Setting tab indexes to 0"); | |||
for (AbstractField f : fields) { | |||
f.setTabIndex(0); | |||
} | |||
@@ -57,7 +55,7 @@ public class TabIndexes extends AbstractTestUI { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
log.log("Setting tab indexes to 1"); | |||
log("Setting tab indexes to 1"); | |||
for (AbstractField f : fields) { | |||
f.setTabIndex(1); | |||
} | |||
@@ -70,7 +68,7 @@ public class TabIndexes extends AbstractTestUI { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
int tabIndex = 1; | |||
log.log("Setting tab indexes to 1..N"); | |||
log("Setting tab indexes to 1..N"); | |||
for (AbstractField f : fields) { | |||
f.setTabIndex(tabIndex++); | |||
} | |||
@@ -84,7 +82,7 @@ public class TabIndexes extends AbstractTestUI { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
int tabIndex = fields.size(); | |||
log.log("Setting tab indexes to N..1"); | |||
log("Setting tab indexes to N..1"); | |||
for (AbstractField f : fields) { | |||
f.setTabIndex(tabIndex--); | |||
} | |||
@@ -153,8 +151,7 @@ public class TabIndexes extends AbstractTestUI { | |||
@Override | |||
protected String getTestDescription() { | |||
// TODO Auto-generated method stub | |||
return null; | |||
return "Tab index should be propagated into html"; | |||
} | |||
} |
@@ -0,0 +1,164 @@ | |||
package com.vaadin.tests.fields; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.openqa.selenium.WebElement; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class TabIndexesTest extends MultiBrowserTest { | |||
@Override | |||
public void setup() throws Exception { | |||
super.setup(); | |||
openTestURL(); | |||
} | |||
@Test | |||
public void testTabIndexesSetToZero() { | |||
// clicked by default | |||
assertLogText("1. Setting tab indexes to 0"); | |||
for (WebElement element : getFieldElements()) { | |||
assertTabIndex("0", element); | |||
} | |||
} | |||
@Test | |||
public void testTabIndexesSetToOne() { | |||
setTabIndexesTo("1"); | |||
for (WebElement element : getFieldElements()) { | |||
assertTabIndex("1", element); | |||
} | |||
} | |||
@Test | |||
public void testTabIndexesSetToOneThroughN() { | |||
setTabIndexesTo("1..N"); | |||
int counter = 0; | |||
for (WebElement element : getFieldElements()) { | |||
++counter; | |||
assertTabIndex(String.valueOf(counter), element); | |||
} | |||
} | |||
@Test | |||
public void testTabIndexesSetToNThroughOne() { | |||
setTabIndexesTo("N..1"); | |||
List<WebElement> fieldElements = getFieldElements(); | |||
int counter = fieldElements.size(); | |||
for (WebElement element : fieldElements) { | |||
assertTabIndex(String.valueOf(counter), element); | |||
--counter; | |||
} | |||
} | |||
private void setTabIndexesTo(String expected) { | |||
String caption = String.format("Set %stab indexes to %s", | |||
(expected.contains("N") ? "" : "all "), expected); | |||
$(ButtonElement.class).caption(caption).first().click(); | |||
assertLogText("2. Setting tab indexes to " + expected); | |||
} | |||
private void assertLogText(String expected) { | |||
Assert.assertEquals("Unexpected log contents,", expected, getLogRow(0)); | |||
} | |||
private void assertTabIndex(String expected, WebElement element) { | |||
Assert.assertEquals("Unexpected tab index,", expected, | |||
element.getAttribute("tabIndex")); | |||
} | |||
private List<WebElement> getFieldElements() { | |||
List<WebElement> fieldElements = new ArrayList<WebElement>(); | |||
fieldElements.add(getElement1()); | |||
fieldElements.add(getElement2()); | |||
fieldElements.add(getElement3()); | |||
fieldElements.add(getElement4()); | |||
fieldElements.add(getElement5()); | |||
fieldElements.add(getElement6()); | |||
fieldElements.add(getElement7()); | |||
fieldElements.add(getElement8()); | |||
fieldElements.add(getElement9()); | |||
fieldElements.add(getElement10()); | |||
fieldElements.add(getElement11()); | |||
fieldElements.add(getElement12()); | |||
fieldElements.add(getElement13()); | |||
fieldElements.add(getElement14()); | |||
fieldElements.add(getElement15()); | |||
fieldElements.add(getElement16()); | |||
fieldElements.add(getElement17()); | |||
return fieldElements; | |||
} | |||
private WebElement getElement1() { | |||
return vaadinElement("PID_Sfield-1/domChild[1]/domChild[1]"); | |||
} | |||
private WebElement getElement2() { | |||
return vaadinElement("PID_Sfield-2/domChild[0]"); | |||
} | |||
private WebElement getElement3() { | |||
return vaadinElement("PID_Sfield-3/domChild[0]"); | |||
} | |||
private WebElement getElement4() { | |||
return vaadinElement("PID_Sfield-4/domChild[0]"); | |||
} | |||
private WebElement getElement5() { | |||
return vaadinElement("PID_Sfield-5"); | |||
} | |||
private WebElement getElement6() { | |||
return vaadinElement("PID_Sfield-6/domChild[0]"); | |||
} | |||
private WebElement getElement7() { | |||
return vaadinElement("PID_Sfield-7/domChild[0]"); | |||
} | |||
private WebElement getElement8() { | |||
return vaadinElement("PID_Sfield-8/domChild[0]/domChild[0]"); | |||
} | |||
private WebElement getElement9() { | |||
return vaadinElement("PID_Sfield-9/domChild[1]/domChild[1]"); | |||
} | |||
private WebElement getElement10() { | |||
return vaadinElement("PID_Sfield-10/domChild[1]"); | |||
} | |||
private WebElement getElement11() { | |||
return vaadinElement("PID_Sfield-11/domChild[1]"); | |||
} | |||
private WebElement getElement12() { | |||
return vaadinElement("PID_Sfield-12"); | |||
} | |||
private WebElement getElement13() { | |||
return vaadinElement("PID_Sfield-13"); | |||
} | |||
private WebElement getElement14() { | |||
return vaadinElement("PID_Sfield-14"); | |||
} | |||
private WebElement getElement15() { | |||
return vaadinElement("PID_Sfield-15/domChild[1]"); | |||
} | |||
private WebElement getElement16() { | |||
return vaadinElement("PID_Sfield-16/domChild[0]"); | |||
} | |||
private WebElement getElement17() { | |||
return vaadinElement("PID_Sfield-17"); | |||
} | |||
} |
@@ -0,0 +1,100 @@ | |||
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.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class NavigatorListenerModifiesListeners extends AbstractTestUI { | |||
private Navigator navigator; | |||
protected static final String LABEL_MAINVIEW_ID = "LABEL_MAINVIEW_ID"; | |||
protected static final String LABEL_ANOTHERVIEW_ID = "LABEL_ANOTHERVIEW_ID"; | |||
// NOP view change listener | |||
private class MyViewChangeListener implements ViewChangeListener { | |||
@Override | |||
public boolean beforeViewChange(ViewChangeEvent event) { | |||
navigator.removeViewChangeListener(listener1); | |||
navigator.addViewChangeListener(listener2); | |||
return true; | |||
} | |||
@Override | |||
public void afterViewChange(ViewChangeEvent event) { | |||
navigator.removeViewChangeListener(listener2); | |||
navigator.addViewChangeListener(listener1); | |||
} | |||
} | |||
private MyViewChangeListener listener1 = new MyViewChangeListener(); | |||
private MyViewChangeListener listener2 = new MyViewChangeListener(); | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
navigator = new Navigator(this, this); | |||
navigator.addView(MainView.NAME, new MainView()); | |||
navigator.addView(AnotherView.NAME, new AnotherView()); | |||
navigator.addViewChangeListener(listener1); | |||
navigator.navigateTo(MainView.NAME); | |||
} | |||
class MainView extends VerticalLayout implements View { | |||
public static final String NAME = "mainview"; | |||
public MainView() { | |||
Label label = new Label("MainView content"); | |||
label.setId(LABEL_MAINVIEW_ID); | |||
addComponent(label); | |||
Button buttonNavToAnotherView = new Button( | |||
"Navigate to another view", new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
navigator.navigateTo(AnotherView.NAME); | |||
} | |||
}); | |||
addComponent(buttonNavToAnotherView); | |||
} | |||
@Override | |||
public void enter(ViewChangeEvent event) { | |||
} | |||
} | |||
class AnotherView extends VerticalLayout implements View { | |||
public static final String NAME = "another"; | |||
public AnotherView() { | |||
Label label = new Label("AnotherView content"); | |||
label.setId(LABEL_ANOTHERVIEW_ID); | |||
addComponent(label); | |||
} | |||
@Override | |||
public void enter(ViewChangeEvent event) { | |||
} | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Adding and removing view change listeners from view change listeners should not cause a ConcurrentModificationException"; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 17477; | |||
} | |||
} |
@@ -0,0 +1,68 @@ | |||
/* | |||
* Copyright 2000-2014 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.tests.navigator; | |||
import static org.junit.Assert.assertEquals; | |||
import org.junit.Test; | |||
import org.openqa.selenium.By; | |||
import org.openqa.selenium.WebElement; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.tests.tb3.SingleBrowserTest; | |||
public class NavigatorListenerModifiesListenersTest extends SingleBrowserTest { | |||
@Test | |||
public void testIfConfirmBack() { | |||
openTestURL(); | |||
// keep URL of main view | |||
final String initialUrl = driver.getCurrentUrl(); | |||
// do it 2 times to verify that this is not broken after first time | |||
for (int i = 0; i < 2; i++) { | |||
// go to prompted view | |||
WebElement button = $(ButtonElement.class).first(); | |||
button.click(); | |||
// verify we are in another view and url is correct | |||
waitForElementPresent(By | |||
.id(NavigatorListenerModifiesListeners.LABEL_ANOTHERVIEW_ID)); | |||
String currentUrl = driver.getCurrentUrl(); | |||
assertEquals( | |||
"Current URL should be equal to another view URL", | |||
initialUrl | |||
.replace( | |||
NavigatorListenerModifiesListeners.MainView.NAME, | |||
NavigatorListenerModifiesListeners.AnotherView.NAME), | |||
currentUrl); | |||
// click back button | |||
driver.navigate().back(); | |||
// verify we are in main view and url is correct | |||
// without the fix for #17477, we get | |||
// ConcurrentModificationException | |||
waitForElementPresent(By | |||
.id(NavigatorListenerModifiesListeners.LABEL_MAINVIEW_ID)); | |||
currentUrl = driver.getCurrentUrl(); | |||
assertEquals("Current URL should be equal to the initial view URL", | |||
initialUrl, currentUrl); | |||
} | |||
} | |||
} |
@@ -1,52 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |||
<head profile="http://selenium-ide.openqa.org/profiles/test-case"> | |||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |||
<link rel="selenium.base" href="" /> | |||
<title>New Test</title> | |||
</head> | |||
<body> | |||
<table cellpadding="1" cellspacing="1" border="1"> | |||
<thead> | |||
<tr><td rowspan="1" colspan="3">New Test</td></tr> | |||
</thead><tbody> | |||
<tr> | |||
<td>open</td> | |||
<td>/run/com.vaadin.tests.components.ui.CurrentUiRetained?restartApplication</td> | |||
<td></td> | |||
</tr> | |||
<tr> | |||
<td>pause</td> | |||
<td>2000</td> | |||
<td></td> | |||
</tr> | |||
<tr> | |||
<td>click</td> | |||
<td>vaadin=runcomvaadintestscomponentsuiCurrentUiRetained::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td> | |||
<td></td> | |||
</tr> | |||
<tr> | |||
<td>assertText</td> | |||
<td>vaadin=runcomvaadintestscomponentsuiCurrentUiRetained::PID_SLog_row_3</td> | |||
<td>1. Correct UI.getCurrent before GC: true</td> | |||
</tr> | |||
<tr> | |||
<td>assertText</td> | |||
<td>vaadin=runcomvaadintestscomponentsuiCurrentUiRetained::PID_SLog_row_2</td> | |||
<td>2. Correct UI.getCurrent after GC: true</td> | |||
</tr> | |||
<tr> | |||
<td>assertText</td> | |||
<td>vaadin=runcomvaadintestscomponentsuiCurrentUiRetained::PID_SLog_row_1</td> | |||
<td>3. GC probe available before GC: true</td> | |||
</tr> | |||
<tr> | |||
<td>assertText</td> | |||
<td>vaadin=runcomvaadintestscomponentsuiCurrentUiRetained::PID_SLog_row_0</td> | |||
<td>4. GC probe available after GC: false</td> | |||
</tr> | |||
</tbody></table> | |||
</body> | |||
</html> |