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