;; 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.ui.text-options-test (:require ["react-dom/server" :as rds] [app.main.data.workspace.texts :as dwt] [app.main.ui.ds.controls.select :as select] [app.main.ui.shapes.text.html-text :as html-text] [app.main.ui.shapes.text.styles :as text-styles] [app.main.ui.workspace.sidebar.options.menus.text-japanese-layout :as tjl] [app.util.text.content.styles :as content-styles] [cljs.test :as t :include-macros true] [cuerdas.core :as str] [rumext.v2 :as mf])) (def ^:private japanese-span-attrs [:text-combine-upright :text-emphasis :ruby :ruby-hidden :ruby-size :ruby-align :ruby-overhang :ruby-side :warichu :font-features :annotation-clearance]) (def ^:private radio-selected @#'tjl/radio-selected) (def ^:private span-input-value @#'tjl/span-input-value) (def ^:private span-select-value @#'tjl/span-select-value) (def ^:private with-mixed-span-option @#'tjl/with-mixed-span-option) (def ^:private ruby-common-props @#'tjl/ruby-common-props) (t/deftest japanese-layout-controls-follow-file-or-profile-configuration (t/is (false? (tjl/japanese-layout-config-enabled? {} {}))) (t/is (true? (tjl/japanese-layout-config-enabled? {:options {:japanese-layout true}} {}))) (t/is (true? (tjl/japanese-layout-config-enabled? {} {:props {:japanese-layout-all-files true}}))) (t/is (true? (tjl/japanese-layout-config-enabled? {:options {:japanese-layout true}} {:props {:japanese-layout-all-files false}})))) (t/deftest text-emphasis-select-reports-and-restores-canonical-values (let [options (tjl/text-emphasis-options identity) reported-id (:id (select/get-option options "filled-dot"))] (t/is (= "filled-dot" reported-id)) (t/is (= "filled-dot" (:id (select/get-option options reported-id)))))) (t/deftest annotation-clearance-select-reports-canonical-values (let [options (tjl/annotation-clearance-options identity)] (t/is (= ["none" "auto"] (mapv :id options))) (t/is (= "auto" (:id (select/get-option options "auto")))))) (t/deftest unrestricted-tcy-is-only-offered-for-a-text-selection (t/is (= ["none" "digits"] (mapv :value (tjl/text-combine-upright-options false identity)))) (t/is (= ["none" "all" "digits"] (mapv :value (tjl/text-combine-upright-options true identity))))) (t/deftest ruby-container-styles-preserve-customization (let [style (text-styles/generate-ruby-container-styles {:ruby-align "space-between" :ruby-overhang "none" :ruby-side "under"})] (t/is (= "space-between" (.-rubyAlign style))) (t/is (= "none" (.-rubyOverhang style))) (t/is (= "under" (.-rubyPosition style))))) (t/deftest advanced-furigana-options-are-collapsed-by-default (let [markup (rds/renderToStaticMarkup (mf/element tjl/ruby-presentation-options* #js {:values {} :on-change identity :on-blur identity}))] (t/is (str/includes? markup "data-testid=\"ruby-presentation-options-toggle\"")) (t/is (str/includes? markup "aria-expanded=\"false\"")) (t/is (str/includes? markup "workspace.options.text-options.ruby-advanced-options")))) (t/deftest advanced-furigana-options-include-hide-toggle (let [markup (rds/renderToStaticMarkup (mf/element tjl/ruby-customization-options* #js {:values {:ruby-hidden true} :on-change identity :on-blur identity}))] (t/is (str/includes? markup "workspace.options.text-options.ruby-hidden")) (t/is (str/includes? markup "role=\"switch\"")) (t/is (str/includes? markup "aria-checked=\"true\"")))) (t/deftest hidden-furigana-renders-base-text-without-ruby-layout (let [markup (rds/renderToStaticMarkup (mf/element html-text/render-text* #js {:node {:text "日" :ruby "にち" :ruby-hidden true} :parent {} :shape {}}))] (t/is (str/includes? markup ">日")) (t/is (not (str/includes? markup "styles {:text-combine-upright "digits2"}) "text-combine-upright"))) (t/is (= {:text-combine-upright "digits3"} (content-styles/styles->attrs {"text-combine-upright" "digits 3"})))) (t/deftest hidden-furigana-round-trips-through-editor-styles (t/is (= "true" (unchecked-get (content-styles/attrs->styles {:ruby-hidden true}) "--ruby-hidden"))) (t/is (= {:ruby-hidden false} (content-styles/styles->attrs {"--ruby-hidden" "false"}))) (t/is (= {:ruby-hidden nil} (content-styles/styles->attrs {"--ruby-hidden" ""})))) (t/deftest japanese-controls-distinguish-horizontal-and-vertical-modes (t/is (false? (tjl/vertical-japanese-layout? {}))) (t/is (false? (tjl/vertical-japanese-layout? {:writing-mode "horizontal-tb"}))) (t/is (true? (tjl/vertical-japanese-layout? {:writing-mode "vertical-rl"}))) (t/is (= "palt" (tjl/proportional-metrics-feature "horizontal-tb"))) (t/is (= "palt" (tjl/proportional-metrics-feature nil))) (t/is (= "vpal" (tjl/proportional-metrics-feature "vertical-rl"))))