    :timestamp      1465059173965
    :md             "Moving to #cljc"})
 
+(def state-from-backend
+  {:entries [test-entry st/some-test-entry]
+   :linked-entries-list []
+   :hashtags            #{"#drama" "#hashtag" "#blah"}
+   :mentions            #{"@myself" "@me" "@I"}
+   :stats               {:entry-count 4118 :node-count 5636 :edge-count 28726}
+   :duration-ms         19})
+
 (def entry-update
   {:timestamp 1465059173965
    :md        "Moving to #cljc. Edited entry."})
+
+(def entry-geo-update
+  {:mentions   #{}
+   :tags       #{}
+   :timezone   "Europe/Berlin"
+   :new-entry  true
+   :utc-offset -120
+   :longitude  9.9
+   :latitude   53.5
+   :timestamp  1465059173965
+   :md         ""})
+
+(deftest new-state-test
+  (let [current-state @(:state (store/initial-state-fn #()))
+        new-state (:new-state (store/new-state-fn {:current-state current-state
+                                                   :msg-payload   state-from-backend}))]
+    (testing "entries are on new state"
+      (is (= (:entries new-state) (:entries state-from-backend))))
+    (testing "entries map is on new state"
+      (is (= (:entries-map new-state)
+             (into {} (map (fn [entry] [(:timestamp entry) entry]) (:entries state-from-backend))))))
+    (testing "hashtags are on new state"
+      (is (= (:hashtags (:cfg new-state)) (:hashtags state-from-backend))))
+    (testing "mentions are on new state"
+      (is (= (:mentions (:cfg new-state)) (:mentions state-from-backend))))
+    (testing "stats are on new state"
+      (is (= (:stats new-state) (:stats state-from-backend))))
+    (testing "query duration is on new state"
+      (is (= (:duration-ms new-state) (:duration-ms state-from-backend))))))
+
+(deftest set-active-test
+  "Test that active entry is updated properly in store component state"
+  (let [current-state @(:state (store/initial-state-fn #()))
+        new-state (:new-state (store/set-active-fn {:current-state current-state
+                                                    :msg-payload   test-entry}))]
+    (testing "active entry is set"
+      (is (= test-entry (:active new-state))))))
 
 (deftest update-query-test
   "Test that new query is updated properly in store component state"

(deftest pomodoro-inc-test
  "Test the time increment handler for running pomodoros. Expectation is that the :completed-time key
  is incremented on every call."
  (let [current-state @(:state (store/initial-state-fn #()))
        new-state (:new-state (store/update-local-fn {:current-state current-state :msg-payload test-entry}))
        new-state1 (:new-state (store/pomodoro-inc-fn {:current-state new-state :msg-payload pomodoro-inc-msg}))
        new-state2 (:new-state (store/pomodoro-inc-fn {:current-state new-state1 :msg-payload pomodoro-inc-msg}))]
    (testing "pomodoro test entry in new-entries"
      (is (= test-entry (get-in new-state [:new-entries 1465059173965]))))
    (testing "time incremented"
      (is (= 1 (get-in new-state1 [:new-entries 1465059173965 :completed-time]))))
    (testing "time incremented"
      (is (= 2 (get-in new-state2 [:new-entries 1465059173965 :completed-time]))))))

      (is (= :state/get (first emit-msg)))
      (is (= updated-query (second emit-msg))))))

(deftest new-entry-test
  "Test that local entry is properly set in state."
  (with-redefs [store/new-entries-ls (atom {})]
    (let [current-state @(:state (store/initial-state-fn #()))
          new-state (:new-state (store/new-entry-fn {:current-state current-state :msg-payload test-entry}))]
      (testing "pomodoro test entry in new-entries"
        (is (= test-entry (get-in new-state [:new-entries 1465059173965]))))
      (testing "new entries atom properly updated - this would be backed by localstorage on client"
        (is (= (:new-entries new-state) @store/new-entries-ls))))))

(deftest update-local-test
  "Test that local entry is properly attached to state."
  (with-redefs [store/new-entries-ls (atom {})]
    (let [current-state @(:state (store/initial-state-fn #()))
          new-state (:new-state (store/update-local-fn {:current-state current-state :msg-payload test-entry}))
          new-state2 (:new-state (store/update-local-fn {:current-state new-state :msg-payload entry-update}))]
      (testing "pomodoro test entry in new-entries"
        (is (= test-entry (get-in new-state [:new-entries 1465059173965]))))
      (testing "entry update is merged with previous entry, thus allows omitting keys"
        (is (= (merge test-entry entry-update) (get-in new-state2 [:new-entries 1465059173965]))))
      (testing "new entries atom properly updated - this would be backed by localstorage on client"
        (is (= (:new-entries new-state2) @store/new-entries-ls))))))

(deftest geo-enrich-test
  "Test that local entry is properly attached to state."
  (with-redefs [store/new-entries-ls (atom {})]
    (let [current-state @(:state (store/initial-state-fn #()))
          new-state (:new-state (store/update-local-fn {:current-state current-state :msg-payload test-entry}))
          new-state2 (:new-state (store/geo-enrich-fn {:current-state new-state :msg-payload entry-geo-update}))]
      (testing "pomodoro test entry in new-entries"
        (is (= test-entry (get-in new-state [:new-entries 1465059173965]))))
      (testing "entry update is merged with previous entry, thus allows omitting keys"
        (is (= (merge entry-geo-update test-entry) (get-in new-state2 [:new-entries 1465059173965]))))
      (testing "new entries atom properly updated - this would be backed by localstorage on client"
        (is (= (:new-entries new-state2) @store/new-entries-ls))))))

(deftest remove-local-test
  "Test that local entry is properly removed from state after delete message."
  (with-redefs [store/new-entries-ls (atom {})]
    (let [current-state @(:state (store/initial-state-fn #()))
          new-state (:new-state (store/update-local-fn {:current-state current-state :msg-payload test-entry}))
          new-state2 (:new-state (store/remove-local-fn {:current-state new-state :msg-payload entry-update}))]
      (testing "pomodoro test entry in new-entries"
        (is (= test-entry (get-in new-state [:new-entries 1465059173965]))))
      (testing "entry update is removed from component state"
        (is (not (get-in new-state2 [:new-entries 1465059173965]))))
      (testing "new entries atom properly updated - this would be backed by localstorage on client"
        (is (= (:new-entries new-state2) @store/new-entries-ls))))))

(deftest entry-saved-test
  "New entry removed after backend confirms save."
  (with-redefs [store/new-entries-ls (atom {})]
    (let [current-state @(:state (store/initial-state-fn #()))
          new-state (:new-state (store/update-local-fn {:current-state current-state :msg-payload test-entry}))
          new-state2 (:new-state (store/entry-saved-fn {:current-state new-state :msg-payload entry-update}))]
      (testing "test entry in new-entries"
        (is (= test-entry (get-in new-state [:new-entries 1465059173965]))))
      (testing "entry update is removed from component state after receiving save confirmation"
        (is (not (get-in new-state2 [:new-entries 1465059173965]))))
      (testing "new entries atom properly updated - this would be backed by localstorage on client"
        (is (= (:new-entries new-state2) @store/new-entries-ls))))))

(def pomodoro-inc-msg
  {:timestamp 1465059173965})
