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.annotation.Alerts;
19  import org.htmlunit.junit.annotation.HtmlUnitNYI;
20  import org.junit.jupiter.api.Test;
21  
22  /**
23   * Tests for {@link HtmlMonthInput}.
24   *
25   * @author Anton Demydenko
26   * @author Ronald Brill
27   */
28  public class HtmlMonthInput2Test extends SimpleWebTestCase {
29  
30      /**
31       * @throws Exception if the test fails
32       */
33      @Test
34      @Alerts({"true", "false", "true", "true", "true", "true"})
35      @HtmlUnitNYI(FF = {"true", "true", "true", "true", "true", "true"},
36              FF_ESR = {"true", "true", "true", "true", "true", "true"})
37      public void minValidation() throws Exception {
38          final String htmlContent = DOCTYPE_HTML
39                  + "<html>\n"
40                  + "<head></head>\n"
41                  + "<body>\n"
42                  + "<form id='form1'>\n"
43                  + "  <input type='month' id='first' min='2018-12'>\n"
44                  + "  <input type='month' id='second'>\n"
45                  + "  <input type='month' id='third' min='foo'>\n"
46                  + "</form>\n"
47                  + "</body></html>";
48  
49          final HtmlPage page = loadPage(htmlContent);
50  
51          final HtmlMonthInput first = (HtmlMonthInput) page.getElementById("first");
52          final HtmlMonthInput second = (HtmlMonthInput) page.getElementById("second");
53          final HtmlMonthInput third = (HtmlMonthInput) page.getElementById("third");
54  
55          // empty
56          assertEquals(getExpectedAlerts()[0], Boolean.toString(first.isValid()));
57          // lesser
58          first.setValue("2018-11");
59          assertEquals(getExpectedAlerts()[1], Boolean.toString(first.isValid()));
60          // equal
61          first.setValue("2018-12");
62          assertEquals(getExpectedAlerts()[2], Boolean.toString(first.isValid()));
63          // bigger
64          first.setValue("2018-12");
65          assertEquals(getExpectedAlerts()[3], Boolean.toString(first.isValid()));
66  
67          second.setValue("2018-11");
68          assertEquals(getExpectedAlerts()[4], Boolean.toString(second.isValid()));
69          assertTrue(second.isValid());
70          third.setValue("2018-11");
71          assertEquals(getExpectedAlerts()[5], Boolean.toString(third.isValid()));
72      }
73  
74      /**
75       * @throws Exception if the test fails
76       */
77      @Test
78      @Alerts({"true", "true", "true", "false", "true", "true"})
79      @HtmlUnitNYI(FF = {"true", "true", "true", "true", "true", "true"},
80              FF_ESR = {"true", "true", "true", "true", "true", "true"})
81      public void maxValidation() throws Exception {
82          final String htmlContent = DOCTYPE_HTML
83                  + "<html>\n"
84                  + "<head></head>\n"
85                  + "<body>\n"
86                  + "<form id='form1'>\n"
87                  + "  <input type='month' id='first' max='2018-12'>\n"
88                  + "  <input type='month' id='second'>\n"
89                  + "  <input type='month' id='third' max='foo'>\n"
90                  + "</form>\n"
91                  + "</body></html>";
92  
93          final HtmlPage page = loadPage(htmlContent);
94  
95          final HtmlMonthInput first = (HtmlMonthInput) page.getElementById("first");
96          final HtmlMonthInput second = (HtmlMonthInput) page.getElementById("second");
97          final HtmlMonthInput third = (HtmlMonthInput) page.getElementById("third");
98  
99          // empty
100         assertEquals(getExpectedAlerts()[0], Boolean.toString(first.isValid()));
101         // lesser
102         first.setValue("2018-11");
103         assertEquals(getExpectedAlerts()[1], Boolean.toString(first.isValid()));
104         // equal
105         first.setValue("2018-12");
106         assertEquals(getExpectedAlerts()[2], Boolean.toString(first.isValid()));
107         // bigger
108         first.setValue("2019-01");
109         assertEquals(getExpectedAlerts()[3], Boolean.toString(first.isValid()));
110 
111         second.setValue("2018-12");
112         assertEquals(getExpectedAlerts()[4], Boolean.toString(second.isValid()));
113         third.setValue("2018-12");
114         assertEquals(getExpectedAlerts()[5], Boolean.toString(third.isValid()));
115     }
116 }