mirror of
https://github.com/penpot/penpot.git
synced 2026-09-25 13:26:16 +00:00
🐛 Fix unit tests after merge
This commit is contained in:
parent
8a3aecd75a
commit
e92a6ae466
@ -1811,9 +1811,6 @@
|
|||||||
(not (string? value))
|
(not (string? value))
|
||||||
(u/not-valid plugin-id :value value)
|
(u/not-valid plugin-id :value value)
|
||||||
|
|
||||||
(not (r/check-permission plugin-id "content:write"))
|
|
||||||
(u/not-valid plugin-id :switchVariant "Plugin doesn't have 'content:write' permission")
|
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(let [shape (u/locate-shape file-id page-id id)]
|
(let [shape (u/locate-shape file-id page-id id)]
|
||||||
(if (dwv/valid-variant-switch? @st/state shape pos value)
|
(if (dwv/valid-variant-switch? @st/state shape pos value)
|
||||||
|
|||||||
@ -177,17 +177,20 @@
|
|||||||
(first @errors)))))))
|
(first @errors)))))))
|
||||||
|
|
||||||
(t/deftest flow-starting-board-setter-checks-permission
|
(t/deftest flow-starting-board-setter-checks-permission
|
||||||
(let [plugin-id "test-plugin"
|
;; The board must be a valid flow starting frame, otherwise the setter
|
||||||
file-id (uuid/next)
|
;; rejects the value before it ever checks the permission.
|
||||||
page-id (uuid/next)
|
(let [result (setup-with-board)
|
||||||
flow-id (uuid/next)
|
file-id (:id (:file result))
|
||||||
errors (atom [])]
|
page-id (cthf/current-page-id (:file result))
|
||||||
|
board-id (:board-id result)
|
||||||
|
flow-id (uuid/next)
|
||||||
|
errors (atom [])]
|
||||||
(with-redefs [r/check-permission (constantly false)
|
(with-redefs [r/check-permission (constantly false)
|
||||||
u/not-valid (mock/stub (fn [pid prop msg] (swap! errors conj [pid prop msg])))
|
u/not-valid (mock/stub (fn [pid prop msg] (swap! errors conj [pid prop msg])))
|
||||||
st/emit! mock/noop
|
st/emit! mock/noop]
|
||||||
shape/shape-proxy? (constantly true)]
|
(let [proxy (page/flow-proxy plugin-id file-id page-id flow-id)
|
||||||
(let [proxy (page/flow-proxy plugin-id file-id page-id flow-id)]
|
board (shape/shape-proxy plugin-id file-id page-id board-id)]
|
||||||
(set! (.-startingBoard proxy) #js {})
|
(set! (.-startingBoard proxy) board)
|
||||||
(t/is (= 1 (count @errors)))
|
(t/is (= 1 (count @errors)))
|
||||||
(t/is (= [plugin-id :startingBoard "Plugin doesn't have 'content:write' permission"]
|
(t/is (= [plugin-id :startingBoard "Plugin doesn't have 'content:write' permission"]
|
||||||
(first @errors)))))))
|
(first @errors)))))))
|
||||||
@ -208,16 +211,18 @@
|
|||||||
(first @errors)))))))
|
(first @errors)))))))
|
||||||
|
|
||||||
(t/deftest create-flow-checks-permission
|
(t/deftest create-flow-checks-permission
|
||||||
(let [plugin-id "test-plugin"
|
;; The frame must be a valid flow starting frame, otherwise createFlow
|
||||||
file-id (uuid/next)
|
;; rejects the argument before it ever checks the permission.
|
||||||
page-id (uuid/next)
|
(let [result (setup-with-board)
|
||||||
errors (atom [])]
|
file-id (:id (:file result))
|
||||||
|
page-id (cthf/current-page-id (:file result))
|
||||||
|
board-id (:board-id result)
|
||||||
|
errors (atom [])]
|
||||||
(with-redefs [r/check-permission (constantly false)
|
(with-redefs [r/check-permission (constantly false)
|
||||||
u/not-valid (mock/stub (fn [pid prop msg] (swap! errors conj [pid prop msg])))
|
u/not-valid (mock/stub (fn [pid prop msg] (swap! errors conj [pid prop msg])))
|
||||||
st/emit! mock/noop
|
st/emit! mock/noop]
|
||||||
shape/shape-proxy? (constantly true)]
|
|
||||||
(let [proxy (page/page-proxy plugin-id file-id page-id)
|
(let [proxy (page/page-proxy plugin-id file-id page-id)
|
||||||
frame #js {"$id" (uuid/next)}]
|
frame (shape/shape-proxy plugin-id file-id page-id board-id)]
|
||||||
(.createFlow proxy "flow-name" frame)
|
(.createFlow proxy "flow-name" frame)
|
||||||
(t/is (= 1 (count @errors)))
|
(t/is (= 1 (count @errors)))
|
||||||
(t/is (= [plugin-id :createFlow "Plugin doesn't have 'content:write' permission"]
|
(t/is (= [plugin-id :createFlow "Plugin doesn't have 'content:write' permission"]
|
||||||
|
|||||||
@ -176,6 +176,7 @@
|
|||||||
(with-redefs [u/locate-shape (fn [_file _page id] {:id id :component-id id})
|
(with-redefs [u/locate-shape (fn [_file _page id] {:id id :component-id id})
|
||||||
u/locate-library-component (constantly {:id (uuid/next)})
|
u/locate-library-component (constantly {:id (uuid/next)})
|
||||||
ctk/is-variant? (constantly false)
|
ctk/is-variant? (constantly false)
|
||||||
|
dwv/valid-components-for-variants? (constantly true)
|
||||||
dwv/combine-as-variants
|
dwv/combine-as-variants
|
||||||
(fn [ids opts]
|
(fn [ids opts]
|
||||||
(reset! captured {:ids ids :opts opts})
|
(reset! captured {:ids ids :opts opts})
|
||||||
@ -381,6 +382,7 @@
|
|||||||
errors (atom [])]
|
errors (atom [])]
|
||||||
(with-redefs [u/locate-shape (constantly {:id shape-id :component-id shape-id})
|
(with-redefs [u/locate-shape (constantly {:id shape-id :component-id shape-id})
|
||||||
u/locate-library-component (constantly {:id (uuid/next)})
|
u/locate-library-component (constantly {:id (uuid/next)})
|
||||||
|
u/page-active? (constantly true)
|
||||||
u/not-valid (mock/stub (fn [pid prop msg] (swap! errors conj [pid prop msg])))
|
u/not-valid (mock/stub (fn [pid prop msg] (swap! errors conj [pid prop msg])))
|
||||||
r/check-permission (constantly false)
|
r/check-permission (constantly false)
|
||||||
st/emit! mock/noop]
|
st/emit! mock/noop]
|
||||||
|
|||||||
@ -22,29 +22,42 @@
|
|||||||
;; Regression coverage for issue #9780.
|
;; Regression coverage for issue #9780.
|
||||||
;;
|
;;
|
||||||
;; `letterSpacing` accepts negative tracking in the product UI (-200..200,
|
;; `letterSpacing` accepts negative tracking in the product UI (-200..200,
|
||||||
;; see typography.cljs), but the plugin validator regex rejected any leading
|
;; see typography.cljs), but the plugin setter rejected any leading minus,
|
||||||
;; minus, so negative values were refused. `letter-spacing-re` is the shared
|
;; so negative values were refused. Pin the accept/reject contract of the
|
||||||
;; predicate behind both the shape- and range-level setters; pin its
|
;; plugin setter here.
|
||||||
;; accept/reject contract here.
|
|
||||||
|
|
||||||
(def ^:private letter-spacing-re @#'plugins.text/letter-spacing-re)
|
(defn- apply-letter-spacing
|
||||||
|
"Sets `letterSpacing` on a text range proxy and returns the attributes sent
|
||||||
|
to the update event, or nil when the plugin rejected the value."
|
||||||
|
[value]
|
||||||
|
(let [captured (atom nil)
|
||||||
|
range (plugins.text/text-range-proxy
|
||||||
|
plugin-id (random-uuid) (random-uuid) (random-uuid) 0 4)]
|
||||||
|
(with-redefs [r/check-permission (constantly true)
|
||||||
|
u/page-active? (constantly true)
|
||||||
|
u/not-valid (fn [_ _ _] nil)
|
||||||
|
dwt/update-text-range
|
||||||
|
(fn [_ _ _ attrs]
|
||||||
|
(reset! captured attrs)
|
||||||
|
:update-text-range)
|
||||||
|
st/emit! mock/noop]
|
||||||
|
(set! (.-letterSpacing range) value)
|
||||||
|
@captured)))
|
||||||
|
|
||||||
(defn- valid? [s] (boolean (re-matches letter-spacing-re s)))
|
(t/deftest letter-spacing-accepts-negative-values
|
||||||
|
(t/is (= {:letter-spacing "-0.56"} (apply-letter-spacing "-0.56")))
|
||||||
|
(t/is (= {:letter-spacing "-12"} (apply-letter-spacing "-12")))
|
||||||
|
(t/is (= {:letter-spacing "-200"} (apply-letter-spacing "-200"))))
|
||||||
|
|
||||||
(t/deftest letter-spacing-re-accepts-negative-values
|
(t/deftest letter-spacing-accepts-non-negative-values
|
||||||
(t/is (valid? "-0.56"))
|
(t/is (= {:letter-spacing "0"} (apply-letter-spacing "0")))
|
||||||
(t/is (valid? "-12"))
|
(t/is (= {:letter-spacing "12"} (apply-letter-spacing "12")))
|
||||||
(t/is (valid? "-200")))
|
(t/is (= {:letter-spacing "1.5"} (apply-letter-spacing "1.5"))))
|
||||||
|
|
||||||
(t/deftest letter-spacing-re-accepts-non-negative-values
|
(t/deftest letter-spacing-rejects-non-numeric
|
||||||
(t/is (valid? "0"))
|
(t/is (nil? (apply-letter-spacing "abc")))
|
||||||
(t/is (valid? "12"))
|
(t/is (nil? (apply-letter-spacing "1-2")))
|
||||||
(t/is (valid? "1.5")))
|
(t/is (nil? (apply-letter-spacing "--1"))))
|
||||||
|
|
||||||
(t/deftest letter-spacing-re-rejects-non-numeric
|
|
||||||
(t/is (not (valid? "abc")))
|
|
||||||
(t/is (not (valid? "1-2")))
|
|
||||||
(t/is (not (valid? "--1"))))
|
|
||||||
|
|
||||||
|
|
||||||
(t/deftest font-apply-to-text-uses-font-id-not-shape-id
|
(t/deftest font-apply-to-text-uses-font-id-not-shape-id
|
||||||
|
|||||||
@ -142,7 +142,7 @@
|
|||||||
(ctob/make-token :id token-id
|
(ctob/make-token :id token-id
|
||||||
:name "spacing.medium"
|
:name "spacing.medium"
|
||||||
:type :spacing
|
:type :spacing
|
||||||
:value 16)))))
|
:value "16")))))
|
||||||
store (ths/setup-store file)
|
store (ths/setup-store file)
|
||||||
_ (set! st/state store)
|
_ (set! st/state store)
|
||||||
_ (set! st/stream (ptk/input-stream store))
|
_ (set! st/stream (ptk/input-stream store))
|
||||||
@ -341,15 +341,29 @@
|
|||||||
(t/is (not (contains? (-> @captured second :theme :sets) "Primitives"))))))
|
(t/is (not (contains? (-> @captured second :theme :sets) "Primitives"))))))
|
||||||
|
|
||||||
(t/deftest font-family-token-value-accepts-a-string
|
(t/deftest font-family-token-value-accepts-a-string
|
||||||
(let [file-id (cthi/new-id! :file)
|
;; The setter validates the candidate token against the file tokens library,
|
||||||
set-id (cthi/new-id! :set)
|
;; so the token has to live in a real library.
|
||||||
token-id (cthi/new-id! :token)
|
(let [set-id (cthi/new-id! :token-set)
|
||||||
|
token-id (cthi/new-id! :font-token)
|
||||||
|
file (-> (cthf/sample-file :file1 :page-label :page1)
|
||||||
|
(ctht/add-tokens-lib)
|
||||||
|
(ctht/update-tokens-lib
|
||||||
|
#(-> %
|
||||||
|
(ctob/add-set
|
||||||
|
(ctob/make-token-set :id set-id
|
||||||
|
:name "fonts"))
|
||||||
|
(ctob/add-token
|
||||||
|
set-id
|
||||||
|
(ctob/make-token :id token-id
|
||||||
|
:name "font.primary"
|
||||||
|
:type :font-family
|
||||||
|
:value ["Inter"])))))
|
||||||
|
store (ths/setup-store file)
|
||||||
|
_ (set! st/state store)
|
||||||
|
_ (set! st/stream (ptk/input-stream store))
|
||||||
|
file-id (:id file)
|
||||||
captured (atom nil)]
|
captured (atom nil)]
|
||||||
(with-redefs [r/check-permission (constantly true)
|
(with-redefs [r/check-permission (constantly true)
|
||||||
u/locate-token (constantly {:id token-id
|
|
||||||
:name "font.primary"
|
|
||||||
:type :font-family
|
|
||||||
:value ["Inter"]})
|
|
||||||
dwtl/update-token (mock/stub (fn [set-id token-id attrs]
|
dwtl/update-token (mock/stub (fn [set-id token-id attrs]
|
||||||
(reset! captured {:set-id set-id
|
(reset! captured {:set-id set-id
|
||||||
:token-id token-id
|
:token-id token-id
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user