2020-04-30 16:44:17 +02:00
|
|
|
(ns status-im.search.core-test
|
2018-10-24 11:16:32 +02:00
|
|
|
(:require [cljs.test :refer-macros [deftest testing is]]
|
2023-10-16 15:47:20 +02:00
|
|
|
[status-im.subs.wallet.search :as search.subs]))
|
2022-09-21 16:03:06 +02:00
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn extract-chat-attributes
|
|
|
|
[chat]
|
2022-09-21 16:03:06 +02:00
|
|
|
(let [{:keys [name alias tags]} (val chat)]
|
|
|
|
(into [name alias] tags)))
|
2018-10-24 11:16:32 +02:00
|
|
|
|
|
|
|
(deftest filter-chats
|
2022-12-20 22:45:37 +08:00
|
|
|
(let [chats {:chat-1 {:name "name1"
|
2020-05-20 16:27:11 +02:00
|
|
|
:alias "alias1"
|
2022-12-20 22:45:37 +08:00
|
|
|
:tags #{"tag1"}}
|
|
|
|
:chat-2 {:name "name2"
|
2020-05-20 16:27:11 +02:00
|
|
|
:alias "alias2"
|
2022-12-20 22:45:37 +08:00
|
|
|
:tags #{"tag2" "tag3"}}
|
|
|
|
:chat-3 {:name "name3"
|
2020-05-20 16:27:11 +02:00
|
|
|
:alias "alias3"
|
2022-12-20 22:45:37 +08:00
|
|
|
:tags #{}}
|
|
|
|
:chat-4 {:name "name4"
|
2020-05-20 16:27:11 +02:00
|
|
|
:alias "alias4"
|
2022-12-20 22:45:37 +08:00
|
|
|
:tags #{"tag4"}}}]
|
2018-10-24 11:16:32 +02:00
|
|
|
(testing "no search filter"
|
2020-01-20 11:52:07 +02:00
|
|
|
(is (= (count chats)
|
2019-02-07 11:18:00 +01:00
|
|
|
(count (search.subs/apply-filter ""
|
|
|
|
chats
|
2022-09-21 16:03:06 +02:00
|
|
|
extract-chat-attributes
|
2019-09-07 14:57:22 +02:00
|
|
|
false)))))
|
2018-10-24 11:16:32 +02:00
|
|
|
(testing "searching for a specific tag"
|
2019-02-07 11:18:00 +01:00
|
|
|
(is (= 1
|
|
|
|
(count (search.subs/apply-filter "tag2"
|
|
|
|
chats
|
2022-09-21 16:03:06 +02:00
|
|
|
extract-chat-attributes
|
2019-09-07 14:57:22 +02:00
|
|
|
false)))))
|
2018-10-24 11:16:32 +02:00
|
|
|
(testing "searching for a partial tag"
|
2019-02-07 11:18:00 +01:00
|
|
|
(is (= 3
|
|
|
|
(count (search.subs/apply-filter "tag"
|
|
|
|
chats
|
2022-09-21 16:03:06 +02:00
|
|
|
extract-chat-attributes
|
2019-09-07 14:57:22 +02:00
|
|
|
false)))))
|
2020-05-20 16:27:11 +02:00
|
|
|
(testing "searching for a specific alias"
|
2019-02-07 11:18:00 +01:00
|
|
|
(is (= 1
|
2020-05-20 16:27:11 +02:00
|
|
|
(count (search.subs/apply-filter "alias4"
|
2019-02-07 11:18:00 +01:00
|
|
|
chats
|
2022-09-21 16:03:06 +02:00
|
|
|
extract-chat-attributes
|
2019-09-07 14:57:22 +02:00
|
|
|
false)))))
|
2020-05-20 16:27:11 +02:00
|
|
|
(testing "searching for a partial alias"
|
2019-02-07 11:18:00 +01:00
|
|
|
(is (= 4
|
2020-05-20 16:27:11 +02:00
|
|
|
(count (search.subs/apply-filter "alias"
|
2019-02-07 11:18:00 +01:00
|
|
|
chats
|
2022-09-21 16:03:06 +02:00
|
|
|
extract-chat-attributes
|
2019-09-07 14:57:22 +02:00
|
|
|
false)))))
|
2018-10-24 11:16:32 +02:00
|
|
|
(testing "searching for a specific chat name"
|
2019-02-07 11:18:00 +01:00
|
|
|
(is (= 1
|
|
|
|
(count (search.subs/apply-filter "name4"
|
|
|
|
chats
|
2022-09-21 16:03:06 +02:00
|
|
|
extract-chat-attributes
|
2019-09-07 14:57:22 +02:00
|
|
|
false)))))))
|