chapter 6: Replace unit by property test

This commit is contained in:
Alexander Kobjolke 2023-12-16 23:30:33 +01:00
parent 034b147740
commit 5e735e1b62

View file

@ -3,6 +3,7 @@ module PhotoGrooveTest exposing (..)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import Json.Decode as J
import Json.Encode as Encode exposing (Value)
import PhotoGroove as Testee
import Test exposing (..)
@ -10,10 +11,16 @@ import Test exposing (..)
suite : Test
suite =
describe "photoDecoder"
[ test "title defaults to '(untitled)'" <|
\_ ->
"""{"url": "example.com", "size": 5}"""
|> J.decodeString Testee.photoDecoder
|> Result.map (\p -> p.title)
[ fuzz2 Fuzz.string Fuzz.int "title always defaults to '(untitled)'" <|
\url size ->
mkPhoto url size
|> J.decodeValue Testee.photoDecoder
|> Result.map .title
|> Expect.equal (Ok "(untitled)")
]
mkPhoto : String -> Int -> Value
mkPhoto url size =
[ ( "url", Encode.string url ), ( "size", Encode.int size ) ]
|> Encode.object