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

93 lines
2.6 KiB
Elm
Raw Normal View History

2023-12-24 00:26:06 +00:00
module Test.Values.Settings exposing (..)
import Expect
import Fuzz exposing (Fuzzer)
import Internal.Config.Default as Default
import Internal.Values.Settings as Settings exposing (Settings)
import Json.Decode as D
import Json.Encode as E
import Test exposing (..)
fuzzer : Fuzzer Settings
fuzzer =
2024-07-16 08:20:38 +00:00
Fuzz.map5 Settings
2023-12-24 00:26:06 +00:00
(Fuzz.oneOf
[ Fuzz.constant Default.currentVersion
, Fuzz.string
]
)
(Fuzz.oneOf
[ Fuzz.constant Default.deviceName
, Fuzz.string
]
)
2024-07-16 08:20:38 +00:00
(Fuzz.maybe Fuzz.string)
(Fuzz.oneOf
[ Fuzz.constant Default.removePasswordOnLogin
, Fuzz.bool
]
)
2023-12-24 00:26:06 +00:00
(Fuzz.oneOf
[ Fuzz.constant Default.syncTime
, Fuzz.int
]
)
suite : Test
suite =
describe "Settings"
[ describe "init"
[ test "Current version"
(Settings.init
|> .currentVersion
|> Expect.equal Default.currentVersion
|> always
)
, test "Device name"
(Settings.init
|> .deviceName
|> Expect.equal Default.deviceName
|> always
)
, test "Remove password on login"
(Settings.init
|> .removePasswordOnLogin
|> Expect.equal Default.removePasswordOnLogin
|> always
)
2023-12-24 00:26:06 +00:00
, test "Sync time"
(Settings.init
|> .syncTime
|> Expect.equal Default.syncTime
|> always
)
, test "JSON encode init is {}"
(Settings.init
|> Settings.encode
|> E.encode 0
|> Expect.equal "{}"
|> always
)
, test "JSON decode {} is init"
("{}"
|> D.decodeString Settings.decoder
|> Expect.equal (Ok ( Settings.init, [] ))
2023-12-24 00:26:06 +00:00
|> always
)
]
, describe "JSON"
[ fuzz2 fuzzer
Fuzz.int
"JSON encode -> JSON decode -> identical"
(\settings indent ->
settings
|> Settings.encode
|> E.encode indent
|> D.decodeString Settings.decoder
|> Expect.equal (Ok ( settings, [] ))
2023-12-24 00:26:06 +00:00
)
]
]