roam test with cljs

pull/1181/head
Adam Schmideg 2021-01-19 23:04:21 +01:00 committed by Tienson Qin
parent 836b1dad7e
commit d1e595ff76
5 changed files with 43 additions and 7 deletions

View File

@ -40,7 +40,8 @@
:main-opts ["-m" "shadow.cljs.devtools.cli"]}
:test
{:extra-paths ["src/test/"]
:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.764"}
:extra-deps {cheshire/cheshire {:mvn/version "5.10.0"}
org.clojure/clojurescript {:mvn/version "1.10.764"}
org.clojure/test.check {:mvn/version "RELEASE"}}
:main-opts ["-m" "shadow.cljs.devtools.cli"]}
:runner

View File

@ -2,9 +2,9 @@
(defprotocol External
(toMarkdownFiles [this content config]
"Should return a map of markdown's file name to contents.")
"Should return a map of markdown's file name to contents."))
;; Long-term goal:
;; (toMldocAst [this content])
;; (fromMldocAst [this ast])
)

View File

@ -1,6 +1,7 @@
(ns frontend.external.roam
(:require [frontend.external.protocol :as protocol]
[cljs-bean.core :as bean]
(:require #?(:cljs [cljs-bean.core :as bean]
:clj [cheshire.core :as json])
[frontend.external.protocol :as protocol]
[medley.core :as medley]
[clojure.walk :as walk]
[clojure.string :as string]
@ -122,8 +123,9 @@
(defrecord Roam []
protocol/External
(toMarkdownFiles [this content _config]
(let [data (bean/->clj (js/JSON.parse content))]
(->files data))))
#?(:cljs (let [data (bean/->clj (js/JSON.parse content))]
(->files data))
:clj (-> content json/parse-string ->files))))
(comment
(defonce test-roam-json (frontend.db/get-file "same.json"))

View File

@ -0,0 +1,33 @@
(ns frontend.external.roam-test
(:require #?(:clj [clojure.test :refer :all]
:cljs [cljs.test :refer [is deftest]])
;[frontend.external.roam :as roam]
[frontend.external :refer [to-markdown-files]]))
(def minimal-json "
[
{
\"create-email\": \"adam@example.com\",
\"create-time\": 1610708403162,
\"title\": \"Export JSON\",
\"children\": [
{
\"string\": \"Hello, world!\",
\"create-email\": \"adam@example.com\",
\"create-time\": 1610708405787,
\"uid\": \"7c5um7hSz\",
\"edit-time\": 1610708415484,
\"edit-email\": \"adam@example.com\"}
],
\"edit-time\": 1610708403169,
\"edit-email\": \"adam@example.com\"}]
")
(deftest roam-import-test
(let [got (to-markdown-files :roam minimal-json {})
md (first got)]
(is (= 1 (count got)))
(is (= "Export JSON" (:title md)))
(is (:created-at md))
(is (:last-modified-at md))
(is (= "---\ntitle: Export JSON\n---\n\n## Hello, world!\n" (:text md)))))