blob: 37e56949305790364af9c39e5fd4ac5d6dc92900 (
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
65
66
67
68
69
70
71
72
73
74
75
|
package com.vaadin.tests.components.datefield;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.junit.Test;
import org.openqa.selenium.ElementNotInteractableException;
import org.openqa.selenium.WebElement;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.DateTimeFieldElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
public class DateTimeFieldReadOnlyTest extends MultiBrowserTest {
@Test
public void readOnlyDateFieldPopupShouldNotOpen()
throws IOException, InterruptedException {
openTestURL();
DateTimeFieldElement df = $(DateTimeFieldElement.class).first();
WebElement dfButton = df
.findElement(By.className("v-datefield-button"));
// ensure initial read-only state works and pop-up cannot be opened
assertTrue(df.hasClassName("v-readonly"));
assertEquals("none", dfButton.getCssValue("display"));
assertTrue(findElements(By.className("v-datefield-calendarpanel"))
.isEmpty());
assertFalse(openPopup(df));
assertTrue(findElements(By.className("v-datefield-calendarpanel"))
.isEmpty());
// ensure read-only state can be removed and the component is still
// functional
toggleReadOnly();
assertFalse(df.hasClassName("v-readonly"));
assertEquals("inline-block", dfButton.getCssValue("display"));
assertTrue(openPopup(df));
assertEquals(1,
findElements(By.className("v-datefield-calendarpanel")).size());
// ensure read-only state can be re-applied, pop-up is closed and cannot
// be re-opened
toggleReadOnly();
assertTrue(df.hasClassName("v-readonly"));
assertEquals("none", dfButton.getCssValue("display"));
assertTrue(findElements(By.className("v-datefield-calendarpanel"))
.isEmpty());
assertFalse(openPopup(df));
assertTrue(findElements(By.className("v-datefield-calendarpanel"))
.isEmpty());
}
private boolean openPopup(DateTimeFieldElement df) {
// ensure the hidden button cannot be interacted with
try {
df.openPopup();
return true;
} catch (ElementNotInteractableException e) {
return false;
}
}
private void toggleReadOnly() {
$(ButtonElement.class).caption("Switch read-only").first().click();
}
}
|