mirror of
https://github.com/penpot/penpot.git
synced 2026-08-19 19:28:36 +00:00
* ✨ Add component synchronization to waitForLayoutUpdate * 🐛 Fix async mock leak in workspace-reflow-test Use mock/with-mocks instead of with-redefs for http/send! mock in failed-google-font-css-does-not-abort-shared-consumers test. with-redefs restores bindings when the block exits synchronously, but the RxJS subscription fires asynchronously. This caused the mock to leak into subsequent tests (workspace-media-test), producing 3 spurious failures. AI-assisted-by: mimo-v2.5-pro * ♻️ Replace async with-redefs with mock/with-mocks in frontend tests with-redefs restores bindings when the block exits synchronously, which is too early for async code (t/async, rx/subs!, promises). mock/with-mocks uses set! and restores in the done callback, keeping mocks alive across async boundaries. Converted 15 with-redefs usages across 4 test files: - workspace_reflow_test.cljs: 2 genuinely async tests (P1) - routes_test.cljs: 3 SSO caching tests (P2) - main_errors_test.cljs: 8 expired-org SSO tests (P2) - comments_test.cljs: 2 comment thread tests (P2) 36 purely sync with-redefs usages left unchanged — with-redefs is correct for synchronous code. AI-assisted-by: mimo-v2.5-pro * 📎 Fix fmt issues --------- Co-authored-by: Andrey Antukh <niwi@niwi.nz>
71 lines
2.6 KiB
Clojure
71 lines
2.6 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 INC Sucursal en España SL
|
|
|
|
(ns frontend-tests.plugins.comments-test
|
|
(:require
|
|
[app.main.data.comments :as dc]
|
|
[app.main.store :as st]
|
|
[app.plugins.comments :as comments]
|
|
[app.plugins.page :as page]
|
|
[app.plugins.register :as r]
|
|
[cljs.test :as t :include-macros true]
|
|
[frontend-tests.helpers.mock :as mock]))
|
|
|
|
(def ^:private plugin-id "00000000-0000-0000-0000-000000000000")
|
|
|
|
(t/deftest comment-thread-remove-allows-the-owner
|
|
(t/async done
|
|
(let [owner-id (random-uuid)
|
|
file-id (random-uuid)
|
|
page-id (random-uuid)
|
|
thread-id (random-uuid)
|
|
emitted (atom nil)
|
|
thread (comments/comment-thread-proxy
|
|
plugin-id
|
|
file-id
|
|
page-id
|
|
{:id thread-id :owner-id owner-id})]
|
|
(set! st/state (atom {:profile {:id owner-id}}))
|
|
(mock/with-mocks
|
|
{r/check-permission (constantly true)
|
|
dc/delete-comment-thread-on-workspace
|
|
(mock/stub (fn [params callback]
|
|
(callback)
|
|
[:delete-thread params]))
|
|
st/emit! (mock/stub (fn [event] (reset! emitted event)))}
|
|
(fn [done']
|
|
(let [result (.remove thread)]
|
|
(t/is (instance? js/Promise result))
|
|
(t/is (= [:delete-thread {:id thread-id}] @emitted))
|
|
(done')))
|
|
done))))
|
|
|
|
(t/deftest page-remove-comment-thread-emits-delete-event
|
|
(t/async done
|
|
(let [file-id (random-uuid)
|
|
page-id (random-uuid)
|
|
thread-id (random-uuid)
|
|
emitted (atom nil)
|
|
page (page/page-proxy plugin-id file-id page-id)
|
|
thread (comments/comment-thread-proxy
|
|
plugin-id
|
|
file-id
|
|
page-id
|
|
{:id thread-id :owner-id (random-uuid)})]
|
|
(mock/with-mocks
|
|
{r/check-permission (constantly true)
|
|
dc/delete-comment-thread-on-workspace
|
|
(mock/stub (fn [params callback]
|
|
(callback)
|
|
[:delete-thread params]))
|
|
st/emit! (mock/stub (fn [event] (reset! emitted event)))}
|
|
(fn [done']
|
|
(let [result (.removeCommentThread page thread)]
|
|
(t/is (instance? js/Promise result))
|
|
(t/is (= [:delete-thread {:id thread-id}] @emitted))
|
|
(done')))
|
|
done))))
|