/**
 * Copyright (C) 2014-2015 Philip Helger (www.helger.com)
 * philip[at]helger[dot]com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.helger.photon.uictrls.autonumeric;

import static org.junit.Assert.assertEquals;

import java.util.Locale;

import org.junit.Rule;
import org.junit.Test;

import com.helger.commons.system.ENewLineMode;
import com.helger.html.EHTMLVersion;
import com.helger.html.hc.conversion.HCConversionSettings;
import com.helger.html.hc.html.HCDiv;
import com.helger.html.hc.render.HCRenderer;
import com.helger.photon.core.form.RequestField;
import com.helger.photon.core.mock.PhotonCoreTestRule;

public final class HCAutoNumericTest
{
  private static final String CRLF = ENewLineMode.DEFAULT.getText ();

  @Rule
  public final PhotonCoreTestRule m_aRule = new PhotonCoreTestRule ();

  @Test
  public void testGetJS ()
  {
    final HCAutoNumeric a = new HCAutoNumeric (new RequestField ("dummy"), Locale.GERMANY);
    final String sID = a.getID ();
    assertEquals ("<input id=\"" +
                  sID +
                  "\" class=\"auto-numeric-edit\" name=\"dummy\" type=\"text\" value=\"\" />" +
                  CRLF,
                  HCRenderer.getAsHTMLString (a, new HCConversionSettings (EHTMLVersion.HTML5)));

    a.setThousandSeparator ("");
    assertEquals ("<input id=\"" +
                  sID +
                  "\" class=\"auto-numeric-edit\" name=\"dummy\" type=\"text\" value=\"\" />" +
                  CRLF,
                  HCRenderer.getAsHTMLString (a, new HCConversionSettings (EHTMLVersion.HTML5)));
  }

  @Test
  public void testAddAndRemove ()
  {
    final HCAutoNumeric a = new HCAutoNumeric (new RequestField ("dummy"), Locale.GERMANY);
    final HCDiv aDiv = new HCDiv ();
    assertEquals (0, aDiv.getChildCount ());
    // Add the auto numeric which also adds the JS
    aDiv.addChild (a);
    assertEquals (2, aDiv.getChildCount ());
    // Remove the auto numeric should also remove the JS
    aDiv.removeChild (a);
    assertEquals (0, aDiv.getChildCount ());
  }
}

@@ -814,16 +814,83 @@
 it.Test;
+%0Aimport org.junit.rules.RuleChain;%0Aimport org.junit.rules.TestRule;
 %0A%0Aimport
@@ -971,67 +971,8 @@
 on;%0A
-import com.helger.html.hc.conversion.HCConversionSettings;%0A
 impo
@@ -1050,16 +1050,116 @@
 nderer;%0A
+import com.helger.html.mock.HCTestRuleHTMLVersion;%0Aimport com.helger.html.mock.HCTestRuleOptimized;%0A
 import c
@@ -1388,26 +1388,16 @@
 c final 
-PhotonCore
 TestRule
@@ -1407,16 +1407,37 @@
 aRule = 
+RuleChain.outerRule (
 new Phot
@@ -1453,16 +1453,197 @@
 tRule ()
+)%0A                                           .around (new HCTestRuleOptimized ())%0A                                           .around (new HCTestRuleHTMLVersion (EHTMLVersion.HTML5))
 ;%0A%0A  @Te
@@ -1972,33 +1972,34 @@
             CRLF
-,
+ +
 %0A               
@@ -2005,121 +2005,537 @@
     
-HCRenderer.getAsHTMLString (a, new HCConversionSettings (EHTMLVersion.HTML5)));%0A%0A    a.setThousandSeparator (%22%22);
+%22%3Cscript type=%5C%22text/javascript%5C%22%3E$(document).ready(function()%7B$('#id10001').autoNumeric('init',%7B%22 +%0A                  CRLF +%0A                  %22  aSep:'.',%22 +%0A                  CRLF +%0A                  %22  aDec:',',%22 +%0A                  CRLF +%0A                  %22  vMin:'-999999999'%22 +%0A                  CRLF +%0A                  %22%7D);%7D);%3C/script%3E%22 +%0A                  CRLF,%0A                  HCRenderer.getAsHTMLString (a));%0A%0A    a.setThousandSeparator (%22%22);%0A    // Script is not emitted afterwards, because it was already emitted
 %0A   
@@ -2761,55 +2761,8 @@
 g (a
-, new HCConversionSettings (EHTMLVersion.HTML5)
 ));%0A
@@ -2800,20 +2800,20 @@
 AddAndRe
-move
+nder
  ()%0A  %7B%0A
@@ -3078,17 +3078,17 @@
 Equals (
-2
+1
 , aDiv.g
@@ -3116,81 +3116,58 @@
  // 
-Remove the auto numeric should also remove the JS%0A    aDiv.removeChild (a
+Add the script node%0A    HCRenderer.getAsNode (aDiv
 );%0A 
@@ -3175,33 +3175,33 @@
   assertEquals (
-0
+2
 , aDiv.getChildC

Test fix