mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-23 11:55:41 +03:00
Update elm-test and elm-test-rs, and remove redundant describe in test.
This commit is contained in:
parent
6aff87539f
commit
e5e9f8211a
@ -3,6 +3,6 @@
|
||||
"elm": "0.19.1",
|
||||
"elm-format": "0.8.5",
|
||||
"elm-json": "0.2.10",
|
||||
"elm-test-rs": "2.0.0"
|
||||
"elm-test-rs": "2.0.1"
|
||||
}
|
||||
}
|
||||
|
182
package-lock.json
generated
182
package-lock.json
generated
@ -45,8 +45,8 @@
|
||||
"cypress": "^9.5.1",
|
||||
"elm-optimize-level-2": "^0.1.5",
|
||||
"elm-review": "^2.7.2",
|
||||
"elm-test": "^0.19.1-revision7",
|
||||
"elm-tooling": "^1.3.0",
|
||||
"elm-test": "^0.19.1-revision8",
|
||||
"elm-tooling": "^1.8.0",
|
||||
"elm-verify-examples": "^5.2.0",
|
||||
"elmi-to-json": "^1.2.0",
|
||||
"mocha": "^9.1.0",
|
||||
@ -1184,9 +1184,9 @@
|
||||
"integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w=="
|
||||
},
|
||||
"node_modules/commander": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-9.0.0.tgz",
|
||||
"integrity": "sha512-JJfP2saEKbQqvW+FI93OYUB4ByV5cizMpFMiiJI8xDbBvQvSkIk0VvQdn1CZ8mqAO8Loq2h0gYTYtDFUZUeERw==",
|
||||
"version": "9.3.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-9.3.0.tgz",
|
||||
"integrity": "sha512-hv95iU5uXPbK83mjrJKuZyFM/LBAoCV/XhVGkS5Je6tl7sxr6A0ITMw5WoRV46/UaJ46Nllm3Xt7IaJhXTIkzw==",
|
||||
"engines": {
|
||||
"node": "^12.20.0 || >=14"
|
||||
}
|
||||
@ -1760,59 +1760,80 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/elm-solve-deps-wasm": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/elm-solve-deps-wasm/-/elm-solve-deps-wasm-1.0.1.tgz",
|
||||
"integrity": "sha512-A05XKZKhzM8vWTo8KvNR4g1ICt9iMPOAMfo79OK25c+tQaLSfQ8iMYvW6XgSEd+SgRfM5VSKX4hKEiH6iTiWsg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/elm-test": {
|
||||
"version": "0.19.1-revision7",
|
||||
"resolved": "https://registry.npmjs.org/elm-test/-/elm-test-0.19.1-revision7.tgz",
|
||||
"integrity": "sha512-sd3nCQMeYMaY84Sz41bVJ30ZvQN1/4ZcD8uYMOuUbM39FDh58NY9/AcImVJ7Z+gjCFdcSU6VscZzhUoPW8jp6Q==",
|
||||
"version": "0.19.1-revision8",
|
||||
"resolved": "https://registry.npmjs.org/elm-test/-/elm-test-0.19.1-revision8.tgz",
|
||||
"integrity": "sha512-n89sr4N1C/5KRPeVdbSd49UqOHkk1yDE+69Pxd98XGLt4OGkE/DlP1yrmUGEBSrsKzW/P2pvZcCFXrjtPhzoLw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"chalk": "^4.1.0",
|
||||
"chokidar": "^3.5.1",
|
||||
"commander": "^7.1.0",
|
||||
"chalk": "^4.1.2",
|
||||
"chokidar": "^3.5.3",
|
||||
"commander": "^9.3.0",
|
||||
"cross-spawn": "^7.0.3",
|
||||
"elm-tooling": "^1.2.0",
|
||||
"glob": "^7.1.6",
|
||||
"graceful-fs": "^4.2.4",
|
||||
"rimraf": "^3.0.2",
|
||||
"elm-solve-deps-wasm": "^1.0.1",
|
||||
"glob": "^8.0.3",
|
||||
"graceful-fs": "^4.2.10",
|
||||
"split": "^1.0.1",
|
||||
"which": "^2.0.2",
|
||||
"xmlbuilder": "^15.1.0"
|
||||
"xmlbuilder": "^15.1.1"
|
||||
},
|
||||
"bin": {
|
||||
"elm-test": "bin/elm-test"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
"node": ">=12.20.0"
|
||||
}
|
||||
},
|
||||
"node_modules/elm-test/node_modules/commander": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz",
|
||||
"integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/elm-test/node_modules/rimraf": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
|
||||
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
|
||||
"node_modules/elm-test/node_modules/brace-expansion": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
|
||||
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"glob": "^7.1.3"
|
||||
"balanced-match": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/elm-test/node_modules/glob": {
|
||||
"version": "8.0.3",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz",
|
||||
"integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"fs.realpath": "^1.0.0",
|
||||
"inflight": "^1.0.4",
|
||||
"inherits": "2",
|
||||
"minimatch": "^5.0.1",
|
||||
"once": "^1.3.0"
|
||||
},
|
||||
"bin": {
|
||||
"rimraf": "bin.js"
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/elm-test/node_modules/minimatch": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz",
|
||||
"integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"brace-expansion": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/elm-tooling": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/elm-tooling/-/elm-tooling-1.7.0.tgz",
|
||||
"integrity": "sha512-EHZ54voWrG3BhUONbH/wFw5U95H6N7R4QFgXHDrPIaDBDdeyNkpFu4QWArSWkhzxyCF7hqT8ya2yy7SferDsgg==",
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/elm-tooling/-/elm-tooling-1.8.0.tgz",
|
||||
"integrity": "sha512-IjMvW/VHqxLidlJSAocBGDBmqiZ1NS0lK/UCMRU4ULEEaTVjpSd/9Dv0mH2ok0H0egSTYx19GnrdL4Lq9h+z+A==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"elm-tooling": "index.js"
|
||||
@ -2964,9 +2985,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.9",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz",
|
||||
"integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ=="
|
||||
"version": "4.2.10",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz",
|
||||
"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA=="
|
||||
},
|
||||
"node_modules/gray-matter": {
|
||||
"version": "4.0.3",
|
||||
@ -7193,9 +7214,9 @@
|
||||
"integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w=="
|
||||
},
|
||||
"commander": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-9.0.0.tgz",
|
||||
"integrity": "sha512-JJfP2saEKbQqvW+FI93OYUB4ByV5cizMpFMiiJI8xDbBvQvSkIk0VvQdn1CZ8mqAO8Loq2h0gYTYtDFUZUeERw=="
|
||||
"version": "9.3.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-9.3.0.tgz",
|
||||
"integrity": "sha512-hv95iU5uXPbK83mjrJKuZyFM/LBAoCV/XhVGkS5Je6tl7sxr6A0ITMw5WoRV46/UaJ46Nllm3Xt7IaJhXTIkzw=="
|
||||
},
|
||||
"common-tags": {
|
||||
"version": "1.8.2",
|
||||
@ -7648,46 +7669,67 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"elm-solve-deps-wasm": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/elm-solve-deps-wasm/-/elm-solve-deps-wasm-1.0.1.tgz",
|
||||
"integrity": "sha512-A05XKZKhzM8vWTo8KvNR4g1ICt9iMPOAMfo79OK25c+tQaLSfQ8iMYvW6XgSEd+SgRfM5VSKX4hKEiH6iTiWsg==",
|
||||
"dev": true
|
||||
},
|
||||
"elm-test": {
|
||||
"version": "0.19.1-revision7",
|
||||
"resolved": "https://registry.npmjs.org/elm-test/-/elm-test-0.19.1-revision7.tgz",
|
||||
"integrity": "sha512-sd3nCQMeYMaY84Sz41bVJ30ZvQN1/4ZcD8uYMOuUbM39FDh58NY9/AcImVJ7Z+gjCFdcSU6VscZzhUoPW8jp6Q==",
|
||||
"version": "0.19.1-revision8",
|
||||
"resolved": "https://registry.npmjs.org/elm-test/-/elm-test-0.19.1-revision8.tgz",
|
||||
"integrity": "sha512-n89sr4N1C/5KRPeVdbSd49UqOHkk1yDE+69Pxd98XGLt4OGkE/DlP1yrmUGEBSrsKzW/P2pvZcCFXrjtPhzoLw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chalk": "^4.1.0",
|
||||
"chokidar": "^3.5.1",
|
||||
"commander": "^7.1.0",
|
||||
"chalk": "^4.1.2",
|
||||
"chokidar": "^3.5.3",
|
||||
"commander": "^9.3.0",
|
||||
"cross-spawn": "^7.0.3",
|
||||
"elm-tooling": "^1.2.0",
|
||||
"glob": "^7.1.6",
|
||||
"graceful-fs": "^4.2.4",
|
||||
"rimraf": "^3.0.2",
|
||||
"elm-solve-deps-wasm": "^1.0.1",
|
||||
"glob": "^8.0.3",
|
||||
"graceful-fs": "^4.2.10",
|
||||
"split": "^1.0.1",
|
||||
"which": "^2.0.2",
|
||||
"xmlbuilder": "^15.1.0"
|
||||
"xmlbuilder": "^15.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz",
|
||||
"integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==",
|
||||
"dev": true
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
|
||||
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
|
||||
"brace-expansion": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
|
||||
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"glob": "^7.1.3"
|
||||
"balanced-match": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"glob": {
|
||||
"version": "8.0.3",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz",
|
||||
"integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs.realpath": "^1.0.0",
|
||||
"inflight": "^1.0.4",
|
||||
"inherits": "2",
|
||||
"minimatch": "^5.0.1",
|
||||
"once": "^1.3.0"
|
||||
}
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz",
|
||||
"integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^2.0.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"elm-tooling": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/elm-tooling/-/elm-tooling-1.7.0.tgz",
|
||||
"integrity": "sha512-EHZ54voWrG3BhUONbH/wFw5U95H6N7R4QFgXHDrPIaDBDdeyNkpFu4QWArSWkhzxyCF7hqT8ya2yy7SferDsgg==",
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/elm-tooling/-/elm-tooling-1.8.0.tgz",
|
||||
"integrity": "sha512-IjMvW/VHqxLidlJSAocBGDBmqiZ1NS0lK/UCMRU4ULEEaTVjpSd/9Dv0mH2ok0H0egSTYx19GnrdL4Lq9h+z+A==",
|
||||
"dev": true
|
||||
},
|
||||
"elm-verify-examples": {
|
||||
@ -8464,9 +8506,9 @@
|
||||
}
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "4.2.9",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz",
|
||||
"integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ=="
|
||||
"version": "4.2.10",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz",
|
||||
"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA=="
|
||||
},
|
||||
"gray-matter": {
|
||||
"version": "4.0.3",
|
||||
|
@ -56,8 +56,8 @@
|
||||
"cypress": "^9.5.1",
|
||||
"elm-optimize-level-2": "^0.1.5",
|
||||
"elm-review": "^2.7.2",
|
||||
"elm-test": "^0.19.1-revision7",
|
||||
"elm-tooling": "^1.3.0",
|
||||
"elm-test": "^0.19.1-revision8",
|
||||
"elm-tooling": "^1.8.0",
|
||||
"elm-verify-examples": "^5.2.0",
|
||||
"elmi-to-json": "^1.2.0",
|
||||
"mocha": "^9.1.0",
|
||||
|
@ -7,148 +7,147 @@ import Pages.Field as Field exposing (Field(..))
|
||||
import Test exposing (Test, describe, test)
|
||||
|
||||
|
||||
all : Test
|
||||
all : List Test
|
||||
all =
|
||||
describe "FieldTests"
|
||||
[ test "options" <|
|
||||
\() ->
|
||||
(Field.select
|
||||
[ ( "link", Link )
|
||||
, ( "post", Post )
|
||||
[ test "options" <|
|
||||
\() ->
|
||||
(Field.select
|
||||
[ ( "link", Link )
|
||||
, ( "post", Post )
|
||||
]
|
||||
(\_ -> "Invalid")
|
||||
|> Field.required "Required"
|
||||
)
|
||||
|> expect
|
||||
[ ( Just "link", Ok Link )
|
||||
, ( Just "post", Ok Post )
|
||||
, ( Just "unexpected", Err [ "Invalid" ] )
|
||||
]
|
||||
(\_ -> "Invalid")
|
||||
|> Field.required "Required"
|
||||
)
|
||||
|> expect
|
||||
[ ( Just "link", Ok Link )
|
||||
, ( Just "post", Ok Post )
|
||||
, ( Just "unexpected", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "validates optional ints" <|
|
||||
\() ->
|
||||
Field.int { invalid = \_ -> "Invalid" }
|
||||
|> expect
|
||||
[ ( Just "", Ok Nothing )
|
||||
, ( Nothing, Ok Nothing )
|
||||
, ( Just "1", Ok (Just 1) )
|
||||
, ( Just "1.23", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "required int" <|
|
||||
\() ->
|
||||
Field.int { invalid = \_ -> "Invalid" }
|
||||
|> Field.required "Required"
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Required" ] )
|
||||
, ( Nothing, Err [ "Required" ] )
|
||||
, ( Just "1", Ok 1 )
|
||||
, ( Just "1.23", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "required int with range" <|
|
||||
\() ->
|
||||
Field.int { invalid = \_ -> "Invalid" }
|
||||
|> Field.required "Required"
|
||||
|> Field.withMin (Value.int 100) "Must be at least 100"
|
||||
--|> Field.withMax (Value.int 200)
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Required" ] )
|
||||
, ( Nothing, Err [ "Required" ] )
|
||||
, ( Just "1", Err [ "Must be at least 100" ] )
|
||||
, ( Just "100", Ok 100 )
|
||||
, ( Just "1.23", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "required float with range" <|
|
||||
\() ->
|
||||
Field.float { invalid = \_ -> "Invalid" }
|
||||
|> Field.required "Required"
|
||||
|> Field.withMin (Value.float 100) "Must be at least 100"
|
||||
|> Field.withMax (Value.float 200) "Too large"
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Required" ] )
|
||||
, ( Nothing, Err [ "Required" ] )
|
||||
, ( Just "1", Err [ "Must be at least 100" ] )
|
||||
, ( Just "100.1", Ok 100.1 )
|
||||
, ( Just "200", Ok 200 )
|
||||
, ( Just "200.1", Err [ "Too large" ] )
|
||||
, ( Just "201", Err [ "Too large" ] )
|
||||
, ( Just "99.9", Err [ "Must be at least 100" ] )
|
||||
]
|
||||
, test "optional text" <|
|
||||
\() ->
|
||||
Field.text
|
||||
|> expect
|
||||
[ ( Just "", Ok Nothing )
|
||||
, ( Nothing, Ok Nothing )
|
||||
, ( Just "Hello", Ok (Just "Hello") )
|
||||
]
|
||||
, test "text with minlength and maxlength" <|
|
||||
\() ->
|
||||
Field.text
|
||||
|> Field.withMinLength 4 "Must be at least 4 characters"
|
||||
|> Field.withMaxLength 10 "Must be at most 10 characters"
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Must be at least 4 characters" ] )
|
||||
, ( Nothing, Err [ "Must be at least 4 characters" ] )
|
||||
, ( Just "abc", Err [ "Must be at least 4 characters" ] )
|
||||
, ( Just "abcd", Ok (Just "abcd") )
|
||||
, ( Just "abcde", Ok (Just "abcde") )
|
||||
, ( Just "1234567890", Ok (Just "1234567890") )
|
||||
, ( Just "1234567890a", Err [ "Must be at most 10 characters" ] )
|
||||
]
|
||||
, test "required date with range" <|
|
||||
\() ->
|
||||
Field.date { invalid = \_ -> "Invalid" }
|
||||
|> Field.required "Required"
|
||||
|> Field.withMin (Value.date (Date.fromRataDie 738156)) "Must be 2022 or later"
|
||||
|> Field.withMax (Value.date (Date.fromRataDie 738158)) "Choose an earlier date"
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Required" ] )
|
||||
, ( Nothing, Err [ "Required" ] )
|
||||
, ( Just "2021-12-31", Err [ "Must be 2022 or later" ] )
|
||||
, ( Just "2022-01-01", Ok (Date.fromRataDie 738156) )
|
||||
, ( Just "2022-01-02", Ok (Date.fromRataDie 738157) )
|
||||
, ( Just "2022-01-04", Err [ "Choose an earlier date" ] )
|
||||
, ( Just "1.23", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "optional date with range" <|
|
||||
\() ->
|
||||
Field.date { invalid = \_ -> "Invalid" }
|
||||
|> Field.withMin (Value.date (Date.fromRataDie 738156)) "Must be 2022 or later"
|
||||
|> Field.withMax (Value.date (Date.fromRataDie 738158)) "Choose an earlier date"
|
||||
|> expect
|
||||
[ ( Just "", Ok Nothing )
|
||||
, ( Nothing, Ok Nothing )
|
||||
, ( Just "2021-12-31", Err [ "Must be 2022 or later" ] )
|
||||
, ( Just "2022-01-01", Ok (Just (Date.fromRataDie 738156)) )
|
||||
, ( Just "2022-01-02", Ok (Just (Date.fromRataDie 738157)) )
|
||||
, ( Just "2022-01-04", Err [ "Choose an earlier date" ] )
|
||||
, ( Just "1.23", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "optional date" <|
|
||||
\() ->
|
||||
Field.date { invalid = \_ -> "Invalid" }
|
||||
|> expect
|
||||
[ ( Just "", Ok Nothing )
|
||||
, ( Nothing, Ok Nothing )
|
||||
, ( Just "2022-01-01", Ok (Just (Date.fromRataDie 738156)) )
|
||||
]
|
||||
, test "required date" <|
|
||||
\() ->
|
||||
Field.date { invalid = \_ -> "Invalid" }
|
||||
|> Field.required "Required"
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Required" ] )
|
||||
, ( Nothing, Err [ "Required" ] )
|
||||
, ( Just "2022-01-01", Ok (Date.fromRataDie 738156) )
|
||||
]
|
||||
, test "optional time" <|
|
||||
\() ->
|
||||
Field.time { invalid = \_ -> "Invalid" }
|
||||
|> expect
|
||||
[ ( Just "", Ok Nothing )
|
||||
, ( Nothing, Ok Nothing )
|
||||
, ( Just "13:45", Ok (Just { hours = 13, minutes = 45 }) )
|
||||
]
|
||||
]
|
||||
, test "validates optional ints" <|
|
||||
\() ->
|
||||
Field.int { invalid = \_ -> "Invalid" }
|
||||
|> expect
|
||||
[ ( Just "", Ok Nothing )
|
||||
, ( Nothing, Ok Nothing )
|
||||
, ( Just "1", Ok (Just 1) )
|
||||
, ( Just "1.23", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "required int" <|
|
||||
\() ->
|
||||
Field.int { invalid = \_ -> "Invalid" }
|
||||
|> Field.required "Required"
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Required" ] )
|
||||
, ( Nothing, Err [ "Required" ] )
|
||||
, ( Just "1", Ok 1 )
|
||||
, ( Just "1.23", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "required int with range" <|
|
||||
\() ->
|
||||
Field.int { invalid = \_ -> "Invalid" }
|
||||
|> Field.required "Required"
|
||||
|> Field.withMin (Value.int 100) "Must be at least 100"
|
||||
--|> Field.withMax (Value.int 200)
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Required" ] )
|
||||
, ( Nothing, Err [ "Required" ] )
|
||||
, ( Just "1", Err [ "Must be at least 100" ] )
|
||||
, ( Just "100", Ok 100 )
|
||||
, ( Just "1.23", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "required float with range" <|
|
||||
\() ->
|
||||
Field.float { invalid = \_ -> "Invalid" }
|
||||
|> Field.required "Required"
|
||||
|> Field.withMin (Value.float 100) "Must be at least 100"
|
||||
|> Field.withMax (Value.float 200) "Too large"
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Required" ] )
|
||||
, ( Nothing, Err [ "Required" ] )
|
||||
, ( Just "1", Err [ "Must be at least 100" ] )
|
||||
, ( Just "100.1", Ok 100.1 )
|
||||
, ( Just "200", Ok 200 )
|
||||
, ( Just "200.1", Err [ "Too large" ] )
|
||||
, ( Just "201", Err [ "Too large" ] )
|
||||
, ( Just "99.9", Err [ "Must be at least 100" ] )
|
||||
]
|
||||
, test "optional text" <|
|
||||
\() ->
|
||||
Field.text
|
||||
|> expect
|
||||
[ ( Just "", Ok Nothing )
|
||||
, ( Nothing, Ok Nothing )
|
||||
, ( Just "Hello", Ok (Just "Hello") )
|
||||
]
|
||||
, test "text with minlength and maxlength" <|
|
||||
\() ->
|
||||
Field.text
|
||||
|> Field.withMinLength 4 "Must be at least 4 characters"
|
||||
|> Field.withMaxLength 10 "Must be at most 10 characters"
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Must be at least 4 characters" ] )
|
||||
, ( Nothing, Err [ "Must be at least 4 characters" ] )
|
||||
, ( Just "abc", Err [ "Must be at least 4 characters" ] )
|
||||
, ( Just "abcd", Ok (Just "abcd") )
|
||||
, ( Just "abcde", Ok (Just "abcde") )
|
||||
, ( Just "1234567890", Ok (Just "1234567890") )
|
||||
, ( Just "1234567890a", Err [ "Must be at most 10 characters" ] )
|
||||
]
|
||||
, test "required date with range" <|
|
||||
\() ->
|
||||
Field.date { invalid = \_ -> "Invalid" }
|
||||
|> Field.required "Required"
|
||||
|> Field.withMin (Value.date (Date.fromRataDie 738156)) "Must be 2022 or later"
|
||||
|> Field.withMax (Value.date (Date.fromRataDie 738158)) "Choose an earlier date"
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Required" ] )
|
||||
, ( Nothing, Err [ "Required" ] )
|
||||
, ( Just "2021-12-31", Err [ "Must be 2022 or later" ] )
|
||||
, ( Just "2022-01-01", Ok (Date.fromRataDie 738156) )
|
||||
, ( Just "2022-01-02", Ok (Date.fromRataDie 738157) )
|
||||
, ( Just "2022-01-04", Err [ "Choose an earlier date" ] )
|
||||
, ( Just "1.23", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "optional date with range" <|
|
||||
\() ->
|
||||
Field.date { invalid = \_ -> "Invalid" }
|
||||
|> Field.withMin (Value.date (Date.fromRataDie 738156)) "Must be 2022 or later"
|
||||
|> Field.withMax (Value.date (Date.fromRataDie 738158)) "Choose an earlier date"
|
||||
|> expect
|
||||
[ ( Just "", Ok Nothing )
|
||||
, ( Nothing, Ok Nothing )
|
||||
, ( Just "2021-12-31", Err [ "Must be 2022 or later" ] )
|
||||
, ( Just "2022-01-01", Ok (Just (Date.fromRataDie 738156)) )
|
||||
, ( Just "2022-01-02", Ok (Just (Date.fromRataDie 738157)) )
|
||||
, ( Just "2022-01-04", Err [ "Choose an earlier date" ] )
|
||||
, ( Just "1.23", Err [ "Invalid" ] )
|
||||
]
|
||||
, test "optional date" <|
|
||||
\() ->
|
||||
Field.date { invalid = \_ -> "Invalid" }
|
||||
|> expect
|
||||
[ ( Just "", Ok Nothing )
|
||||
, ( Nothing, Ok Nothing )
|
||||
, ( Just "2022-01-01", Ok (Just (Date.fromRataDie 738156)) )
|
||||
]
|
||||
, test "required date" <|
|
||||
\() ->
|
||||
Field.date { invalid = \_ -> "Invalid" }
|
||||
|> Field.required "Required"
|
||||
|> expect
|
||||
[ ( Just "", Err [ "Required" ] )
|
||||
, ( Nothing, Err [ "Required" ] )
|
||||
, ( Just "2022-01-01", Ok (Date.fromRataDie 738156) )
|
||||
]
|
||||
, test "optional time" <|
|
||||
\() ->
|
||||
Field.time { invalid = \_ -> "Invalid" }
|
||||
|> expect
|
||||
[ ( Just "", Ok Nothing )
|
||||
, ( Nothing, Ok Nothing )
|
||||
, ( Just "13:45", Ok (Just { hours = 13, minutes = 45 }) )
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
expect : List ( Maybe String, Result (List error) parsed ) -> Field error parsed data kind constraints -> Expect.Expectation
|
||||
|
Loading…
Reference in New Issue
Block a user