(ns emptyhead.test.idea.crud
  (:require [cljs.test :as t :include-macros true]
            [emptyhead.idea.crud :as crud]
            [emptyhead.idea.state :as s :refer [state]]
            [emptyhead.idea.protocol :as prtc]
            [emptyhead.test.fixtures :as fx]))

(t/use-fixtures :once fx/temporary-state)
(t/use-fixtures :each fx/pre-reset)

(t/deftest have-idea!
  (t/testing "Idea creation"
    (let [idea (crud/have-idea!)]
      (t/is (get @state idea)))))

(t/deftest idea-updating
  (t/testing "Idea updating"
    (let [idea (crud/have-idea!)]
      (crud/extend-idea! idea {:foo :bar})
      (t/is (= :bar (prtc/val-fn :foo idea)))
      (crud/swap-idea! idea {:baz :quux})
      (t/is (not (prtc/val-fn :foo idea)))
      (t/is (= :quux (prtc/val-fn :baz idea)))
)))

(t/deftest forget!
  (t/testing "Idea deletion"
    (let [idea (crud/have-idea!)]
      (crud/forget-idea! idea)
      (t/is (= nil (get @state idea))))))
