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