mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-27 05:44:17 +03:00
Fix test failure.
This commit is contained in:
parent
669bc2e53f
commit
b6d03955bc
@ -1,4 +1,4 @@
|
||||
module Validation exposing (Validation, andMap, andThen, fail, fromMaybe, fromResult, map, map2, succeed, withField)
|
||||
module Validation exposing (Validation, andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withField)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
|
||||
@ -12,11 +12,21 @@ succeed parsed =
|
||||
( Just parsed, Dict.empty )
|
||||
|
||||
|
||||
parseWithError : parsed -> ( String, error ) -> Validation error parsed
|
||||
parseWithError parsed ( key, error ) =
|
||||
( Just parsed, Dict.singleton key [ error ] )
|
||||
|
||||
|
||||
fail : String -> error -> Validation error parsed
|
||||
fail key parsed =
|
||||
( Nothing, Dict.singleton key [ parsed ] )
|
||||
|
||||
|
||||
withError : String -> error -> Validation error parsed -> Validation error parsed
|
||||
withError key error ( maybeParsedA, errorsA ) =
|
||||
( maybeParsedA, errorsA |> insertIfNonempty key [ error ] )
|
||||
|
||||
|
||||
map : (parsed -> mapped) -> Validation error parsed -> Validation error mapped
|
||||
map mapFn ( maybeParsedA, errorsA ) =
|
||||
( Maybe.map mapFn maybeParsedA, errorsA )
|
||||
|
@ -156,18 +156,19 @@ all =
|
||||
]
|
||||
, describe "dependent validations" <|
|
||||
let
|
||||
--checkinFormParser : Form.HtmlForm String ( Date, Date ) data msg
|
||||
checkinFormParser : Form.Form String ( Maybe ( Date, Date ), Dict String (List String) ) data (Form.Context String data -> MyView)
|
||||
checkinFormParser : Form String (Validation String ( Date, Date )) data (Form.Context String data -> MyView)
|
||||
checkinFormParser =
|
||||
Form.init
|
||||
(\checkin checkout ->
|
||||
Validation.succeed
|
||||
(\checkinValue checkoutValue ->
|
||||
if Date.toRataDie checkinValue >= Date.toRataDie checkoutValue then
|
||||
Validation.fail checkin.name "Must be before checkout"
|
||||
Validation.succeed ( checkinValue, checkoutValue )
|
||||
|> (if Date.toRataDie checkinValue >= Date.toRataDie checkoutValue then
|
||||
Validation.withError checkin.name "Must be before checkout"
|
||||
|
||||
else
|
||||
Validation.succeed ( checkinValue, checkoutValue )
|
||||
else
|
||||
identity
|
||||
)
|
||||
)
|
||||
|> Validation.withField checkin
|
||||
|> Validation.withField checkout
|
||||
@ -203,7 +204,6 @@ all =
|
||||
checkinFormParser
|
||||
|> Expect.equal
|
||||
( Just ( Date.fromRataDie 738158, Date.fromRataDie 738156 )
|
||||
--( Just (Date.fromRataDie 738158)
|
||||
, Dict.fromList
|
||||
[ ( "checkin", [ "Must be before checkout" ] )
|
||||
]
|
||||
@ -219,20 +219,26 @@ all =
|
||||
(Form.init
|
||||
(\postForm_ ->
|
||||
postForm_ ()
|
||||
-- TODO @@@@ remove Tuple.first
|
||||
|> Tuple.first
|
||||
-- TODO simplify
|
||||
|> Tuple.mapFirst Just
|
||||
|> Validation.andThen identity
|
||||
)
|
||||
(\formState postForm_ -> ( [], [ Div ] ))
|
||||
|> Form.dynamic
|
||||
(\() ->
|
||||
Form.init
|
||||
(\password passwordConfirmation ->
|
||||
if password.value == passwordConfirmation.value then
|
||||
Form.ok password.value
|
||||
Validation.succeed
|
||||
(\passwordValue passwordConfirmationValue ->
|
||||
if passwordValue == passwordConfirmationValue then
|
||||
Validation.succeed { password = passwordValue }
|
||||
|
||||
else
|
||||
--Form.ok password.value|>
|
||||
Form.fail passwordConfirmation "Must match password"
|
||||
else
|
||||
Validation.fail passwordConfirmation.name "Must match password"
|
||||
)
|
||||
|> Validation.withField password
|
||||
|> Validation.withField passwordConfirmation
|
||||
|> Validation.andThen identity
|
||||
)
|
||||
(\formState password passwordConfirmation -> [ Div ])
|
||||
|> Form.field "password" (Field.text |> Field.password |> Field.required "Required")
|
||||
@ -289,8 +295,9 @@ all =
|
||||
|> Validation.andThen
|
||||
(\kindValue ->
|
||||
postForm_ kindValue
|
||||
-- TODO @@@@@ remove Tuple.first
|
||||
|> Tuple.first
|
||||
---- TODO simplify
|
||||
|> Tuple.mapFirst Just
|
||||
|> Validation.andThen identity
|
||||
)
|
||||
)
|
||||
(\fieldErrors kind postForm_ ->
|
||||
|
Loading…
Reference in New Issue
Block a user