                       (th/test-translations "index page" (constantly page)))))
 
        (fact "when password is too long"
-             (let [long-password (apply str (repeat 255 "x"))
+             (let [long-password (string-of-length 255)
                    errors {:sign-in-password :too-long}
                    params {:sign-in-password long-password}
                    page (-> (th/create-request {} errors params) index)]

                (fact "correct error message is displayed"
                      (html/select page [[:.clj--registration-email__validation (html/attr= :data-l8n error-translation)]]) =not=> empty?)
                (fact "invalid value is preserved in input field"
                      (-> page (html/select [:.clj--registration-email__input]) first :attrs :value) => "invalidEmail")
                (fact "there are no missing translations"
                      (th/test-translations "index page" (constantly page)))))

       (facts "when email is a duplicate"
              (let [errors {:registration-email :duplicate}
                    params {:registration-email "valid@email.com"}
                    page (-> (th/create-request {} errors params) index)
                    error-translation "content:index/register-email-address-duplicate-validation-message"]
                (fact "validation summary includes the error message"
                      (html/select page [[:.clj--registration-validation-summary__item (html/attr= :data-l8n error-translation)]]) =not=> empty?)
                (fact "the class for styling errors is added"
                      (html/select page [[:.clj--registration-email :.form-row--invalid]]) =not=> empty?)
                (fact "email validation element is present"
                      (html/select page [:.clj--registration-email__validation]) =not=> empty?)
                (fact "correct error message is displayed"
                      (html/select page [[:.clj--registration-email__validation (html/attr= :data-l8n error-translation)]]) =not=> empty?)
                (fact "duplicate email is preserved"
                      (-> page (html/select [:.clj--registration-email__input]) first :attrs :value) => "valid@email.com")
                (fact "there are no missing translations"
                      (th/test-translations "index page" (constantly page)))))

       (facts "when email is too long"
              (let [long-email-address (apply str (repeat 255 "x"))
                    errors {:registration-email :too-long}
                    params {:registration-email long-email-address}
                    page (-> (th/create-request {} errors params) index)
                    error-translation "content:index/register-email-address-too-long-validation-message"]
                (fact "validation summary includes the error message"
                      (html/select page [[:.clj--registration-validation-summary__item (html/attr= :data-l8n error-translation)]]) =not=> empty?)
                (fact "the class for styling errors is added"
                      (html/select page [[:.clj--registration-email :.form-row--invalid]]) =not=> empty?)
                (fact "email validation element is present"
                      (html/select page [:.clj--registration-email__validation]) =not=> empty?)
                (fact "correct error message is displayed"
                      (html/select page [[:.clj--registration-email__validation (html/attr= :data-l8n error-translation)]]) =not=> empty?)
                (fact "there are no missing translations"
                      (th/test-translations "index page" (constantly page)))))

       (fact "when password is blank"
             (let [errors {:registration-password :blank}
                   params {:registration-password ""}
                   page (-> (th/create-request {} errors params) index)
                   error-translation "content:index/register-password-blank-validation-message"]
               (fact "validation summary includes the error message"
                     (html/select page [[:.clj--registration-validation-summary__item (html/attr= :data-l8n error-translation)]]) =not=> empty?)
               (fact "the class for styling errors is added"
                     (html/select page [[:.clj--registration-password :.form-row--invalid]]) =not=> empty?)
               (fact "password validation element is present"
                     (html/select page [:.clj--registration-password__validation]) =not=> empty?)
               (fact "correct error message is displayed"
                     (html/select page [[:.clj--registration-password__validation (html/attr= :data-l8n error-translation)]]) =not=> empty?)
               (fact "there are no missing translations"
                      (th/test-translations "index page" (constantly page)))))

       (fact "when password is too short"
             (let [errors {:registration-password :too-short}
                   params {:registration-password "short"}
                   page (-> (th/create-request {} errors params) index)
                   error-translation "content:index/register-password-too-short-validation-message"]
               (fact "validation summary includes the error message"
                     (html/select page [[:.clj--registration-validation-summary__item (html/attr= :data-l8n error-translation)]]) =not=> empty?)
               (fact "the class for styling errors is added"
                     (html/select page [[:.clj--registration-password :.form-row--invalid]]) =not=> empty?)
               (fact "password validation element is present"
                     (html/select page [:.clj--registration-password__validation]) =not=> empty?)
               (fact "correct error message is displayed"
                     (html/select page [[:.clj--registration-password__validation (html/attr= :data-l8n error-translation)]]) =not=> empty?)
               (fact "there are no missing translations"
                     (th/test-translations "index page" (constantly page)))))

       (fact "when password is too long"
             (let [long-password (apply str (repeat 255 "x"))
                   errors {:registration-password :too-long}
                   params {:registration-password long-password}
                   page (-> (th/create-request {} errors params) index)
                   error-translation "content:index/register-password-too-long-validation-message"]
               (fact "validation summary includes the error message"
                     (html/select page [[:.clj--registration-validation-summary__item (html/attr= :data-l8n error-translation)]]) =not=> empty?)
               (fact "the class for styling errors is added"
                     (html/select page [[:.clj--registration-password :.form-row--invalid]]) =not=> empty?)
               (fact "password validation element is present"
                     (html/select page [:.clj--registration-password__validation]) =not=> empty?)
               (fact "correct error message is displayed"
                     (html/select page [[:.clj--registration-password__validation (html/attr= :data-l8n error-translation)]]) =not=> empty?)
               (fact "there are no missing translations"
                     (th/test-translations "index page" (constantly page))))))

            [stonecutter.test.view.test-helpers :as th]
            [stonecutter.view.index :refer [index]]))

(defn string-of-length [n]
  (apply str (repeat n "x")))

(facts "about index page"
       (let [page (-> (th/create-request) index)]
