1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import org.htmlunit.SimpleWebTestCase;
18 import org.htmlunit.junit.BrowserRunner;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21
22
23
24
25
26
27 @RunWith(BrowserRunner.class)
28 public class HtmlDateInput2Test extends SimpleWebTestCase {
29
30
31
32
33 @Test
34 public void minValidation() throws Exception {
35 final String htmlContent = DOCTYPE_HTML
36 + "<html>\n"
37 + "<head></head>\n"
38 + "<body>\n"
39 + "<form id='form1'>\n"
40 + " <input type='date' id='first' min='2018-12-01'>\n"
41 + " <input type='date' id='second'>\n"
42 + " <input type='date' id='third' min='foo'>\n"
43 + "</form>\n"
44 + "</body></html>";
45
46 final HtmlPage page = loadPage(htmlContent);
47
48 final HtmlDateInput first = (HtmlDateInput) page.getElementById("first");
49 final HtmlDateInput second = (HtmlDateInput) page.getElementById("second");
50 final HtmlDateInput third = (HtmlDateInput) page.getElementById("third");
51
52
53 assertTrue(first.isValid());
54
55 first.setValue("2018-11-01");
56 assertFalse(first.isValid());
57
58 first.setValue("2018-12-01");
59 assertTrue(first.isValid());
60
61 first.setValue("2018-12-11");
62 assertTrue(first.isValid());
63
64 second.setValue("2018-11-01");
65 assertTrue(second.isValid());
66 third.setValue("2018-11-01");
67 assertTrue(third.isValid());
68 }
69
70
71
72
73 @Test
74 public void maxValidation() throws Exception {
75 final String htmlContent = DOCTYPE_HTML
76 + "<html>\n"
77 + "<head></head>\n"
78 + "<body>\n"
79 + "<form id='form1'>\n"
80 + " <input type='date' id='first' max='2018-12-01'>\n"
81 + " <input type='date' id='second'>\n"
82 + " <input type='date' id='third' max='foo'>\n"
83 + "</form>\n"
84 + "</body></html>";
85
86 final HtmlPage page = loadPage(htmlContent);
87
88 final HtmlDateInput first = (HtmlDateInput) page.getElementById("first");
89 final HtmlDateInput second = (HtmlDateInput) page.getElementById("second");
90 final HtmlDateInput third = (HtmlDateInput) page.getElementById("third");
91
92
93 assertTrue(first.isValid());
94
95 first.setValue("2018-11-01");
96 assertTrue(first.isValid());
97
98 first.setValue("2018-12-01");
99 assertTrue(first.isValid());
100
101 first.setValue("2018-12-11");
102 assertFalse(first.isValid());
103
104 second.setValue("2018-12-01");
105 assertTrue(second.isValid());
106 third.setValue("2018-12-01");
107 assertTrue(third.isValid());
108 }
109 }