From 77451b47277995bffdcb00c67fc94658cd8798ba Mon Sep 17 00:00:00 2001 From: Anna Miroshnik Date: Tue, 23 Sep 2014 17:18:45 +0400 Subject: fix: Tooltip does not shrink when content changes (#11871) Change-Id: I6b0cc0996560b2f8dd28e110e455445952c0fbd9 --- .../vaadin/tests/tooltip/TooltipWidthUpdating.java | 69 ++++++++++++++++++++++ .../tests/tooltip/TooltipWidthUpdatingTest.java | 46 +++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/tooltip/TooltipWidthUpdating.java create mode 100644 uitest/src/com/vaadin/tests/tooltip/TooltipWidthUpdatingTest.java (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/tooltip/TooltipWidthUpdating.java b/uitest/src/com/vaadin/tests/tooltip/TooltipWidthUpdating.java new file mode 100644 index 0000000000..c5e49d1af3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tooltip/TooltipWidthUpdating.java @@ -0,0 +1,69 @@ +package com.vaadin.tests.tooltip; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.util.LoremIpsum; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +/** + * Test to see if the width of the tooltip element is updated if a narrower + * tooltip is opened to replace a tooltip with wider content. + * + * @author Vaadin Ltd + */ +public class TooltipWidthUpdating extends AbstractTestUI { + + private static final long serialVersionUID = 1L; + protected static final String SHORT_TOOLTIP_TEXT = "This is a short tooltip"; + protected static final String LONG_TOOLTIP_TEXT = LoremIpsum.get(5000); + protected static final Integer MAX_WIDTH = 500; + + @Override + protected void setup(VaadinRequest request) { + NativeButton componentWithShortTooltip = new NativeButton( + "Short tooltip"); + componentWithShortTooltip.setDescription(SHORT_TOOLTIP_TEXT); + componentWithShortTooltip.setId("shortTooltip"); + + getTooltipConfiguration().setMaxWidth(MAX_WIDTH); + getTooltipConfiguration().setCloseTimeout(200); + + NativeButton componentWithLongTooltip = new NativeButton("Long tooltip"); + componentWithLongTooltip.setId("longTooltip"); + componentWithLongTooltip.setDescription(LONG_TOOLTIP_TEXT); + + VerticalLayout vl = new VerticalLayout(); + + TextField component1 = new TextField("TextField"); + component1.setId("component1"); + TextField component2 = new TextField("TextField"); + TextField component3 = new TextField("TextField"); + TextField component4 = new TextField("TextField"); + TextField component5 = new TextField("TextField"); + TextField component6 = new TextField("TextField"); + TextField component7 = new TextField("TextField"); + TextField component8 = new TextField("TextField"); + + // some count of any components should be added before (between) buttons + // to make defect reproducible + vl.addComponents(component1, component2, component2, component3, + component4, component5, component5, component6, component7, + component8); + + getLayout().addComponents(componentWithShortTooltip, vl, + componentWithLongTooltip); + } + + @Override + protected String getTestDescription() { + return "Tests that tooltip element width is updated if a narrower tooltip is opened to replace a tooltip with wider content"; + } + + @Override + protected Integer getTicketNumber() { + return 11871; + } + +} diff --git a/uitest/src/com/vaadin/tests/tooltip/TooltipWidthUpdatingTest.java b/uitest/src/com/vaadin/tests/tooltip/TooltipWidthUpdatingTest.java new file mode 100644 index 0000000000..150d0e070e --- /dev/null +++ b/uitest/src/com/vaadin/tests/tooltip/TooltipWidthUpdatingTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2013 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.tooltip; + +import static org.hamcrest.Matchers.lessThan; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.TooltipTest; + +public class TooltipWidthUpdatingTest extends TooltipTest { + + @Test + public void testTooltipWidthUpdating() { + openTestURL(); + + WebElement btnLongTooltip = vaadinElementById("longTooltip"); + WebElement btnShortTooltip = vaadinElementById("shortTooltip"); + + moveMouseToTopLeft(btnLongTooltip); + testBenchElement(btnLongTooltip).showTooltip(); + + moveMouseToTopLeft(btnShortTooltip); + testBenchElement(btnShortTooltip).showTooltip(); + + assertThat(getDriver().findElement(By.className("popupContent")) + .getSize().getWidth(), lessThan(TooltipWidthUpdating.MAX_WIDTH)); + } + +} \ No newline at end of file -- cgit v1.2.3 From 961f74b080f643c67ffd8e7415ff9ac9716adbfb Mon Sep 17 00:00:00 2001 From: Guillermo Alvarez Date: Wed, 15 Oct 2014 15:33:18 +0300 Subject: Add missing tests (#12976) Adapted TB2 tests included in changeset number [26188] of Vaadin 6.8 SVN Change-Id: Ib935524538e06bd51acc01068df6ad86beba05fb --- .../components/table/UpdateTableWhenUnfocused.java | 67 ++++++++++++++++++++++ .../table/UpdateTableWhenUnfocusedTest.java | 53 +++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocused.java create mode 100644 uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocusedTest.java (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocused.java b/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocused.java new file mode 100644 index 0000000000..231375c2ea --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocused.java @@ -0,0 +1,67 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.util.IndexedContainer; +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.TabSheet; +import com.vaadin.ui.Table; + +public class UpdateTableWhenUnfocused extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + final Table table = createTable(); + + TabSheet tabSheet = new TabSheet(); + tabSheet.addTab(table, "tab1"); + tabSheet.setHeight("5000px"); + tabSheet.setWidth("100%"); + addComponent(tabSheet); + + final Button button = new Button("Refresh table"); + button.addClickListener(new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + button.focus(); + table.refreshRowCache(); + } + }); + addComponent(button); + + } + + private Table createTable() { + Table table = new Table("Table"); + table.setImmediate(true); + table.setMultiSelect(true); + table.setSizeFull(); + table.setSelectable(true); + + Container ds = new IndexedContainer(); + ds.addContainerProperty("column", Integer.class, null); + for (int i = 0; i < 500; i++) { + Item item = ds.addItem(i); + item.getItemProperty("column").setValue(i); + } + table.setContainerDataSource(ds); + + return table; + } + + @Override + protected String getTestDescription() { + return "Clicking the button after selecting a row in the table should not cause the window to scroll."; + } + + @Override + protected Integer getTicketNumber() { + return 12976; + } + +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocusedTest.java b/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocusedTest.java new file mode 100644 index 0000000000..fcd73f541d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/UpdateTableWhenUnfocusedTest.java @@ -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.table; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.IOException; + +import org.junit.Test; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UpdateTableWhenUnfocusedTest extends MultiBrowserTest { + + @Test + public void testWindowIsNotScrolled() throws IOException { + openTestURL(); + + TestBenchElement cell = $(TableElement.class).first().getCell(3, 0); + cell.click(); + + TestBenchElement button = $(ButtonElement.class).first(); + button.focus(); + + int buttonLocation = button.getLocation().getY(); + + button.click(); + + int newButtonLocation = button.getLocation().getY(); + + assertThat( + "Button location has changed after table refresh, window has scrolled and it shouldn't have", + newButtonLocation, is(buttonLocation)); + + } +} -- cgit v1.2.3 From f3f89d66b1792ef862342aaee3366575713987ce Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Wed, 15 Oct 2014 13:24:37 +0300 Subject: Update atmosphere-runtime to 2.1.2.vaadin6. (#14674, #14861) Change-Id: Ie239bf110909f8acb47f2141431965061f9ac407 --- push/build.xml | 2 +- push/ivy.xml | 2 +- server/src/com/vaadin/server/Constants.java | 2 +- .../vaadin/tests/push/BasicPushWebsocketTest.java | 2 +- .../push/ExtremelyLongPushTimeWebsocketTest.java | 2 +- .../tests/push/IdlePushChannelWebsocketTest.java | 2 +- .../vaadin/tests/push/ReconnectWebsocketTest.java | 2 +- .../tests/push/RefreshCloseConnectionTest.java | 2 +- .../vaadin/tests/push/SendMultibyteCharacters.java | 23 ++++++++++++ .../SendMultibyteCharactersLongPollingTest.java | 9 +++++ .../push/SendMultibyteCharactersStreamingTest.java | 9 +++++ .../tests/push/SendMultibyteCharactersTest.java | 42 ++++++++++++++++++++++ .../push/SendMultibyteCharactersWebSocketTest.java | 19 ++++++++++ .../src/com/vaadin/tests/tb3/MultiBrowserTest.java | 10 ++++++ uitest/src/com/vaadin/tests/tb3/WebsocketTest.java | 24 ++----------- 15 files changed, 122 insertions(+), 30 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/push/SendMultibyteCharacters.java create mode 100644 uitest/src/com/vaadin/tests/push/SendMultibyteCharactersLongPollingTest.java create mode 100644 uitest/src/com/vaadin/tests/push/SendMultibyteCharactersStreamingTest.java create mode 100644 uitest/src/com/vaadin/tests/push/SendMultibyteCharactersTest.java create mode 100644 uitest/src/com/vaadin/tests/push/SendMultibyteCharactersWebSocketTest.java (limited to 'uitest/src/com') diff --git a/push/build.xml b/push/build.xml index 9983886b7e..0a106f5023 100644 --- a/push/build.xml +++ b/push/build.xml @@ -16,7 +16,7 @@ - + diff --git a/push/ivy.xml b/push/ivy.xml index 0d42103bce..fef53b4c9b 100644 --- a/push/ivy.xml +++ b/push/ivy.xml @@ -1,7 +1,7 @@ - + ]> diff --git a/server/src/com/vaadin/server/Constants.java b/server/src/com/vaadin/server/Constants.java index fc0bf7381a..14113fda3c 100644 --- a/server/src/com/vaadin/server/Constants.java +++ b/server/src/com/vaadin/server/Constants.java @@ -67,7 +67,7 @@ public interface Constants { // Keep the version number in sync with push/build.xml and other locations // listed in that file - static final String REQUIRED_ATMOSPHERE_RUNTIME_VERSION = "2.1.2.vaadin5"; + static final String REQUIRED_ATMOSPHERE_RUNTIME_VERSION = "2.1.2.vaadin6"; static final String INVALID_ATMOSPHERE_VERSION_WARNING = "\n" + "=================================================================\n" diff --git a/uitest/src/com/vaadin/tests/push/BasicPushWebsocketTest.java b/uitest/src/com/vaadin/tests/push/BasicPushWebsocketTest.java index 093ee348b8..cd779a7318 100644 --- a/uitest/src/com/vaadin/tests/push/BasicPushWebsocketTest.java +++ b/uitest/src/com/vaadin/tests/push/BasicPushWebsocketTest.java @@ -24,6 +24,6 @@ import com.vaadin.tests.tb3.WebsocketTest; public class BasicPushWebsocketTest extends BasicPushTest { @Override public List getBrowsersToTest() { - return WebsocketTest.getWebsocketBrowsers(); + return getBrowsersSupportingWebSocket(); } } diff --git a/uitest/src/com/vaadin/tests/push/ExtremelyLongPushTimeWebsocketTest.java b/uitest/src/com/vaadin/tests/push/ExtremelyLongPushTimeWebsocketTest.java index c0b188bbab..54775d572d 100644 --- a/uitest/src/com/vaadin/tests/push/ExtremelyLongPushTimeWebsocketTest.java +++ b/uitest/src/com/vaadin/tests/push/ExtremelyLongPushTimeWebsocketTest.java @@ -26,6 +26,6 @@ public class ExtremelyLongPushTimeWebsocketTest extends @Override public List getBrowsersToTest() { - return WebsocketTest.getWebsocketBrowsers(); + return getBrowsersSupportingWebSocket(); } } diff --git a/uitest/src/com/vaadin/tests/push/IdlePushChannelWebsocketTest.java b/uitest/src/com/vaadin/tests/push/IdlePushChannelWebsocketTest.java index 644dbd7580..7559d22264 100644 --- a/uitest/src/com/vaadin/tests/push/IdlePushChannelWebsocketTest.java +++ b/uitest/src/com/vaadin/tests/push/IdlePushChannelWebsocketTest.java @@ -30,6 +30,6 @@ public class IdlePushChannelWebsocketTest extends IdlePushChannelTest { @Override public List getBrowsersToTest() { - return WebsocketTest.getWebsocketBrowsers(); + return getBrowsersSupportingWebSocket(); } } diff --git a/uitest/src/com/vaadin/tests/push/ReconnectWebsocketTest.java b/uitest/src/com/vaadin/tests/push/ReconnectWebsocketTest.java index efaf5d493e..bad00eba47 100644 --- a/uitest/src/com/vaadin/tests/push/ReconnectWebsocketTest.java +++ b/uitest/src/com/vaadin/tests/push/ReconnectWebsocketTest.java @@ -25,7 +25,7 @@ public class ReconnectWebsocketTest extends ReconnectTest { @Override public List getBrowsersToTest() { - return WebsocketTest.getWebsocketBrowsers(); + return getBrowsersSupportingWebSocket(); } @Override diff --git a/uitest/src/com/vaadin/tests/push/RefreshCloseConnectionTest.java b/uitest/src/com/vaadin/tests/push/RefreshCloseConnectionTest.java index ef461ab0da..42babb00d0 100644 --- a/uitest/src/com/vaadin/tests/push/RefreshCloseConnectionTest.java +++ b/uitest/src/com/vaadin/tests/push/RefreshCloseConnectionTest.java @@ -42,6 +42,6 @@ public class RefreshCloseConnectionTest extends MultiBrowserTest { @Override public List getBrowsersToTest() { - return WebsocketTest.getWebsocketBrowsers(); + return getBrowsersSupportingWebSocket(); } } diff --git a/uitest/src/com/vaadin/tests/push/SendMultibyteCharacters.java b/uitest/src/com/vaadin/tests/push/SendMultibyteCharacters.java new file mode 100644 index 0000000000..e41f769724 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/SendMultibyteCharacters.java @@ -0,0 +1,23 @@ +package com.vaadin.tests.push; + +import com.vaadin.annotations.Push; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.TextArea; + +@Push +public class SendMultibyteCharacters extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + TextArea textArea = new TextArea(); + textArea.setImmediate(true); + + addComponent(textArea); + } + + @Override + protected Integer getTicketNumber() { + return 14674; + } +} diff --git a/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersLongPollingTest.java b/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersLongPollingTest.java new file mode 100644 index 0000000000..fd89982253 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersLongPollingTest.java @@ -0,0 +1,9 @@ +package com.vaadin.tests.push; + +public class SendMultibyteCharactersLongPollingTest extends SendMultibyteCharactersTest { + + @Override + protected String getTransport() { + return "long-polling"; + } +} diff --git a/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersStreamingTest.java b/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersStreamingTest.java new file mode 100644 index 0000000000..7b9ec38487 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersStreamingTest.java @@ -0,0 +1,9 @@ +package com.vaadin.tests.push; + +public class SendMultibyteCharactersStreamingTest extends SendMultibyteCharactersTest { + + @Override + protected String getTransport() { + return "streaming"; + } +} diff --git a/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersTest.java b/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersTest.java new file mode 100644 index 0000000000..1ced2fb506 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersTest.java @@ -0,0 +1,42 @@ +package com.vaadin.tests.push; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.tests.annotations.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; + +@TestCategory("push") +public abstract class SendMultibyteCharactersTest extends MultiBrowserTest { + + @Override + protected Class getUIClass() { + return SendMultibyteCharacters.class; + } + + protected abstract String getTransport(); + + @Test + public void transportSupportsMultibyteCharacters() { + setDebug(true); + openTestURL("transport=" + getTransport()); + openDebugLogTab(); + + TextAreaElement textArea = $(TextAreaElement.class).first(); + + StringBuilder text = new StringBuilder(); + for(int i=0;i < 20;i++) { + text.append("之は日本語です、テストです。"); + } + + textArea.sendKeys(text.toString()); + + clearDebugMessages(); + + findElement(By.tagName("body")).click(); + + waitForDebugMessage("Variable burst to be sent to server:", 5); + waitForDebugMessage("Handling message from server", 10); + } + +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersWebSocketTest.java b/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersWebSocketTest.java new file mode 100644 index 0000000000..f37fb2efcb --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/SendMultibyteCharactersWebSocketTest.java @@ -0,0 +1,19 @@ +package com.vaadin.tests.push; + + +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.util.List; + +public class SendMultibyteCharactersWebSocketTest extends SendMultibyteCharactersTest { + + @Override + public List getBrowsersToTest() { + return getBrowsersSupportingWebSocket(); + } + + @Override + protected String getTransport() { + return "websocket"; + } +} diff --git a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java index d6eed3e5c8..ebcb02002e 100644 --- a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java +++ b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java @@ -40,6 +40,16 @@ import org.openqa.selenium.remote.DesiredCapabilities; */ public abstract class MultiBrowserTest extends PrivateTB3Configuration { + protected List getBrowsersSupportingWebSocket() { + List browsers = new ArrayList(getAllBrowsers()); + + browsers.remove(Browser.IE8.getDesiredCapabilities()); + browsers.remove(Browser.IE9.getDesiredCapabilities()); + browsers.remove(Browser.PHANTOMJS.getDesiredCapabilities()); + + return browsers; + } + protected List getBrowsersExcludingPhantomJS() { List browsers = new ArrayList(getAllBrowsers()); diff --git a/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java index 778c8b9113..ddcc6d5d76 100644 --- a/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java +++ b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java @@ -35,30 +35,10 @@ import com.vaadin.tests.tb3.MultiBrowserTest.Browser; * @author Vaadin Ltd */ @TestCategory("push") -public abstract class WebsocketTest extends PrivateTB3Configuration { - private static List websocketBrowsers = new ArrayList(); - static { - websocketBrowsers.addAll(MultiBrowserTest.getAllBrowsers()); - websocketBrowsers.remove(Browser.IE8.getDesiredCapabilities()); - websocketBrowsers.remove(Browser.IE9.getDesiredCapabilities()); - websocketBrowsers.remove(Browser.PHANTOMJS.getDesiredCapabilities()); - } - - /** - * @return All supported browsers which are actively tested and support - * websockets - */ - public static List getWebsocketBrowsers() { - return Collections.unmodifiableList(websocketBrowsers); - } +public abstract class WebsocketTest extends MultiBrowserTest { - /* - * (non-Javadoc) - * - * @see com.vaadin.tests.tb3.AbstractTB3Test#getBrowserToRunOn() - */ @Override public List getBrowsersToTest() { - return new ArrayList(getWebsocketBrowsers()); + return new ArrayList(getBrowsersSupportingWebSocket()); } } -- cgit v1.2.3 From 6b64bd23760f63cf8c3e3c6f49facd64f376a27f Mon Sep 17 00:00:00 2001 From: Guillermo Alvarez Date: Thu, 16 Oct 2014 15:40:51 +0300 Subject: New tests for Removing and re-adding all rows in Table (#14581) Refactor of test into separate tests. Addition of new cases to test when a new container is added and when all items are removed and only one item is added Change-Id: I6103404d1f21c02d7469f61ce942f7379b00a17b --- ...ableRepairsScrollPositionOnReAddingAllRows.java | 46 +++++- ...RepairsScrollPositionOnReAddingAllRowsTest.java | 182 ++++++++++----------- 2 files changed, 123 insertions(+), 105 deletions(-) (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java index df06580dae..bee0839663 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java +++ b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java @@ -115,11 +115,11 @@ public class TableRepairsScrollPositionOnReAddingAllRows extends AbstractTestUI } }); - Button buttonReplaceByWholeSubsetPlusOnNew = new Button( + Button buttonReplaceByWholeSubsetPlusOneNew = new Button( "Replace rows by whole subset plus one new item"); - buttonReplaceByWholeSubsetPlusOnNew - .setId("buttonReplaceByWholeSubsetPlusOnNew"); - buttonReplaceByWholeSubsetPlusOnNew + buttonReplaceByWholeSubsetPlusOneNew + .setId("buttonReplaceByWholeSubsetPlusOneNew"); + buttonReplaceByWholeSubsetPlusOneNew .addClickListener(new ClickListener() { @Override @@ -136,6 +136,40 @@ public class TableRepairsScrollPositionOnReAddingAllRows extends AbstractTestUI } }); + Button buttonRemoveAllAddOne = new Button( + "Remove all items and add only one new item"); + buttonRemoveAllAddOne.setId("buttonRemoveAllAddOne"); + buttonRemoveAllAddOne.addClickListener(new ClickListener() { + + @Override + public void buttonClick(com.vaadin.ui.Button.ClickEvent event) { + cont.removeAllItems(); + TableItem ti = new TableItem(); + ti.setName("Item_" + 20); + cont.addBean(ti); + } + }); + + // This should be the last test as it changes the table datasource + Button buttonReplaceByNewDatasource = new Button( + "Remove all items and add new datasource"); + buttonReplaceByNewDatasource.setId("buttonReplaceByNewDatasource"); + buttonReplaceByNewDatasource.addClickListener(new ClickListener() { + + @Override + public void buttonClick(com.vaadin.ui.Button.ClickEvent event) { + cont.removeAllItems(); + BeanItemContainer newContainer = new BeanItemContainer( + TableItem.class); + for (int i = 0; i < 50; i++) { + TableItem ti = new TableItem(); + ti.setName("Item_" + i); + newContainer.addBean(ti); + } + table.setContainerDataSource(newContainer); + } + }); + for (int i = 0; i < 80; i++) { TableItem ti = new TableItem(); ti.setName("Item_" + i); @@ -147,7 +181,9 @@ public class TableRepairsScrollPositionOnReAddingAllRows extends AbstractTestUI getLayout().addComponent(buttonReplaceByAnotherCollectionViaAddAll); getLayout().addComponent(buttonReplaceByAnotherCollectionViaAdd); getLayout().addComponent(buttonReplaceBySubsetOfSmallerSize); - getLayout().addComponent(buttonReplaceByWholeSubsetPlusOnNew); + getLayout().addComponent(buttonReplaceByWholeSubsetPlusOneNew); + getLayout().addComponent(buttonRemoveAllAddOne); + getLayout().addComponent(buttonReplaceByNewDatasource); getLayout().addComponent(buttonRestore); getLayout().addComponent(table); } diff --git a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java index a3e7f29dfe..4ca3ed406b 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java +++ b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java @@ -18,17 +18,10 @@ package com.vaadin.tests.components.table; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.number.IsCloseTo.closeTo; +import org.junit.Before; import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.ExpectedCondition; -import com.vaadin.testbench.commands.TestBenchCommandExecutor; import com.vaadin.testbench.elements.TableElement; -import com.vaadin.testbench.screenshot.ImageComparison; -import com.vaadin.testbench.screenshot.ReferenceNameGenerator; import com.vaadin.tests.tb3.MultiBrowserTest; /** @@ -40,138 +33,127 @@ import com.vaadin.tests.tb3.MultiBrowserTest; public class TableRepairsScrollPositionOnReAddingAllRowsTest extends MultiBrowserTest { - @Test - public void testScrollRepairsAfterReAddingAllRows() - throws InterruptedException { - openTestURL(); - - WebElement row0 = $(TableElement.class).first().getCell(0, 0); - int rowLocation0 = row0.getLocation().getY(); + private int rowLocation0; - // case 1 - scrollUp(); + @Override + @Before + public void setup() throws Exception { + super.setup(); + openTestURL(); - waitUntilNot(new ExpectedCondition() { - @Override - public Boolean apply(WebDriver input) { - return $(TableElement.class).first().getCell(48, 0) == null; - } - }, 10); + rowLocation0 = getCellY(0); + scrollToBottom(); + } - WebElement row = $(TableElement.class).first().getCell(48, 0); - int rowLocation = row.getLocation().getY(); + @Test + public void testReAddAllViaAddAll() { + int rowLocation = getCellY(70); // This button is for re-adding all rows (original itemIds) at once // (removeAll() + addAll()) hitButton("buttonReAddAllViaAddAll"); - row = $(TableElement.class).first().getCell(48, 0); - int newRowLocation = row.getLocation().getY(); + int newRowLocation = getCellY(70); - // ranged check because IE9 consistently misses the mark by 1 pixel - assertThat( + assertCloseTo( "Scroll position should be the same as before Re-Adding rows via addAll()", - (double) newRowLocation, - closeTo(rowLocation, row.getSize().height + 1)); - - // case 2 - scrollUp(); + newRowLocation, rowLocation); - waitUntilNot(new ExpectedCondition() { - @Override - public Boolean apply(WebDriver input) { - return $(TableElement.class).first().getCell(48, 0) == null; - } - }, 10); + } - row = $(TableElement.class).first().getCell(48, 0); - rowLocation = row.getLocation().getY(); + @Test + public void testReplaceByAnotherCollectionViaAddAll() { + int rowLocation = getCellY(70); // This button is for replacing all rows at once (removeAll() + // addAll()) hitButton("buttonReplaceByAnotherCollectionViaAddAll"); - row = $(TableElement.class).first().getCell(48, 0); - newRowLocation = row.getLocation().getY(); + // new collection has one less element + int newRowLocation = getCellY(69); - // ranged check because IE9 consistently misses the mark by 1 pixel - assertThat( + assertCloseTo( "Scroll position should be the same as before Replacing rows via addAll()", - (double) newRowLocation, - closeTo(rowLocation, row.getSize().height + 1)); + newRowLocation, rowLocation); + } + + @Test + public void testReplaceByAnotherCollectionViaAdd() { - // case 3 // This button is for replacing all rows one by one (removeAll() + add() // + add()..) hitButton("buttonReplaceByAnotherCollectionViaAdd"); - row = $(TableElement.class).first().getCell(0, 0); - newRowLocation = row.getLocation().getY(); + int newRowLocation = getCellY(0); - // ranged check because IE9 consistently misses the mark by 1 pixel - assertThat("Scroll position should be 0", (double) newRowLocation, - closeTo(rowLocation0, 1)); - - // case 4 - // This button is for restoring initial list and for scrolling to 0 - // position - hitButton("buttonRestore"); - scrollUp(); - - waitUntilNot(new ExpectedCondition() { - @Override - public Boolean apply(WebDriver input) { - return $(TableElement.class).first().getCell(48, 0) == null; - } - }, 10); + assertCloseTo("Scroll position should be 0", newRowLocation, + rowLocation0); + } + @Test + public void testReplaceBySubsetOfSmallerSize() { // This button is for replacing all rows at once but the count of rows // is less then first index to scroll hitButton("buttonReplaceBySubsetOfSmallerSize"); - row = $(TableElement.class).first().getCell(5, 0); + int newRowLocation = getCellY(5); - newRowLocation = row.getLocation().getY(); + assertCloseTo("Scroll position should be 0", newRowLocation, + rowLocation0); + } - // ranged check because IE9 consistently misses the mark by 1 pixel - assertThat("Scroll position should be 0", (double) newRowLocation, - closeTo(rowLocation0, 1)); + @Test + public void testReplaceByWholeSubsetPlusOneNew() { + int rowLocation = getCellY(70); - // case 5 - // This button is for restoring initial list and for scrolling to 0 - // position - hitButton("buttonRestore"); - scrollUp(); + // This button is for replacing by whole original sub-set of items plus + // one new + hitButton("buttonReplaceByWholeSubsetPlusOneNew"); - waitUntilNot(new ExpectedCondition() { - @Override - public Boolean apply(WebDriver input) { - return $(TableElement.class).first().getCell(48, 0) == null; - } - }, 10); + int newRowLocation = getCellY(70); - row = $(TableElement.class).first().getCell(48, 0); - rowLocation = row.getLocation().getY(); + assertCloseTo("Scroll position should be the same as before Replacing", + newRowLocation, rowLocation); - // This button is for replacing by whole original sub-set of items plus - // one new - hitButton("buttonReplaceByWholeSubsetPlusOnNew"); + } - row = $(TableElement.class).first().getCell(48, 0); - newRowLocation = row.getLocation().getY(); + @Test + public void testRemoveAllAddOne() { + // This button is for removing all and then adding only one new item + hitButton("buttonRemoveAllAddOne"); - // ranged check because IE9 consistently misses the mark by 1 pixel - assertThat("Scroll position should be the same as before Replacing", - (double) newRowLocation, - closeTo(rowLocation, row.getSize().height + 1)); + int newRowLocation = getCellY(0); + + assertCloseTo("Scroll position should be 0", newRowLocation, + rowLocation0); + } + + @Test + public void testReplaceByNewDatasource() { + // This button is for remove all items and add new datasource + hitButton("buttonReplaceByNewDatasource"); + + int newRowLocation = getCellY(0); + + assertCloseTo("Scroll position should be 0", newRowLocation, + rowLocation0); + } + + private TableElement getTable() { + return $(TableElement.class).first(); + } + private void scrollToBottom() { + scrollTable(getTable(), 80, 70); } - private void scrollUp() { - WebElement actualElement = getDriver().findElement( - By.className("v-table-body-wrapper")); - JavascriptExecutor js = new TestBenchCommandExecutor(getDriver(), - new ImageComparison(), new ReferenceNameGenerator()); - js.executeScript("arguments[0].scrollTop = " + 1205, actualElement); + private int getCellY(int row) { + return getTable().getCell(row, 0).getLocation().getY(); } + + private void assertCloseTo(String reason, int actual, int expected) { + // ranged check because IE9 consistently misses the mark by 1 pixel + assertThat(reason, (double) actual, closeTo(expected, 1)); + } + } -- cgit v1.2.3 From a26e300746c0857aadc10f292e2f644f25334123 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Tue, 14 Oct 2014 22:16:00 +0300 Subject: Correct positioning and sizing logic for context menu (#14863). Change-Id: Ic2edd6e6f53cd8ae3dc2d39477f59261356beafd --- client/src/com/vaadin/client/ui/VContextMenu.java | 13 +- .../tests/components/table/ContextMenuSize.java | 77 ++++++++++++ .../components/table/ContextMenuSizeTest.java | 131 +++++++++++++++++++++ 3 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/table/ContextMenuSize.java create mode 100644 uitest/src/com/vaadin/tests/components/table/ContextMenuSizeTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VContextMenu.java b/client/src/com/vaadin/client/ui/VContextMenu.java index 1b0181fb7d..fa6d67fc0c 100644 --- a/client/src/com/vaadin/client/ui/VContextMenu.java +++ b/client/src/com/vaadin/client/ui/VContextMenu.java @@ -143,6 +143,9 @@ public class VContextMenu extends VOverlay implements SubPartAware { // context menu is closed focusedElement = Util.getFocusedElement(); + // reset height (if it has been previously set explicitly) + setHeight(""); + setPopupPositionAndShow(new PositionCallback() { @Override public void setPosition(int offsetWidth, int offsetHeight) { @@ -158,12 +161,10 @@ public class VContextMenu extends VOverlay implements SubPartAware { } } if (offsetHeight + top > Window.getClientHeight()) { - top = top - offsetHeight; - if (top < 0) { - top = 0; - - setHeight(Window.getClientHeight() + "px"); - } + top = Math.max(0, Window.getClientHeight() - offsetHeight); + } + if (top == 0) { + setHeight(Window.getClientHeight() + "px"); } setPopupPosition(left, top); diff --git a/uitest/src/com/vaadin/tests/components/table/ContextMenuSize.java b/uitest/src/com/vaadin/tests/components/table/ContextMenuSize.java new file mode 100644 index 0000000000..ec7301099f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/ContextMenuSize.java @@ -0,0 +1,77 @@ +/* + * 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.table; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.event.Action; +import com.vaadin.event.Action.Handler; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Table; + +/** + * Test UI for table context menu position and size. + * + * @author Vaadin Ltd + */ +public class ContextMenuSize extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Table table = new Table(); + table.setPageLength(1); + table.addActionHandler(new Handler() { + + @Override + public void handleAction(Action action, Object sender, Object target) { + } + + @Override + public Action[] getActions(Object target, Object sender) { + return new Action[] { new Action("action1"), + new Action("action2"), new Action("action3"), + new Action("action4") }; + } + }); + BeanItemContainer container = new BeanItemContainer( + Bean.class); + container.addBean(new Bean()); + table.setContainerDataSource(container); + addComponent(table); + } + + @Override + public String getDescription() { + return "If context menu original position doesn't allow to show it then " + + "its bottom should be aligned with the window bottom and height " + + "should be reset after repositioning."; + } + + @Override + protected Integer getTicketNumber() { + return 14863; + } + + public static class Bean { + + public String getName() { + return "name"; + } + + public void setName() { + } + } +} diff --git a/uitest/src/com/vaadin/tests/components/table/ContextMenuSizeTest.java b/uitest/src/com/vaadin/tests/components/table/ContextMenuSizeTest.java new file mode 100644 index 0000000000..bb7001bc97 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/ContextMenuSizeTest.java @@ -0,0 +1,131 @@ +/* + * 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.table; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test for context menu position and size. + * + * @author Vaadin Ltd + */ +public class ContextMenuSizeTest extends MultiBrowserTest { + + @Test + public void testContextMenuBottom() { + openTestURL(); + + WebElement menu = openContextMenu(); + int initialHeight = menu.getSize().getHeight(); + int y = menu.getLocation().getY(); + + closeContextMenu(); + + Dimension size = getDriver().manage().window().getSize(); + + int windowHeight = y + initialHeight - 10; + if (isElementPresent(By.className("v-ff"))) { + // FF does something wrong with window height + windowHeight = y + initialHeight + 90; + } else if (isElementPresent(By.className("v-ch"))) { + // Chrome does something wrong with window height + windowHeight = y + initialHeight + 20; + } + getDriver().manage().window() + .setSize(new Dimension(size.getWidth(), windowHeight)); + + menu = openContextMenu(); + int height = menu.getSize().getHeight(); + + Assert.assertEquals("Context menu height has been changed after " + + "window height update which allows to show context as is", + initialHeight, height); + + } + + @Test + public void testContextMenuSize() { + openTestURL(); + + WebElement menu = openContextMenu(); + int initialHeight = menu.getSize().getHeight(); + int y = menu.getLocation().getY(); + + closeContextMenu(); + + Dimension size = getDriver().manage().window().getSize(); + + int windowHeight = initialHeight - 10; + if (isElementPresent(By.className("v-ch"))) { + // Chrome does something wrong with window height + windowHeight = y + initialHeight; + } + getDriver().manage().window() + .setSize(new Dimension(size.getWidth(), windowHeight)); + + menu = openContextMenu(); + int height = menu.getSize().getHeight(); + + Assert.assertTrue( + "Context menu height has not been descreased after " + + "window height update to value lower than context menu initial height", + initialHeight > height); + closeContextMenu(); + + getDriver().manage().window() + .setSize(new Dimension(size.getWidth(), size.getHeight())); + menu = openContextMenu(); + height = menu.getSize().getHeight(); + Assert.assertEquals("Context menu height has not been reset after " + + "window height reset", initialHeight, height); + } + + @Override + public List getBrowsersToTest() { + List browsers = new ArrayList( + getAllBrowsers()); + + // context menu doesn't work in phantom JS and works wired with IE8 and + // selenium. + browsers.remove(Browser.PHANTOMJS.getDesiredCapabilities()); + browsers.remove(Browser.IE8.getDesiredCapabilities()); + return browsers; + } + + private WebElement openContextMenu() { + Actions actions = new Actions(getDriver()); + actions.contextClick(findElement(By.className("v-table-cell-wrapper"))); + actions.perform(); + return findElement(By.className("v-contextmenu")); + } + + private void closeContextMenu() { + Actions actions = new Actions(getDriver()); + actions.click().build().perform(); + } + +} -- cgit v1.2.3 From f24fe92ed3fea53f8907924a92fc235f84cdec0e Mon Sep 17 00:00:00 2001 From: Guillermo Alvarez Date: Mon, 20 Oct 2014 14:40:38 +0300 Subject: Added missing test when unframed (#14450) Now we check closing element is present in unframed tabsheets Change-Id: If29c1006db0f9267d213b5f063a1c478efe60ea9 --- uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java b/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java index d4ddf2dcf9..b0af0db8c6 100644 --- a/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java +++ b/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java @@ -171,6 +171,17 @@ public class ValoThemeUITest extends MultiBrowserTest { compareScreen("tabs-closable-disabled"); } + @Test + public void tabsClosableUnframed() throws Exception { + openTestURL("test"); + open("Tabs 123", "Tabs"); + check("Closable"); + // Framed option is checked by default so we are actually unchecking + check("Framed"); + check("Overflow"); + compareScreen("tabs-closable-unframed"); + } + @Test public void tabsAlignRight() throws Exception { openTestURL("test"); -- cgit v1.2.3 From e144659cba47a9fdd48348e531480537b2036db2 Mon Sep 17 00:00:00 2001 From: Dmitrii Rogozin Date: Mon, 20 Oct 2014 16:25:22 +0300 Subject: Fix VaadinFinderLocator for UIElement (#14010). Change-Id: If25ebdcdd4df438402d1cdc60a63c629e84c73a0 --- .../client/componentlocator/LocatorUtil.java | 29 +++++++++ .../VaadinFinderLocatorStrategy.java | 38 +++-------- .../src/com/vaadin/client/LocatorUtilTest.java | 73 ++++++++++++++++++++++ .../ui/VaadinFinderLocatorUISearchTest.java | 43 +++++++++++++ 4 files changed, 155 insertions(+), 28 deletions(-) create mode 100644 client/tests/src/com/vaadin/client/LocatorUtilTest.java create mode 100644 uitest/src/com/vaadin/tests/components/ui/VaadinFinderLocatorUISearchTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/componentlocator/LocatorUtil.java b/client/src/com/vaadin/client/componentlocator/LocatorUtil.java index 1d1c06587b..7de0de3855 100644 --- a/client/src/com/vaadin/client/componentlocator/LocatorUtil.java +++ b/client/src/com/vaadin/client/componentlocator/LocatorUtil.java @@ -15,6 +15,8 @@ */ package com.vaadin.client.componentlocator; +import com.google.gwt.regexp.shared.RegExp; + /** * Common String manipulator utilities used in VaadinFinderLocatorStrategy and * SelectorPredicates. @@ -73,4 +75,31 @@ public class LocatorUtil { protected static int indexOfIgnoringQuoted(String str, char find) { return indexOfIgnoringQuoted(str, find, 0); } + + /** + * Checks if path refers to vaadin UI element com.vaadin.ui.UI. + * + * @param path + * to vaadin element + * @return true if path refers to UI element, false otherwise + */ + public static boolean isUIElement(String path) { + String regex = "^\\/{0,2}(com\\.vaadin\\.ui\\.)?V?UI[\\/\\[]?"; + RegExp regexp = RegExp.compile(regex); + return regexp.test(path); + } + + /** + * Checks if path refers to vaadin Notification element + * com.vaadin.ui.Notification. + * + * @param path + * to vaadin element + * @return true if path refers to Notification element, false otherwise + */ + public static boolean isNotificationElement(String path) { + String regex = "^\\/{0,2}(com\\.vaadin\\.ui\\.)?V?Notification[\\/\\[]?"; + RegExp regexp = RegExp.compile(regex); + return regexp.test(path); + } } diff --git a/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java b/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java index a36ea1ac85..7346e489e5 100644 --- a/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java +++ b/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java @@ -267,32 +267,6 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { return connectorHierarchy; } - private boolean isNotificationExpression(String path) { - String[] starts = { "//", "/" }; - - String[] frags = { "com.vaadin.ui.Notification.class", - "com.vaadin.ui.Notification", "VNotification.class", - "VNotification", "Notification.class", "Notification" }; - - String[] ends = { "/", "[" }; - - for (String s : starts) { - for (String f : frags) { - if (path.equals(s + f)) { - return true; - } - - for (String e : ends) { - if (path.startsWith(s + f + e)) { - return true; - } - } - } - } - - return false; - } - /** * {@inheritDoc} */ @@ -305,7 +279,7 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { } List elements = new ArrayList(); - if (isNotificationExpression(path)) { + if (LocatorUtil.isNotificationElement(path)) { for (VNotification n : findNotificationsByPath(path)) { elements.add(n.getElement()); @@ -579,11 +553,19 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { ComponentConnector parent, String pathFragment, boolean collectRecursively) { ArrayList potentialMatches = new ArrayList(); + String widgetName = getWidgetName(pathFragment); + // Special case when searching for UIElement. + if (LocatorUtil.isUIElement(pathFragment)) { + if (connectorMatchesPathFragment(parent, widgetName)) { + potentialMatches.add(parent); + } + } if (parent instanceof HasComponentsConnector) { + List children = ((HasComponentsConnector) parent) .getChildComponents(); for (ComponentConnector child : children) { - String widgetName = getWidgetName(pathFragment); + if (connectorMatchesPathFragment(child, widgetName)) { potentialMatches.add(child); } diff --git a/client/tests/src/com/vaadin/client/LocatorUtilTest.java b/client/tests/src/com/vaadin/client/LocatorUtilTest.java new file mode 100644 index 0000000000..15536ac6fc --- /dev/null +++ b/client/tests/src/com/vaadin/client/LocatorUtilTest.java @@ -0,0 +1,73 @@ +/* + * 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.client; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.vaadin.client.componentlocator.LocatorUtil; + +/* + * Test LocatorUtil.isUIElement() & isNotificaitonElement methods + */ +public class LocatorUtilTest extends TestCase { + + public void testIsUI1() { + boolean isUI = LocatorUtil.isUIElement("com.vaadin.ui.UI"); + Assert.assertTrue(isUI); + } + + public void testIsUI2() { + boolean isUI = LocatorUtil.isUIElement("/com.vaadin.ui.UI"); + Assert.assertTrue(isUI); + } + + public void testIsUI3() { + boolean isUI = LocatorUtil + .isUIElement("//com.vaadin.ui.UI[RandomString"); + Assert.assertTrue(isUI); + } + + public void testIsUI4() { + boolean isUI = LocatorUtil.isUIElement("//com.vaadin.ui.UI[0]"); + Assert.assertTrue(isUI); + } + + public void testIsNotification1() { + boolean isUI = LocatorUtil + .isNotificationElement("com.vaadin.ui.VNotification"); + Assert.assertTrue(isUI); + } + + public void testIsNotification2() { + boolean isUI = LocatorUtil + .isNotificationElement("com.vaadin.ui.Notification"); + Assert.assertTrue(isUI); + } + + public void testIsNotification3() { + boolean isUI = LocatorUtil + .isNotificationElement("/com.vaadin.ui.VNotification["); + Assert.assertTrue(isUI); + } + + public void testIsNotification4() { + boolean isUI = LocatorUtil + .isNotificationElement("//com.vaadin.ui.VNotification[0]"); + Assert.assertTrue(isUI); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/VaadinFinderLocatorUISearchTest.java b/uitest/src/com/vaadin/tests/components/ui/VaadinFinderLocatorUISearchTest.java new file mode 100644 index 0000000000..37766dd060 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/VaadinFinderLocatorUISearchTest.java @@ -0,0 +1,43 @@ +/* + * 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.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.UIElement; +import com.vaadin.tests.components.button.ButtonClick; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * + * @since + * @author Vaadin Ltd + */ +public class VaadinFinderLocatorUISearchTest extends MultiBrowserTest { + + @Override + protected Class getUIClass() { + return ButtonClick.class; + } + + @Test + public void getUIElementTest() { + openTestURL(); + UIElement ui = $(UIElement.class).first(); + Assert.assertNotNull("Couldn't find the UI Element on the page", ui); + } +} -- cgit v1.2.3 From 4c8e883dc4c809dc08a60b4ea49313a302bcea05 Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Wed, 22 Oct 2014 11:26:52 +0300 Subject: Test fix now that FormLayout margins work again. (#14890) Change-Id: Ifa7d4ae9d36c1180a5c635833a9a13ad576d5c70 --- uitest/src/com/vaadin/tests/themes/valo/DateFields.java | 1 + 1 file changed, 1 insertion(+) (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/themes/valo/DateFields.java b/uitest/src/com/vaadin/tests/themes/valo/DateFields.java index 5a752cd985..4b29f83621 100644 --- a/uitest/src/com/vaadin/tests/themes/valo/DateFields.java +++ b/uitest/src/com/vaadin/tests/themes/valo/DateFields.java @@ -203,6 +203,7 @@ public class DateFields extends VerticalLayout implements View { item.addItemProperty("date", new ObjectProperty(getDefaultDate())); FormLayout form = new FormLayout(); + form.setMargin(false); FieldGroup binder = new FieldGroup(item); form.addComponent(binder.buildAndBind( -- cgit v1.2.3 From 63efaa9aef402bc3d9afa075b8109961ef0cd301 Mon Sep 17 00:00:00 2001 From: Anna Miroshnik Date: Tue, 7 Oct 2014 19:37:30 +0400 Subject: Fix: Empty space on page after expanded component (#12672) Full defect name: Empty space on page after expanded component - incorrect height calculation in Chrome Layout: [ Panel (auto x auto) [ Grid (auto x auto) ] AnyComponent (100% x 100%) Also sleep() was removed from tests BaseLayoutExpandTest and BaseAddReplaceMoveTest Change-Id: Ie8a14a58dd53a26a133ea99a7b809d92c1b33a1f --- .../AbstractOrderedLayoutConnector.java | 15 +++- .../EmptySpaceOnPageAfterExpandedComponent.java | 82 ++++++++++++++++++++++ ...EmptySpaceOnPageAfterExpandedComponentTest.java | 61 ++++++++++++++++ .../layouttester/BaseAddReplaceMoveTest.java | 5 +- .../layouts/layouttester/BaseLayoutExpandTest.java | 10 +-- 5 files changed, 163 insertions(+), 10 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/layout/EmptySpaceOnPageAfterExpandedComponent.java create mode 100644 uitest/src/com/vaadin/tests/components/layout/EmptySpaceOnPageAfterExpandedComponentTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index 0c09ae49c6..aace349392 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -152,7 +152,20 @@ public abstract class AbstractOrderedLayoutConnector extends public void onElementResize(ElementResizeEvent e) { updateLayoutHeight(); if (needsExpand()) { - getWidget().updateExpandCompensation(); + /* + * updateLayoutHeight causes calling of + * getLayoutManager().setNeedsMeasure(this) which informs this + * LayoutManager that the size of a component might have + * changed. Then a new layout phase is scheduled. So + * updateExpandCompensation must be delayed until layout phase + * will be completed. #12672 + */ + Scheduler.get().scheduleFinally(new ScheduledCommand() { + @Override + public void execute() { + getWidget().updateExpandCompensation(); + } + }); } } }; diff --git a/uitest/src/com/vaadin/tests/components/layout/EmptySpaceOnPageAfterExpandedComponent.java b/uitest/src/com/vaadin/tests/components/layout/EmptySpaceOnPageAfterExpandedComponent.java new file mode 100644 index 0000000000..c873a7efe7 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/layout/EmptySpaceOnPageAfterExpandedComponent.java @@ -0,0 +1,82 @@ +/* + * 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.layout; + +import com.vaadin.server.Page; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Panel; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +public class EmptySpaceOnPageAfterExpandedComponent extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + getLayout().setHeight("200px"); + + VerticalLayout container = new VerticalLayout(); + container.setStyleName("mystyle"); + container.setId("container"); + container.setSpacing(true); + container.setSizeFull(); + addComponent(container); + + Page.getCurrent().getStyles() + .add(".mystyle {border: 1px solid black;}"); + + GridLayout grid = new GridLayout(); + grid.setSpacing(true); + + TextField text1 = new TextField(); + text1.setCaption("Text1"); + text1.setRequired(true); + + grid.setColumns(1); + grid.setRows(1); + + grid.addComponent(text1); + + grid.setSizeUndefined(); + + Panel panel = new Panel(); + panel.setContent(grid); + + panel.setSizeUndefined(); + + container.addComponent(panel); + + TextArea expand = new TextArea(); + expand.setId("expandedElement"); + expand.setSizeFull(); + container.addComponent(expand); + + container.setExpandRatio(expand, 1); + } + + @Override + protected String getTestDescription() { + return "Height calculation should be correct in Chrome. There should not be any empty space after expanded component."; + } + + @Override + protected Integer getTicketNumber() { + return 12672; + } +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/layout/EmptySpaceOnPageAfterExpandedComponentTest.java b/uitest/src/com/vaadin/tests/components/layout/EmptySpaceOnPageAfterExpandedComponentTest.java new file mode 100644 index 0000000000..09d19034e6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/layout/EmptySpaceOnPageAfterExpandedComponentTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2013 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.layout; + +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test to make sure that there is no any empty space (in Google Chrome) on page + * after expanded component (#12672) + * + * Layout: + * + * [ Panel (auto x auto) [ Grid (auto x auto) ] + * + * AnyComponent (100% x 100%) + * + * ] + * + * @author Vaadin Ltd + */ +public class EmptySpaceOnPageAfterExpandedComponentTest extends + MultiBrowserTest { + + @Test + public void testNoEmptySpaceOnPageAfterExpandedComponent() { + openTestURL(); + + final WebElement expandedElement = vaadinElementById("expandedElement"); + final WebElement containerElement = vaadinElementById("container"); + + waitUntil(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver input) { + int expandedElementBottom = expandedElement.getLocation() + .getY() + expandedElement.getSize().getHeight(); + int containerElementBottom = containerElement.getLocation() + .getY() + containerElement.getSize().getHeight(); + + return expandedElementBottom + 1 == containerElementBottom; + } + }); + } +} diff --git a/uitest/src/com/vaadin/tests/layouts/layouttester/BaseAddReplaceMoveTest.java b/uitest/src/com/vaadin/tests/layouts/layouttester/BaseAddReplaceMoveTest.java index 73dc39009d..786e47cef1 100644 --- a/uitest/src/com/vaadin/tests/layouts/layouttester/BaseAddReplaceMoveTest.java +++ b/uitest/src/com/vaadin/tests/layouts/layouttester/BaseAddReplaceMoveTest.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.util.List; import org.junit.Test; +import org.openqa.selenium.By; import com.vaadin.testbench.elements.ButtonElement; import com.vaadin.tests.tb3.MultiBrowserTest; @@ -27,7 +28,7 @@ public abstract class BaseAddReplaceMoveTest extends MultiBrowserTest { @Test public void LayoutAlignment() throws IOException, InterruptedException { openTestURL(); - sleep(500); + waitForElementPresent(By.className("v-table")); compareScreen("initial"); String[] states = { "add", "replace", "move", "remove" }; List buttons = $(ButtonElement.class).all(); @@ -35,7 +36,7 @@ public abstract class BaseAddReplaceMoveTest extends MultiBrowserTest { // go through all buttons click them and see result for (ButtonElement btn : buttons) { btn.click(); - sleep(500); + waitForElementPresent(By.className("v-table")); compareScreen(states[index]); index++; } diff --git a/uitest/src/com/vaadin/tests/layouts/layouttester/BaseLayoutExpandTest.java b/uitest/src/com/vaadin/tests/layouts/layouttester/BaseLayoutExpandTest.java index 08f5aed808..036b053fb5 100644 --- a/uitest/src/com/vaadin/tests/layouts/layouttester/BaseLayoutExpandTest.java +++ b/uitest/src/com/vaadin/tests/layouts/layouttester/BaseLayoutExpandTest.java @@ -19,21 +19,17 @@ import java.io.IOException; import java.util.List; import org.junit.Test; +import org.openqa.selenium.By; import com.vaadin.testbench.elements.ButtonElement; import com.vaadin.tests.tb3.MultiBrowserTest; -/** - * - * @since - * @author Vaadin Ltd - */ public abstract class BaseLayoutExpandTest extends MultiBrowserTest { @Test public void LayoutExpand() throws IOException, InterruptedException { openTestURL(); - sleep(500); + waitForElementPresent(By.className("v-table")); compareScreen("initial"); String[] states = { "expand_100_0", "expand_50_50", "expand_25_75" }; List buttons = $(ButtonElement.class).all(); @@ -41,7 +37,7 @@ public abstract class BaseLayoutExpandTest extends MultiBrowserTest { // go through all buttons click them and see result for (ButtonElement btn : buttons) { btn.click(); - sleep(500); + waitForElementPresent(By.className("v-table")); compareScreen(states[index]); index++; } -- cgit v1.2.3 From dd682d365ebd79cb0a11791a70cfad9832d5fb29 Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Mon, 13 Oct 2014 14:56:50 +0300 Subject: Add addButton() AbstractTestUI. Change-Id: I55a02e96466b63f6b00047cc87ab111f6c08e45b --- .../com/vaadin/tests/applicationservlet/SessionExpiration.java | 5 +---- uitest/src/com/vaadin/tests/components/AbstractTestUI.java | 7 +++++++ .../vaadin/tests/components/accordion/AccordionRemoveTab.java | 5 +---- .../com/vaadin/tests/components/datefield/DateFieldIsValid.java | 5 +---- uitest/src/com/vaadin/tests/components/page/PageReload.java | 5 +---- .../com/vaadin/tests/components/table/FocusOnSelectedItem.java | 4 +--- .../com/vaadin/tests/components/table/LeftColumnAlignment.java | 5 +---- .../com/vaadin/tests/components/table/TableWidthItemRemove.java | 9 ++------- .../tests/components/tabsheet/TabSelectionRevertedByServer.java | 5 +---- .../com/vaadin/tests/components/tree/TreeItemDoubleClick.java | 5 +---- uitest/src/com/vaadin/tests/push/BarInUIDL.java | 4 +--- uitest/src/com/vaadin/tests/push/PushWithPreserveOnRefresh.java | 6 +----- uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFly.java | 4 +--- 13 files changed, 20 insertions(+), 49 deletions(-) (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/applicationservlet/SessionExpiration.java b/uitest/src/com/vaadin/tests/applicationservlet/SessionExpiration.java index 8fc6d56161..206e763497 100644 --- a/uitest/src/com/vaadin/tests/applicationservlet/SessionExpiration.java +++ b/uitest/src/com/vaadin/tests/applicationservlet/SessionExpiration.java @@ -17,7 +17,6 @@ package com.vaadin.tests.applicationservlet; 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; @@ -26,15 +25,13 @@ public class SessionExpiration extends AbstractTestUIWithLog { @Override protected void setup(VaadinRequest request) { getSession().getSession().setMaxInactiveInterval(2); - Button b = new Button("Click to avoid expiration"); - b.addClickListener(new ClickListener() { + addButton("Click to avoid expiration", new ClickListener() { @Override public void buttonClick(ClickEvent event) { log("Clicked"); } }); - addComponent(b); } @Override diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java index 558379260b..3a7d42e29c 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java @@ -10,6 +10,7 @@ import com.vaadin.shared.communication.PushMode; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.shared.ui.ui.Transport; import com.vaadin.shared.ui.ui.UIState.PushConfigurationState; +import com.vaadin.ui.Button; import com.vaadin.ui.Component; import com.vaadin.ui.Label; import com.vaadin.ui.Notification; @@ -181,6 +182,12 @@ public abstract class AbstractTestUI extends UI { getLayout().replaceComponent(oldComponent, newComponent); } + protected void addButton(String caption, Button.ClickListener listener) { + Button button = new Button(caption); + button.addClickListener(listener); + addComponent(button); + } + protected String getTestDescription() { return null; }; diff --git a/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTab.java b/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTab.java index 86e718596e..af54e15b5a 100644 --- a/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTab.java +++ b/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTab.java @@ -53,16 +53,13 @@ public class AccordionRemoveTab extends AbstractTestUI { Tab last = tabs.addTab(l); last.setCaption("Three"); - Button remove = new Button("Remove First"); - remove.addClickListener(new Button.ClickListener() { + addButton("Remove First", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { tabs.removeComponent(tabs.iterator().next()); } }); - - addComponent(remove); } @Override diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldIsValid.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldIsValid.java index d3f30f3b37..66d1c34ab7 100644 --- a/uitest/src/com/vaadin/tests/components/datefield/DateFieldIsValid.java +++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldIsValid.java @@ -7,7 +7,6 @@ import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.Property.ValueChangeListener; 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; import com.vaadin.ui.DateField; @@ -42,8 +41,7 @@ public class DateFieldIsValid extends AbstractTestUIWithLog { } }); addComponent(dateField); - Button button = new Button("check dateField"); - button.addClickListener(new ClickListener() { + addButton("check dateField", new ClickListener() { @Override public void buttonClick(ClickEvent event) { @@ -51,7 +49,6 @@ public class DateFieldIsValid extends AbstractTestUIWithLog { + ", is valid: " + dateField.isValid()); } }); - addComponent(button); } /** diff --git a/uitest/src/com/vaadin/tests/components/page/PageReload.java b/uitest/src/com/vaadin/tests/components/page/PageReload.java index c1799b29e3..033da4e0e8 100644 --- a/uitest/src/com/vaadin/tests/components/page/PageReload.java +++ b/uitest/src/com/vaadin/tests/components/page/PageReload.java @@ -2,7 +2,6 @@ package com.vaadin.tests.components.page; 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,14 +9,12 @@ public class PageReload extends AbstractTestUIWithLog { @Override protected void setup(VaadinRequest request) { - Button b = new Button("Press to reload"); - b.addClickListener(new ClickListener() { + addButton("Press to reload", new ClickListener() { @Override public void buttonClick(ClickEvent event) { getPage().reload(); } }); - addComponent(b); log("UI id: " + getUIId()); } diff --git a/uitest/src/com/vaadin/tests/components/table/FocusOnSelectedItem.java b/uitest/src/com/vaadin/tests/components/table/FocusOnSelectedItem.java index 4c0bea77ac..177f4d68fc 100644 --- a/uitest/src/com/vaadin/tests/components/table/FocusOnSelectedItem.java +++ b/uitest/src/com/vaadin/tests/components/table/FocusOnSelectedItem.java @@ -49,8 +49,7 @@ public class FocusOnSelectedItem extends AbstractTestUI { } addComponent(table); - Button button = new Button("Select"); - button.addClickListener(new Button.ClickListener() { + addButton("Select", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { table.setValue("Item 198"); @@ -58,7 +57,6 @@ public class FocusOnSelectedItem extends AbstractTestUI { table.focus(); } }); - addComponent(button); } /* diff --git a/uitest/src/com/vaadin/tests/components/table/LeftColumnAlignment.java b/uitest/src/com/vaadin/tests/components/table/LeftColumnAlignment.java index e783951d86..7789d0ae19 100644 --- a/uitest/src/com/vaadin/tests/components/table/LeftColumnAlignment.java +++ b/uitest/src/com/vaadin/tests/components/table/LeftColumnAlignment.java @@ -19,7 +19,6 @@ import com.vaadin.annotations.Theme; import com.vaadin.data.util.BeanItemContainer; 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.Table; @@ -53,15 +52,13 @@ public class LeftColumnAlignment extends AbstractTestUI { addComponent(table); - Button button = new Button("Align to Left"); - button.addClickListener(new ClickListener() { + addButton("Align to Left", new ClickListener() { @Override public void buttonClick(ClickEvent event) { table.setColumnAlignment("name", Align.LEFT); } }); - addComponent(button); } @Override diff --git a/uitest/src/com/vaadin/tests/components/table/TableWidthItemRemove.java b/uitest/src/com/vaadin/tests/components/table/TableWidthItemRemove.java index 79a85cd49b..bd84fab309 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableWidthItemRemove.java +++ b/uitest/src/com/vaadin/tests/components/table/TableWidthItemRemove.java @@ -17,7 +17,6 @@ package com.vaadin.tests.components.table; 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.Table; @@ -46,17 +45,14 @@ public class TableWidthItemRemove extends AbstractTestUI { table.setColumnWidth("lastName", 100); table.setColumnWidth("year", 50); - Button cleanButton = new Button("Clean"); - cleanButton.addClickListener(new ClickListener() { + addButton("Clean", new ClickListener() { @Override public void buttonClick(ClickEvent event) { table.removeAllItems(); } }); - addComponent(cleanButton); - Button populateButton = new Button("Populate"); - populateButton.addClickListener(new ClickListener() { + addButton("Populate", new ClickListener() { @Override public void buttonClick(ClickEvent event) { table.addItem( @@ -64,7 +60,6 @@ public class TableWidthItemRemove extends AbstractTestUI { Math.random() * 1000); } }); - addComponent(populateButton); addComponent(table); } diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServer.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServer.java index b51a8dde08..0d7ec48a99 100644 --- a/uitest/src/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServer.java +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServer.java @@ -2,7 +2,6 @@ package com.vaadin.tests.components.tabsheet; 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.Component; @@ -59,15 +58,13 @@ public class TabSelectionRevertedByServer extends AbstractTestUI { addComponent(tabsheet); - Button button = new Button("Select Last Tab"); - button.addClickListener(new ClickListener() { + addButton("Select Last Tab", new ClickListener() { @Override public void buttonClick(ClickEvent event) { tabsheet.setSelectedTab(lastTab); } }); - addComponent(button); } @Override diff --git a/uitest/src/com/vaadin/tests/components/tree/TreeItemDoubleClick.java b/uitest/src/com/vaadin/tests/components/tree/TreeItemDoubleClick.java index 8b7890e63c..9031a76e66 100644 --- a/uitest/src/com/vaadin/tests/components/tree/TreeItemDoubleClick.java +++ b/uitest/src/com/vaadin/tests/components/tree/TreeItemDoubleClick.java @@ -32,8 +32,7 @@ public class TreeItemDoubleClick extends AbstractTestUIWithLog { addComponent(tree); - Button button = new Button("Change immediate flag"); - button.addClickListener(new Button.ClickListener() { + addButton("Change immediate flag", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { @@ -44,8 +43,6 @@ public class TreeItemDoubleClick extends AbstractTestUIWithLog { }); - addComponent(button); - } @Override diff --git a/uitest/src/com/vaadin/tests/push/BarInUIDL.java b/uitest/src/com/vaadin/tests/push/BarInUIDL.java index b380edcb75..a5d23dcd1f 100644 --- a/uitest/src/com/vaadin/tests/push/BarInUIDL.java +++ b/uitest/src/com/vaadin/tests/push/BarInUIDL.java @@ -35,14 +35,12 @@ public class BarInUIDL extends AbstractTestUI { */ @Override protected void setup(VaadinRequest request) { - Button button = new Button("Click Me"); - button.addClickListener(new Button.ClickListener() { + addButton("Click Me", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { addComponent(new Label("Thank you for clicking | bar")); } }); - addComponent(button); } diff --git a/uitest/src/com/vaadin/tests/push/PushWithPreserveOnRefresh.java b/uitest/src/com/vaadin/tests/push/PushWithPreserveOnRefresh.java index 8834a05069..af19f8849f 100644 --- a/uitest/src/com/vaadin/tests/push/PushWithPreserveOnRefresh.java +++ b/uitest/src/com/vaadin/tests/push/PushWithPreserveOnRefresh.java @@ -5,7 +5,6 @@ import com.vaadin.annotations.Push; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.util.Log; -import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Label; @@ -24,16 +23,13 @@ public class PushWithPreserveOnRefresh extends AbstractTestUI { addComponent(new Label("UI id: " + getUIId())); addComponent(log); - Button b = new Button("click me"); - b.addClickListener(new ClickListener() { + addButton("click me", new ClickListener() { @Override public void buttonClick(ClickEvent event) { log.log("Button has been clicked " + (++times) + " times"); } }); - - addComponent(b); } @Override diff --git a/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFly.java b/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFly.java index ec22edd205..0ea5c18bc9 100644 --- a/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFly.java +++ b/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFly.java @@ -36,8 +36,7 @@ public class ThemeChangeOnTheFly extends AbstractTestUIWithLog { @Override protected void setup(VaadinRequest request) { - Button inject = new Button("Inject blue background"); - inject.addClickListener(new ClickListener() { + addButton("Inject blue background", new ClickListener() { @Override public void buttonClick(ClickEvent event) { @@ -46,7 +45,6 @@ public class ThemeChangeOnTheFly extends AbstractTestUIWithLog { } }); - addComponent(inject); GridLayout gl = new GridLayout(2, 4); gl.setCaption("Change theme by clicking a button"); -- cgit v1.2.3 From 98a6367842b34f9de56fc19d41dfbbe079c248c1 Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Sun, 12 Oct 2014 23:42:28 +0300 Subject: Set v-disabled on Button inside Upload when disabled. (#14655) Change-Id: Ic28c8e4020eddae32a71b5c7f9da0ad61f2f7af9 --- client/src/com/vaadin/client/ui/VUpload.java | 10 +++- .../components/upload/DisabledUploadButton.java | 41 ++++++++++++++++ .../upload/DisabledUploadButtonTest.java | 55 ++++++++++++++++++++++ 3 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/upload/DisabledUploadButton.java create mode 100644 uitest/src/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VUpload.java b/client/src/com/vaadin/client/ui/VUpload.java index f234ef6d65..42fb08fb3c 100644 --- a/client/src/com/vaadin/client/ui/VUpload.java +++ b/client/src/com/vaadin/client/ui/VUpload.java @@ -184,7 +184,7 @@ public class VUpload extends SimplePanel { /** For internal use only. May be removed or replaced in the future. */ public void disableUpload() { - submitButton.setEnabled(false); + setEnabledForSubmitButton(false); if (!submitted) { // Cannot disable the fileupload while submitting or the file won't // be submitted at all @@ -195,7 +195,7 @@ public class VUpload extends SimplePanel { /** For internal use only. May be removed or replaced in the future. */ public void enableUpload() { - submitButton.setEnabled(true); + setEnabledForSubmitButton(true); fu.getElement().setPropertyBoolean("disabled", false); enabled = true; if (submitted) { @@ -209,6 +209,12 @@ public class VUpload extends SimplePanel { } } + private void setEnabledForSubmitButton(boolean enabled) { + submitButton.setEnabled(enabled); + submitButton.setStyleName(ApplicationConnection.DISABLED_CLASSNAME, + !enabled); + } + /** * Re-creates file input field and populates panel. This is needed as we * want to clear existing values from our current file input field. diff --git a/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButton.java b/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButton.java new file mode 100644 index 0000000000..dcf2ac2784 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButton.java @@ -0,0 +1,41 @@ +package com.vaadin.tests.components.upload; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Upload; + +public class DisabledUploadButton extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Upload upload = new Upload(); + + addComponent(upload); + + addButton("Set readonly", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + upload.setReadOnly(true); + } + }); + + addButton("Set disabled", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + upload.setEnabled(false); + } + }); + } + + @Override + public String getDescription() { + return "Upload button should be disabled when upload " + + "is set to readonly and/or disabled"; + } + + @Override + protected Integer getTicketNumber() { + return 14655; + } +} diff --git a/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java b/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java new file mode 100644 index 0000000000..cc97b4d7d1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java @@ -0,0 +1,55 @@ +package com.vaadin.tests.components.upload; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.UploadElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DisabledUploadButtonTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + } + + private String getUploadButtonClass() { + WebElement uploadButton = getUploadButton(); + + return uploadButton.getAttribute("class"); + } + + private void clickButton(String caption) { + $(ButtonElement.class).caption(caption).first().click(); + } + + private WebElement getUploadButton() { + UploadElement upload = $(UploadElement.class).first(); + return upload.findElement(By.className("v-button")); + } + + @Test + public void buttonIsReadonly() { + assertThat(getUploadButtonClass(), not(containsString("v-disabled"))); + + clickButton("Set readonly"); + + assertThat(getUploadButtonClass(), containsString("v-disabled")); + } + + @Test + public void buttonIsDisabled() { + assertThat(getUploadButtonClass(), not(containsString("v-disabled"))); + + clickButton("Set disabled"); + + assertThat(getUploadButtonClass(), containsString("v-disabled")); + } +} \ No newline at end of file -- cgit v1.2.3 From 949215f3d89485d02a57bebdd45d7ea2904e28e1 Mon Sep 17 00:00:00 2001 From: "denis.magdenkov" Date: Wed, 1 Oct 2014 17:50:30 +0400 Subject: Fix button on immediate upload does not obey setWidth() (#14485) Added sass selector for upload in base theme. Change-Id: Iebf796f0965de6afeac98d6e2a2a9246c9251bab --- WebContent/VAADIN/themes/base/upload/upload.scss | 3 ++ .../upload/UploadImmediateButtonWidth.java | 55 ++++++++++++++++++++++ .../upload/UploadImmediateButtonWidthTest.java | 47 ++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java create mode 100644 uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthTest.java (limited to 'uitest/src/com') diff --git a/WebContent/VAADIN/themes/base/upload/upload.scss b/WebContent/VAADIN/themes/base/upload/upload.scss index 933482764c..e705fc1c78 100644 --- a/WebContent/VAADIN/themes/base/upload/upload.scss +++ b/WebContent/VAADIN/themes/base/upload/upload.scss @@ -9,6 +9,9 @@ position: relative; margin: 0; overflow: hidden; + .v-button{ + width:100%; + } } .v-ff & .#{$primaryStyleName}-immediate, diff --git a/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java new file mode 100644 index 0000000000..b0314e9907 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java @@ -0,0 +1,55 @@ +/* + * 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.upload; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Upload; +import com.vaadin.ui.VerticalLayout; + +public class UploadImmediateButtonWidth extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout lt = new VerticalLayout(); + lt.setWidth("500px"); + + Upload upload1 = new Upload(); + upload1.setImmediate(true); + upload1.setId("upload1"); + upload1.setWidth("300px"); + lt.addComponent(upload1); + + Upload upload2 = new Upload(); + upload2.setImmediate(true); + upload2.setWidth("50%"); + upload2.setId("upload2"); + lt.addComponent(upload2); + + addComponent(lt); + } + + @Override + protected String getTestDescription() { + return "Width of immediate upload button should obey setWidth()"; + } + + @Override + protected Integer getTicketNumber() { + return 14485; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthTest.java b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthTest.java new file mode 100644 index 0000000000..37dcb47929 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthTest.java @@ -0,0 +1,47 @@ +/* + * 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.upload; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UploadImmediateButtonWidthTest extends MultiBrowserTest { + + private void checkButtonWidth(String id, int expectedWidth) { + WebElement upload = driver.findElement(By.id(id)); + WebElement button = upload.findElement(By.className("v-button")); + assertEquals("width of button " + id + " is incorrect", expectedWidth, + button.getSize().getWidth()); + } + + @Test + public void buttonWithPixelWidth() { + openTestURL(); + checkButtonWidth("upload1", 300); + } + + @Test + public void buttonWithPercentageWidth() { + openTestURL(); + checkButtonWidth("upload2", 250); + } + +} -- cgit v1.2.3 From 8d036d968a24dc1ee1690d86bdc73cbe718a8ad7 Mon Sep 17 00:00:00 2001 From: Anna Miroshnik Date: Wed, 24 Sep 2014 11:33:01 +0400 Subject: Fix: Navigation to invisible days of week in VAADIN calendar (#12243) Some changes in BasicBackwardHandler and BasicForwardHandler. Also test was added (CalendarBackwardForwardTest). Changes after review. Change-Id: Ibe0283534b784e3c18134619e1843440ca74e65c --- .../calendar/handler/BasicBackwardHandler.java | 16 +++ .../calendar/handler/BasicForwardHandler.java | 16 +++ .../calendar/CalendarBackwardForward.java | 132 +++++++++++++++++++++ .../calendar/CalendarBackwardForwardTest.java | 99 ++++++++++++++++ 4 files changed, 263 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/calendar/CalendarBackwardForward.java create mode 100644 uitest/src/com/vaadin/tests/components/calendar/CalendarBackwardForwardTest.java (limited to 'uitest/src/com') diff --git a/server/src/com/vaadin/ui/components/calendar/handler/BasicBackwardHandler.java b/server/src/com/vaadin/ui/components/calendar/handler/BasicBackwardHandler.java index f4d47f89d4..0e99b26856 100644 --- a/server/src/com/vaadin/ui/components/calendar/handler/BasicBackwardHandler.java +++ b/server/src/com/vaadin/ui/components/calendar/handler/BasicBackwardHandler.java @@ -47,6 +47,7 @@ public class BasicBackwardHandler implements BackwardHandler { // calculate amount to move back int durationInDays = (int) (((end.getTime()) - start.getTime()) / DateConstants.DAYINMILLIS); durationInDays++; + // for week view durationInDays = -7, for day view durationInDays = -1 durationInDays = -durationInDays; // set new start and end times @@ -59,6 +60,21 @@ public class BasicBackwardHandler implements BackwardHandler { javaCalendar.add(java.util.Calendar.DATE, durationInDays); Date newEnd = javaCalendar.getTime(); + if (start.equals(end)) { // day view + int firstDay = event.getComponent().getFirstVisibleDayOfWeek(); + int lastDay = event.getComponent().getLastVisibleDayOfWeek(); + int dayOfWeek = javaCalendar.get(Calendar.DAY_OF_WEEK); + + // we suppose that 7 >= lastDay >= firstDay >= 1 + while (!(firstDay <= dayOfWeek && dayOfWeek <= lastDay)) { + javaCalendar.add(java.util.Calendar.DATE, -1); + dayOfWeek = javaCalendar.get(Calendar.DAY_OF_WEEK); + } + + newStart = javaCalendar.getTime(); + newEnd = javaCalendar.getTime(); + } + setDates(event, newStart, newEnd); } diff --git a/server/src/com/vaadin/ui/components/calendar/handler/BasicForwardHandler.java b/server/src/com/vaadin/ui/components/calendar/handler/BasicForwardHandler.java index 96c3c097dc..45b44cb673 100644 --- a/server/src/com/vaadin/ui/components/calendar/handler/BasicForwardHandler.java +++ b/server/src/com/vaadin/ui/components/calendar/handler/BasicForwardHandler.java @@ -45,6 +45,7 @@ public class BasicForwardHandler implements ForwardHandler { // calculate amount to move forward int durationInDays = (int) (((end.getTime()) - start.getTime()) / DateConstants.DAYINMILLIS); + // for week view durationInDays = 7, for day view durationInDays = 1 durationInDays++; // set new start and end times @@ -57,6 +58,21 @@ public class BasicForwardHandler implements ForwardHandler { javaCalendar.add(java.util.Calendar.DATE, durationInDays); Date newEnd = javaCalendar.getTime(); + if (start.equals(end)) { // day view + int firstDay = event.getComponent().getFirstVisibleDayOfWeek(); + int lastDay = event.getComponent().getLastVisibleDayOfWeek(); + int dayOfWeek = javaCalendar.get(Calendar.DAY_OF_WEEK); + + // we suppose that 7 >= lastDay >= firstDay >= 1 + while (!(firstDay <= dayOfWeek && dayOfWeek <= lastDay)) { + javaCalendar.add(java.util.Calendar.DATE, 1); + dayOfWeek = javaCalendar.get(Calendar.DAY_OF_WEEK); + } + + newStart = javaCalendar.getTime(); + newEnd = javaCalendar.getTime(); + } + setDates(event, newStart, newEnd); } diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarBackwardForward.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarBackwardForward.java new file mode 100644 index 0000000000..5a21353d7d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarBackwardForward.java @@ -0,0 +1,132 @@ +/* + * 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.calendar; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Locale; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Calendar; +import com.vaadin.ui.Calendar.TimeFormat; +import com.vaadin.ui.components.calendar.CalendarComponentEvents.EventResizeHandler; +import com.vaadin.ui.components.calendar.event.BasicEvent; + +/** + * Test: Vaadin Calendar: Navigation to invisible days of week (#12243) + * + * @author Vaadin Ltd + */ +@Theme("tests-calendar") +public class CalendarBackwardForward extends AbstractTestUI { + + private static final long serialVersionUID = 1L; + private Calendar calendar; + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. + * VaadinRequest) + */ + @Override + protected void setup(VaadinRequest request) { + calendar = new Calendar(); + + try { + + BasicEvent event = new BasicEvent("EVENT NAME 1", + "EVENT TOOLTIP 1", + new SimpleDateFormat("yyyy-MM-dd HH:mm") + .parse("2013-09-05 15:30"), new SimpleDateFormat( + "yyyy-MM-dd HH:mm").parse("2013-09-07 22:20")); + event.setStyleName("color1"); + calendar.addEvent(event); + + event = new BasicEvent("EVENT NAME 2", "EVENT TOOLTIP 2", + new SimpleDateFormat("yyyy-MM-dd HH:mm") + .parse("2013-09-05 12:10"), new SimpleDateFormat( + "yyyy-MM-dd HH:mm").parse("2013-09-05 13:20")); + event.setStyleName("color2"); + calendar.addEvent(event); + + event = new BasicEvent("EVENT NAME 3", "EVENT TOOLTIP 3", + new SimpleDateFormat("yyyy-MM-dd HH:mm") + .parse("2013-09-01 11:30"), new SimpleDateFormat( + "yyyy-MM-dd HH:mm").parse("2013-09-29 15:20")); + event.setStyleName("color3"); + calendar.addEvent(event); + + event = new BasicEvent("EVENT NAME 4", "EVENT TOOLTIP 4", + new SimpleDateFormat("yyyy-MM-dd HH:mm") + .parse("2013-09-01 11:30"), new SimpleDateFormat( + "yyyy-MM-dd HH:mm").parse("2013-09-01 15:20")); + event.setStyleName("color4"); + event.setAllDay(true); + calendar.addEvent(event); + } catch (ParseException e1) { // Nothing to do + e1.printStackTrace(); + } + + try { + calendar.setStartDate(new SimpleDateFormat("yyyy-MM-dd") + .parse("2013-09-01")); + calendar.setEndDate(new SimpleDateFormat("yyyy-MM-dd") + .parse("2013-09-30")); + } catch (ParseException e) { // Nothing to do + + } + + calendar.setImmediate(true); + + // in english locale first day of week - sunday + calendar.setLocale(Locale.ENGLISH); + // show only working days: 2 - monday, 6 - friday + calendar.setFirstVisibleDayOfWeek(2); + calendar.setLastVisibleDayOfWeek(6); + + calendar.setTimeFormat(TimeFormat.Format24H); + calendar.setHandler((EventResizeHandler) null); + setEnabled(true); + + addComponent(calendar); + calendar.setSizeFull(); + setSizeFull(); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() + */ + @Override + protected String getTestDescription() { + return "If one uses the feature setVisibleDaysOfWeek of Calendar, the invisible days should be skipped in single-day-mode."; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() + */ + @Override + protected Integer getTicketNumber() { + return 12243; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarBackwardForwardTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarBackwardForwardTest.java new file mode 100644 index 0000000000..98773f475b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarBackwardForwardTest.java @@ -0,0 +1,99 @@ +/* + * 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.calendar; + +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.IOException; +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests: Vaadin Calendar: Navigation to invisible days of week (#12243) + * + * @author Vaadin Ltd + */ +public class CalendarBackwardForwardTest extends MultiBrowserTest { + + @Test + public void testCalendar() throws InterruptedException, IOException { + openTestURL(); + + openWeekView(); + openDayView(); + clickCalendarNext(); + + WebElement headerDayElement = getDriver().findElement( + By.className("v-calendar-header-day")); + + assertThat("This day should be Monday 9/9/13", headerDayElement + .getText().equals("Monday 9/9/13")); + + for (int i = 0; i < 6; i++) { + clickCalendarBack(); + } + + headerDayElement = getDriver().findElement( + By.className("v-calendar-header-day")); + + assertThat("This day should be Friday 8/30/13", headerDayElement + .getText().equals("Friday 8/30/13")); + } + + private void openWeekView() { + List elements = getDriver().findElements( + By.className("v-calendar-week-number")); + + for (WebElement webElement : elements) { + if (webElement.getText().equals("36")) { + webElement.click(); + break; + } + } + } + + private void openDayView() { + List elements = getDriver().findElements( + By.className("v-calendar-header-day")); + + for (WebElement webElement : elements) { + if (webElement.getText().contains("Friday 9/6/13")) { + webElement.click(); + break; + } + } + } + + private void clickCalendarNext() { + List elements = getDriver().findElements( + By.className("v-calendar-next")); + + elements.get(0).click(); + } + + private void clickCalendarBack() { + List elements = getDriver().findElements( + By.className("v-calendar-back")); + + elements.get(0).click(); + } + +} -- cgit v1.2.3 From 7237b88645a27b157bc85d62292dc93faddd19f9 Mon Sep 17 00:00:00 2001 From: Sara Seppola Date: Tue, 28 Oct 2014 16:42:35 +0200 Subject: Table column width can be changed from defined to expandratio (#15101) Change-Id: I8dead7fd77b44c8adc5e973f29d5e14bae6fb293 --- client/src/com/vaadin/client/ui/VScrollTable.java | 1 + .../tests/components/table/TableExpandRatio.java | 110 +++++++++++++++++++++ .../components/table/TableExpandRatioTest.java | 88 +++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/table/TableExpandRatio.java create mode 100644 uitest/src/com/vaadin/tests/components/table/TableExpandRatioTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 42fef9f0c0..9c02d30a04 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -3630,6 +3630,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, c.setWidth(widthWithoutAddedIndent, true); } } else if (col.hasAttribute("er")) { + c.setUndefinedWidth(); c.setExpandRatio(col.getFloatAttribute("er")); } else if (recalcWidths) { diff --git a/uitest/src/com/vaadin/tests/components/table/TableExpandRatio.java b/uitest/src/com/vaadin/tests/components/table/TableExpandRatio.java new file mode 100644 index 0000000000..92c9b8d988 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableExpandRatio.java @@ -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.components.table; + +import java.util.Arrays; + +import com.vaadin.annotations.PreserveOnRefresh; +import com.vaadin.annotations.Theme; +import com.vaadin.data.util.BeanItemContainer; +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.Table; +import com.vaadin.ui.VerticalLayout; + +@PreserveOnRefresh +@Theme("valo") +public class TableExpandRatio extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + BeanItemContainer container = new BeanItemContainer( + MyItem.class, Arrays.asList(new MyItem("one", 1), new MyItem( + "two", 2))); + + final Table table = new Table(null, container); + + table.setWidth("800px"); + table.setImmediate(true); + + Button widthButton = new Button("Set Width", + new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + table.setColumnWidth("value", 300); + + } + }); + + Button expandButton = new Button("Set Expand Ratio", + new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + table.setColumnExpandRatio("value", 1); + + } + }); + + widthButton.setId("widthbutton"); + expandButton.setId("expandbutton"); + + VerticalLayout layout = new VerticalLayout(widthButton, expandButton, + table); + addComponent(layout); + } + + public class MyItem { + + private String name; + private Integer value; + + public MyItem(String name, Integer value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + } + + @Override + protected String getTestDescription() { + return "When a column has fixed width and it is changed to expand ratio, the width should update accordingly"; + } + + @Override + protected Integer getTicketNumber() { + return 15101; + } +} diff --git a/uitest/src/com/vaadin/tests/components/table/TableExpandRatioTest.java b/uitest/src/com/vaadin/tests/components/table/TableExpandRatioTest.java new file mode 100644 index 0000000000..3cf66d4e4b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableExpandRatioTest.java @@ -0,0 +1,88 @@ +/* + * 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.table; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.number.IsCloseTo.closeTo; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TableExpandRatioTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL(); + } + + /* + * Needed for IE to get focus when button is clicked + */ + @Override + protected boolean requireWindowFocusForIE() { + + return true; + } + + @Test + public void cellWidthUpdatesWhenExpandRatioSetAfterDefinedWidth() { + + // test that after setting defined size to the second column, the first + // column will have correct size + + setDefinedWidth(); + + assertThat(getFirstCellWidth(), closeTo(500, 10)); + + // test that after setting expandratio to the second column, it is + // correct + + setExpandRatio(); + + assertThat(getFirstCellWidth(), closeTo(65, 5)); + + } + + private void setExpandRatio() { + $(ButtonElement.class).id("expandbutton").click(); + } + + private void setDefinedWidth() { + $(ButtonElement.class).id("widthbutton").click(); + } + + private double getFirstCellWidth() { + + List rows = $(TableElement.class).first() + .findElement(By.className("v-table-body")) + .findElements(By.tagName("tr")); + WebElement firstrow = rows.get(0); + List cells = firstrow.findElements(By + .className("v-table-cell-content")); + + int cellwidth = cells.get(0).getSize().getWidth(); + return cellwidth; + } +} -- cgit v1.2.3 From 54ed43adad5b853dfffdc48aebbc74087e34b735 Mon Sep 17 00:00:00 2001 From: Mika Murtojarvi Date: Mon, 27 Oct 2014 17:44:16 +0200 Subject: Fix a regression in VMenuBar.getSubpartElement (#14879). A change done in an earlier patch set (https://dev.vaadin.com/review/#/c/5283/) caused a test failure with Internet Explorer 8. Change-Id: I8159135ab7ec4b73682e90daf393b879bf587930 --- client/src/com/vaadin/client/ui/VMenuBar.java | 2 +- .../components/menubar/MenuBarsWithNesting.java | 125 +++++++++++++++++++++ .../menubar/MenuBarsWithNestingTest.java | 83 ++++++++++++++ 3 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNesting.java create mode 100644 uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNestingTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VMenuBar.java b/client/src/com/vaadin/client/ui/VMenuBar.java index 9948940717..5102e6faea 100644 --- a/client/src/com/vaadin/client/ui/VMenuBar.java +++ b/client/src/com/vaadin/client/ui/VMenuBar.java @@ -1583,7 +1583,7 @@ public class VMenuBar extends SimpleFocusablePanel implements /*-{ var n = element.childNodes.length; if(n > 0){ - return element.childNodes[n - 1].textContent; + return element.childNodes[n - 1].nodeValue; } else{ return ""; diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNesting.java b/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNesting.java new file mode 100644 index 0000000000..16a0896aa2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNesting.java @@ -0,0 +1,125 @@ +/* + * 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.menubar; + +import com.vaadin.server.FontAwesome; +import com.vaadin.server.Resource; +import com.vaadin.server.ThemeResource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.ui.MenuBar; +import com.vaadin.ui.MenuBar.MenuItem; + +/** + * A UI for testing VMenuBar.getSubPartElement(String). The UI contains two + * MenuBars, one without icons and one containing items with and without icons. + * Some of the icons are textual (using FontAwesome) and should behave like + * items with image icons: the icon should not be considered to be a part of the + * item's caption. + * + * @since + * @author Vaadin + */ +@SuppressWarnings("serial") +public class MenuBarsWithNesting extends AbstractTestUI { + + // The label displays the last selection. + private final Label label = new Label("Initial content"); + + // The captions and icons used in the second MenuBar. + public final static String[] itemNames = { "Icon item", "Arrow down", + "Arrow up", "Warning" }; + private final static Resource[] itemIcons = { + new ThemeResource("window/img/restore.png"), + FontAwesome.ARROW_DOWN, FontAwesome.ARROW_UP, FontAwesome.WARNING }; + + // The last menu item is nested with the following submenu items. + public final static String[] nestedItemnames = { "No icon", "Font icon", + "Image icon" }; + private final static Resource[] nestedItemIcons = { null, FontAwesome.LINK, + new ThemeResource("window/img/restore.png") }; + + private MenuBar.Command selectionCommand; + + @Override + protected void setup(VaadinRequest request) { + selectionCommand = new MenuBar.Command() { + @Override + public void menuSelected(MenuItem selectedItem) { + label.setValue(selectedItem.getText()); + } + }; + addComponent(createFirstMenuBar()); + addComponent(createSecondMenuBar()); + addComponent(label); + } + + /* + * Returns a menu bar with three levels of nesting but no icons. + */ + private MenuBar createFirstMenuBar() { + MenuBar menuBar = new MenuBar(); + MenuItem file = menuBar.addItem("File", null); + file.addItem("Open", selectionCommand); + file.addItem("Save", selectionCommand); + file.addItem("Save As..", selectionCommand); + file.addSeparator(); + MenuItem export = file.addItem("Export..", null); + export.addItem("As PDF...", selectionCommand); + export.addItem("As Doc...", selectionCommand); + file.addSeparator(); + file.addItem("Exit", selectionCommand); + + MenuItem edit = menuBar.addItem("Edit", null); + edit.addItem("Copy", selectionCommand); + edit.addItem("Cut", selectionCommand); + edit.addItem("Paste", selectionCommand); + + menuBar.addItem("Help", selectionCommand); + return menuBar; + } + + /* + * Returns a menu bar containing items with icons. The last menu item is + * nested and its submenu contains items with and without icons. + */ + private MenuBar createSecondMenuBar() { + MenuBar menuBar = new MenuBar(); + int n = itemNames.length; + for (int i = 0; i < n - 1; i++) { + menuBar.addItem(itemNames[i], itemIcons[i], selectionCommand); + } + MenuItem last = menuBar.addItem(itemNames[n - 1], itemIcons[n - 1], + null); + for (int i = 0; i < nestedItemnames.length; i++) { + last.addItem(nestedItemnames[i], nestedItemIcons[i], + selectionCommand); + } + return menuBar; + } + + @Override + protected String getTestDescription() { + return "This UI is used for testing subpart functionality of MenuBar. The " + + "functionality is used in TestBench tests."; + } + + @Override + protected Integer getTicketNumber() { + return 14879; + } +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNestingTest.java b/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNestingTest.java new file mode 100644 index 0000000000..4c3383c5d6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuBarsWithNestingTest.java @@ -0,0 +1,83 @@ +/* + * 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.menubar; + +import static com.vaadin.tests.components.menubar.MenuBarsWithNesting.itemNames; +import static com.vaadin.tests.components.menubar.MenuBarsWithNesting.nestedItemnames; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.MenuBarElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * This class tests the method VMenuBar.getSubPartElement(String) by using + * Vaadin locators for finding the items of a MenuBar. + * + * @since + * @author Vaadin Ltd + */ +public class MenuBarsWithNestingTest extends MultiBrowserTest { + private MenuBarElement firstMenuBar, secondMenuBar; + private LabelElement label; + + @Before + public void init() { + openTestURL(); + firstMenuBar = $(MenuBarElement.class).first(); + secondMenuBar = $(MenuBarElement.class).get(1); + label = $(LabelElement.class).get(1); + } + + @Test + public void testMenuWithoutIcons() { + WebElement fileMenu = firstMenuBar.findElement(By.vaadin("#File")); + fileMenu.click(); + WebElement exportMenu = fileMenu.findElement(By.vaadin("#Export..")); + exportMenu.click(); + waitUntil(ExpectedConditions.visibilityOfElementLocated(By + .xpath(".//*[text() = 'As PDF...']"))); + } + + @Test + public void testMenuWithIcons() throws InterruptedException { + // There is a separate test for the last item of the second menu. + for (int i = 0; i < itemNames.length - 1; i++) { + String itemName = itemNames[i]; + secondMenuBar.findElement(By.vaadin("#" + itemName)).click(); + waitUntil(ExpectedConditions.textToBePresentInElement( + label.getWrappedElement(), itemName)); + } + } + + @Test + public void testNestedMenuWithIcons() throws InterruptedException { + String selection = itemNames[itemNames.length - 1]; + for (String itemName : nestedItemnames) { + WebElement lastMenuItem = secondMenuBar.findElement(By.vaadin("#" + + selection)); + lastMenuItem.click(); + lastMenuItem.findElement(By.vaadin("#" + itemName)).click(); + waitUntil(ExpectedConditions.textToBePresentInElement( + label.getWrappedElement(), itemName)); + } + } +} \ No newline at end of file -- cgit v1.2.3 From 77bb7ac886bd9f82e5295323254cd9fbb8ea8a10 Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Thu, 30 Oct 2014 16:11:10 +0200 Subject: Set upload button width to 100% when immediate on Valo. (#14485) Change-Id: I473fc080c143bc242326bd6f2b819450c42ffae5 --- WebContent/VAADIN/themes/base/upload/upload.scss | 5 ++- .../VAADIN/themes/valo/components/_upload.scss | 8 +++-- .../upload/UploadImmediateButtonWidth.java | 41 +++++++++++++--------- .../UploadImmediateButtonWidthChameleonTest.java | 36 +++++++++++++++++++ .../UploadImmediateButtonWidthReindeerTest.java | 36 +++++++++++++++++++ .../upload/UploadImmediateButtonWidthRunoTest.java | 36 +++++++++++++++++++ .../upload/UploadImmediateButtonWidthTest.java | 36 ++++++++++++------- .../upload/UploadImmediateButtonWidthValoTest.java | 36 +++++++++++++++++++ 8 files changed, 200 insertions(+), 34 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthChameleonTest.java create mode 100644 uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthReindeerTest.java create mode 100644 uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthRunoTest.java create mode 100644 uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthValoTest.java (limited to 'uitest/src/com') diff --git a/WebContent/VAADIN/themes/base/upload/upload.scss b/WebContent/VAADIN/themes/base/upload/upload.scss index e705fc1c78..f8e707446c 100644 --- a/WebContent/VAADIN/themes/base/upload/upload.scss +++ b/WebContent/VAADIN/themes/base/upload/upload.scss @@ -4,12 +4,11 @@ white-space: nowrap; } - .#{$primaryStyleName}-immediate { position: relative; margin: 0; overflow: hidden; - .v-button{ + .v-button { width:100%; } } @@ -39,4 +38,4 @@ text-align: left; } -} \ No newline at end of file +} diff --git a/WebContent/VAADIN/themes/valo/components/_upload.scss b/WebContent/VAADIN/themes/valo/components/_upload.scss index c301be060a..07a51f03ef 100644 --- a/WebContent/VAADIN/themes/valo/components/_upload.scss +++ b/WebContent/VAADIN/themes/valo/components/_upload.scss @@ -1,7 +1,7 @@ /** * * - * @param {string} $primary-stylename (v-upload) - + * @param {string} $primary-stylename (v-upload) - * * @group upload */ @@ -10,6 +10,10 @@ @include valo-widget-style; } + .#{$primary-stylename}-immediate .v-button { + width: 100%; + } + .#{$primary-stylename}-immediate input[type="file"] { @include opacity(0); z-index: 2; @@ -20,4 +24,4 @@ border: none; background: transparent; } -} \ No newline at end of file +} diff --git a/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java index b0314e9907..48dd96bc43 100644 --- a/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java +++ b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java @@ -20,31 +20,38 @@ import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Upload; import com.vaadin.ui.VerticalLayout; +// We're explicitly testing only immediate uploads here because non-immediate +// width issues still require planning before we can provide a fix. public class UploadImmediateButtonWidth extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { - VerticalLayout lt = new VerticalLayout(); - lt.setWidth("500px"); - - Upload upload1 = new Upload(); - upload1.setImmediate(true); - upload1.setId("upload1"); - upload1.setWidth("300px"); - lt.addComponent(upload1); - - Upload upload2 = new Upload(); - upload2.setImmediate(true); - upload2.setWidth("50%"); - upload2.setId("upload2"); - lt.addComponent(upload2); - - addComponent(lt); + + // Let's use a separate layout without margins to make the + // button widths not dependent on the selected theme. + VerticalLayout layout = new VerticalLayout(); + layout.setWidth("500px"); + + layout.addComponent(getImmediateUpload("upload1", "300px")); + layout.addComponent(getImmediateUpload("upload2", "50%")); + layout.addComponent(getImmediateUpload("upload3", "")); + + addComponent(layout); + } + + private Upload getImmediateUpload(String id, String width) { + Upload upload = new Upload(); + + upload.setId(id); + upload.setWidth(width); + upload.setImmediate(true); + + return upload; } @Override protected String getTestDescription() { - return "Width of immediate upload button should obey setWidth()"; + return "Width of the upload button should obey setWidth() when using immediate"; } @Override diff --git a/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthChameleonTest.java b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthChameleonTest.java new file mode 100644 index 0000000000..a0d6d471fb --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthChameleonTest.java @@ -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.upload; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.closeTo; + +import com.vaadin.ui.themes.*; +import org.junit.Test; + +public class UploadImmediateButtonWidthChameleonTest extends + UploadImmediateButtonWidthTest { + + @Override + protected String getTheme() { + return ChameleonTheme.THEME_NAME; + } + + @Test + public void immediateButtonWithUndefinedWidth() { + assertThat(getButtonWidth("upload3"), closeTo(69, 4)); + } +} diff --git a/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthReindeerTest.java b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthReindeerTest.java new file mode 100644 index 0000000000..c22e416a25 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthReindeerTest.java @@ -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.upload; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.closeTo; + +import com.vaadin.ui.themes.*; +import org.junit.Test; + +public class UploadImmediateButtonWidthReindeerTest extends + UploadImmediateButtonWidthTest { + + @Override + protected String getTheme() { + return Reindeer.THEME_NAME; + } + + @Test + public void immediateButtonWithUndefinedWidth() { + assertThat(getButtonWidth("upload3"), closeTo(67, 8)); + } +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthRunoTest.java b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthRunoTest.java new file mode 100644 index 0000000000..0ab4fbbc7e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthRunoTest.java @@ -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.upload; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.closeTo; + +import com.vaadin.ui.themes.*; +import org.junit.Test; + +public class UploadImmediateButtonWidthRunoTest extends + UploadImmediateButtonWidthTest { + + @Override + protected String getTheme() { + return Runo.THEME_NAME; + } + + @Test + public void immediateButtonWithUndefinedWidth() { + assertThat(getButtonWidth("upload3"), closeTo(72, 6)); + } +} diff --git a/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthTest.java b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthTest.java index 37dcb47929..b2a29c92e3 100644 --- a/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthTest.java +++ b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthTest.java @@ -15,7 +15,8 @@ */ package com.vaadin.tests.components.upload; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; import org.openqa.selenium.WebElement; @@ -23,25 +24,36 @@ import org.openqa.selenium.WebElement; import com.vaadin.testbench.By; import com.vaadin.tests.tb3.MultiBrowserTest; -public class UploadImmediateButtonWidthTest extends MultiBrowserTest { +public abstract class UploadImmediateButtonWidthTest extends MultiBrowserTest { - private void checkButtonWidth(String id, int expectedWidth) { + protected abstract String getTheme(); + + protected double getButtonWidth(String id) { WebElement upload = driver.findElement(By.id(id)); WebElement button = upload.findElement(By.className("v-button")); - assertEquals("width of button " + id + " is incorrect", expectedWidth, - button.getSize().getWidth()); + + return button.getSize().getWidth(); } - @Test - public void buttonWithPixelWidth() { - openTestURL(); - checkButtonWidth("upload1", 300); + @Override + protected Class getUIClass() { + return UploadImmediateButtonWidth.class; + } + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL(String.format("theme=%s", getTheme())); } @Test - public void buttonWithPercentageWidth() { - openTestURL(); - checkButtonWidth("upload2", 250); + public void immediateButtonWithPixelWidth() { + assertThat(getButtonWidth("upload1"), is(300.0)); } + @Test + public void immediateButtonWithPercentageWidth() { + assertThat(getButtonWidth("upload2"), is(250.0)); + } } diff --git a/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthValoTest.java b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthValoTest.java new file mode 100644 index 0000000000..9d8fe6ba9e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/upload/UploadImmediateButtonWidthValoTest.java @@ -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.upload; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.closeTo; + +import com.vaadin.ui.themes.*; +import org.junit.Test; + +public class UploadImmediateButtonWidthValoTest extends + UploadImmediateButtonWidthTest { + + @Override + protected String getTheme() { + return ValoTheme.THEME_NAME; + } + + @Test + public void immediateButtonWithUndefinedWidth() { + assertThat(getButtonWidth("upload3"), closeTo(89, 2)); + } +} -- cgit v1.2.3 From dda24122a7a0a0491fc5cac69792fe37a826803e Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Sat, 1 Nov 2014 14:04:39 +0200 Subject: Reverse asc and desc table sorting indicators for Valo. (#15123) Change-Id: If649d7ab0b4257cfaa1488dfff88afa8ef122f67 --- .../VAADIN/themes/valo/components/_table.scss | 4 +- .../tests/themes/valo/TableSortIndicator.java | 34 ++++++++++++++++ .../tests/themes/valo/TableSortIndicatorTest.java | 46 ++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/themes/valo/TableSortIndicator.java create mode 100644 uitest/src/com/vaadin/tests/themes/valo/TableSortIndicatorTest.java (limited to 'uitest/src/com') diff --git a/WebContent/VAADIN/themes/valo/components/_table.scss b/WebContent/VAADIN/themes/valo/components/_table.scss index d8a673294d..a70532ccfd 100644 --- a/WebContent/VAADIN/themes/valo/components/_table.scss +++ b/WebContent/VAADIN/themes/valo/components/_table.scss @@ -612,7 +612,7 @@ $v-table-background-color: null !default; * @group table */ @mixin valo-table-sort-asc-icon-style { - content: '\f0dd'; + content: '\f0de'; font-family: FontAwesome; } @@ -623,7 +623,7 @@ $v-table-background-color: null !default; * @group table */ @mixin valo-table-sort-desc-icon-style { - content: '\f0de'; + content: '\f0dd'; font-family: FontAwesome; } diff --git a/uitest/src/com/vaadin/tests/themes/valo/TableSortIndicator.java b/uitest/src/com/vaadin/tests/themes/valo/TableSortIndicator.java new file mode 100644 index 0000000000..74e5fcd0ef --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/valo/TableSortIndicator.java @@ -0,0 +1,34 @@ +package com.vaadin.tests.themes.valo; + +import com.vaadin.annotations.*; +import com.vaadin.server.*; +import com.vaadin.tests.components.*; +import com.vaadin.ui.*; + +@Theme("valo") +public class TableSortIndicator extends AbstractTestUI { + @Override + protected void setup(VaadinRequest request) { + Table table = new Table(); + table.addContainerProperty("Index", Integer.class, ""); + + for(int i=0;i<10;i++) { + table.addItem(new Object[] {i}, i); + } + + table.setPageLength(0); + + addComponent(table); + } + + @Override + protected String getTestDescription() { + return "For Valo, sorting indicators should point up when sorted asc " + + "and down when sorted desc."; + } + + @Override + protected Integer getTicketNumber() { + return 15123; + } +} diff --git a/uitest/src/com/vaadin/tests/themes/valo/TableSortIndicatorTest.java b/uitest/src/com/vaadin/tests/themes/valo/TableSortIndicatorTest.java new file mode 100644 index 0000000000..42f0b2aeae --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/valo/TableSortIndicatorTest.java @@ -0,0 +1,46 @@ +package com.vaadin.tests.themes.valo; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.*; +import org.junit.*; +import org.openqa.selenium.*; + +import java.io.*; + +public class TableSortIndicatorTest extends MultiBrowserTest { + + private void clickOnCellHeader() { + clickElementByClass("v-table-header-cell"); + } + + @Test + public void ascendingIndicatorIsShown() throws IOException { + openTestURL(); + + clickOnCellHeader(); + + compareScreen("ascending"); + } + + @Test + public void descendingIndicatorIsShown() throws IOException { + openTestURL(); + + clickOnCellHeader(); + clickOnSortIndicator(); + + compareScreen("descending"); + } + + private void clickOnSortIndicator() { + clickElementByClass("v-table-sort-indicator"); + } + + private void clickElementByClass(String className) { + findElementByClass(className).click(); + } + + private WebElement findElementByClass(String className) { + return driver.findElement(By.className(className)); + } +} \ No newline at end of file -- cgit v1.2.3 From eb94e2a9be2d8ce34620fdedc90425e05785cdd8 Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Sat, 4 Oct 2014 00:03:38 +0300 Subject: Fix VCalendar to use correct year of week. (#14783) Change-Id: Id55ad5ed620bd5c187b70ae2a2d0a4c4adea382a --- client/src/com/vaadin/client/ui/VCalendar.java | 2 +- .../client/ui/calendar/CalendarConnector.java | 2 +- .../client/ui/calendar/schedule/CalendarDay.java | 8 ++++- server/src/com/vaadin/ui/Calendar.java | 22 ++++++++++-- .../vaadin/shared/ui/calendar/CalendarState.java | 1 + .../components/calendar/CalendarWeekSelection.java | 39 ++++++++++++++++++++ .../calendar/CalendarWeekSelectionTest.java | 41 ++++++++++++++++++++++ 7 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/calendar/CalendarWeekSelection.java create mode 100644 uitest/src/com/vaadin/tests/components/calendar/CalendarWeekSelectionTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VCalendar.java b/client/src/com/vaadin/client/ui/VCalendar.java index f0f1bc89ca..c59a78108c 100644 --- a/client/src/com/vaadin/client/ui/VCalendar.java +++ b/client/src/com/vaadin/client/ui/VCalendar.java @@ -588,7 +588,7 @@ public class VCalendar extends Composite implements VHasDropHandler { int x = pos - (y * columns); if (x == 0 && daysCount > 7) { // Add week to weekToolbar for navigation - weekToolbar.addWeek(week, d.getYear()); + weekToolbar.addWeek(week, day.getYearOfWeek()); } final SimpleDayCell cell = new SimpleDayCell(this, y, x); cell.setMonthGrid(monthGrid); diff --git a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java index cbf63768a3..8f5e9d9a59 100644 --- a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java +++ b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java @@ -675,7 +675,7 @@ public class CalendarConnector extends AbstractComponentConnector implements List list = new ArrayList(days.size()); for (CalendarState.Day day : days) { CalendarDay d = new CalendarDay(day.date, day.localizedDateFormat, - day.dayOfWeek, day.week); + day.dayOfWeek, day.week, day.yearOfWeek); list.add(d); } diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/CalendarDay.java b/client/src/com/vaadin/client/ui/calendar/schedule/CalendarDay.java index 44b82f166f..0fceb6b6f9 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/CalendarDay.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/CalendarDay.java @@ -27,14 +27,16 @@ public class CalendarDay { private String localizedDateFormat; private int dayOfWeek; private int week; + private int yearOfWeek; public CalendarDay(String date, String localizedDateFormat, int dayOfWeek, - int week) { + int week, int yearOfWeek) { super(); this.date = date; this.localizedDateFormat = localizedDateFormat; this.dayOfWeek = dayOfWeek; this.week = week; + this.yearOfWeek = yearOfWeek; } public String getDate() { @@ -52,4 +54,8 @@ public class CalendarDay { public int getWeek() { return week; } + + public int getYearOfWeek() { + return yearOfWeek; + } } diff --git a/server/src/com/vaadin/ui/Calendar.java b/server/src/com/vaadin/ui/Calendar.java index 63ac9fe35c..72ff6eb0e0 100644 --- a/server/src/com/vaadin/ui/Calendar.java +++ b/server/src/com/vaadin/ui/Calendar.java @@ -516,7 +516,8 @@ public class Calendar extends AbstractComponent implements day.date = df_date.format(date); day.localizedDateFormat = weeklyCaptionFormatter.format(date); day.dayOfWeek = getDowByLocale(currentCalendar); - day.week = currentCalendar.get(java.util.Calendar.WEEK_OF_YEAR); + day.week = getWeek(currentCalendar); + day.yearOfWeek = getYearOfWeek(currentCalendar); days.add(day); @@ -560,6 +561,23 @@ public class Calendar extends AbstractComponent implements state.actions = createActionsList(actionMap); } + private int getWeek(java.util.Calendar calendar) { + return calendar.get(java.util.Calendar.WEEK_OF_YEAR); + } + + private int getYearOfWeek(java.util.Calendar calendar) { + // Would use calendar.getWeekYear() but it's only available since 1.7. + int week = getWeek(calendar); + int month = calendar.get(java.util.Calendar.MONTH); + int year = calendar.get(java.util.Calendar.YEAR); + + if (week == 1 && month == java.util.Calendar.DECEMBER) { + return year + 1; + } + + return year; + } + private void setActionsForEachHalfHour( Map> actionMap, Date start, Date end, Action.Handler actionHandler) { @@ -1772,7 +1790,7 @@ public class Calendar extends AbstractComponent implements String[] splitted = event.split("w"); if (splitted.length == 2) { try { - int yr = 1900 + Integer.parseInt(splitted[0]); + int yr = Integer.parseInt(splitted[0]); int week = Integer.parseInt(splitted[1]); fireWeekClick(week, yr); } catch (NumberFormatException e) { diff --git a/shared/src/com/vaadin/shared/ui/calendar/CalendarState.java b/shared/src/com/vaadin/shared/ui/calendar/CalendarState.java index de48f1a06a..93bd05bc1e 100644 --- a/shared/src/com/vaadin/shared/ui/calendar/CalendarState.java +++ b/shared/src/com/vaadin/shared/ui/calendar/CalendarState.java @@ -44,6 +44,7 @@ public class CalendarState extends AbstractComponentState { public String localizedDateFormat; public int dayOfWeek; public int week; + public int yearOfWeek; } public static class Action implements java.io.Serializable { diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarWeekSelection.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarWeekSelection.java new file mode 100644 index 0000000000..c74f2a53e3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarWeekSelection.java @@ -0,0 +1,39 @@ +package com.vaadin.tests.components.calendar; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Locale; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Calendar; + +public class CalendarWeekSelection extends AbstractTestUI { + @Override + protected void setup(VaadinRequest request) { + Calendar calendar = new Calendar(); + calendar.setLocale(Locale.US); + + try { + calendar.setStartDate(new SimpleDateFormat("yyyy-MM-dd") + .parse("2013-12-15")); + calendar.setEndDate(new SimpleDateFormat("yyyy-MM-dd") + .parse("2014-01-15")); + } catch (ParseException e) { + e.printStackTrace(); + } + + addComponent(calendar); + } + + @Override + protected Integer getTicketNumber() { + return 14783; + } + + @Override + protected String getTestDescription() { + return "December 2013 - January 2014. Clicking the week 1 " + + "should open the week view for the first week of 2014."; + } +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarWeekSelectionTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarWeekSelectionTest.java new file mode 100644 index 0000000000..83f41994ae --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarWeekSelectionTest.java @@ -0,0 +1,41 @@ +package com.vaadin.tests.components.calendar; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class CalendarWeekSelectionTest extends MultiBrowserTest { + + @Test + public void correctYearIsSelected() { + openTestURL(); + + clickOnWeek("1"); + + assertThat(getFirstDayOfTheYear().getText(), is("Wednesday 1/1/14")); + } + + private WebElement getFirstDayOfTheYear() { + WebElement header = findElement(By.className("v-calendar-header-week")); + List headerElements = header.findElements(By.tagName("td")); + + // Wednesday is the first day of 2014. + return headerElements.get(4); + } + + private void clickOnWeek(String week) { + for (WebElement e : findElements(By.className("v-calendar-week-number"))) { + if (e.getText().equals(week)) { + e.click(); + break; + } + } + } +} \ No newline at end of file -- cgit v1.2.3 From aaabbe3d58128245a5ae3156d924ea97e6f1fcab Mon Sep 17 00:00:00 2001 From: Mika Murtojarvi Date: Fri, 5 Sep 2014 16:58:08 +0300 Subject: Fix NPE and scroll behavior in TabSheet (#14348). After removing a tab, the TabSheet now scrolls when it is necessary to show the remaining tabs. A test (TabSheetScrollOnTabCloseTest) ensures that no scrolling occurs when the removed tab is not in the visible area. Change-Id: I81e4e504167ec4d0a527e6bfe94dba8b29fb26bc --- client/src/com/vaadin/client/ui/VTabsheet.java | 65 +++++++- .../tests/components/tabsheet/TabSheetClose.java | 72 +++++++++ .../components/tabsheet/TabSheetCloseTest.java | 58 +++++++ .../tabsheet/TabSheetScrollOnTabClose.java | 98 ++++++++++++ .../tabsheet/TabSheetScrollOnTabCloseTest.java | 171 +++++++++++++++++++++ 5 files changed, 462 insertions(+), 2 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/tabsheet/TabSheetClose.java create mode 100644 uitest/src/com/vaadin/tests/components/tabsheet/TabSheetCloseTest.java create mode 100644 uitest/src/com/vaadin/tests/components/tabsheet/TabSheetScrollOnTabClose.java create mode 100644 uitest/src/com/vaadin/tests/components/tabsheet/TabSheetScrollOnTabCloseTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VTabsheet.java b/client/src/com/vaadin/client/ui/VTabsheet.java index 745f2bca61..bcca117395 100644 --- a/client/src/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/com/vaadin/client/ui/VTabsheet.java @@ -512,6 +512,18 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware return (Tab) super.getWidget(index); } + private int getTabIndex(String tabId) { + if (tabId == null) { + return -1; + } + for (int i = 0; i < getTabCount(); i++) { + if (tabId.equals(getTab(i).id)) { + return i; + } + } + return -1; + } + public void selectTab(int index) { final Tab newSelected = getTab(index); final Tab oldSelected = selected; @@ -572,8 +584,40 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware if (tab == selected) { selected = null; } - // FIXME: Shouldn't something be selected instead? + + int scrollerIndexCandidate = getTabIndex(getTabsheet().scrollerPositionTabId); + if (scrollerIndexCandidate < 0) { + // The tab with id scrollerPositionTabId has been removed + scrollerIndexCandidate = getTabsheet().scrollerIndex; + } + scrollerIndexCandidate = selectNewShownTab(scrollerIndexCandidate); + if (scrollerIndexCandidate >= 0 + && scrollerIndexCandidate < getTabCount()) { + getTabsheet().scrollIntoView(getTab(scrollerIndexCandidate)); + } + } + + private int selectNewShownTab(int oldPosition) { + // After removing a tab, find a new scroll position. In most + // cases the scroll position does not change, but if the tab + // at the scroll position was removed, need to find a nearby + // tab that is visible. + for (int i = oldPosition; i < getTabCount(); i++) { + Tab tab = getTab(i); + if (!tab.isHiddenOnServer()) { + return i; + } + } + + for (int i = oldPosition - 1; i >= 0; i--) { + Tab tab = getTab(i); + if (!tab.isHiddenOnServer()) { + return i; + } + } + + return -1; } private boolean isFirstVisibleTab(int index) { @@ -685,6 +729,14 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware * The index of the first visible tab (when scrolled) */ private int scrollerIndex = 0; + /** + * The id of the tab at position scrollerIndex. This is used for keeping the + * scroll position unchanged when a tab is removed from the server side and + * the removed tab lies to the left of the current scroll position. For other + * cases scrollerIndex alone would be sufficient. Since the tab at the current + * scroll position can be removed, scrollerIndex is required in addition to this variable. + */ + private String scrollerPositionTabId; final TabBar tb = new TabBar(this); /** For internal use only. May be removed or replaced in the future. */ @@ -911,6 +963,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware if (newFirstIndex != -1) { scrollerIndex = newFirstIndex; + scrollerPositionTabId = tb.getTab(scrollerIndex).id; updateTabScroller(); } @@ -1206,6 +1259,8 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware /** For internal use only. May be removed or replaced in the future. */ public void showAllTabs() { scrollerIndex = tb.getFirstVisibleTab(); + scrollerPositionTabId = scrollerIndex < 0 ? null : tb + .getTab(scrollerIndex).id; for (int i = 0; i < tb.getTabCount(); i++) { Tab t = tb.getTab(i); if (!t.isHiddenOnServer()) { @@ -1780,12 +1835,18 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware } updateTabScroller(); } + if (scrollerIndex >= 0 && scrollerIndex < tb.getTabCount()) { + scrollerPositionTabId = tb.getTab(scrollerIndex).id; + } + else{ + scrollerPositionTabId = null; + } } } /** * Makes tab bar visible. - * + * * @since 7.2 */ public void showTabs() { diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetClose.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetClose.java new file mode 100644 index 0000000000..2cadde567f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetClose.java @@ -0,0 +1,72 @@ +/* + * 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.tabsheet; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.TabSheet.Tab; + +/** + * This test UI is used for checking that when a tab is closed, another one is + * scrolled into view. + * + * @since + * @author Vaadin Ltd + */ +public class TabSheetClose extends AbstractTestUI { + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. + * VaadinRequest) + */ + @Override + protected void setup(VaadinRequest request) { + TabSheet tabsheet = new TabSheet(); + for (int loop = 0; loop < 3; loop++) { + Tab tab = tabsheet.addTab(new CssLayout(), "tab " + loop); + tab.setClosable(true); + tab.setId("tab" + loop); + } + CssLayout layout = new CssLayout(); + layout.addComponent(tabsheet); + layout.setWidth("150px"); + addComponent(layout); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() + */ + @Override + protected String getTestDescription() { + return "When all tabs have not been closed, at least one tab should be visible. "; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() + */ + @Override + protected Integer getTicketNumber() { + return 14348; + } +} diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetCloseTest.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetCloseTest.java new file mode 100644 index 0000000000..5314038d72 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetCloseTest.java @@ -0,0 +1,58 @@ +/* + * 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.tabsheet; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests that when closing the last tab on a TabSheet, another tab gets selected + * with no error. Only the last tab should be visible, so the actual TabSheet + * width should be small. + * + * @since + * @author Vaadin Ltd + */ +public class TabSheetCloseTest extends MultiBrowserTest { + + private static final String TAB_CLOSE = "//span[@class = 'v-tabsheet-caption-close']"; + private static final String LAST_TAB = "//*[@id = 'tab2']/div/div"; + private static final String SCROLLER_NEXT = "//button[@class = 'v-tabsheet-scrollerNext']"; + private static final String FIRST_TAB = "//*[@id = 'tab0']"; + private static final String SECOND_TAB = "//*[@id = 'tab1']"; + + @Test + public void testClosingOfLastTab() throws Exception { + openTestURL(); + + // Click next button twice to get to the last tab + findElement(By.xpath(SCROLLER_NEXT)).click(); + findElement(By.xpath(SCROLLER_NEXT)).click(); + + findElement(By.xpath(LAST_TAB)).click(); + + // Closing last tab will take back to the second tab. Closing that + // will leave the first tab visible. + findElements(By.xpath(TAB_CLOSE)).get(2).click(); + assertTrue(findElement(By.xpath(SECOND_TAB)).isDisplayed()); + findElements(By.xpath(TAB_CLOSE)).get(1).click(); + assertTrue(findElement(By.xpath(FIRST_TAB)).isDisplayed()); + } +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetScrollOnTabClose.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetScrollOnTabClose.java new file mode 100644 index 0000000000..1400100f3b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetScrollOnTabClose.java @@ -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.components.tabsheet; + +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.CssLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.TabSheet.Tab; + +/** + * This testUI is used for testing that the scroll position of a tab sheet does + * not change when tabs are removed. The exception is removing the leftmost + * visible tab. + * + * @since + * @author Vaadin Ltd + */ +public class TabSheetScrollOnTabClose extends AbstractTestUI { + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. + * VaadinRequest) + */ + @Override + protected void setup(VaadinRequest request) { + final TabSheet tabSheet = new TabSheet(); + for (int i = 0; i < 10; i++) { + Tab tab = tabSheet.addTab(new CssLayout(), "tab " + i); + tab.setClosable(true); + tab.setId("tab" + i); + } + tabSheet.setWidth(250, Unit.PIXELS); + addComponent(tabSheet); + addComponent(new Label("Close tab number")); + for (int i = 0; i < 10; i++) { + final String tabCaption = "tab " + i; + final Button b = new Button("" + i); + b.addClickListener(new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + b.setEnabled(false); + tabSheet.removeTab(getTab(tabSheet, tabCaption)); + } + }); + addComponent(b); + } + } + + private Tab getTab(TabSheet ts, String tabCaption) { + for (int i = 0; i < ts.getComponentCount(); i++) { + String caption = ts.getTab(i).getCaption(); + if (tabCaption.equals(caption)) { + return ts.getTab(i); + } + } + return null; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() + */ + @Override + protected String getTestDescription() { + return "Scroll position should not change when closing tabs."; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() + */ + @Override + protected Integer getTicketNumber() { + return 14348; + } +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetScrollOnTabCloseTest.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetScrollOnTabCloseTest.java new file mode 100644 index 0000000000..8247b436d0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetScrollOnTabCloseTest.java @@ -0,0 +1,171 @@ +/* + * 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.tabsheet; + +import java.util.List; +import java.util.NoSuchElementException; + +import org.junit.Test; +import org.openqa.selenium.StaleElementReferenceException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TabSheetElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests removing tabs that have been scrolled out of view. This should cause no + * change to the scroll position. + * + * @since + * @author Vaadin Ltd + */ +public class TabSheetScrollOnTabCloseTest extends MultiBrowserTest { + + @Test + public void testScrollPositionAfterClosing() throws Exception { + openTestURL(); + TabSheetElement ts = $(TabSheetElement.class).first(); + WebElement tabSheetScroller = ts.findElement(By + .className("v-tabsheet-scrollerNext")); + // scroll to the right + for (int i = 0; i < 4; i++) { + tabSheetScroller.click(); + } + // check that tab 4 is the first visible tab + checkDisplayedStatus(ts, "tab3", false); + checkDisplayedStatus(ts, "tab4", true); + // remove tabs from the left, check that tab4 is still the first visible + // tab + for (int i = 0; i < 4; i++) { + $(ButtonElement.class).get(i).click(); + checkDisplayedStatus(ts, "tab3" + i, false); + checkDisplayedStatus(ts, "tab4", true); + checkDisplayedStatus(ts, "tab6", true); + } + // remove tabs from the right and check scroll position + for (int i = 7; i < 10; i++) { + $(ButtonElement.class).get(i).click(); + checkFirstTab(ts, "tab4"); + checkDisplayedStatus(ts, "tab6", true); + } + } + + /** + * Checks that the visible status of the tab with the given id is equal to + * shouldBeVisible. That is, the tab with the given id should be visible if + * and only if shouldBeVisible is true. Used for checking that the leftmost + * visible tab is the expected one when there should be tabs (hidden because + * of scroll position) to the left of tabId. + * + * If there is no tab with the specified id, the tab is considered not to be + * visible. + */ + private void checkDisplayedStatus(TabSheetElement tabSheet, String tabId, + boolean shouldBeVisible) { + org.openqa.selenium.By locator = By.cssSelector("#" + tabId); + waitUntil(visibilityOfElement(locator, shouldBeVisible)); + } + + /** + * Checks that there are no hidden tabs in tabSheet and that the id of the + * first tab is tabId. Used for checking that the leftmost visible tab is + * the expected one when there are no tabs to the left of the tab with the + * given id. When there are tabs to the left of tabId, check instead that + * tabId is visible and the previous tab is hidden (see + * checkDisplayedStatus). + */ + private void checkFirstTab(TabSheetElement tabSheet, String tabId) { + waitUntil(visibilityOfElement( + By.cssSelector(".v-tabsheet-tabitemcell[aria-hidden]"), false)); + waitUntil(leftmostTabHasId(tabSheet, tabId)); + } + + /** + * An expectation for checking that the visibility status of the specified + * element is correct. If the element does not exist in the DOM, it is + * considered not to be visible. If several elements match the locator, only + * the visibility of the first matching element is considered. + * + * @param locator + * used to find the element + * @param expectedVisibility + * whether the element should be visible + */ + private static ExpectedCondition visibilityOfElement( + final org.openqa.selenium.By locator, + final boolean expectedVisibility) { + return new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driver) { + List matchingElements = driver + .findElements(locator); + if (matchingElements.isEmpty()) { + return !expectedVisibility; + } else { + try { + WebElement first = matchingElements.get(0); + return first.isDisplayed() == expectedVisibility; + } catch (StaleElementReferenceException e) { + // The element was initially in DOM but has been + // removed. + return !expectedVisibility; + } + } + } + + @Override + public String toString() { + return "element " + (expectedVisibility ? "" : "not ") + + "expected to be visible: " + locator; + } + }; + } + + /** + * An expectation for checking that the leftmost tab has id equal to tabId. + * + * @param tabSheet + * the tab sheet containing the tab + * @param tabId + * the id of the tab that should be the leftmost tab + */ + private static ExpectedCondition leftmostTabHasId( + final TabSheetElement tabSheet, final String tabId) { + return new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driver) { + try { + WebElement leftElement = tabSheet.findElement(By + .cssSelector(".v-tabsheet-tabitemcell")); + String leftId = leftElement.getAttribute("id"); + return leftId.equals(tabId); + } catch (NoSuchElementException e) { + return false; + } + } + + @Override + public String toString() { + return "expected tab index of the leftmost tab in the tab sheet: " + + tabId; + } + }; + } +} \ No newline at end of file -- cgit v1.2.3 From aacb2f8289bc2faaab1225bd8b0dacd873d7839a Mon Sep 17 00:00:00 2001 From: Mika Murtojarvi Date: Wed, 5 Nov 2014 16:47:07 +0200 Subject: Position tooltips in the visible area (#15129). Change-Id: If4f13a859fd2e6fc363781bf04e52f780206e9e1 --- client/src/com/vaadin/client/VTooltip.java | 8 ++ .../vaadin/tests/components/TooltipPosition.java | 71 ++++++++++ .../tests/components/TooltipPositionTest.java | 156 +++++++++++++++++++++ .../tests/components/menubar/MenuTooltipTest.java | 1 + 4 files changed, 236 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/TooltipPosition.java create mode 100644 uitest/src/com/vaadin/tests/components/TooltipPositionTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/VTooltip.java b/client/src/com/vaadin/client/VTooltip.java index edd1273bf5..2fb5a8a293 100644 --- a/client/src/com/vaadin/client/VTooltip.java +++ b/client/src/com/vaadin/client/VTooltip.java @@ -210,6 +210,10 @@ public class VTooltip extends VOverlay { x = Window.getClientWidth() - offsetWidth - MARGIN + Window.getScrollLeft(); } + // Do not allow x to be zero, for otherwise the tooltip does + // not close when the mouse is moved (see isTooltipOpen()). + int minX = Window.getScrollLeft() + MARGIN; + x = Math.max(x, minX); return x; } @@ -245,6 +249,10 @@ public class VTooltip extends VOverlay { y = Window.getScrollTop(); } } + // Do not allow y to be zero, for otherwise the tooltip does + // not close when the mouse is moved (see isTooltipOpen()). + int minY = Window.getScrollTop() + MARGIN; + y = Math.max(y, minY); return y; } }); diff --git a/uitest/src/com/vaadin/tests/components/TooltipPosition.java b/uitest/src/com/vaadin/tests/components/TooltipPosition.java new file mode 100644 index 0000000000..d6475e0a0a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/TooltipPosition.java @@ -0,0 +1,71 @@ +/* + * 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 com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Button; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +/** + * This UI is used for testing that a tooltip is not positioned partially + * outside the browser window when there is enough space to display it. + * + * @since + * @author Vaadin Ltd + */ +public class TooltipPosition extends AbstractTestUI { + + public static final int NUMBER_OF_BUTTONS = 5; + + @Override + protected void setup(VaadinRequest request) { + // These tooltip delay settings can be removed once #13854 is resolved. + getTooltipConfiguration().setOpenDelay(0); + getTooltipConfiguration().setQuickOpenDelay(0); + getTooltipConfiguration().setCloseTimeout(1000); + + VerticalLayout layout = new VerticalLayout(); + layout.setSpacing(true); + layout.setHeight(UI.getCurrent().getPage().getBrowserWindowHeight(), + Unit.PIXELS); + addComponent(layout); + for (int i = 0; i < NUMBER_OF_BUTTONS; i++) { + Button button = new Button("Button"); + button.setDescription(generateTooltipText()); + layout.addComponent(button); + } + } + + private String generateTooltipText() { + String result = ""; + for (int i = 0; i < 50; i++) { + result += "This is the line " + i + + " of the long tooltip text.
"; + } + return result; + } + + @Override + public String getTestDescription() { + return "The tooltips of the buttons should not be clipped when there is enough space to display them."; + } + + @Override + public Integer getTicketNumber() { + return 15129; + } +} diff --git a/uitest/src/com/vaadin/tests/components/TooltipPositionTest.java b/uitest/src/com/vaadin/tests/components/TooltipPositionTest.java new file mode 100644 index 0000000000..bffc63f6c6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/TooltipPositionTest.java @@ -0,0 +1,156 @@ +/* + * 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.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.StaleElementReferenceException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebDriver.Window; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests that the tooltip is positioned so that it fits in the displayed area. + * + * @since + * @author Vaadin Ltd + */ +public class TooltipPositionTest extends MultiBrowserTest { + + @Test + public void testTooltipPosition() throws Exception { + openTestURL(); + for (int i = 0; i < TooltipPosition.NUMBER_OF_BUTTONS; i++) { + ButtonElement button = $(ButtonElement.class).get(i); + // Move the mouse to display the tooltip. + Actions actions = new Actions(driver); + actions.moveToElement(button, 10, 10); + actions.build().perform(); + waitUntil(tooltipToBeInsideWindow(By.cssSelector(".v-tooltip"), + driver.manage().window())); + + if (i < TooltipPosition.NUMBER_OF_BUTTONS - 1) { + // Remove the tooltip by moving the mouse. + actions = new Actions(driver); + actions.moveByOffset(300, 0); + actions.build().perform(); + waitUntil(tooltipNotToBeShown(By.cssSelector(".v-tooltip"), + driver.manage().window())); + } + } + } + + /* + * An expectation for checking that the tooltip found by the given locator + * is present in the DOM and entirely inside the browser window. The + * coordinate of the top left corner of the window is supposed to be (0, 0). + */ + private ExpectedCondition tooltipToBeInsideWindow( + final By tooltipLocator, final Window window) { + return new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver input) { + List elements = findElements(tooltipLocator); + if (elements.isEmpty()) { + return false; + } + WebElement element = elements.get(0); + try { + if (!element.isDisplayed()) { + return false; + } + Point topLeft = element.getLocation(); + int xLeft = topLeft.getX(); + int yTop = topLeft.getY(); + if (xLeft < 0 || yTop < 0) { + return false; + } + Dimension elementSize = element.getSize(); + int xRight = xLeft + elementSize.getWidth() - 1; + int yBottom = yTop + elementSize.getHeight() - 1; + Dimension browserSize = window.getSize(); + return xRight < browserSize.getWidth() + && yBottom < browserSize.getHeight(); + } catch (StaleElementReferenceException e) { + return false; + } + } + + @Override + public String toString() { + return "the tooltip to be displayed inside the window"; + } + }; + }; + + /* + * An expectation for checking that the tooltip found by the given locator + * is not shown in the window, even partially. The top left corner of window + * should have coordinates (0, 0). + */ + private ExpectedCondition tooltipNotToBeShown( + final By tooltipLocator, final Window window) { + return new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver input) { + List elements = findElements(tooltipLocator); + if (elements.isEmpty()) { + return true; + } + WebElement tooltip = elements.get(0); + try { + if (!tooltip.isDisplayed()) { + return true; + } + // The tooltip is shown, at least partially, if + // its intervals of both horizontal and vertical coordinates + // overlap those of the window. + Point topLeft = tooltip.getLocation(); + Dimension tooltipSize = tooltip.getSize(); + Dimension windowSize = window.getSize(); + int xLeft = topLeft.getX(); + int yTop = topLeft.getY(); + int xRight = xLeft + tooltipSize.getWidth() - 1; + int yBottom = yTop + tooltipSize.getHeight() - 1; + boolean overlapHorizontally = !(xRight < 0 || xLeft >= windowSize + .getWidth()); + boolean overlapVertically = !(yBottom < 0 || yTop >= windowSize + .getHeight()); + return !(overlapHorizontally && overlapVertically); + } catch (StaleElementReferenceException e) { + return true; + } + } + + @Override + public String toString() { + return "the tooltip not to be displayed inside the window"; + } + + }; + } +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuTooltipTest.java b/uitest/src/com/vaadin/tests/components/menubar/MenuTooltipTest.java index 24025b9f39..091f7be954 100644 --- a/uitest/src/com/vaadin/tests/components/menubar/MenuTooltipTest.java +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuTooltipTest.java @@ -49,6 +49,7 @@ public class MenuTooltipTest extends MultiBrowserTest { Coordinates elementCoordinates = getCoordinates($(MenuBarElement.class) .first()); + sleep(1000); Mouse mouse = ((HasInputDevices) getDriver()).getMouse(); -- cgit v1.2.3 From 0f5625d3ce241aa2de85ad6c5dd02d318759b021 Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Wed, 5 Nov 2014 14:09:45 +0200 Subject: Column drag'n'drop disables HeaderClickEvents until left-click (#15167) Change-Id: Ic64c0eb685c3dd9d7fdb10d9e19745ae2cc36be5 --- client/src/com/vaadin/client/ui/VScrollTable.java | 19 +++-- .../table/HeaderRightClickAfterDrag.java | 86 ++++++++++++++++++++++ .../table/HeaderRightClickAfterDragTest.java | 72 ++++++++++++++++++ 3 files changed, 169 insertions(+), 8 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDrag.java create mode 100644 uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDragTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 9c02d30a04..a382db573c 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -3138,6 +3138,15 @@ public class VScrollTable extends FlowPanel implements HasWidgets, && Util.isTouchEventOrLeftMouseButton(event)) { dragging = false; DOM.releaseCapture(getElement()); + + if (Util.isTouchEvent(event)) { + /* + * Prevent using in e.g. scrolling and prevent generated + * events. + */ + event.preventDefault(); + event.stopPropagation(); + } if (moved) { hideFloatingCopy(); tHead.removeSlotFocus(); @@ -3149,14 +3158,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, reOrderColumn(cid, closestSlot); } } - } - if (Util.isTouchEvent(event)) { - /* - * Prevent using in e.g. scrolling and prevent generated - * events. - */ - event.preventDefault(); - event.stopPropagation(); + moved = false; + break; } } diff --git a/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDrag.java b/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDrag.java new file mode 100644 index 0000000000..e9c948ddf7 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDrag.java @@ -0,0 +1,86 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.ui.Table; +import com.vaadin.ui.Window; + +public class HeaderRightClickAfterDrag extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Table table = new Table(); + table.setContainerDataSource(new BeanItemContainer( + TestBean.class)); + for (int i = 0; i < 10; i++) { + table.addItem(new TestBean(i)); + } + + table.setPageLength(10); + table.setColumnReorderingAllowed(true); + table.addHeaderClickListener(new Table.HeaderClickListener() { + @Override + public void headerClick(Table.HeaderClickEvent event) { + if (MouseEventDetails.MouseButton.RIGHT.equals(event + .getButton())) { + Window window = new Window("Right-clicked:", new Label( + "
" + + event.getPropertyId().toString() + .toUpperCase() + "
", + ContentMode.HTML)); + window.setPositionX(event.getClientX()); + window.setPositionY(event.getClientY()); + window.setResizable(false); + addWindow(window); + } + } + }); + + addComponent(table); + } + + @Override + protected String getTestDescription() { + return "1) Right click a column header and see a popup
" + + "2) Reorder (or at least start dragging) that column
" + + "3) Right click that same column header, and you should get a popup again.
" + + "Before fix: no popup, unless you first left-click the header."; + } + + @Override + protected Integer getTicketNumber() { + return 15167; + } + + public class TestBean { + + private String foo, bar, baz, fiz; + + public TestBean(int i) { + foo = "Foo " + i; + bar = "Bar " + i; + baz = "Baz " + i; + fiz = "Fix " + i; + } + + public String getFoo() { + return foo; + } + + public String getBar() { + return bar; + } + + public String getBaz() { + return baz; + } + + public String getFiz() { + return fiz; + } + } +} diff --git a/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDragTest.java b/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDragTest.java new file mode 100644 index 0000000000..f5f8bcce2a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDragTest.java @@ -0,0 +1,72 @@ +/* + * 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.table; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.testbench.elements.WindowElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests whether right-click on a column header works after the column is + * dragged. + * + * @author Vaadin Ltd + */ +public class HeaderRightClickAfterDragTest extends MultiBrowserTest { + + @Test + public void dragAndRightClick() { + openTestURL(); + + waitForElementPresent(By.className("v-table")); + + TableElement table = $(TableElement.class).first(); + TestBenchElement header0 = table.getHeaderCell(0); + Actions actions = new Actions(getDriver()); + actions.contextClick(header0).perform(); + + // check that right-click opened a window + waitForElementPresent(By.className("v-window")); + + closeWindow(); + + actions.clickAndHold(header0).moveToElement(table.getHeaderCell(1)) + .release(); + + actions.contextClick(header0).perform(); + + // check that right-click still opened a window + waitForElementPresent(By.className("v-window")); + } + + private void closeWindow() { + WindowElement window = $(WindowElement.class).first(); + window.findElement(By.className("v-window-closebox")).click(); + waitUntil(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driver) { + return findElements(By.className("v-window")).isEmpty(); + } + }); + } +} -- cgit v1.2.3 From 6d1b5a7121d4029cc237e6effaa54e5478443e34 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Sun, 21 Sep 2014 12:36:21 +0300 Subject: Allow move any event in month calendar view (#12413). Change-Id: I63491488356a32a233a4ba9a7434a9f4a1f5b9d1 --- .../client/ui/calendar/schedule/SimpleDayCell.java | 68 +++++++++---- .../calendar/CalendarMonthViewDndEvent.java | 109 +++++++++++++++++++++ .../calendar/CalendarMonthViewDndEventTest.java | 81 +++++++++++++++ 3 files changed, 241 insertions(+), 17 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEvent.java create mode 100644 uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java b/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java index 8e83dc4e36..db8452af9a 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/SimpleDayCell.java @@ -74,8 +74,15 @@ public class SimpleDayCell extends FocusableFlowPanel implements private int startY = -1; private int startYrelative; private int startXrelative; - private Date startDateFrom; - private Date startDateTo; + // "from" date of date which is source of Dnd + private Date dndSourceDateFrom; + // "to" date of date which is source of Dnd + private Date dndSourceDateTo; + // "from" time of date which is source of Dnd + private Date dndSourceStartDateTime; + // "to" time of date which is source of Dnd + private Date dndSourceEndDateTime; + private int prevDayDiff = 0; private int prevWeekDiff = 0; private HandlerRegistration moveRegistration; @@ -392,8 +399,7 @@ public class SimpleDayCell extends FocusableFlowPanel implements prevDayDiff = 0; prevWeekDiff = 0; - if (!mel.isTimeSpecificEvent() - && (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3)) { + if (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3) { eventMoved(moveEvent); } else if (calendar.getEventClickListener() != null) { @@ -528,20 +534,47 @@ public class SimpleDayCell extends FocusableFlowPanel implements Date from = e.getStart(); Date to = e.getEnd(); - long duration = to.getTime() - from.getTime(); long daysMs = dayDiff * DateConstants.DAYINMILLIS; long weeksMs = weekDiff * DateConstants.WEEKINMILLIS; - from.setTime(startDateFrom.getTime() + weeksMs + daysMs); - to.setTime((from.getTime() + duration)); + + setDates(e, from, to, weeksMs + daysMs, false); e.setStart(from); e.setEnd(to); - e.setStartTime(new Date(from.getTime())); - e.setEndTime(new Date(to.getTime())); + if (w.isTimeSpecificEvent()) { + Date start = new Date(); + Date end = new Date(); + setDates(e, start, end, weeksMs + daysMs, true); + e.setStartTime(start); + e.setEndTime(end); + } else { + e.setStartTime(new Date(from.getTime())); + e.setEndTime(new Date(to.getTime())); + } updateDragPosition(w, dayDiff, weekDiff); } + private void setDates(CalendarEvent e, Date start, Date end, long shift, + boolean isDateTime) { + Date currentStart; + Date currentEnd; + if (isDateTime) { + currentStart = e.getStartTime(); + currentEnd = e.getEndTime(); + } else { + currentStart = e.getStart(); + currentEnd = e.getEnd(); + } + long duration = currentEnd.getTime() - currentStart.getTime(); + if (isDateTime) { + start.setTime(dndSourceStartDateTime.getTime() + shift); + } else { + start.setTime(dndSourceDateFrom.getTime() + shift); + } + end.setTime((start.getTime() + duration)); + } + private void eventMoved(CalendarEvent e) { calendar.updateEventToMonthGrid(e); if (calendar.getEventMovedListener() != null) { @@ -551,10 +584,6 @@ public class SimpleDayCell extends FocusableFlowPanel implements public void startCalendarEventDrag(MouseDownEvent event, final MonthEventLabel w) { - if (w.isTimeSpecificEvent()) { - return; - } - moveRegistration = addMouseMoveHandler(this); startX = event.getClientX(); startY = event.getClientY(); @@ -564,8 +593,11 @@ public class SimpleDayCell extends FocusableFlowPanel implements % getWidth(); CalendarEvent e = getEventByWidget(w); - startDateFrom = (Date) e.getStart().clone(); - startDateTo = (Date) e.getEnd().clone(); + dndSourceDateFrom = (Date) e.getStart().clone(); + dndSourceDateTo = (Date) e.getEnd().clone(); + + dndSourceStartDateTime = (Date) e.getStartTime().clone(); + dndSourceEndDateTime = (Date) e.getEndTime().clone(); Event.setCapture(getElement()); keyDownHandler = addKeyDownHandler(new KeyDownHandler() { @@ -591,8 +623,10 @@ public class SimpleDayCell extends FocusableFlowPanel implements moveEvent = getEventByWidget(w); } - moveEvent.setStart(startDateFrom); - moveEvent.setEnd(startDateTo); + moveEvent.setStart(dndSourceDateFrom); + moveEvent.setEnd(dndSourceDateTo); + moveEvent.setStartTime(dndSourceStartDateTime); + moveEvent.setEndTime(dndSourceEndDateTime); calendar.updateEventToMonthGrid(moveEvent); // reset drag-related properties diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEvent.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEvent.java new file mode 100644 index 0000000000..b36b4d200e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEvent.java @@ -0,0 +1,109 @@ +/* + * 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.calendar; + +import java.util.Date; +import java.util.List; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Calendar; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.components.calendar.event.BasicEvent; +import com.vaadin.ui.components.calendar.event.BasicEventProvider; +import com.vaadin.ui.components.calendar.event.CalendarEvent; +import com.vaadin.ui.components.calendar.event.CalendarEventProvider.EventSetChangeEvent; +import com.vaadin.ui.components.calendar.event.CalendarEventProvider.EventSetChangeListener; + +/** + * Test UI for DnD regular (not all day event) in month view. + * + * @author Vaadin Ltd + */ +public class CalendarMonthViewDndEvent extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Calendar calendar = new Calendar("Test calendar"); + final java.util.Calendar cal = getAdjustedCalendar(); + + Date from = cal.getTime(); + + Date start = new Date(from.getTime() - 24 * 3600000); + calendar.setStartDate(start); + + cal.add(java.util.Calendar.HOUR, 1); + Date to = cal.getTime(); + + cal.add(java.util.Calendar.MONTH, 1); + calendar.setEndDate(cal.getTime()); + + final BasicEvent basicEvent = new BasicEvent("event", "description", + from, to); + + HorizontalLayout info = new HorizontalLayout(); + info.setSpacing(true); + info.setMargin(true); + addComponent(info); + final Label startLbl = new Label(String.valueOf(from.getTime())); + startLbl.addStyleName("start"); + info.addComponent(startLbl); + + final Label endLbl = new Label(String.valueOf(to.getTime())); + endLbl.addStyleName("end"); + info.addComponent(endLbl); + + BasicEventProvider provider = new BasicEventProvider(); + provider.addEvent(basicEvent); + calendar.setEventProvider(provider); + provider.addEventSetChangeListener(new EventSetChangeListener() { + + @Override + public void eventSetChange(EventSetChangeEvent event) { + List events = event.getProvider().getEvents( + new Date(0), new Date(Long.MAX_VALUE)); + CalendarEvent calEvent = events.get(0); + Date startEvent = calEvent.getStart(); + Date endEvent = calEvent.getEnd(); + + startLbl.setValue(String.valueOf(startEvent.getTime())); + endLbl.setValue(String.valueOf(endEvent.getTime())); + } + }); + + addComponent(calendar); + } + + @Override + protected String getTestDescription() { + return "Allow DnD any events in Calendar Month view"; + } + + @Override + protected Integer getTicketNumber() { + return 12413; + } + + private java.util.Calendar getAdjustedCalendar() { + final java.util.Calendar cal = java.util.Calendar.getInstance(); + + cal.set(java.util.Calendar.SECOND, 0); + cal.set(java.util.Calendar.MILLISECOND, 0); + return cal; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java new file mode 100644 index 0000000000..2efcd1f88d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java @@ -0,0 +1,81 @@ +/* + * 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.calendar; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.DndActionsTest; + +/** + * Test to check how DnD works for regular (not all day event) in calendar month + * view. + * + * @author Vaadin Ltd + */ +public class CalendarMonthViewDndEventTest extends DndActionsTest { + + @Test + public void dragAndDropEventToNextDay() { + openTestURL(); + + WebElement event = getDriver().findElement( + By.className("v-calendar-event")); + int x = event.getLocation().getX(); + int width = event.getSize().getWidth(); + + WebElement cell = getDriver().findElement( + By.className("v-calendar-month-day")); + + int cellY = cell.getLocation().getY(); + int cellHeight = cell.getSize().getHeight(); + + long origStart = getTime("start"); + long origEnd = getTime("end"); + + dragAndDrop(event, event.getSize().getWidth() + 5, 0); + + event = getDriver().findElement(By.className("v-calendar-event")); + int newX = event.getLocation().getX(); + int newY = event.getLocation().getY(); + + Assert.assertTrue( + "Moved event has wrong Y position (not the same row)", + newY >= cellY && newY < cellY + cellHeight); + Assert.assertTrue( + "Moved event has wrong X position (not after original event)", + newX >= x + width - 1); + + long start = getTime("start"); + long end = getTime("end"); + + int day = 24 * 3600000; + Assert.assertEquals( + "Start date of moved event is not next day, same time", + origStart + day, start); + Assert.assertEquals( + "End date of moved event is not next day, same time", origEnd + + day, end); + } + + private long getTime(String style) { + WebElement start = getDriver().findElement(By.className(style)); + return Long.parseLong(start.getText()); + } + +} -- cgit v1.2.3 From 457e802e2fe59ec35089a55acdc7b0321a2d4a5a Mon Sep 17 00:00:00 2001 From: Anna Miroshnik Date: Fri, 24 Oct 2014 20:07:36 +0400 Subject: DateField popup doesn't close when click on popup button (#14857) Fix and tests. Change-Id: I99d92c32727323fae543a24dfb90e849c3338a8c --- .../src/com/vaadin/client/ui/VPopupCalendar.java | 79 +++++++++++++++++++--- .../datefield/DateFieldPopupClosing.java | 43 ++++++++++++ .../datefield/DateFieldPopupClosingTest.java | 42 ++++++++++++ 3 files changed, 153 insertions(+), 11 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/datefield/DateFieldPopupClosing.java create mode 100644 uitest/src/com/vaadin/tests/components/datefield/DateFieldPopupClosingTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VPopupCalendar.java b/client/src/com/vaadin/client/ui/VPopupCalendar.java index 51b2ee22ec..fbd66cff09 100644 --- a/client/src/com/vaadin/client/ui/VPopupCalendar.java +++ b/client/src/com/vaadin/client/ui/VPopupCalendar.java @@ -27,6 +27,10 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.DomEvent; import com.google.gwt.event.dom.client.KeyCodes; +import com.google.gwt.event.dom.client.MouseOutEvent; +import com.google.gwt.event.dom.client.MouseOutHandler; +import com.google.gwt.event.dom.client.MouseOverEvent; +import com.google.gwt.event.dom.client.MouseOverHandler; import com.google.gwt.event.logical.shared.CloseEvent; import com.google.gwt.event.logical.shared.CloseHandler; import com.google.gwt.i18n.client.DateTimeFormat; @@ -60,7 +64,8 @@ import com.vaadin.shared.ui.datefield.Resolution; * */ public class VPopupCalendar extends VTextualDate implements Field, - ClickHandler, CloseHandler, SubPartAware { + ClickHandler, MouseOverHandler, MouseOutHandler, + CloseHandler, SubPartAware { /** For internal use only. May be removed or replaced in the future. */ public final Button calendarToggle = new Button(); @@ -75,6 +80,20 @@ public class VPopupCalendar extends VTextualDate implements Field, public boolean parsable = true; private boolean open = false; + /* + * To resolve #14857. If to click on calendarToggle button when calendar + * popup is opened (*1) then we have the following chain of calls: + * + * 1) onClose() 2) onClick() + * + * In this case we should prevent calling openCalendarPanel() in onClick. + */ + private boolean preventOpenPopupCalendar = false; + /* + * To resolve #14857. To determine this situation (*1) we use onMouseOver + * and OnMouseOut (for calendarToggle button). + */ + private boolean cursorOverCalendarToggleButton = false; private boolean textFieldEnabled = true; @@ -89,6 +108,10 @@ public class VPopupCalendar extends VTextualDate implements Field, calendarToggle.setText(""); calendarToggle.addClickHandler(this); + + calendarToggle.addMouseOverHandler(this); + calendarToggle.addMouseOutHandler(this); + // -2 instead of -1 to avoid FocusWidget.onAttach to reset it calendarToggle.getElement().setTabIndex(-2); @@ -441,7 +464,10 @@ public class VPopupCalendar extends VTextualDate implements Field, @Override public void onClick(ClickEvent event) { if (event.getSource() == calendarToggle && isEnabled()) { - openCalendarPanel(); + if (!preventOpenPopupCalendar) { + openCalendarPanel(); + } + preventOpenPopupCalendar = false; } } @@ -464,15 +490,22 @@ public class VPopupCalendar extends VTextualDate implements Field, focus(); } - // TODO resolve what the "Sigh." is all about and document it here - // Sigh. - Timer t = new Timer() { - @Override - public void run() { - open = false; - } - }; - t.schedule(100); + open = false; + + if (cursorOverCalendarToggleButton) { + preventOpenPopupCalendar = true; + + // To resolve the problem: onMouseOut event not triggered when + // moving mouse fast (GWT - all browsers) + Timer unPreventClickTimer = new Timer() { + @Override + public void run() { + preventOpenPopupCalendar = false; + } + }; + + unPreventClickTimer.schedule(300); + } } } @@ -642,4 +675,28 @@ public class VPopupCalendar extends VTextualDate implements Field, calendar.setRangeEnd(rangeEnd); } + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.dom.client.MouseOverHandler#onMouseOver(com.google + * .gwt.event.dom.client.MouseOverEvent) + */ + @Override + public void onMouseOver(MouseOverEvent event) { + cursorOverCalendarToggleButton = true; + } + + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.dom.client.MouseOutHandler#onMouseOut(com.google + * .gwt.event.dom.client.MouseOutEvent) + */ + @Override + public void onMouseOut(MouseOutEvent event) { + cursorOverCalendarToggleButton = false; + } + } diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldPopupClosing.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldPopupClosing.java new file mode 100644 index 0000000000..60508a30d4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldPopupClosing.java @@ -0,0 +1,43 @@ +/* + * 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.datefield; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.DateField; + +public class DateFieldPopupClosing extends AbstractTestUI { + + static final String DATEFIELD_ID = "datefield"; + + @Override + protected void setup(VaadinRequest request) { + final DateField df = new DateField(); + df.setId(DATEFIELD_ID); + addComponent(df); + } + + @Override + protected String getTestDescription() { + return "DateField popup should be closed when click on popup button"; + } + + @Override + protected Integer getTicketNumber() { + return 14857; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldPopupClosingTest.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldPopupClosingTest.java new file mode 100644 index 0000000000..ecbd6dd667 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldPopupClosingTest.java @@ -0,0 +1,42 @@ +package com.vaadin.tests.components.datefield; + +import java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DateFieldPopupClosingTest extends MultiBrowserTest { + /* + * try to open/close many times (not one time) because this defect is + * reproduced randomly (depends on timer) + */ + private static final int N = 100; + + @Test + public void testDateFieldPopupClosing() throws InterruptedException, + IOException { + openTestURL(); + + for (int i = 0; i < N; i++) { + clickDateDatePickerButton(); + + waitUntil(ExpectedConditions.visibilityOfElementLocated(By + .className("v-datefield-popup"))); + + clickDateDatePickerButton(); + + waitUntil(ExpectedConditions.invisibilityOfElementLocated(By + .className("v-datefield-popup"))); + } + } + + private void clickDateDatePickerButton() { + DateFieldElement dateField = $(DateFieldElement.class).first(); + dateField.findElement(By.tagName("button")).click(); + } + +} \ No newline at end of file -- cgit v1.2.3 From 67f669035a12d6c0ec3661f283d28717279e144d Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Tue, 28 Oct 2014 16:51:45 +0200 Subject: TreeTable column header and footer height fix (#15121) Fix for regression caused by (#14812) + Valo test for TreeTables. Change-Id: I57f911cbf33e52196fa219b4feddfe62db7f6ded --- WebContent/VAADIN/themes/valo/components/_treetable.scss | 6 ++++++ uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java | 9 +++++++++ 2 files changed, 15 insertions(+) (limited to 'uitest/src/com') diff --git a/WebContent/VAADIN/themes/valo/components/_treetable.scss b/WebContent/VAADIN/themes/valo/components/_treetable.scss index e025df2bc9..60b696315b 100644 --- a/WebContent/VAADIN/themes/valo/components/_treetable.scss +++ b/WebContent/VAADIN/themes/valo/components/_treetable.scss @@ -14,6 +14,12 @@ padding-left: 0; padding-right: 0; } + + [class*="caption-container"], + [class*="footer-container"] { + $vertical-padding: round(($v-table-row-height - $v-table-header-font-size)/2); + min-height: $v-table-row-height - $vertical-padding - ($vertical-padding - $v-table-border-width); + } [class*="cell-wrapper"] { min-height: $v-font-size; diff --git a/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java b/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java index b0af0db8c6..92cb837b38 100644 --- a/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java +++ b/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java @@ -132,6 +132,15 @@ public class ValoThemeUITest extends MultiBrowserTest { compareScreen("tables"); } + @Test + public void treeTables() throws Exception { + openTestURL("test"); + open("Tables"); + check("Hierarchical"); + check("Footer"); + compareScreen("treetables"); + } + @Test public void dragging() throws Exception { openTestURL("test"); -- cgit v1.2.3 From 3b0ed7a67553ca48e40f9c78da5655256a1fe5ea Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Sun, 24 Aug 2014 14:48:03 +0300 Subject: Update selection after changes in underlying data source (#13580). Change-Id: I6354d85bd6bc37b1cbb69f388559278d5a163256 --- server/src/com/vaadin/ui/AbstractSelect.java | 19 ++++ .../TestAbstractSelectValueUpdate.java | 81 ++++++++++++++ .../TableClickAndDragOnIconAndComponents.java | 10 +- .../components/table/TableDeleteSelectedRow.java | 117 +++++++++++++++++++++ .../table/TableDeleteSelectedRowTest.java | 65 ++++++++++++ 5 files changed, 289 insertions(+), 3 deletions(-) create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractselect/TestAbstractSelectValueUpdate.java create mode 100644 uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRow.java create mode 100644 uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRowTest.java (limited to 'uitest/src/com') diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index b083db3183..2c4dd5be5d 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -1675,6 +1675,8 @@ public abstract class AbstractSelect extends AbstractField implements // Clears the item id mapping table itemIdMapper.removeAll(); + adjustSelection(); + // Notify all listeners fireItemSetChange(); } @@ -1712,6 +1714,23 @@ public abstract class AbstractSelect extends AbstractField implements markAsDirty(); } + /** + * Removes orphaned ids from selection. + */ + protected void adjustSelection() { + Object value = getValue(); + if (isMultiSelect() && (value instanceof Collection)) { + Collection collection = (Collection) value; + for (Object id : collection) { + if (!containsId(id)) { + unselect(id); + } + } + } else if (!containsId(value)) { + unselect(value); + } + } + /** * Implementation of item set change event. */ diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestAbstractSelectValueUpdate.java b/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestAbstractSelectValueUpdate.java new file mode 100644 index 0000000000..e81f6e09b6 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestAbstractSelectValueUpdate.java @@ -0,0 +1,81 @@ +/* + * 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.abstractselect; + +import java.util.Collection; +import java.util.Collections; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.ui.AbstractSelect; + +public class TestAbstractSelectValueUpdate { + + @Test + public void removeItem_deleteItemFromUnderlyingContainer_selectValueIsUpdated() { + BeanItemContainer container = new BeanItemContainer( + Object.class); + Object item1 = new Object(); + Object item2 = new Object(); + container.addBean(item1); + container.addBean(item2); + TestSelect select = new TestSelect(); + select.setContainerDataSource(container); + + select.setValue(item1); + + Assert.assertNotNull("Value is null after selection", select.getValue()); + + container.removeItem(item1); + + Assert.assertNull("Value is not null after removal", select.getValue()); + } + + @Test + public void removeItem_multiselectSectionDeleteItemFromUnderlyingContainer_selectValueIsUpdated() { + BeanItemContainer container = new BeanItemContainer( + Object.class); + Object item1 = new Object(); + Object item2 = new Object(); + container.addBean(item1); + container.addBean(item2); + TestSelect select = new TestSelect(); + select.setMultiSelect(true); + select.setContainerDataSource(container); + + select.setValue(Collections.singletonList(item1)); + + checkSelectedItemsCount(select, 1); + + container.removeItem(item1); + + checkSelectedItemsCount(select, 0); + } + + private void checkSelectedItemsCount(TestSelect select, int count) { + Assert.assertNotNull("Selected value is null", select.getValue()); + Assert.assertTrue("Selected value is not a collection", + select.getValue() instanceof Collection); + Assert.assertEquals("Wrong number of selected items", + ((Collection) select.getValue()).size(), count); + } + + private class TestSelect extends AbstractSelect { + + } +} diff --git a/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponents.java b/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponents.java index 64f1a64558..4bdec81ccf 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponents.java +++ b/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponents.java @@ -38,7 +38,7 @@ public class TableClickAndDragOnIconAndComponents extends AbstractTestUI { table.setId("testable-table"); addComponent(table); for (int i = 0; i < 5; i++) { - addItemAfter(i + "foo", null); + addItemAfter(i + "foo", null, false); } table.addGeneratedColumn("Label", new ColumnGenerator() { @@ -118,14 +118,15 @@ public class TableClickAndDragOnIconAndComponents extends AbstractTestUI { IndexedContainer container = (IndexedContainer) table .getContainerDataSource(); + boolean selected = table.getValue().equals(dragged); container.removeItem(dragged); - addItemAfter(dragged, target); + addItemAfter(dragged, target, selected); } }); } @SuppressWarnings("unchecked") - private void addItemAfter(Object itemId, Object afterItemId) { + private void addItemAfter(Object itemId, Object afterItemId, boolean select) { Item item; if (afterItemId != null) { item = table.addItemAfter(afterItemId, itemId); @@ -136,6 +137,9 @@ public class TableClickAndDragOnIconAndComponents extends AbstractTestUI { item.getItemProperty("red").setValue("red " + itemId); item.getItemProperty("icon").setValue( new ThemeResource("../runo/icons/16/ok.png")); + if (select) { + table.select(itemId); + } } @Override diff --git a/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRow.java b/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRow.java new file mode 100644 index 0000000000..349fbc73fe --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRow.java @@ -0,0 +1,117 @@ +/* + * 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.table; + +import java.util.Collection; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.MultiSelectMode; +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.Table; + +/** + * Test UI for delete rows operation in multiselect table. + * + * @author Vaadin Ltd + */ +public class TableDeleteSelectedRow extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Table table = new Table(); + table.setSelectable(true); + table.setImmediate(true); + + BeanItemContainer container = createContainer(); + + table.setContainerDataSource(container); + + final Label selectedSize = new Label(); + selectedSize.addStyleName("selected-rows"); + + Button changeMode = new Button("Set multiselect", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + table.setMultiSelect(true); + table.setMultiSelectMode(MultiSelectMode.SIMPLE); + + BeanItemContainer container = createContainer(); + + table.setContainerDataSource(container); + } + }); + changeMode.addStyleName("multiselect"); + + Button delete = new Button("Delete selected", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + if (table.getValue() instanceof Collection) { + Collection rows = (Collection) table.getValue(); + for (Object row : rows) { + table.getContainerDataSource().removeItem(row); + } + rows = (Collection) table.getValue(); + selectedSize.setValue(String.valueOf(rows.size())); + } else { + table.getContainerDataSource().removeItem(table.getValue()); + selectedSize.setValue(table.getValue() == null ? "0" : "1"); + } + } + }); + delete.addStyleName("delete"); + + addComponents(delete, changeMode, selectedSize, table); + } + + @Override + protected String getTestDescription() { + return "Items deleted via container data source should not be available as selected in the table."; + } + + @Override + protected Integer getTicketNumber() { + return 13580; + } + + private BeanItemContainer createContainer() { + BeanItemContainer container = new BeanItemContainer( + TableBean.class); + container.addBean(new TableBean("first")); + container.addBean(new TableBean("second")); + container.addBean(new TableBean("third")); + return container; + } + + public static class TableBean { + + TableBean(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + private String name; + } +} diff --git a/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRowTest.java b/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRowTest.java new file mode 100644 index 0000000000..0e807edf14 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableDeleteSelectedRowTest.java @@ -0,0 +1,65 @@ +/* + * 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.table; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test to check selected rows in multiselect table after deletion. + * + * @author Vaadin Ltd + */ +public class TableDeleteSelectedRowTest extends MultiBrowserTest { + + @Test + public void deleteSelectedRows() { + openTestURL(); + + // Select row in the table + findElement(By.className("v-table-row-odd")).click(); + + // Delete selected row + findElement(By.className("delete")).click(); + + WebElement selectedSize = findElement(By.className("selected-rows")); + int size = Integer.parseInt(selectedSize.getText()); + + Assert.assertEquals( + "Non empty collection of selected rows after remove via container", + 0, size); + + // Reset table and set multiselect mode + findElement(By.className("multiselect")).click(); + + // Select row in the table + findElement(By.className("v-table-row-odd")).click(); + + // Delete selected row + findElement(By.className("delete")).click(); + + selectedSize = findElement(By.className("selected-rows")); + size = Integer.parseInt(selectedSize.getText()); + + Assert.assertEquals( + "Non empty collection of selected rows after remove via container", + 0, size); + } +} -- cgit v1.2.3 From 14bf04331f09a60f6006da2b56887ee86bdb5a20 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Sat, 8 Nov 2014 14:05:07 +0200 Subject: Unit test correction for moving any event in month calendar view(#12413) Change-Id: I6e80c77f758a451ffb23c5487e7a25f3c0eed3c7 --- .../calendar/CalendarMonthViewDndEventTest.java | 76 ++++++++++++++++------ 1 file changed, 57 insertions(+), 19 deletions(-) (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java index 2efcd1f88d..3248804eed 100644 --- a/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarMonthViewDndEventTest.java @@ -34,13 +34,20 @@ public class CalendarMonthViewDndEventTest extends DndActionsTest { public void dragAndDropEventToNextDay() { openTestURL(); - WebElement event = getDriver().findElement( - By.className("v-calendar-event")); + WebElement calendar = findElement(By.className("v-calendar")); + int calendarRight = calendar.getLocation().getX() + + calendar.getSize().getWidth(); + + WebElement event = findElement(By.className("v-calendar-event")); int x = event.getLocation().getX(); int width = event.getSize().getWidth(); - WebElement cell = getDriver().findElement( - By.className("v-calendar-month-day")); + // does calendar have space on the right for one more event (i.e. day + // cell on the right). + boolean moveRight = event.getLocation().getX() + 2 + * event.getSize().getWidth() <= calendarRight; + + WebElement cell = getParentCell(event, "v-calendar-month-day"); int cellY = cell.getLocation().getY(); int cellHeight = cell.getSize().getHeight(); @@ -48,34 +55,65 @@ public class CalendarMonthViewDndEventTest extends DndActionsTest { long origStart = getTime("start"); long origEnd = getTime("end"); - dragAndDrop(event, event.getSize().getWidth() + 5, 0); + if (moveRight) { + dragAndDrop(event, event.getSize().getWidth() + 5, 0); + } else { + dragAndDrop(event, -width / 2, 0); + } - event = getDriver().findElement(By.className("v-calendar-event")); + event = findElement(By.className("v-calendar-event")); int newX = event.getLocation().getX(); int newY = event.getLocation().getY(); Assert.assertTrue( - "Moved event has wrong Y position (not the same row)", - newY >= cellY && newY < cellY + cellHeight); - Assert.assertTrue( - "Moved event has wrong X position (not after original event)", - newX >= x + width - 1); + "Moved event has wrong Y position (not the same row), new Y position=" + + newY + ", cell Y position=" + cellY + + ", cell height=" + cellHeight, newY >= cellY + && newY < cellY + cellHeight); + if (moveRight) { + Assert.assertTrue( + "Moved event has wrong X position (not after original event)", + newX >= x + width - 1); + } else { + width = event.getSize().getWidth(); + Assert.assertTrue( + "Moved event has wrong X position (not after original event)", + x >= newX + width - 1); + } long start = getTime("start"); long end = getTime("end"); int day = 24 * 3600000; - Assert.assertEquals( - "Start date of moved event is not next day, same time", - origStart + day, start); - Assert.assertEquals( - "End date of moved event is not next day, same time", origEnd - + day, end); + if (moveRight) { + Assert.assertEquals( + "Start date of moved event is not next day, same time", + origStart + day, start); + Assert.assertEquals( + "End date of moved event is not next day, same time", + origEnd + day, end); + } else { + Assert.assertEquals( + "Start date of moved event is not previous day, same time", + origStart - day, start); + Assert.assertEquals( + "End date of moved event is not previous day, same time", + origEnd - day, end); + + } + } + + private WebElement getParentCell(WebElement element, String style) { + WebElement parent = element; + do { + // ".." xpath expression chooses the parent of the element + parent = parent.findElement(By.xpath("..")); + } while (!parent.getAttribute("class").contains(style)); + return parent; } private long getTime(String style) { - WebElement start = getDriver().findElement(By.className(style)); + WebElement start = findElement(By.className(style)); return Long.parseLong(start.getText()); } - } -- cgit v1.2.3 From a42404312f3eac48e6e866526cc627cb972c89d1 Mon Sep 17 00:00:00 2001 From: Sara Seppola Date: Tue, 4 Nov 2014 11:44:45 +0200 Subject: Table is not caching thousands of rows in vain (#13576) Change-Id: I6f6382dd3468db40c36e507b94f84ab1191e100f --- client/src/com/vaadin/client/ui/VScrollTable.java | 37 ++++++--- .../table/TableCacheMinimizingOnFetchRows.java | 92 ++++++++++++++++++++++ .../table/TableCacheMinimizingOnFetchRowsTest.java | 48 +++++++++++ 3 files changed, 167 insertions(+), 10 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRows.java create mode 100644 uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRowsTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index a382db573c..b07d2dc9c0 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -2600,11 +2600,12 @@ public class VScrollTable extends FlowPanel implements HasWidgets, @Override public void run() { + if (client.hasActiveRequest() || navKeyDown) { // if client connection is busy, don't bother loading it more VConsole.log("Postponed rowfetch"); schedule(250); - } else if (!updatedReqRows && allRenderedRowsAreNew()) { + } else if (allRenderedRowsAreNew() && !updatedReqRows) { /* * If all rows are new, there might have been a server-side call @@ -2625,6 +2626,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, setReqRows(last - getReqFirstRow() + 1); updatedReqRows = true; schedule(250); + } else { int firstRendered = scrollBody.getFirstRendered(); @@ -2712,6 +2714,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, client.updateVariable(paintableId, "firstvisible", firstRowInViewPort, false); } + client.updateVariable(paintableId, "reqfirstrow", reqFirstRow, false); client.updateVariable(paintableId, "reqrows", reqRows, true); @@ -4209,7 +4212,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } /** - * Returns the expand ration of the cell + * Returns the expand ratio of the cell * * @return The expand ratio */ @@ -4697,10 +4700,12 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } public int getLastRendered() { + return lastRendered; } public int getFirstRendered() { + return firstRendered; } @@ -4784,10 +4789,12 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } else if (firstIndex + rows == firstRendered) { final VScrollTableRow[] rowArray = new VScrollTableRow[rows]; int i = rows; + while (it.hasNext()) { i--; rowArray[i] = prepareRow((UIDL) it.next()); } + for (i = 0; i < rows; i++) { addRowBeforeFirstRendered(rowArray[i]); firstRendered--; @@ -4812,10 +4819,12 @@ public class VScrollTable extends FlowPanel implements HasWidgets, setLastRendered(lastRendered + 1); setContainerHeight(); fixSpacers(); + while (it.hasNext()) { addRow(prepareRow((UIDL) it.next())); setLastRendered(lastRendered + 1); } + fixSpacers(); } @@ -4830,6 +4839,14 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * has changed since the last request. */ protected void ensureCacheFilled() { + + /** + * Fixes cache issue #13576 where unnecessary rows are fetched + */ + if (isLazyScrollerActive()) { + return; + } + int reactFirstRow = (int) (firstRowInViewPort - pageLength * cache_react_rate); int reactLastRow = (int) (firstRowInViewPort + pageLength + pageLength @@ -6137,7 +6154,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, touchStart = event; Touch touch = event.getChangedTouches().get(0); // save position to fields, touches in events are same - // isntance during the operation. + // instance during the operation. touchStartX = touch.getClientX(); touchStartY = touch.getClientY(); /* @@ -6445,8 +6462,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, startRow = focusedRow; selectionRangeStart = focusedRow; // If start row is null then we have a multipage selection - // from - // above + // from above if (startRow == null) { startRow = (VScrollTableRow) scrollBody.iterator() .next(); @@ -7281,6 +7297,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } if (preLimit < firstRendered) { // need some rows to the beginning of the rendered area + rowRequestHandler .setReqFirstRow((int) (firstRowInViewPort - pageLength * cache_rate)); @@ -7666,13 +7683,13 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // viewport selectLastItemInNextRender = true; multiselectPending = shift; - scrollByPagelenght(1); + scrollByPagelength(1); } } } } else { /* No selections, go page down by scrolling */ - scrollByPagelenght(1); + scrollByPagelength(1); } return true; } @@ -7718,13 +7735,13 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // viewport selectFirstItemInNextRender = true; multiselectPending = shift; - scrollByPagelenght(-1); + scrollByPagelength(-1); } } } } else { /* No selections, go page up by scrolling */ - scrollByPagelenght(-1); + scrollByPagelength(-1); } return true; @@ -7798,7 +7815,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, .getRowHeight()); } - private void scrollByPagelenght(int i) { + private void scrollByPagelength(int i) { int pixels = i * scrollBodyPanel.getOffsetHeight(); int newPixels = scrollBodyPanel.getScrollPosition() + pixels; if (newPixels < 0) { diff --git a/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRows.java b/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRows.java new file mode 100644 index 0000000000..745f2344a3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRows.java @@ -0,0 +1,92 @@ +package com.vaadin.tests.components.table; + +import java.io.Serializable; +import java.util.List; + +import com.vaadin.data.util.BeanContainer; +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.Table; + +@SuppressWarnings("serial") +public class TableCacheMinimizingOnFetchRows extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + getLayout().setMargin(true); + + final Table table = new Table("Beans of All Sorts"); + + BeanContainer beans = new BeanContainer( + Bean.class) { + @Override + public List getItemIds(int startIndex, int numberOfIds) { + + // numberOfIds should be about 60 after scrolling down the table + log.log("requested " + numberOfIds + " rows"); + + return super.getItemIds(startIndex, numberOfIds); + } + }; + beans.setBeanIdProperty("name"); + + for (int i = 0; i < 10000; i++) { + beans.addBean(new Bean("Common bean" + i, i)); + } + + table.setContainerDataSource(beans); + table.setPageLength(20); + table.setVisibleColumns(new Object[] { "name", "value" }); + table.setWidth("800px"); + + Button button = new Button("scroll down"); + button.addClickListener(new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + table.setCurrentPageFirstItemIndex(table.size()); + } + }); + + addComponent(table); + addComponent(button); + } + + public class Bean implements Serializable { + + String name; + int value; + + public Bean(String name, int value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + } + + @Override + protected String getTestDescription() { + return "Ensure that when scrolling from top to bottom in a big table with 10000 items, not all rows in the range are cached"; + } + + @Override + protected Integer getTicketNumber() { + return 13576; + } +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRowsTest.java b/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRowsTest.java new file mode 100644 index 0000000000..edb0f3851a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRowsTest.java @@ -0,0 +1,48 @@ +/* + * 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.table; + +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TableCacheMinimizingOnFetchRowsTest extends MultiBrowserTest { + + @Test + public void testCacheSize() throws InterruptedException { + + openTestURL(); + + scrollToBottomOfTable(); + + // the row request might vary slightly with different browsers + String logtext1 = "requested 60 rows"; + String logtext2 = "requested 61 rows"; + + assertThat("Requested cached rows did not match expected", + logContainsText(logtext1) || logContainsText(logtext2)); + + } + + private void scrollToBottomOfTable() { + waitForElementPresent(By.className("v-button")); + $(ButtonElement.class).first().click(); + } +} -- cgit v1.2.3 From c7d698cc57e2c2baba5d168d65e061789d973054 Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Tue, 11 Nov 2014 11:42:47 +0200 Subject: Add test suites for running changed and affected tests. Change-Id: I388e592d4e98d9417fe5273f8e7f7d3e1f7b63e9 --- uitest/ivy.xml | 3 + .../vaadin/tests/tb3/AffectedTB3TestLocator.java | 97 +++++++++ .../src/com/vaadin/tests/tb3/AffectedTB3Tests.java | 27 +++ .../vaadin/tests/tb3/ChangedTB3TestLocator.java | 158 +++++++++++++++ .../src/com/vaadin/tests/tb3/ChangedTB3Tests.java | 41 ++++ .../src/com/vaadin/tests/tb3/TB3TestLocator.java | 218 +++++++++++++++++++++ uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java | 207 +------------------ 7 files changed, 552 insertions(+), 199 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/tb3/AffectedTB3TestLocator.java create mode 100644 uitest/src/com/vaadin/tests/tb3/AffectedTB3Tests.java create mode 100644 uitest/src/com/vaadin/tests/tb3/ChangedTB3TestLocator.java create mode 100644 uitest/src/com/vaadin/tests/tb3/ChangedTB3Tests.java create mode 100644 uitest/src/com/vaadin/tests/tb3/TB3TestLocator.java (limited to 'uitest/src/com') diff --git a/uitest/ivy.xml b/uitest/ivy.xml index 9af209662c..14c8bc6ce3 100644 --- a/uitest/ivy.xml +++ b/uitest/ivy.xml @@ -107,6 +107,9 @@ + + diff --git a/uitest/src/com/vaadin/tests/tb3/AffectedTB3TestLocator.java b/uitest/src/com/vaadin/tests/tb3/AffectedTB3TestLocator.java new file mode 100644 index 0000000000..a3bee26675 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/AffectedTB3TestLocator.java @@ -0,0 +1,97 @@ +/* + * 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.tb3; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class AffectedTB3TestLocator extends TB3TestLocator { + + private final ChangedTB3TestLocator changedTB3TestLocator; + + public AffectedTB3TestLocator() { + changedTB3TestLocator = new ChangedTB3TestLocator(); + } + + @Override + protected List> findClasses(Class baseClass, + String basePackage, String[] ignoredPackages) throws IOException { + List> allTestClasses = super.findClasses(baseClass, + basePackage, ignoredPackages); + + List> changedTestClasses = changedTB3TestLocator + .findClasses(baseClass, basePackage, ignoredPackages); + + return getAffectedTestClasses(allTestClasses, changedTestClasses); + } + + private List> getAffectedTestClasses( + List> allTestClasses, + List> changedTestClasses) throws IOException { + List> affectedWithPackageTestClasses = getTestClassesWithAffectedPackageName(allTestClasses); + List> affectedTestClasses = new ArrayList>(); + affectedTestClasses.addAll(affectedWithPackageTestClasses); + + // Removing duplicate entries before adding changed test classes. + for (Class changedTestClass : changedTestClasses) { + for (Class affectedTestClass : affectedWithPackageTestClasses) { + if (!changedTestClass.getName().equals( + affectedTestClass.getName())) { + affectedTestClasses.add(changedTestClass); + + break; + } + } + } + return affectedTestClasses; + } + + private List> getTestClassesWithAffectedPackageName( + List> classes) { + List> affectedTestClasses = new ArrayList>(); + List affectedFiles = getAffectedFiles(); + + for (Class c : classes) { + String[] packageParts = c.getName().split("\\."); + String lastPart = packageParts[packageParts.length - 2]; + + for (String f : affectedFiles) { + if (f.toLowerCase().contains(lastPart.toLowerCase())) { + affectedTestClasses.add(c); + + // Break here not to accidentally add the same test class + // multiple times if it matches more than one file. + break; + } + } + } + + return affectedTestClasses; + } + + private List getAffectedFiles() { + List affectedFilePaths = new ArrayList(); + + for (String path : changedTB3TestLocator.getChangedFilePaths()) { + if (!path.toLowerCase().contains("test")) { + affectedFilePaths.add(path); + } + } + + return affectedFilePaths; + } +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/tb3/AffectedTB3Tests.java b/uitest/src/com/vaadin/tests/tb3/AffectedTB3Tests.java new file mode 100644 index 0000000000..6736bc3990 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/AffectedTB3Tests.java @@ -0,0 +1,27 @@ +package com.vaadin.tests.tb3; + +import org.junit.runner.RunWith; +import org.junit.runners.model.InitializationError; + +import com.vaadin.tests.tb3.AffectedTB3Tests.AffectedTB3TestSuite; + +/** + * Test suite that runs tests from test classes which have changes or have + * similar package name compare the the changes files in the current workspace. + * If there are no changes in the workspace, it will run the changes to test + * classes introduced in the HEAD commit. + * + * @author Vaadin Ltd + */ +@RunWith(AffectedTB3TestSuite.class) +public class AffectedTB3Tests { + + public static class AffectedTB3TestSuite extends TB3TestSuite { + + public AffectedTB3TestSuite(Class klass) throws InitializationError { + super(klass, AbstractTB3Test.class, "com.vaadin.tests", + new String[] { "com.vaadin.tests.integration" }, + new AffectedTB3TestLocator()); + } + } +} diff --git a/uitest/src/com/vaadin/tests/tb3/ChangedTB3TestLocator.java b/uitest/src/com/vaadin/tests/tb3/ChangedTB3TestLocator.java new file mode 100644 index 0000000000..b425de48b5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/ChangedTB3TestLocator.java @@ -0,0 +1,158 @@ +/* + * 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.tb3; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jgit.api.DiffCommand; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.diff.DiffEntry; +import org.eclipse.jgit.diff.DiffEntry.ChangeType; +import org.eclipse.jgit.diff.DiffFormatter; +import org.eclipse.jgit.diff.RawTextComparator; +import org.eclipse.jgit.errors.AmbiguousObjectException; +import org.eclipse.jgit.errors.IncorrectObjectTypeException; +import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.errors.NoWorkTreeException; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.eclipse.jgit.util.io.DisabledOutputStream; + +/** + * + * @since + * @author Vaadin Ltd + */ +public class ChangedTB3TestLocator extends TB3TestLocator { + + @Override + protected List> findClasses(Class baseClass, + String basePackage, String[] ignoredPackages) throws IOException { + + return getChangedTestClasses(baseClass); + } + + protected List getChangedFilePaths() { + List filePaths = new ArrayList(); + + for (DiffEntry diff : getDiffs()) { + if (diff.getChangeType() != ChangeType.DELETE) { + filePaths.add(diff.getNewPath()); + System.out.println("Using changed file: " + diff.getNewPath()); + } + } + + return filePaths; + } + + private List getDiffs() { + try { + FileRepositoryBuilder builder = new FileRepositoryBuilder(); + Repository repository = builder.setWorkTree(new File(".")) + .readEnvironment() // scan environment GIT_* variables + .findGitDir() // scan up the file system tree + .build(); + + List diffsInWorkingTree = getDiffsInWorkingTree(repository); + + if (diffsInWorkingTree.isEmpty()) { + return getDiffsInHead(repository); + } + + return diffsInWorkingTree; + + } catch (IOException e) { + e.printStackTrace(); + } catch (NoWorkTreeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (GitAPIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + private List getDiffsInWorkingTree(Repository repository) + throws GitAPIException { + Git git = new Git(repository); + DiffCommand diffCommand = git.diff(); + + List diffsInWorkingTree = new ArrayList(); + + for (DiffEntry diff : diffCommand.call()) { + // Exclude temporary junit files. + if (!diff.getNewPath().startsWith("uitest/junit")) { + diffsInWorkingTree.add(diff); + } + } + + return diffsInWorkingTree; + } + + private List getDiffsInHead(Repository repository) + throws AmbiguousObjectException, IncorrectObjectTypeException, + IOException, MissingObjectException { + RevWalk rw = new RevWalk(repository); + ObjectId head = repository.resolve(Constants.HEAD); + RevCommit commit = rw.parseCommit(head); + RevCommit parent = rw.parseCommit(commit.getParent(0).getId()); + DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE); + df.setRepository(repository); + df.setDiffComparator(RawTextComparator.DEFAULT); + df.setDetectRenames(true); + List diffs = df.scan(parent.getTree(), commit.getTree()); + + return diffs; + } + + private List> getChangedTestClasses( + Class baseClass) { + List changedTestFilePaths = getTestFilePaths(); + List> testClasses = new ArrayList>(); + + for (String filePath : changedTestFilePaths) { + String path = filePath.replace("uitest/src/", "").replace(".java", + ""); + String className = path.replace("/", "."); + addClassIfMatches(testClasses, className, baseClass); + } + + return testClasses; + } + + private List getTestFilePaths() { + List changedTestFilePaths = new ArrayList(); + + for (String filePath : getChangedFilePaths()) { + if (filePath.toLowerCase().startsWith("uitest") + && filePath.toLowerCase().endsWith(".java")) { + changedTestFilePaths.add(filePath); + } + } + + return changedTestFilePaths; + } + +} diff --git a/uitest/src/com/vaadin/tests/tb3/ChangedTB3Tests.java b/uitest/src/com/vaadin/tests/tb3/ChangedTB3Tests.java new file mode 100644 index 0000000000..2200566b84 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/ChangedTB3Tests.java @@ -0,0 +1,41 @@ +/* + * 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.tb3; + +import org.junit.runner.RunWith; +import org.junit.runners.model.InitializationError; + +import com.vaadin.tests.tb3.ChangedTB3Tests.ChangedTB3TestsSuite; + +/** + * Test suite that runs tests from test classes which have changes in the + * current workspace. If there are no changes in the workspace, it will run the + * changes to test classes introduced in the HEAD commit. + * + * @since + * @author Vaadin Ltd + */ +@RunWith(ChangedTB3TestsSuite.class) +public class ChangedTB3Tests { + public static class ChangedTB3TestsSuite extends TB3TestSuite { + public ChangedTB3TestsSuite(Class klass) throws InitializationError { + super(klass, AbstractTB3Test.class, "com.vaadin.tests", + new String[] { "com.vaadin.tests.integration" }, + new ChangedTB3TestLocator()); + + } + } +} diff --git a/uitest/src/com/vaadin/tests/tb3/TB3TestLocator.java b/uitest/src/com/vaadin/tests/tb3/TB3TestLocator.java new file mode 100644 index 0000000000..a0fbf51195 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/TB3TestLocator.java @@ -0,0 +1,218 @@ +/* + * 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.tb3; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.net.JarURLConnection; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Enumeration; +import java.util.List; +import java.util.jar.JarEntry; + +public class TB3TestLocator { + /** + * Traverses the directory on the classpath (inside or outside a Jar file) + * specified by 'basePackage'. Collects all classes inside the location + * which can be assigned to 'baseClass' except for classes inside packages + * listed in 'ignoredPackages'. + * + * @param baseClass + * @param basePackage + * @param ignorePackages + * @return + */ + public Class[] findTests(Class baseClass, + String basePackage, String[] ignorePackages) { + try { + List l = findClasses(baseClass, basePackage, ignorePackages); + return l.toArray(new Class[] {}); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + /** + * Traverses the directory on the classpath (inside or outside a Jar file) + * specified by 'basePackage'. Collects all classes inside the location + * which can be assigned to 'baseClass' except for classes inside packages + * listed in 'ignoredPackages'. + * + * @param baseClass + * @param basePackage + * @param ignoredPackages + * @return + * @throws IOException + */ + protected List> findClasses(Class baseClass, + String basePackage, String[] ignoredPackages) throws IOException { + List> classes = new ArrayList>(); + String basePackageDirName = "/" + basePackage.replace('.', '/'); + URL location = baseClass.getResource(basePackageDirName); + if (location.getProtocol().equals("file")) { + try { + File f = new File(location.toURI()); + if (!f.exists()) { + throw new IOException("Directory " + f.toString() + + " does not exist"); + } + findPackages(f, basePackage, baseClass, classes, + ignoredPackages); + } catch (URISyntaxException e) { + throw new IOException(e.getMessage()); + } + } else if (location.getProtocol().equals("jar")) { + JarURLConnection juc = (JarURLConnection) location.openConnection(); + findClassesInJar(juc, basePackage, baseClass, classes); + } + + Collections.sort(classes, new Comparator>() { + + @Override + public int compare(Class o1, Class o2) { + return o1.getName().compareTo(o2.getName()); + } + + }); + + return classes; + } + + /** + * Traverses the given directory and collects all classes which are inside + * the given 'javaPackage' and can be assigned to the given 'baseClass'. The + * found classes are added to 'result'. + * + * @param parent + * The directory to traverse + * @param javaPackage + * The java package which 'parent' contains + * @param baseClass + * The class which the target classes extend + * @param result + * The collection to which found classes are added + * @param ignoredPackages + * A collection of packages (including sub packages) to ignore + */ + private void findPackages(File parent, String javaPackage, + Class baseClass, Collection> result, + String[] ignoredPackages) { + for (String ignoredPackage : ignoredPackages) { + if (javaPackage.equals(ignoredPackage)) { + return; + } + } + + for (File file : parent.listFiles()) { + if (file.isDirectory()) { + findPackages(file, javaPackage + "." + file.getName(), + baseClass, result, ignoredPackages); + } else if (file.getName().endsWith(".class")) { + String fullyQualifiedClassName = javaPackage + "." + + file.getName().replace(".class", ""); + addClassIfMatches(result, fullyQualifiedClassName, baseClass); + } + } + + } + + /** + * Traverses a Jar file using the given connection and collects all classes + * which are inside the given 'javaPackage' and can be assigned to the given + * 'baseClass'. The found classes are added to 'result'. + * + * @param javaPackage + * The java package containing the classes (classes may be in a + * sub package) + * @param baseClass + * The class which the target classes extend + * @param result + * The collection to which found classes are added + * @throws IOException + */ + private void findClassesInJar(JarURLConnection juc, String javaPackage, + Class baseClass, Collection> result) + throws IOException { + String javaPackageDir = javaPackage.replace('.', '/'); + Enumeration ent = juc.getJarFile().entries(); + while (ent.hasMoreElements()) { + JarEntry e = ent.nextElement(); + if (e.getName().endsWith(".class") + && e.getName().startsWith(javaPackageDir)) { + String fullyQualifiedClassName = e.getName().replace('/', '.') + .replace(".class", ""); + addClassIfMatches(result, fullyQualifiedClassName, baseClass); + } + } + } + + /** + * Verifies that the class represented by 'fullyQualifiedClassName' can be + * loaded, assigned to 'baseClass' and is not an abstract or anonymous + * class. + * + * @param result + * The collection to add to + * @param fullyQualifiedClassName + * The candidate class + * @param baseClass + * The class 'fullyQualifiedClassName' should be assignable to + */ + @SuppressWarnings("unchecked") + protected void addClassIfMatches(Collection> result, + String fullyQualifiedClassName, Class baseClass) { + try { + // Try to load the class + + Class c = Class.forName(fullyQualifiedClassName); + if (!baseClass.isAssignableFrom(c)) { + return; + } + if (!includeInSuite(c)) { + return; + } + + if (!Modifier.isAbstract(c.getModifiers()) && !c.isAnonymousClass()) { + result.add((Class) c); + } + } catch (Exception e) { + // Could ignore that class cannot be loaded + e.printStackTrace(); + } catch (LinkageError e) { + // Ignore. Client side classes will at least throw LinkageErrors + } + + } + + /** + * @return true if the class should be included in the suite, false if not + */ + private boolean includeInSuite(Class c) { + if (c.getAnnotation(ExcludeFromSuite.class) != null) { + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java b/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java index 703d01c122..b0554ce0f6 100644 --- a/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java +++ b/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java @@ -16,21 +16,8 @@ package com.vaadin.tests.tb3; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Modifier; -import java.net.JarURLConnection; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Enumeration; -import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.jar.JarEntry; import org.junit.runners.Suite; import org.junit.runners.model.InitializationError; @@ -59,194 +46,16 @@ public class TB3TestSuite extends Suite { public TB3TestSuite(Class klass, Class baseClass, String basePackage, String[] ignorePackages) throws InitializationError { - super(klass, findTests(baseClass, basePackage, ignorePackages)); - setScheduler(new ParallelScheduler(service)); + this(klass, baseClass, basePackage, ignorePackages, + new TB3TestLocator()); } - /** - * Traverses the directory on the classpath (inside or outside a Jar file) - * specified by 'basePackage'. Collects all classes inside the location - * which can be assigned to 'baseClass' except for classes inside packages - * listed in 'ignoredPackages'. - * - * @param baseClass - * @param basePackage - * @param ignorePackages - * @return - */ - private static Class[] findTests( + public TB3TestSuite(Class klass, Class baseClass, String basePackage, - String[] ignorePackages) { - try { - List l = findClasses(baseClass, basePackage, ignorePackages); - return l.toArray(new Class[] {}); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - /** - * Traverses the directory on the classpath (inside or outside a Jar file) - * specified by 'basePackage'. Collects all classes inside the location - * which can be assigned to 'baseClass' except for classes inside packages - * listed in 'ignoredPackages'. - * - * @param baseClass - * @param basePackage - * @param ignoredPackages - * @return - * @throws IOException - */ - private static List> findClasses(Class baseClass, - String basePackage, String[] ignoredPackages) throws IOException { - List> classes = new ArrayList>(); - String basePackageDirName = "/" + basePackage.replace('.', '/'); - URL location = baseClass.getResource(basePackageDirName); - if (location.getProtocol().equals("file")) { - try { - File f = new File(location.toURI()); - if (!f.exists()) { - throw new IOException("Directory " + f.toString() - + " does not exist"); - } - findPackages(f, basePackage, baseClass, classes, - ignoredPackages); - } catch (URISyntaxException e) { - throw new IOException(e.getMessage()); - } - } else if (location.getProtocol().equals("jar")) { - JarURLConnection juc = (JarURLConnection) location.openConnection(); - findClassesInJar(juc, basePackage, baseClass, classes); - } - - Collections.sort(classes, new Comparator>() { - - @Override - public int compare(Class o1, Class o2) { - return o1.getName().compareTo(o2.getName()); - } - - }); - return classes; - } - - /** - * Traverses the given directory and collects all classes which are inside - * the given 'javaPackage' and can be assigned to the given 'baseClass'. The - * found classes are added to 'result'. - * - * @param parent - * The directory to traverse - * @param javaPackage - * The java package which 'parent' contains - * @param baseClass - * The class which the target classes extend - * @param result - * The collection to which found classes are added - * @param ignoredPackages - * A collection of packages (including sub packages) to ignore - */ - private static void findPackages(File parent, String javaPackage, - Class baseClass, Collection> result, - String[] ignoredPackages) { - for (String ignoredPackage : ignoredPackages) { - if (javaPackage.equals(ignoredPackage)) { - return; - } - } - - for (File file : parent.listFiles()) { - if (file.isDirectory()) { - findPackages(file, javaPackage + "." + file.getName(), - baseClass, result, ignoredPackages); - } else if (file.getName().endsWith(".class")) { - String fullyQualifiedClassName = javaPackage + "." - + file.getName().replace(".class", ""); - addClassIfMatches(result, fullyQualifiedClassName, baseClass); - } - } - - } - - /** - * Traverses a Jar file using the given connection and collects all classes - * which are inside the given 'javaPackage' and can be assigned to the given - * 'baseClass'. The found classes are added to 'result'. - * - * @param javaPackage - * The java package containing the classes (classes may be in a - * sub package) - * @param baseClass - * The class which the target classes extend - * @param result - * The collection to which found classes are added - * @throws IOException - */ - private static void findClassesInJar(JarURLConnection juc, - String javaPackage, Class baseClass, - Collection> result) throws IOException { - String javaPackageDir = javaPackage.replace('.', '/'); - Enumeration ent = juc.getJarFile().entries(); - while (ent.hasMoreElements()) { - JarEntry e = ent.nextElement(); - if (e.getName().endsWith(".class") - && e.getName().startsWith(javaPackageDir)) { - String fullyQualifiedClassName = e.getName().replace('/', '.') - .replace(".class", ""); - addClassIfMatches(result, fullyQualifiedClassName, baseClass); - } - } - } - - /** - * Verifies that the class represented by 'fullyQualifiedClassName' can be - * loaded, assigned to 'baseClass' and is not an abstract or anonymous - * class. - * - * @param result - * The collection to add to - * @param fullyQualifiedClassName - * The candidate class - * @param baseClass - * The class 'fullyQualifiedClassName' should be assignable to - */ - @SuppressWarnings("unchecked") - private static void addClassIfMatches( - Collection> result, - String fullyQualifiedClassName, Class baseClass) { - try { - // Try to load the class - - Class c = Class.forName(fullyQualifiedClassName); - if (!baseClass.isAssignableFrom(c)) { - return; - } - if (!includeInSuite(c)) { - return; - } - - if (!Modifier.isAbstract(c.getModifiers()) && !c.isAnonymousClass()) { - result.add((Class) c); - } - } catch (Exception e) { - // Could ignore that class cannot be loaded - e.printStackTrace(); - } catch (LinkageError e) { - // Ignore. Client side classes will at least throw LinkageErrors - } - - } - - /** - * @return true if the class should be included in the suite, false if not - */ - private static boolean includeInSuite(Class c) { - if (c.getAnnotation(ExcludeFromSuite.class) != null) { - return false; - } - - return true; + String[] ignorePackages, TB3TestLocator testLocator) + throws InitializationError { + super(klass, testLocator.findTests(baseClass, basePackage, + ignorePackages)); + setScheduler(new ParallelScheduler(service)); } } -- cgit v1.2.3 From ee6f9483f36eeeecf32730016d02fb22e5cbaab3 Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Thu, 13 Nov 2014 11:53:30 +0200 Subject: Revert "Position tooltips in the visible area (#15129)." This reverts commit aacb2f8289bc2faaab1225bd8b0dacd873d7839a. Changed causes a regression where an empty tooltip appears while the application is initialising. Change-Id: I0e0c8ae38975a2ba3835172652e4737f4bc67e6b --- client/src/com/vaadin/client/VTooltip.java | 8 -- .../vaadin/tests/components/TooltipPosition.java | 71 ---------- .../tests/components/TooltipPositionTest.java | 156 --------------------- .../tests/components/menubar/MenuTooltipTest.java | 1 - 4 files changed, 236 deletions(-) delete mode 100644 uitest/src/com/vaadin/tests/components/TooltipPosition.java delete mode 100644 uitest/src/com/vaadin/tests/components/TooltipPositionTest.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/VTooltip.java b/client/src/com/vaadin/client/VTooltip.java index 2fb5a8a293..edd1273bf5 100644 --- a/client/src/com/vaadin/client/VTooltip.java +++ b/client/src/com/vaadin/client/VTooltip.java @@ -210,10 +210,6 @@ public class VTooltip extends VOverlay { x = Window.getClientWidth() - offsetWidth - MARGIN + Window.getScrollLeft(); } - // Do not allow x to be zero, for otherwise the tooltip does - // not close when the mouse is moved (see isTooltipOpen()). - int minX = Window.getScrollLeft() + MARGIN; - x = Math.max(x, minX); return x; } @@ -249,10 +245,6 @@ public class VTooltip extends VOverlay { y = Window.getScrollTop(); } } - // Do not allow y to be zero, for otherwise the tooltip does - // not close when the mouse is moved (see isTooltipOpen()). - int minY = Window.getScrollTop() + MARGIN; - y = Math.max(y, minY); return y; } }); diff --git a/uitest/src/com/vaadin/tests/components/TooltipPosition.java b/uitest/src/com/vaadin/tests/components/TooltipPosition.java deleted file mode 100644 index d6475e0a0a..0000000000 --- a/uitest/src/com/vaadin/tests/components/TooltipPosition.java +++ /dev/null @@ -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.components; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.ui.Button; -import com.vaadin.ui.UI; -import com.vaadin.ui.VerticalLayout; - -/** - * This UI is used for testing that a tooltip is not positioned partially - * outside the browser window when there is enough space to display it. - * - * @since - * @author Vaadin Ltd - */ -public class TooltipPosition extends AbstractTestUI { - - public static final int NUMBER_OF_BUTTONS = 5; - - @Override - protected void setup(VaadinRequest request) { - // These tooltip delay settings can be removed once #13854 is resolved. - getTooltipConfiguration().setOpenDelay(0); - getTooltipConfiguration().setQuickOpenDelay(0); - getTooltipConfiguration().setCloseTimeout(1000); - - VerticalLayout layout = new VerticalLayout(); - layout.setSpacing(true); - layout.setHeight(UI.getCurrent().getPage().getBrowserWindowHeight(), - Unit.PIXELS); - addComponent(layout); - for (int i = 0; i < NUMBER_OF_BUTTONS; i++) { - Button button = new Button("Button"); - button.setDescription(generateTooltipText()); - layout.addComponent(button); - } - } - - private String generateTooltipText() { - String result = ""; - for (int i = 0; i < 50; i++) { - result += "This is the line " + i - + " of the long tooltip text.
"; - } - return result; - } - - @Override - public String getTestDescription() { - return "The tooltips of the buttons should not be clipped when there is enough space to display them."; - } - - @Override - public Integer getTicketNumber() { - return 15129; - } -} diff --git a/uitest/src/com/vaadin/tests/components/TooltipPositionTest.java b/uitest/src/com/vaadin/tests/components/TooltipPositionTest.java deleted file mode 100644 index bffc63f6c6..0000000000 --- a/uitest/src/com/vaadin/tests/components/TooltipPositionTest.java +++ /dev/null @@ -1,156 +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.components; - -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.Point; -import org.openqa.selenium.StaleElementReferenceException; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebDriver.Window; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.support.ui.ExpectedCondition; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.tests.tb3.MultiBrowserTest; - -/** - * Tests that the tooltip is positioned so that it fits in the displayed area. - * - * @since - * @author Vaadin Ltd - */ -public class TooltipPositionTest extends MultiBrowserTest { - - @Test - public void testTooltipPosition() throws Exception { - openTestURL(); - for (int i = 0; i < TooltipPosition.NUMBER_OF_BUTTONS; i++) { - ButtonElement button = $(ButtonElement.class).get(i); - // Move the mouse to display the tooltip. - Actions actions = new Actions(driver); - actions.moveToElement(button, 10, 10); - actions.build().perform(); - waitUntil(tooltipToBeInsideWindow(By.cssSelector(".v-tooltip"), - driver.manage().window())); - - if (i < TooltipPosition.NUMBER_OF_BUTTONS - 1) { - // Remove the tooltip by moving the mouse. - actions = new Actions(driver); - actions.moveByOffset(300, 0); - actions.build().perform(); - waitUntil(tooltipNotToBeShown(By.cssSelector(".v-tooltip"), - driver.manage().window())); - } - } - } - - /* - * An expectation for checking that the tooltip found by the given locator - * is present in the DOM and entirely inside the browser window. The - * coordinate of the top left corner of the window is supposed to be (0, 0). - */ - private ExpectedCondition tooltipToBeInsideWindow( - final By tooltipLocator, final Window window) { - return new ExpectedCondition() { - - @Override - public Boolean apply(WebDriver input) { - List elements = findElements(tooltipLocator); - if (elements.isEmpty()) { - return false; - } - WebElement element = elements.get(0); - try { - if (!element.isDisplayed()) { - return false; - } - Point topLeft = element.getLocation(); - int xLeft = topLeft.getX(); - int yTop = topLeft.getY(); - if (xLeft < 0 || yTop < 0) { - return false; - } - Dimension elementSize = element.getSize(); - int xRight = xLeft + elementSize.getWidth() - 1; - int yBottom = yTop + elementSize.getHeight() - 1; - Dimension browserSize = window.getSize(); - return xRight < browserSize.getWidth() - && yBottom < browserSize.getHeight(); - } catch (StaleElementReferenceException e) { - return false; - } - } - - @Override - public String toString() { - return "the tooltip to be displayed inside the window"; - } - }; - }; - - /* - * An expectation for checking that the tooltip found by the given locator - * is not shown in the window, even partially. The top left corner of window - * should have coordinates (0, 0). - */ - private ExpectedCondition tooltipNotToBeShown( - final By tooltipLocator, final Window window) { - return new ExpectedCondition() { - - @Override - public Boolean apply(WebDriver input) { - List elements = findElements(tooltipLocator); - if (elements.isEmpty()) { - return true; - } - WebElement tooltip = elements.get(0); - try { - if (!tooltip.isDisplayed()) { - return true; - } - // The tooltip is shown, at least partially, if - // its intervals of both horizontal and vertical coordinates - // overlap those of the window. - Point topLeft = tooltip.getLocation(); - Dimension tooltipSize = tooltip.getSize(); - Dimension windowSize = window.getSize(); - int xLeft = topLeft.getX(); - int yTop = topLeft.getY(); - int xRight = xLeft + tooltipSize.getWidth() - 1; - int yBottom = yTop + tooltipSize.getHeight() - 1; - boolean overlapHorizontally = !(xRight < 0 || xLeft >= windowSize - .getWidth()); - boolean overlapVertically = !(yBottom < 0 || yTop >= windowSize - .getHeight()); - return !(overlapHorizontally && overlapVertically); - } catch (StaleElementReferenceException e) { - return true; - } - } - - @Override - public String toString() { - return "the tooltip not to be displayed inside the window"; - } - - }; - } -} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuTooltipTest.java b/uitest/src/com/vaadin/tests/components/menubar/MenuTooltipTest.java index 091f7be954..24025b9f39 100644 --- a/uitest/src/com/vaadin/tests/components/menubar/MenuTooltipTest.java +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuTooltipTest.java @@ -49,7 +49,6 @@ public class MenuTooltipTest extends MultiBrowserTest { Coordinates elementCoordinates = getCoordinates($(MenuBarElement.class) .first()); - sleep(1000); Mouse mouse = ((HasInputDevices) getDriver()).getMouse(); -- cgit v1.2.3