<commit_before>(ns compassus.tests
  (:require [cljs.test :refer-macros [deftest testing is are use-fixtures]]
            [om.next :as om :refer-macros [defui]]
            [compassus.core :as c]
            [cljsjs.react]))

(def ^:dynamic *app*)

(defui Home
  static om/IQuery
  (query [this]
    [:home/title :home/content]))

(defui About
  static om/IQuery
  (query [this]
    [:about/title :about/content]))

(def init-state
  {:home/title "Home page"
   :home/content "Lorem ipsum dolor sit amet."})

(defmulti app-read om/dispatch)

(defmethod app-read :index
  [{:keys [state query]} k _]
  {:value (select-keys @state query)})

(defn wrap-app [test-fn]
  (binding [*app* (c/application
                    {:routes {:index Home
                              :about About}
                     :reconciler-opts
                     {:state (atom init-state)
                      :parser (om/parser {:read app-read})}})]
    (test-fn)))

(use-fixtures :each wrap-app)

(deftest test-create-app
  (is (instance? c/CompassusApplication *app*))
  (is (om/reconciler? (c/get-reconciler *app*)))
  (is (= (-> (c/get-reconciler *app*)
           om/app-state
           deref
           (dissoc ::c/route))
        init-state))
  (is (contains? (-> (c/get-reconciler *app*)
                   om/app-state
                   deref)
        ::c/route))
  (is (some? (c/app-root *app*)))
  (is (some? (.. (c/app-root *app*) -prototype)))
  (is (true? (.. (c/app-root *app*) -prototype -om$isComponent))))

(deftest test-make-root-class
  (let [root (c/make-root-class {:routes {:index Home
                                          :about About}})]
    (is (true? (.. root -prototype -om$isComponent)))
    (is (= (om/get-query root)
           [::c/route
            {::c/route-data {:index [:home/title :home/content]<commit_msg>add `index-route` to fixture app<commit_after>(ns compassus.tests
  (:require [cljs.test :refer-macros [deftest testing is are use-fixtures]]
            [om.next :as om :refer-macros [defui]]
            [compassus.core :as c]
            [cljsjs.react]))

(def ^:dynamic *app*)

(defui Home
  static om/IQuery
  (query [this]
    [:home/title :home/content]))

(defui About
  static om/IQuery
  (query [this]
    [:about/title :about/content]))

(def init-state
  {:home/title "Home page"
   :home/content "Lorem ipsum dolor sit amet."})

(defmulti app-read om/dispatch)

(defmethod app-read :index
  [{:keys [state query]} k _]
  {:value (select-keys @state query)})

(defn wrap-app [test-fn]
  (binding [*app* (c/application
                    {:routes {:index (c/index-route Home)
                              :about About}
                     :reconciler-opts
                     {:state (atom init-state)
                      :parser (om/parser {:read app-read})}})]
    (test-fn)))

(use-fixtures :each wrap-app)

(deftest test-create-app
  (is (instance? c/CompassusApplication *app*))
  (is (om/reconciler? (c/get-reconciler *app*)))
  (is (= (-> (c/get-reconciler *app*)
           om/app-state
           deref
           (dissoc ::c/route))
        init-state))
  (is (contains? (-> (c/get-reconciler *app*)
                   om/app-state
                   deref)
        ::c/route))
  (is (some? (c/app-root *app*)))
  (is (some? (.. (c/app-root *app*) -prototype)))
  (is (true? (.. (c/app-root *app*) -prototype -om$isComponent))))

(deftest test-make-root-class
  (let [root (c/make-root-class {:routes {:index Home
                                          :about About}})]
    (is (true? (.. root -prototype -om$isComponent)))
    (is (= (om/get-query root)
           [::c/route
            {::c/route-data {:index [:home/title :home/content]
{'fraction_non_alphanumeric': 0.1709424790710235, 'fraction_numerical': 0.0, 'mean_word_length': 2.0335790335790334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3196037', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1276, 'n_words': 302}