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 HtmlTimeInput2Test 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='time' id='first' min='09:00'>\n"
38 + " <input type='time' id='second'>\n"
39 + " <input type='time' id='third' min='foo'>\n"
40 + "</form>\n"
41 + "</body></html>";
42
43 final HtmlPage page = loadPage(htmlContent);
44
45 final HtmlTimeInput first = (HtmlTimeInput) page.getElementById("first");
46 final HtmlTimeInput second = (HtmlTimeInput) page.getElementById("second");
47 final HtmlTimeInput third = (HtmlTimeInput) page.getElementById("third");
48
49
50 assertTrue(first.isValid());
51
52 first.setValue("08:00");
53 assertFalse(first.isValid());
54
55 first.setValue("09:00");
56 assertTrue(first.isValid());
57
58 first.setValue("10:00");
59 assertTrue(first.isValid());
60
61 second.setValue("09:00");
62 assertTrue(second.isValid());
63 third.setValue("09:00");
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='time' id='first' max='09:00'>\n"
78 + " <input type='time' id='second'>\n"
79 + " <input type='time' id='third' max='foo'>\n"
80 + "</form>\n"
81 + "</body></html>";
82
83 final HtmlPage page = loadPage(htmlContent);
84
85 final HtmlTimeInput first = (HtmlTimeInput) page.getElementById("first");
86 final HtmlTimeInput second = (HtmlTimeInput) page.getElementById("second");
87 final HtmlTimeInput third = (HtmlTimeInput) page.getElementById("third");
88
89
90 assertTrue(first.isValid());
91
92 first.setValue("08:00");
93 assertTrue(first.isValid());
94
95 first.setValue("09:00");
96 assertTrue(first.isValid());
97
98 first.setValue("10:00");
99 assertFalse(first.isValid());
100
101 second.setValue("09:00");
102 assertTrue(second.isValid());
103 third.setValue("09:00");
104 assertTrue(third.isValid());
105 }
106 }