diff --git a/src/main/frontend/worker/db_core.cljs b/src/main/frontend/worker/db_core.cljs index acf5470072..68e9e140e8 100644 --- a/src/main/frontend/worker/db_core.cljs +++ b/src/main/frontend/worker/db_core.cljs @@ -1115,6 +1115,12 @@ :feature :markdown-mirror-two-way :reason :collaborated-graph})) + (not (markdown-mirror/enabled? repo)) + (p/rejected (ex-info "Two-way Markdown Mirror requires Markdown Mirror to be enabled" + {:repo repo + :feature :markdown-mirror-two-way + :reason :markdown-mirror-disabled})) + :else (when-let [conn (worker-state/get-datascript-conn repo)] (p/let [_ (markdown-mirror/ (restoring-worker-state (fn [] - (let [set-two-way-enabled! (get-thread-api :thread-api/markdown-mirror-set-two-way-enabled) + (let [set-enabled! (get-thread-api :thread-api/markdown-mirror-set-enabled) + set-two-way-enabled! (get-thread-api :thread-api/markdown-mirror-set-two-way-enabled) conn (d/create-conn) calls (atom [])] (reset! worker-state/*datascript-conns {test-repo conn}) @@ -217,7 +218,9 @@ (fn [& _] (swap! calls conj :mirror-repo) (p/resolved {:status :mirrored}))) - (-> (set-two-way-enabled! test-repo true false) + (-> (p/let [_ (set-enabled! test-repo true) + _ (reset! calls [])] + (set-two-way-enabled! test-repo true false)) (p/then (fn [_] (is (= [:start-file-watcher :mirror-repo] @calls)))))))) (p/catch (fn [error] @@ -253,6 +256,41 @@ (set! markdown-mirror/ + (restoring-worker-state + (fn [] + (let [set-enabled! (get-thread-api :thread-api/markdown-mirror-set-enabled) + set-two-way-enabled! (get-thread-api :thread-api/markdown-mirror-set-two-way-enabled) + conn (d/create-conn) + calls (atom [])] + (reset! worker-state/*datascript-conns {test-repo conn}) + (set! markdown-mirror/ (p/let [_ (set-enabled! test-repo true) + _ (set-enabled! test-repo false)] + (set-two-way-enabled! test-repo true false)) + (p/then (fn [_] + (is false "expected disabled markdown mirror to be rejected"))) + (p/catch (fn [error] + (is (= :markdown-mirror-disabled (:reason (ex-data error)))) + (is (= [:mirror-repo] @calls)))))))) + (p/catch (fn [error] + (is false (str "unexpected error: " error)))) + (p/finally (fn [] + (set! markdown-mirror/ (markdown-mirror/> (:block/refs block) + (remove #(= :block/tags (:db/ident %))) + (map :db/id) + set)] (is (= :imported (:status result))) - (is (some? tag)) - (is (some #(= :logseq.class/Tag (:db/ident %)) (:block/tags tag))) - (is (block-title-includes? @conn block-uuid "#tag1")) - (is (= #{(:db/id tag)} (set (map :db/id (:block/tags block))))) - (is (= #{(:db/id tag)} (set (map :db/id (:block/refs block)))) - (pr-str (map (fn [ref] - (select-keys ref [:db/id :db/ident :block/title :block/uuid])) - (:block/refs block))))))) + (is (some? tag)) + (is (some #(= :logseq.class/Tag (:db/ident %)) (:block/tags tag))) + (is (block-title-includes? @conn block-uuid "#tag1")) + (is (= #{(:db/id tag)} (set (map :db/id (:block/tags block))))) + (is (= #{(:db/id tag)} block-content-ref-ids))))) (p/catch (fn [e] (is false (str "unexpected error: " e)))) (p/finally done)))))