mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-24 12:41:58 +00:00
48a4221ed6
When a contact or group has a simplex_name stored, the share-link render path emits the canonical simplex:/name... URI (via strEncode) instead of the underlying connection link. Falls back to the existing link rendering when simplexName is Nothing. Final commit of the ConnectTarget plumbing chain: end-to-end users can now (a) connect via @alice.simplex / #group.simplex with the agent layer carrying the name, (b) see the simplex name on the contact/group records and in viewConnectionPlan, (c) share the contact using the namespace-canonical form rather than the raw URI.
100 lines
5.3 KiB
Haskell
100 lines
5.3 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module ViewTests where
|
|
|
|
import Data.Time
|
|
import Simplex.Chat.View
|
|
import Simplex.Messaging.Agent.Protocol (SimplexNameDomain (..), SimplexNameInfo (..), SimplexNameType (..), SimplexTLD (..))
|
|
import Test.Hspec
|
|
|
|
viewTests :: Spec
|
|
viewTests = do
|
|
testRecent
|
|
testShareLinkStr
|
|
|
|
testShareLinkStr :: Spec
|
|
testShareLinkStr = describe "shareLinkStr" $ do
|
|
let alice = SimplexNameInfo NTContact (SimplexNameDomain TLDSimplex "alice" [])
|
|
grp = SimplexNameInfo NTPublicGroup (SimplexNameDomain TLDSimplex "team" [])
|
|
fallback = "simplex:/contact#/?v=2-7&smp=smp%3A%2F%2Fexample"
|
|
it "uses simplex:/name URI for a contact's simplex name" $
|
|
shareLinkStr (Just alice) fallback `shouldBe` "simplex:/name@alice.simplex"
|
|
it "uses simplex:/name URI for a public group simplex name" $
|
|
shareLinkStr (Just grp) fallback `shouldBe` "simplex:/name#team.simplex"
|
|
it "falls back to the raw connection link when simplexName is Nothing" $
|
|
shareLinkStr Nothing fallback `shouldBe` fallback
|
|
|
|
testRecent :: Spec
|
|
testRecent = describe "recent" $ do
|
|
let tz = hoursToTimeZone 1
|
|
now1159 = UTCTime (fromGregorian 2023 6 7) (secondsToDiffTime $ 10 * 3600 + 59 * 60) -- 11:59 in tz
|
|
now1200 = UTCTime (fromGregorian 2023 6 7) (secondsToDiffTime $ 11 * 3600) -- 12:00 in tz
|
|
today0000 = UTCTime (fromGregorian 2023 6 6) (secondsToDiffTime $ 23 * 3600) -- 00:00 in tz
|
|
today0600 = UTCTime (fromGregorian 2023 6 7) (secondsToDiffTime $ 5 * 3600) -- 06:00 in tz
|
|
today1200 = UTCTime (fromGregorian 2023 6 7) (secondsToDiffTime $ 11 * 3600) -- 12:00 in tz
|
|
today1800 = UTCTime (fromGregorian 2023 6 7) (secondsToDiffTime $ 17 * 3600) -- 18:00 in tz
|
|
today2359 = UTCTime (fromGregorian 2023 6 7) (secondsToDiffTime $ 22 * 3600 + 59 * 60) -- 23:59 in tz
|
|
yesterday0000 = UTCTime (fromGregorian 2023 6 5) (secondsToDiffTime $ 23 * 3600) -- 00:00 in tz
|
|
yesterday1759 = UTCTime (fromGregorian 2023 6 6) (secondsToDiffTime $ 16 * 3600 + 59 * 60) -- 17:59 in tz
|
|
yesterday1800 = UTCTime (fromGregorian 2023 6 6) (secondsToDiffTime $ 17 * 3600) -- 18:00 in tz
|
|
yesterday2359 = UTCTime (fromGregorian 2023 6 6) (secondsToDiffTime $ 22 * 3600 + 59 * 60) -- 23:59 in tz
|
|
sameDayLastMonth1900 = UTCTime (fromGregorian 2023 5 7) (secondsToDiffTime $ 18 * 3600) -- 19:00 in tz
|
|
prevDayLastMonth1900 = UTCTime (fromGregorian 2023 5 6) (secondsToDiffTime $ 18 * 3600) -- 19:00 in tz
|
|
sameDayLastYear1900 = UTCTime (fromGregorian 2022 6 7) (secondsToDiffTime $ 18 * 3600) -- 19:00 in tz
|
|
prevDayLastYear1900 = UTCTime (fromGregorian 2022 6 6) (secondsToDiffTime $ 18 * 3600) -- 19:00 in tz
|
|
tomorrow0000 = UTCTime (fromGregorian 2023 6 7) (secondsToDiffTime $ 23 * 3600) -- 00:00 in tz
|
|
tomorrow1759 = UTCTime (fromGregorian 2023 6 8) (secondsToDiffTime $ 16 * 3600 + 59 * 60) -- 17:59 in tz
|
|
tomorrow1800 = UTCTime (fromGregorian 2023 6 8) (secondsToDiffTime $ 17 * 3600) -- 18:00 in tz
|
|
tomorrow2359 = UTCTime (fromGregorian 2023 6 8) (secondsToDiffTime $ 22 * 3600 + 59 * 60) -- 23:59 in tz
|
|
sameDayNextMonth1900 = UTCTime (fromGregorian 2023 7 7) (secondsToDiffTime $ 18 * 3600) -- 19:00 in tz
|
|
prevDayNextMonth1900 = UTCTime (fromGregorian 2023 7 6) (secondsToDiffTime $ 18 * 3600) -- 19:00 in tz
|
|
sameDayNextYear1900 = UTCTime (fromGregorian 2024 6 7) (secondsToDiffTime $ 18 * 3600) -- 19:00 in tz
|
|
prevDayNextYear1900 = UTCTime (fromGregorian 2024 6 6) (secondsToDiffTime $ 18 * 3600) -- 19:00 in tz
|
|
test tz now1159 today0000 True
|
|
test tz now1159 today0600 True
|
|
test tz now1159 today1200 True
|
|
test tz now1159 today1800 True
|
|
test tz now1159 today2359 True
|
|
test tz now1159 yesterday0000 False
|
|
test tz now1159 yesterday1759 False
|
|
test tz now1159 yesterday1800 True
|
|
test tz now1159 yesterday2359 True
|
|
test tz now1159 sameDayLastMonth1900 False
|
|
test tz now1159 prevDayLastMonth1900 False
|
|
test tz now1159 sameDayLastYear1900 False
|
|
test tz now1159 prevDayLastYear1900 False
|
|
test tz now1159 tomorrow0000 False
|
|
test tz now1159 tomorrow1759 False
|
|
test tz now1159 tomorrow1800 False
|
|
test tz now1159 tomorrow2359 False
|
|
test tz now1159 sameDayNextMonth1900 False
|
|
test tz now1159 prevDayNextMonth1900 False
|
|
test tz now1159 sameDayNextYear1900 False
|
|
test tz now1159 prevDayNextYear1900 False
|
|
|
|
test tz now1200 today0000 True
|
|
test tz now1200 today0600 True
|
|
test tz now1200 today1200 True
|
|
test tz now1200 today1800 True
|
|
test tz now1200 today2359 True
|
|
test tz now1200 yesterday0000 False
|
|
test tz now1200 yesterday1759 False
|
|
test tz now1200 yesterday1800 False
|
|
test tz now1200 yesterday2359 False
|
|
test tz now1200 sameDayLastMonth1900 False
|
|
test tz now1200 prevDayLastMonth1900 False
|
|
test tz now1200 sameDayLastYear1900 False
|
|
test tz now1200 prevDayLastYear1900 False
|
|
test tz now1200 tomorrow0000 False
|
|
test tz now1200 tomorrow1759 False
|
|
test tz now1200 tomorrow1800 False
|
|
test tz now1200 tomorrow2359 False
|
|
test tz now1200 sameDayNextMonth1900 False
|
|
test tz now1200 prevDayNextMonth1900 False
|
|
test tz now1200 sameDayNextYear1900 False
|
|
test tz now1200 prevDayNextYear1900 False
|
|
where
|
|
test tz now time expected =
|
|
it ("returns " <> show expected <> " for time " <> show time <> " when time zone is " <> show tz <> " and current time is " <> show now) $
|
|
recent now tz time `shouldBe` expected
|