elm-matrix-sdk-beta/tests/Test/Values/Room.elm

73 lines
2.6 KiB
Elm
Raw Normal View History

2024-04-24 09:12:46 +00:00
module Test.Values.Room exposing (..)
import Test exposing (..)
import Fuzz exposing (Fuzzer)
import Internal.Values.Room as Room exposing (Room)
import Test.Values.Event as TestEvent
import Test.Filter.Timeline as TestFilter
import Json.Encode as E
import Json.Decode as D
import Expect
placeholderValue : E.Value
placeholderValue = E.string "foo bar baz"
fuzzer : Fuzzer Room
fuzzer =
Fuzz.string
|> Fuzz.map Room.init
|> addAFewTimes Fuzz.string (\key -> Room.setAccountData key placeholderValue)
|> addAFewTimes (Fuzz.list TestEvent.fuzzer) Room.addEvents
|> add4AFewTimes (Fuzz.list TestEvent.fuzzer) TestFilter.fuzzer (Fuzz.maybe Fuzz.string) Fuzz.string
(\a b c d ->
Room.Batch a b c d
|> Room.addBatch
)
|> add4AFewTimes (Fuzz.list TestEvent.fuzzer) TestFilter.fuzzer (Fuzz.maybe Fuzz.string) Fuzz.string
(\a b c d ->
Room.Batch a b c d
|> Room.addSync
)
addAFewTimes : Fuzzer a -> (a -> Room -> Room) -> Fuzzer Room -> Fuzzer Room
addAFewTimes fuzz f roomFuzzer =
Fuzz.map2
(\items room -> List.foldl f room items)
(Fuzz.list fuzz)
roomFuzzer
add2AFewTimes : Fuzzer a -> Fuzzer b -> (a -> b -> Room -> Room) -> Fuzzer Room -> Fuzzer Room
add2AFewTimes fuzz1 fuzz2 f roomFuzzer =
Fuzz.map2
(\items room -> List.foldl (\(a, b) -> f a b) room items)
( Fuzz.list <| Fuzz.pair fuzz1 fuzz2 )
roomFuzzer
add3AFewTimes : Fuzzer a -> Fuzzer b -> Fuzzer c -> (a -> b -> c -> Room -> Room) -> Fuzzer Room -> Fuzzer Room
add3AFewTimes fuzz1 fuzz2 fuzz3 f roomFuzzer =
Fuzz.map2
(\items room -> List.foldl (\(a, b, c) -> f a b c) room items)
( Fuzz.list <| Fuzz.triple fuzz1 fuzz2 fuzz3 )
roomFuzzer
add4AFewTimes : Fuzzer a -> Fuzzer b -> Fuzzer c -> Fuzzer d -> (a -> b -> c -> d -> Room -> Room) -> Fuzzer Room -> Fuzzer Room
add4AFewTimes fuzz1 fuzz2 fuzz3 fuzz4 f roomFuzzer =
Fuzz.map2
(\items room -> List.foldl (\((a, b), (c, d)) -> f a b c d) room items)
( Fuzz.list <| Fuzz.pair (Fuzz.pair fuzz1 fuzz2) (Fuzz.pair fuzz3 fuzz4) )
roomFuzzer
suite : Test
suite =
describe "Room"
[ fuzz3 fuzzer Fuzz.string Fuzz.string "JSON Account Data can be overridden"
(\room key text ->
room
|> Room.setAccountData key (E.string text)
|> Room.getAccountData key
|> Maybe.map (D.decodeValue D.string)
|> Maybe.andThen Result.toMaybe
|> Expect.equal (Just text)
)
]