View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.html;
16  
17  import org.htmlunit.SimpleWebTestCase;
18  import org.htmlunit.junit.BrowserRunner;
19  import org.htmlunit.junit.annotation.Alerts;
20  import org.htmlunit.junit.annotation.HtmlUnitNYI;
21  import org.junit.Test;
22  import org.junit.runner.RunWith;
23  
24  /**
25   * Tests for {@link HtmlMonthInput}.
26   *
27   * @author Anton Demydenko
28   * @author Ronald Brill
29   */
30  @RunWith(BrowserRunner.class)
31  public class HtmlMonthInput2Test extends SimpleWebTestCase {
32  
33      /**
34       * @throws Exception if the test fails
35       */
36      @Test
37      @Alerts({"true", "false", "true", "true", "true", "true"})
38      @HtmlUnitNYI(FF = {"true", "true", "true", "true", "true", "true"},
39              FF_ESR = {"true", "true", "true", "true", "true", "true"})
40      public void minValidation() throws Exception {
41          final String htmlContent = DOCTYPE_HTML
42                  + "<html>\n"
43                  + "<head></head>\n"
44                  + "<body>\n"
45                  + "<form id='form1'>\n"
46                  + "  <input type='month' id='first' min='2018-12'>\n"
47                  + "  <input type='month' id='second'>\n"
48                  + "  <input type='month' id='third' min='foo'>\n"
49                  + "</form>\n"
50                  + "</body></html>";
51  
52          final HtmlPage page = loadPage(htmlContent);
53  
54          final HtmlMonthInput first = (HtmlMonthInput) page.getElementById("first");
55          final HtmlMonthInput second = (HtmlMonthInput) page.getElementById("second");
56          final HtmlMonthInput third = (HtmlMonthInput) page.getElementById("third");
57  
58          // empty
59          assertEquals(getExpectedAlerts()[0], Boolean.toString(first.isValid()));
60          // lesser
61          first.setValue("2018-11");
62          assertEquals(getExpectedAlerts()[1], Boolean.toString(first.isValid()));
63          // equal
64          first.setValue("2018-12");
65          assertEquals(getExpectedAlerts()[2], Boolean.toString(first.isValid()));
66          // bigger
67          first.setValue("2018-12");
68          assertEquals(getExpectedAlerts()[3], Boolean.toString(first.isValid()));
69  
70          second.setValue("2018-11");
71          assertEquals(getExpectedAlerts()[4], Boolean.toString(second.isValid()));
72          assertTrue(second.isValid());
73          third.setValue("2018-11");
74          assertEquals(getExpectedAlerts()[5], Boolean.toString(third.isValid()));
75      }
76  
77      /**
78       * @throws Exception if the test fails
79       */
80      @Test
81      @Alerts({"true", "true", "true", "false", "true", "true"})
82      @HtmlUnitNYI(FF = {"true", "true", "true", "true", "true", "true"},
83              FF_ESR = {"true", "true", "true", "true", "true", "true"})
84      public void maxValidation() throws Exception {
85          final String htmlContent = DOCTYPE_HTML
86                  + "<html>\n"
87                  + "<head></head>\n"
88                  + "<body>\n"
89                  + "<form id='form1'>\n"
90                  + "  <input type='month' id='first' max='2018-12'>\n"
91                  + "  <input type='month' id='second'>\n"
92                  + "  <input type='month' id='third' max='foo'>\n"
93                  + "</form>\n"
94                  + "</body></html>";
95  
96          final HtmlPage page = loadPage(htmlContent);
97  
98          final HtmlMonthInput first = (HtmlMonthInput) page.getElementById("first");
99          final HtmlMonthInput second = (HtmlMonthInput) page.getElementById("second");
100         final HtmlMonthInput third = (HtmlMonthInput) page.getElementById("third");
101 
102         // empty
103         assertEquals(getExpectedAlerts()[0], Boolean.toString(first.isValid()));
104         // lesser
105         first.setValue("2018-11");
106         assertEquals(getExpectedAlerts()[1], Boolean.toString(first.isValid()));
107         // equal
108         first.setValue("2018-12");
109         assertEquals(getExpectedAlerts()[2], Boolean.toString(first.isValid()));
110         // bigger
111         first.setValue("2019-01");
112         assertEquals(getExpectedAlerts()[3], Boolean.toString(first.isValid()));
113 
114         second.setValue("2018-12");
115         assertEquals(getExpectedAlerts()[4], Boolean.toString(second.isValid()));
116         third.setValue("2018-12");
117         assertEquals(getExpectedAlerts()[5], Boolean.toString(third.isValid()));
118     }
119 }