diff --git a/common/src/app/common/types/variant.cljc b/common/src/app/common/types/variant.cljc index 63acbd706a..40dec6fd48 100644 --- a/common/src/app/common/types/variant.cljc +++ b/common/src/app/common/types/variant.cljc @@ -309,18 +309,22 @@ "Transforms a variant-name (its properties values) into a standard name: the real name of the shape joined by the properties values separated by '/'" [variant] - (cpn/merge-path-item (:name variant) (str/replace (:variant-name variant) #", " " / "))) + (cpn/merge-path-item (str/lower (:name variant)) (str/lower (str/replace (:variant-name variant) #", " " / ")))) (defn find-boolean-pair - "Given a vector, return the map from 'bool-values' that contains both as keys. - Returns nil if none match." - [v] + "Given a vector, return the map from 'bool-values' (case-insensitive) that contains both as keys. + Returns nil if none match." + [vector] (let [bool-values [{"on" true "off" false} {"yes" true "no" false} {"true" true "false" false}]] - (when (= (count v) 2) - (some (fn [b] - (when (and (contains? b (first v)) - (contains? b (last v))) - b)) + + (when (= (count vector) 2) + (some (fn [bool-value] + (let [v1 (str/lower (first vector)) + v2 (str/lower (second vector))] + (when (and (contains? bool-value v1) + (contains? bool-value v2)) + {(first vector) (bool-value v1) + (second vector) (bool-value v2)}))) bool-values)))) diff --git a/common/test/common_tests/variant_test.cljc b/common/test/common_tests/variant_test.cljc index 85060cb241..b06ed65dd5 100644 --- a/common/test/common_tests/variant_test.cljc +++ b/common/test/common_tests/variant_test.cljc @@ -162,10 +162,24 @@ (t/deftest find-boolean-pair - (t/testing "find-boolean-pair" + (t/testing "find-boolean-pair basic cases" (t/is (= (ctv/find-boolean-pair ["off" "on"]) {"on" true "off" false})) (t/is (= (ctv/find-boolean-pair ["on" "off"]) {"on" true "off" false})) (t/is (= (ctv/find-boolean-pair ["off" "on" "other"]) nil)) (t/is (= (ctv/find-boolean-pair ["yes" "no"]) {"yes" true "no" false})) (t/is (= (ctv/find-boolean-pair ["false" "true"]) {"true" true "false" false})) - (t/is (= (ctv/find-boolean-pair ["hello" "bye"]) nil)))) + (t/is (= (ctv/find-boolean-pair ["hello" "bye"]) nil))) + + (t/testing "find-boolean-pair with original casing" + (t/is (= (ctv/find-boolean-pair ["tRue" "faLse"]) {"tRue" true "faLse" false})) + (t/is (= (ctv/find-boolean-pair ["ON" "OFF"]) {"ON" true "OFF" false})) + (t/is (= (ctv/find-boolean-pair ["YeS" "nO"]) {"YeS" true "nO" false}))) + + (t/testing "find-boolean-pair with reversed order and mixed case" + (t/is (= (ctv/find-boolean-pair ["FaLsE" "TrUe"]) {"TrUe" true "FaLsE" false})) + (t/is (= (ctv/find-boolean-pair ["No" "Yes"]) {"Yes" true "No" false}))) + + (t/testing "find-boolean-pair with invalid input" + (t/is (= (ctv/find-boolean-pair ["yes"]) nil)) + (t/is (= (ctv/find-boolean-pair ["true" "false" "extra"]) nil)) + (t/is (= (ctv/find-boolean-pair ["maybe" "nope"]) nil))))