noredink-ui/tests/Spec/Nri/Ui/Util.elm
Erik Feeley db05f49222 Adds tests and updates implementation
One regression the safeIdString method had was that it did not collapse
when there were many dashes. This fixes that and adds some tests around
the behavior. I was hoping to figure out how to fuzz test this but was
unable to do so.
2022-11-02 17:02:09 -04:00

34 lines
1.4 KiB
Elm

module Spec.Nri.Ui.Util exposing (spec)
import Expect
import Nri.Ui.Util as Util
import Test exposing (..)
spec : Test
spec =
describe "Nri.Ui.Util"
[ describe "safeIdString transforms strings as expected"
[ test "with a comma" <|
\() ->
Util.safeIdString "Enable text-to-speech for Angela's account"
|> Expect.equal "enable-text-to-speech-for-angela-s-account"
, test "removes leading non alpha characters" <|
\() ->
Util.safeIdString "#@!!232now we are in business"
|> Expect.equal "now-we-are-in-business"
, test "hard mode" <|
\() ->
Util.safeIdString "!@#21something else interesting321$ ... hi"
|> Expect.equal "something-else-interesting321-hi"
, test "with capitol letters" <|
\() ->
Util.safeIdString "1232!@#%#@JFEKLfds-----SFJK3@#@jj23FDS........''''\"\"***"
|> Expect.equal "jfeklfds-sfjk3-jj23fds-"
, test "lotsa hyphens and dashes" <|
\() ->
Util.safeIdString "hellO----_______---HOw----___---____--ArE------___You___--__--__Today"
|> Expect.equal "hello-how-are-you-today"
]
]