diff --git a/common/src/app/common/test_helpers/texts.cljc b/common/src/app/common/test_helpers/texts.cljc index 2bf5915074..079255509f 100644 --- a/common/src/app/common/test_helpers/texts.cljc +++ b/common/src/app/common/test_helpers/texts.cljc @@ -331,11 +331,15 @@ runs)) (defn restyle - "Set the run style `k` to `v` on every run of `text`." + "Set the run style `k` to `v` on every run of `text`. + Named colors and explicit fills replace each other." [text k v] (update-paragraphs text (fn [[style runs]] - [style (map (fn [[letters run-style]] [letters (assoc run-style k v)]) + [style (map (fn [[letters run-style]] + [letters (cond-> (assoc run-style k v) + (= k :color) (dissoc :fills) + (= k :fills) (dissoc :color))]) (detach-typography runs k))]))) (defn restyle-paragraphs diff --git a/common/test/common_tests/logic/text_notation_test.cljc b/common/test/common_tests/logic/text_notation_test.cljc index bdb0c0405d..23d5b5c912 100644 --- a/common/test/common_tests/logic/text_notation_test.cljc +++ b/common/test/common_tests/logic/text_notation_test.cljc @@ -16,6 +16,20 @@ (t/use-fixtures :each thi/test-fixture) +(t/deftest setting-a-named-color-replaces-explicit-fills + (doseq [fills [nil [] [{:fill-color "#123456" :fill-opacity 0.5}]]] + (let [text [[["Library text" {:fills fills :size 18}]]] + styled (thtx/restyle text :color :red)] + (t/is (= [[["Library text" {:color :red :size 18}]]] + (thtx/normalize styled))) + (t/is (= [{:fill-color "#FF0000" :fill-opacity 1}] + (get-in (thtx/content styled) [:children 0 :children 0 :children 0 :fills])))))) + +(t/deftest setting-explicit-fills-replaces-a-named-color + (let [styled (thtx/restyle [[["Library text" {:color :red :size 18}]]] :fills nil)] + (t/is (= [[["Library text" {:fills nil :size 18}]]] styled)) + (t/is (nil? (get-in (thtx/content styled) [:children 0 :children 0 :children 0 :fills]))))) + (t/deftest content-is-written-as-the-editors-write-it (let [content (thtx/content [[["Price: "] ["$10" {:weight 700 :color :red}]]]) paragraph (first (txt/node-seq txt/is-paragraph-node? content))