Skip to content

Commit

Permalink
Port ItemClickEvents test from TB2 to TB4
Browse files Browse the repository at this point in the history
Change-Id: Ib67ee073a683167753e1cd83922e9027df9ffe6e
  • Loading branch information
thevaadinman authored and Vaadin Code Review committed Jun 26, 2015
1 parent bd41cf7 commit 579d08c
Show file tree
Hide file tree
Showing 4 changed files with 408 additions and 488 deletions.
29 changes: 20 additions & 9 deletions uitest/src/com/vaadin/tests/components/table/ItemClickEvents.java
Expand Up @@ -5,7 +5,8 @@
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.server.ExternalResource;
import com.vaadin.tests.components.TestBase;
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;
Expand All @@ -15,14 +16,20 @@
import com.vaadin.ui.Table;
import com.vaadin.ui.Tree;

public class ItemClickEvents extends TestBase {
public class ItemClickEvents extends AbstractTestUI {

Tree tree = new Tree();
Table table = new Table();
Log log = new Log(5);
private Tree tree;
private Table table;
private Log log;

@Override
public void setup() {
@SuppressWarnings("unchecked")
protected void setup(VaadinRequest request) {

tree = new Tree();
table = new Table();
log = new Log(5);

log.setId("log");

HorizontalLayout ol = createHorizontalLayout(tree);
Expand Down Expand Up @@ -51,9 +58,11 @@ public void buttonClick(ClickEvent event) {
tree.setParent("2. Child 1", "Root 2");
tree.addItem("2. Child 2");
tree.setParent("2. Child 2", "Root 2");
tree.addContainerProperty("icon", ExternalResource.class,
tree.addContainerProperty(
"icon",
ExternalResource.class,
new ExternalResource(
"http://www.itmill.com/res/images/itmill_logo.gif"));
"https://vaadin.com/vaadin-theme/images/vaadin-logo.png"));

tree.addListener(new ItemClickListener() {
@Override
Expand Down Expand Up @@ -104,6 +113,8 @@ protected void logEvent(ItemClickEvent event, String targetComponent) {

String modifiers = "";
if (event.isAltKey()) {
// Most likely won't trigger on Linux due to WMs using alt + mouse
// button
modifiers += "alt ";
}
if (event.isMetaKey()) {
Expand Down Expand Up @@ -145,7 +156,7 @@ private static HorizontalLayout createHorizontalLayout(Component c) {
}

@Override
protected String getDescription() {
protected String getTestDescription() {
return "Click events should always come trough no matter how the table is configured.";
}

Expand Down
180 changes: 180 additions & 0 deletions uitest/src/com/vaadin/tests/components/table/ItemClickEventsTest.java
@@ -0,0 +1,180 @@
/*
* 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.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elements.CheckBoxElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.testbench.elements.TableElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class ItemClickEventsTest extends MultiBrowserTest {

@Before
public void init() {
openTestURL("restartApplication");
}

private void clickElement(TestBenchElement e) {
assertNotNull(e);
e.click(5, 5);
}

private void doubleClickElement(TestBenchElement e) {
assertNotNull(e);
e.doubleClick();
}

private void assertLog(String compare) {
LabelElement logRow = $(LabelElement.class).id("Log_row_0");
assertNotNull(logRow);
assertTrue(logRow.getText().contains(compare));
}

private void assertSelected(TestBenchElement e) {
assertNotNull(e);
assertTrue(hasCssClass(e, "v-selected"));
}

@Test
public void testSingleSelectNull() throws Exception {

// Activate table null selection mode
clickElement($(CheckBoxElement.class).caption("nullsel").get(1));

// Get at the table element
TableElement table = $(TableElement.class).id("table");

// Select the first item
clickElement(table.getRow(0));
assertLog("left click on table/Item 0");

// Do it again
clickElement(table.getRow(0));
assertLog("left click on table/Item 0");

// Select the sixth item
clickElement(table.getRow(5));
assertLog("left click on table/Item 5");

// Double click the sixth item
doubleClickElement(table.getRow(5));
assertLog("doubleClick on table/Item 5");
}

@Test
public void testSingleSelectNotNull() throws Exception {
// Get reference to table
TableElement table = $(TableElement.class).id("table");

// Select first item in list
clickElement(table.getRow(0));
assertSelected(table.getRow(0));

// Check that the log contains "clicked item 0"
assertLog("left click on table/Item 0");

// Click on second item in list
clickElement(table.getRow(1));

// Make sure it got selected
assertSelected(table.getRow(1));

// Check log output
assertLog("left click on table/Item 1");

// Click row 1 again
clickElement(table.getRow(1));
assertLog("left click on table/Item 1");

// Test double click
doubleClickElement(table.getRow(1));
// kludge: testbench seems to send an extra click; that doesn't affect
// our test too much, though, and can be ignored.
assertLog("doubleClick on table/Item 1");

// Double click first item
doubleClickElement(table.getRow(0));
assertLog("doubleClick on table/Item 0");

// Make sure it got selected again
assertSelected(table.getRow(0));
}

@Test
public void testSingleSelectNotSelectable() throws Exception {

// Remove the 'selectable' mode from Table
$(CheckBoxElement.class).caption("selectable").get(1).click();

// Get table element
TableElement table = $(TableElement.class).id("table");

// Click some items and check that clicks go through
clickElement(table.getCell(0, 0));
assertLog("left click on table/Item 0");

clickElement(table.getCell(5, 0));
assertLog("left click on table/Item 5");

clickElement(table.getCell(2, 0));
assertLog("left click on table/Item 2");

clickElement(table.getCell(8, 0));
assertLog("left click on table/Item 8");

clickElement(table.getCell(1, 0));
assertLog("left click on table/Item 1");

clickElement(table.getCell(0, 0));
assertLog("left click on table/Item 0");

}

@Test
public void testNonImmediateSingleSelectable() throws Exception {

// Disable table immediate mode
clickElement($(CheckBoxElement.class).caption("immediate").get(1));

// Get table element
TableElement table = $(TableElement.class).id("table");

// Click items and verify that click event went through
clickElement(table.getCell(1, 0));
assertLog("left click on table/Item 1");

clickElement(table.getCell(8, 0));
assertLog("left click on table/Item 8");

clickElement(table.getCell(1, 0));
assertLog("left click on table/Item 1");

clickElement(table.getCell(0, 0));
assertLog("left click on table/Item 0");

clickElement(table.getCell(6, 0));
assertLog("left click on table/Item 6");

}

}

0 comments on commit 579d08c

Please sign in to comment.