blob: 5b814f0856c9cc5e0d8c8322c8ca4374198e5f2f (
plain)
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
|
package com.vaadin.tests.components.datefield;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
public class DisabledInlineDateFieldTest extends MultiBrowserTest {
@Test
public void testDisabled() {
openTestURL();
testNextMonthControls(".v-disabled");
testDaySelection(".v-disabled");
}
@Test
public void testReadOnly() {
openTestURL();
testNextMonthControls(".v-readonly");
testDaySelection(".v-readonly");
}
private void testNextMonthControls(String cssClass) {
// Get the currently selected month.
String expectedMonth = getSelectedMonth(cssClass);
// Attempt to click the next month button.
driver.findElement(By.cssSelector(cssClass + " .v-button-nextmonth"))
.click();
// Assert that we did not navigate to next month.
String actualMonth = getSelectedMonth(cssClass);
assertEquals(expectedMonth, actualMonth);
}
private void testDaySelection(String cssClass) {
// We know that the first day element is not selected, because of the
// fixed date in the test.
WebElement nonSelectedDay = driver.findElement(By.cssSelector(
cssClass + " .v-inline-datefield-calendarpanel-day"));
// Assert it is not selected before click.
assertFalse(nonSelectedDay.getAttribute("class").contains("selected"));
// Click on the non-selected day.
nonSelectedDay.click();
// Assert that clicking did not select the day.
assertFalse(nonSelectedDay.getAttribute("class").contains("selected"));
}
private String getSelectedMonth(String selectorPrefix) {
return driver
.findElement(By.cssSelector(selectorPrefix
+ " .v-inline-datefield-calendarpanel-month"))
.getText();
}
}
|