 
 (defonce index-page-template (load-template "public/index.html"))
 
-(defn setup-index-page! []
-  (tu/set-html! index-page-template))
-
 (def email-of-length-255
   (str (tu/string-of-length 251) "@x.y"))
 

(def too-short-password "short")
(def too-long-password (tu/string-of-length 255))

(defn invalid-password-state! []
  (tu/enter-text (rfd/input-selector :registration-password) blank-string)
  (tu/lose-focus (rfd/input-selector :registration-password)))

(deftest on-input
         (setup-index-page!)
         (app/start)
         (testing "inputing text in first name field will cause field invalid class to disappear"
                  (dom/add-class! (rfd/form-row-selector :registration-first-name) rfd/field-invalid-class)
                  (tu/enter-text (rfd/input-selector :registration-first-name) valid-name)
                  (tu/test-field-doesnt-have-class (rfd/form-row-selector :registration-first-name) rfd/field-invalid-class))
         (testing "inputing text in last name field will cause field invalid class to disappear"
                  (dom/add-class! (rfd/form-row-selector :registration-last-name) rfd/field-invalid-class)
                  (tu/enter-text (rfd/input-selector :registration-last-name) valid-name)
                  (tu/test-field-doesnt-have-class (rfd/form-row-selector :registration-last-name) rfd/field-invalid-class))
         (testing "inputing text in email address field will cause field invalid class to disappear"
                  (dom/add-class! (rfd/form-row-selector :registration-email) rfd/field-invalid-class)
                  (tu/enter-text (rfd/input-selector :registration-email) valid-email)
                  (tu/test-field-doesnt-have-class (rfd/form-row-selector :registration-email) rfd/field-invalid-class))

         (testing "password"
                  (testing "- inputing valid password causes field valid class to appear"
                           (tu/test-field-doesnt-have-class (rfd/form-row-selector :registration-password) rfd/field-valid-class)
                           (tu/enter-text (rfd/input-selector :registration-password) valid-password)
                           (tu/test-field-has-class (rfd/form-row-selector :registration-password) rfd/field-valid-class))
                  (testing "- from valid password to invalid password causes field valid class to disappear"
                           (tu/test-field-has-class (rfd/form-row-selector :registration-password) rfd/field-valid-class)
                           (tu/enter-text (rfd/input-selector :registration-password) too-short-password)
                           (tu/test-field-doesnt-have-class (rfd/form-row-selector :registration-password) rfd/field-valid-class))
                  (testing "- from invalid password to valid password causes field valid class to appear and field invalid class to disappear"
                           (dom/add-class! (rfd/form-row-selector :registration-password) rfd/field-invalid-class)
                           (dom/remove-class! (rfd/form-row-selector :registration-password) rfd/field-valid-class)
                           (tu/enter-text (rfd/input-selector :registration-password) valid-password)
                           (tu/test-field-doesnt-have-class (rfd/form-row-selector :registration-password) rfd/field-invalid-class)
                           (tu/test-field-has-class (rfd/form-row-selector :registration-password) rfd/field-valid-class))



(deftest losing-focus
         (testing "first-name"
                  (testing "- losing focus when blank adds invalid field class and validation message"
                           (clean-setup!)
                           (tu/lose-focus (rfd/input-selector :registration-first-name))
                           (check-first-name-has-blank-validation-errors))

                  (testing "- losing focus when too-long adds invalid field class and validation message"
                           (clean-setup!)
                           (tu/set-value (rfd/input-selector :registration-first-name) too-long-name)
                           (tu/lose-focus (rfd/input-selector :registration-first-name))
                           (tu/test-field-has-class (rfd/form-row-selector :registration-first-name) rfd/field-invalid-class)
                           (tu/element-has-text (rfd/validation-selector :registration-first-name)
                                                (get-in dom/translations [:index :register-first-name-too-long-validation-message])))

                  (testing "- losing focus when valid removes invalid field class and there is novalidation message"
                           (clean-setup!)
                           (dom/add-class! (rfd/form-row-selector :registration-first-name) rfd/field-invalid-class)
                           (tu/set-value (rfd/input-selector :registration-first-name) valid-name)
                           (tu/lose-focus (rfd/input-selector :registration-first-name))

                           (tu/test-field-doesnt-have-class (rfd/form-row-selector :registration-first-name) rfd/field-invalid-class)
                           (tu/element-has-no-text (rfd/validation-selector :registration-first-name))))

         (testing "last-name"
                  (testing "- losing focus when blank adds invalid field class and validation message"
                           (clean-setup!)
                           (tu/lose-focus (rfd/input-selector :registration-last-name))
                           (check-last-name-has-blank-validation-errors))

                  (testing "- losing focus when too-long adds invalid field class and validation message"
                           (clean-setup!)
                           (tu/set-value (rfd/input-selector :registration-last-name) too-long-name)
                           (tu/lose-focus (rfd/input-selector :registration-last-name))
                           (tu/test-field-has-class (rfd/form-row-selector :registration-last-name) rfd/field-invalid-class)
                           (tu/element-has-text (rfd/validation-selector :registration-last-name)
                                                  (get-in dom/translations [:index :register-last-name-too-long-validation-message])))

                  (testing "- losing focus when valid removes invalid field class and there is no validation message"
                           (clean-setup!)
                           (dom/add-class! (rfd/form-row-selector :registration-last-name) rfd/field-invalid-class)
                           (tu/set-value (rfd/input-selector :registration-last-name) valid-name)
                           (tu/lose-focus (rfd/input-selector :registration-last-name))

