Files
penpot/common/test/common_tests/math_test.cljc
Andrey Antukh 972353eccb 🐛 Fix layout padding persisted as string after invalid input (#10758)
Combined fixes from PR #10656 (numeric-input redesign) and PR #10696
(global finite? guard) for issue #10638.

- Add (number? v) guard to cljs mth/finite? so strings are rejected
- Redesign numeric-input last-value* to store number, not formatted string
- Invalid-input fallback restores display without emitting on-change
- Esc now fully discards typed text (resets raw-value* + dirty flag)
- Token dedup by name instead of resolved value
- Defense-in-depth: d/parse-double at 4 padding/gap handlers
- Math tests (common), unit tests, Storybook play tests, Playwright E2E

AI-assisted-by: deepseek-v4-flash

Co-authored-by: Akshit Nassa <nassaakshit@gmail.com>
Co-authored-by: Ulises Millán <ulises.millanguerrero@gmail.com>
2026-07-30 12:51:44 +02:00

60 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 INC Sucursal en España SL
(ns common-tests.math-test
(:require
[app.common.math :as mth]
[clojure.test :as t]))
(t/deftest finite?-number-test
(t/testing "finite? returns true for positive integer"
(t/is (true? (mth/finite? 16))))
(t/testing "finite? returns true for zero"
(t/is (true? (mth/finite? 0))))
(t/testing "finite? returns true for negative float"
(t/is (true? (mth/finite? -42.5))))
(t/testing "finite? returns true for very large number"
(t/is (true? (mth/finite? 1e308)))))
(t/deftest finite?-string-test
(t/testing "finite? returns false for numeric string"
(t/is (false? (mth/finite? "16"))))
(t/testing "finite? returns false for non-numeric string"
(t/is (false? (mth/finite? "abc"))))
(t/testing "finite? returns false for empty string"
(t/is (false? (mth/finite? ""))))
(t/testing "finite? returns false for string with spaces"
(t/is (false? (mth/finite? " ")))))
(t/deftest finite?-nil-test
(t/testing "finite? returns false for nil"
(t/is (false? (mth/finite? nil)))))
(t/deftest finite?-other-types-test
(t/testing "finite? returns false for keyword"
(t/is (false? (mth/finite? :foo))))
(t/testing "finite? returns false for vector"
(t/is (false? (mth/finite? [1 2 3]))))
(t/testing "finite? returns false for map"
(t/is (false? (mth/finite? {:a 1})))))
#_:clj-kondo/ignore
(t/deftest finite?-nan-test
#?(:cljs
(t/testing "finite? returns false for js/NaN (CLJS)"
(t/is (false? (mth/finite? js/NaN))))
:clj
(t/testing "finite? returns false for Double/NaN (CLJ)"
(t/is (false? (mth/finite? Double/NaN))))))