 (ns frontend.test-gencard
-  (:require [cljs.test :refer-macros [is]]
+  (:require [cljs.test :refer-macros [is testing]]
             [clojure.spec :as s :include-macros true]
             [clojure.test.check.generators :as gen]
             [goog.object :as gobject])

     ".type-a { background-color: blue; }
      .type-b { background-color: green; }
      .long { color: red; }"]
    (let [data (morph-data component ::data-for-component)]
      (map component data))]))

                           [:span {:class "baz" :title "qux"}
                            "Some text."]])))))

(s/def ::data-for-component
  (s/keys :req [::type ::description]))

(s/def ::type #{:type-a :type-b})

(s/def ::description (s/and string? seq))

(defn demo-component [props]
  (html
   [:div {:class (name (::type props))}
    [:.description
     (when (< 2 (count (::description props))) {:class "long"})
     (::description props)]]))

(deftest morph-data-test
  (testing "Generates one set of data for each morph"
    (dotimes [_ 10]
      (let [data (morph-data demo-component ::data-for-component)]
        (is (every? (partial s/valid? ::data-for-component) data))
        (is (= 4 (count data)))
        (is (= 2 (count (group-by ::type data)))))))

  (testing "Returns nil when there are infinite morphs"
    (let [faulty-component #(html [:div {:class (::description %)}])]
      (is (nil? (morph-data faulty-component ::data-for-component))))))

(defcard demo
  (html
