mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-03-14 09:45:42 +00:00

* draft remote protocol types and external api * types (it compiles) * add error * move remote controller from http to remote host client protocol * refactor (doesnt compile) * fix compile * Connect remote session * WIP: wire in remote protocol * add commands and events * cleanup * fix desktop shutdown * prepare for testing remote files * Add file IO * update simplexmq to master with http2 to 4.1.4 * use json transcoder * update simplexmq * collapse RemoteHostSession states * fold RemoteHello back into the protocol command move http-command-response-http wrapper to protocol * use sendRemoteCommand with optional attachments use streaming request/response * ditch lazy body streaming * fix formatting * put body builder/processor closer together * wrap handleRemoteCommand around sending files * handle ChatError's too * remove binary, use 32-bit encoding for JSON bodies * enable tests * refactor * refactor request handling * return ChatError * Flatten remote host --------- Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
85 lines
4.4 KiB
Haskell
85 lines
4.4 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module ViewTests where
|
|
|
|
import Data.Time
|
|
import Simplex.Chat.View
|
|
import Test.Hspec
|
|
|
|
viewTests :: Spec
|
|
viewTests = do
|
|
testRecent
|
|
|
|
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
|