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