mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-25 09:21:57 +03:00
Migrate some test cases.
This commit is contained in:
parent
8a6bd84c11
commit
0e2ab10e50
@ -1,7 +1,7 @@
|
||||
module Form.Validation exposing
|
||||
( Validation, andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withErrorIf, withFallback
|
||||
, value
|
||||
, fail2, fieldName, withError2
|
||||
, fail2, fieldName, withError2, withErrorIf2
|
||||
)
|
||||
|
||||
{-|
|
||||
@ -97,6 +97,21 @@ withErrorIf includeError (Validation _ key _) error (Validation viewField name (
|
||||
)
|
||||
|
||||
|
||||
{-| -}
|
||||
withErrorIf2 : Bool -> Validation error ignored field -> error -> Validation error parsed named -> Validation error parsed named
|
||||
withErrorIf2 includeError (Validation _ key _) error (Validation viewField name ( maybeParsedA, errorsA )) =
|
||||
-- TODO use something like { field : kind } for type variable to check that it represents a field
|
||||
Validation viewField
|
||||
name
|
||||
( maybeParsedA
|
||||
, if includeError then
|
||||
errorsA |> insertIfNonempty (key |> Maybe.withDefault "") [ error ]
|
||||
|
||||
else
|
||||
errorsA
|
||||
)
|
||||
|
||||
|
||||
|
||||
--map : (parsed -> mapped) -> Validation error parsed named -> Validation error mapped named
|
||||
|
||||
|
@ -23,26 +23,28 @@ all =
|
||||
describe "Form Parser" <|
|
||||
let
|
||||
passwordConfirmationParser =
|
||||
Form.init
|
||||
Form.init2
|
||||
(\password passwordConfirmation ->
|
||||
{ combine =
|
||||
Validation.succeed
|
||||
(\passwordValue passwordConfirmationValue ->
|
||||
Validation.succeed { password = passwordValue }
|
||||
|> Validation.withErrorIf (passwordValue /= passwordConfirmationValue)
|
||||
|> Validation.withErrorIf2 (passwordValue /= passwordConfirmationValue)
|
||||
passwordConfirmation
|
||||
"Must match password"
|
||||
)
|
||||
|> Validation.andMap password
|
||||
|> Validation.andMap passwordConfirmation
|
||||
|> Validation.andThen identity
|
||||
, view = \info -> Div
|
||||
}
|
||||
)
|
||||
(\_ _ _ -> Div)
|
||||
|> Form.field "password" (Field.text |> Field.required "Password is required")
|
||||
|> Form.field "password-confirmation" (Field.text |> Field.required "Password confirmation is required")
|
||||
|> Form.field2 "password" (Field.text |> Field.required "Password is required")
|
||||
|> Form.field2 "password-confirmation" (Field.text |> Field.required "Password confirmation is required")
|
||||
in
|
||||
[ test "matching password" <|
|
||||
\() ->
|
||||
Form.runServerSide
|
||||
Form.runServerSide4
|
||||
(fields
|
||||
[ ( "password", "mypassword" )
|
||||
, ( "password-confirmation", "mypassword" )
|
||||
@ -55,7 +57,7 @@ all =
|
||||
)
|
||||
, test "non-matching password" <|
|
||||
\() ->
|
||||
Form.runServerSide
|
||||
Form.runServerSide4
|
||||
(fields
|
||||
[ ( "password", "mypassword" )
|
||||
, ( "password-confirmation", "doesnt-match-password" )
|
||||
|
Loading…
Reference in New Issue
Block a user