Through section 6.2

This commit is contained in:
asonix 2022-10-15 17:45:58 -05:00
parent 0c408d5362
commit 8af7b143e4
3 changed files with 46 additions and 2 deletions

View file

@ -23,7 +23,9 @@
}
},
"test-dependencies": {
"direct": {},
"direct": {
"elm-explorations/test": "2.0.1"
},
"indirect": {}
}
}

View file

@ -1,4 +1,4 @@
port module PhotoGroove exposing (main)
port module PhotoGroove exposing (Model, Msg(..), initialModel, main, photoDecoder, update)
import Browser
import Html exposing (..)

View file

@ -0,0 +1,42 @@
module PhotoGrooveTests exposing (..)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import Json.Decode as Decode exposing (decodeValue)
import Json.Encode as Encode
import PhotoGroove exposing (Model, Msg(..), initialModel, photoDecoder, update)
import Test exposing (..)
decoderTest : Test
decoderTest =
fuzz2 string int "title defaults to (untitled)" <|
\url size ->
Encode.object
[ ( "url", Encode.string url )
, ( "size", Encode.int size )
]
|> decodeValue photoDecoder
|> Result.map .title
|> Expect.equal
(Ok "(untitled)")
sliders : Test
sliders =
describe "Slider sets the desired field in the Model"
[ testSlider "SlidHue" SlidHue .hue
, testSlider "SlidRipple" SlidRipple .ripple
, testSlider "SlidNoise" SlidNoise .noise
]
testSlider : String -> (Int -> Msg) -> (Model -> Int) -> Test
testSlider description toMsg amountFromModel =
fuzz int description <|
\amount ->
initialModel
|> update (toMsg amount)
|> Tuple.first
|> amountFromModel
|> Expect.equal amount