1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package com.vaadin.v7.tests.components.grid;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.vaadin.testbench.parallel.BrowserUtil;
import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
@SuppressWarnings("boxing")
@TestCategory("grid")
public abstract class AbstractGridColumnAutoWidthTest extends MultiBrowserTest {
public static final int TOTAL_MARGIN_PX = 21;
@Before
public void before() {
openTestURL();
}
@Test
public void testNarrowHeaderWideBody() {
WebElement[] col = getColumn(1);
int headerWidth = col[0].getSize().getWidth();
int bodyWidth = col[1].getSize().getWidth();
int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX;
assertLessThan("header should've been narrower than body", headerWidth,
bodyWidth);
assertEquals("column should've been roughly as wide as the body",
bodyWidth, colWidth, 5);
}
@Test
public void testWideHeaderNarrowBody() {
WebElement[] col = getColumn(2);
int headerWidth = col[0].getSize().getWidth();
int bodyWidth = col[1].getSize().getWidth();
int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX;
assertGreater("header should've been wider than body", headerWidth,
bodyWidth);
assertEquals("column should've been roughly as wide as the header",
headerWidth, colWidth, 5);
}
@Test
public void testTooNarrowColumn() {
if (BrowserUtil.isIE(getDesiredCapabilities())) {
// IE can't deal with overflow nicely.
return;
}
WebElement[] col = getColumn(3);
int headerWidth = col[0].getSize().getWidth();
int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX;
assertLessThan("column should've been narrower than content", colWidth,
headerWidth);
}
@Test
public void testTooWideColumn() {
WebElement[] col = getColumn(4);
int headerWidth = col[0].getSize().getWidth();
int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX;
assertGreater("column should've been wider than content", colWidth,
headerWidth);
}
@Test
public void testColumnsRenderCorrectly() throws IOException {
compareScreen("initialRender");
}
private WebElement[] getColumn(int i) {
WebElement[] col = new WebElement[3];
col[0] = getDriver().findElement(
By.xpath("//thead//th[" + (i + 1) + "]/div[1]/span"));
col[1] = getDriver()
.findElement(By.xpath("//tbody//td[" + (i + 1) + "]//span"));
col[2] = getDriver()
.findElement(By.xpath("//tbody//td[" + (i + 1) + "]"));
return col;
}
}
|