penpot/frontend/test/frontend_tests/data/workspace_notifications_test.cljs
Pablo Alba 3cd073fc6a
✨ Add auto-repair for integrity error files (#12524)
* ✨ Add auto-repair for integrity error files

* ✨ MR changes
2026-10-26 11:04:06 +01:00

51 lines
1.8 KiB
Clojure

;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS SUBSIDIARY SL
(ns frontend-tests.data.workspace-notifications-test
(:require
[app.common.data :as d]
[app.common.uuid :as uuid]
[app.main.data.changes :as dch]
[app.main.data.notifications :as ntf]
[app.main.data.workspace.notifications :as dwntf]
[app.util.i18n :as i18n]
[beicon.v2.core :as rx]
[cljs.test :as t :include-macros true]
[frontend-tests.helpers.async :as async]
[potok.v2.core :as ptk]))
(defn- file-change-msg
[extra]
(merge {:type :file-change
:profile-id (uuid/next)
:file-id (uuid/next)
:session-id (uuid/next)
:revn 1
:vern 0
:changes []}
extra))
(defn- ^:async watch-file-change
[msg]
(let [events (atom [])]
(await (async/observe (ptk/watch (dwntf/handle-file-change msg) {} (rx/empty))
:on-next #(swap! events conj %)))
@events))
(t/deftest ^:async repaired-file-change-applies-and-notifies
(let [events (await (watch-file-change (file-change-msg {:repaired true})))
types (mapv ptk/type events)
show (d/seek #(= ::ntf/show (ptk/type %)) events)
state (ptk/update show {})]
(t/is (= [::dch/commit ::ntf/show] types))
(t/is (= :info (get-in state [:notification :level])))
(t/is (= (i18n/tr "workspace.notifications.file-repaired")
(get-in state [:notification :content])))))
(t/deftest ^:async ordinary-file-change-does-not-notify
(let [events (await (watch-file-change (file-change-msg {})))]
(t/is (= [::dch/commit] (mapv ptk/type events)))))