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 HtmlWeekInput}.
24   *
25   * @author Anton Demydenko
26   * @author Ronald Brill
27   */
28  public class HtmlWeekInput2Test 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='week' id='first' min='2018-W10'>\n"
44                  + "  <input type='week' id='second'>\n"
45                  + "  <input type='week' id='third' min='foo'>\n"
46                  + "</form>\n"
47                  + "</body></html>";
48  
49          final HtmlPage page = loadPage(htmlContent);
50  
51          final HtmlWeekInput first = (HtmlWeekInput) page.getElementById("first");
52          final HtmlWeekInput second = (HtmlWeekInput) page.getElementById("second");
53          final HtmlWeekInput third = (HtmlWeekInput) page.getElementById("third");
54  
55          // empty
56          assertEquals(getExpectedAlerts()[0], Boolean.toString(first.isValid()));
57          // lesser
58          first.setValue("2018-W09");
59          assertEquals(getExpectedAlerts()[1], Boolean.toString(first.isValid()));
60          // equal
61          first.setValue("2018-W10");
62          assertEquals(getExpectedAlerts()[2], Boolean.toString(first.isValid()));
63          // bigger
64          first.setValue("2018-W11");
65          assertEquals(getExpectedAlerts()[3], Boolean.toString(first.isValid()));
66  
67          second.setValue("2018-W10");
68          assertEquals(getExpectedAlerts()[4], Boolean.toString(second.isValid()));
69          third.setValue("2018-W10");
70          assertEquals(getExpectedAlerts()[5], Boolean.toString(third.isValid()));
71      }
72  
73      /**
74       * @throws Exception if the test fails
75       */
76      @Test
77      @Alerts({"true", "true", "true", "false", "true", "true"})
78      @HtmlUnitNYI(FF = {"true", "true", "true", "true", "true", "true"},
79              FF_ESR = {"true", "true", "true", "true", "true", "true"})
80      public void naxValidation() throws Exception {
81          final String htmlContent = DOCTYPE_HTML
82                  + "<html>\n"
83                  + "<head></head>\n"
84                  + "<body>\n"
85                  + "<form id='form1'>\n"
86                  + "  <input type='week' id='first' max='2018-W10'>\n"
87                  + "  <input type='week' id='second'>\n"
88                  + "  <input type='week' id='third' max='foo'>\n"
89                  + "</form>\n"
90                  + "</body></html>";
91  
92          final HtmlPage page = loadPage(htmlContent);
93  
94          final HtmlWeekInput first = (HtmlWeekInput) page.getElementById("first");
95          final HtmlWeekInput second = (HtmlWeekInput) page.getElementById("second");
96          final HtmlWeekInput third = (HtmlWeekInput) page.getElementById("third");
97  
98          // empty
99          assertEquals(getExpectedAlerts()[0], Boolean.toString(first.isValid()));
100         // lesser
101         first.setValue("2018-W09");
102         assertEquals(getExpectedAlerts()[1], Boolean.toString(first.isValid()));
103         // equal
104         first.setValue("2018-W10");
105         assertEquals(getExpectedAlerts()[2], Boolean.toString(first.isValid()));
106         // bigger
107         first.setValue("2018-W11");
108         assertEquals(getExpectedAlerts()[3], Boolean.toString(first.isValid()));
109 
110         second.setValue("2018-W10");
111         assertEquals(getExpectedAlerts()[4], Boolean.toString(second.isValid()));
112         third.setValue("2018-W10");
113         assertEquals(getExpectedAlerts()[5], Boolean.toString(third.isValid()));
114     }
115 }