 
 (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"))
 

                  (tu/has-focus? (rfd/input-selector :registration-last-name)))

         (testing "submitting form with only valid first-name and last-name"
                  (tu/enter-text (rfd/input-selector :registration-last-name) valid-name)
                  (tu/press-submit rfd/register-form-element-selector)
                  (check-email-address-has-invalid-validation-errors)
                  (check-password-has-blank-validation-errors)
                  (tu/has-focus? (rfd/input-selector :registration-email)))

         (testing "submitting form with only valid first-name, last-name and email-address"
                  (tu/enter-text (rfd/input-selector :registration-email) valid-email)
                  (tu/press-submit rfd/register-form-element-selector)
                  (check-password-has-blank-validation-errors)
                  (tu/has-focus? (rfd/input-selector :registration-password))))

(defn default-state [] (atom rfc/default-state))

(deftest prevent-default-submit
         (setup-index-page!)
         (app/start)

         (testing "prevents default when page has errors"
                  (let [submit-event (tu/create-event :submit)]
                    (rfc/block-invalid-submit (default-state) submit-event)
                    (tu/default-prevented? submit-event true)))

         (testing "doesn't prevent default when inputs are valid"
                  (let [submit-event (tu/create-event :submit)]
                    (tu/enter-text (rfd/input-selector :registration-first-name) valid-name)
                    (tu/enter-text (rfd/input-selector :registration-last-name) valid-name)
                    (tu/enter-text (rfd/input-selector :registration-email) valid-email)
                    (tu/enter-text (rfd/input-selector :registration-password) valid-password)
                    (rfc/block-invalid-submit (default-state) submit-event)
                    (testing "all error classes are removed"
                             (tu/test-field-doesnt-have-class (rfd/form-row-selector :registration-first-name) rfd/field-invalid-class)
                             (tu/test-field-doesnt-have-class (rfd/form-row-selector :registration-last-name) rfd/field-invalid-class)


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

                  (testing "- losing focus when too-long adds invalid field class and validation message"
                           (clean-setup!)
                           (tu/set-value (rfd/input-selector :registration-email) too-long-email)
                           (tu/lose-focus (rfd/input-selector :registration-email))
                           (tu/test-field-has-class (rfd/form-row-selector :registration-email) rfd/field-invalid-class)
                           (tu/element-has-text (rfd/validation-selector :registration-email)
                                                  (get-in dom/translations [:index :register-email-address-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-email) rfd/field-invalid-class)
                           (tu/set-value (rfd/input-selector :registration-email) valid-email)
                           (tu/lose-focus (rfd/input-selector :registration-email))

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

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

                  (testing "- losing focus when too short adds invalid field class and validation message"
                           (clean-setup!)
                           (tu/set-value (rfd/input-selector :registration-password) too-short-password)
                           (tu/lose-focus (rfd/input-selector :registration-password))
                           (tu/test-field-has-class (rfd/form-row-selector :registration-password) rfd/field-invalid-class)
