Skip to content

Commit

Permalink
Fix tests and reivew
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Aug 17, 2023
1 parent 9505e58 commit d9d6788
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 115 deletions.
2 changes: 1 addition & 1 deletion storybook/.babelrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
]
],
"plugins": []
}
}
8 changes: 4 additions & 4 deletions storybook/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ module.exports = {
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
'storybook-dark-mode',
"storybook-dark-mode",
],

framework: {
name: "@storybook/html-webpack5",
options: {}
options: {},
},

staticDirs: ["../static"],

docs: {
autodocs: true
}
autodocs: true,
},
};
117 changes: 7 additions & 110 deletions tests/UI/DateTimeTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,118 +7,15 @@ import UI.DateTime as DateTime

fromString : Test
fromString =
describe "Slug.fromString"
[ test "Creates a Slug from a valid string" <|
describe "DateTime.fromISO8601"
[ test "Creates a DateTime from a valid ISO8601 string" <|
\_ ->
"tolkien"
|> Slug.fromString
|> Maybe.map Slug.toString
|> Expect.equal (Just "tolkien")
"2023-08-15T15:00:00.998Z"
|> DateTime.fromISO8601
|> Maybe.map DateTime.toISO8601
|> Expect.equal (Just "2023-08-15T15:00:00.998Z")
, test "Fails to create from an invalid string" <|
\_ ->
Slug.fromString "-----"
DateTime.fromISO8601 "-----"
|> Expect.equal Nothing
]


equals : Test
equals =
describe "Slug.equals"
[ test "Returns True when the slugs are the same" <|
\_ ->
let
a =
Slug.fromString "tolkien"

b =
Slug.fromString "tolkien"

result =
Maybe.map2 Slug.equals a b
|> Maybe.withDefault False
in
Expect.equal True result
|> Expect.onFail "Expected slugs tolkien and tolkien to be equal"
, test "Returns False when the slugs are different" <|
\_ ->
let
a =
Slug.fromString "gimli"

b =
Slug.fromString "legolas"

result =
Maybe.map2 Slug.equals a b
|> Maybe.withDefault False
in
Expect.equal False result
|> Expect.onFail "Expected slugs gimli and legolas not to be equal"
]


toString : Test
toString =
describe "Slug.toString"
[ test "Returns a string version of a Slug" <|
\_ ->
let
result =
"gandalf"
|> Slug.fromString
|> Maybe.map Slug.toString
|> Maybe.withDefault "FAIL"
in
Expect.equal "gandalf" result
]


isValidSlug : Test
isValidSlug =
describe "Slug.isValidSlug"
[ test "Can be alphanumeric characters" <|
\_ ->
Slug.isValidSlug "samwise123"
|> Expect.equal True
|> Expect.onFail "Expected alphanumeric characters in slugs to succeed validation"
, test "Can include hyphens" <|
\_ ->
Slug.isValidSlug "can-have-hyphens"
|> Expect.equal True
|> Expect.onFail "Expected hyphens in slugs to succeed validation"
, test "Can' include consecutive hyphens" <|
\_ ->
Slug.isValidSlug "cant-have----consecutive--hyphens"
|> Expect.equal False
|> Expect.onFail "Expected consecutive hyphens in slugs to fail validation"
, test "Can't have spaces" <|
\_ ->
Slug.isValidSlug "cant have spaces"
|> Expect.equal False
|> Expect.onFail "Expected spaces in slugs to fail validation"
, test "Can't have symbols" <|
\_ ->
Slug.isValidSlug "cant have $ymbols$!@#_"
|> Expect.equal False
|> Expect.onFail "Expected symbols in slugs to fail validation"
, test "Can't have underscores" <|
\_ ->
Slug.isValidSlug "cant_have_underscores"
|> Expect.equal False
|> Expect.onFail "Expected underscores in slugs to fail validation"
, test "Can't be longer than 39 characters" <|
\_ ->
Slug.isValidSlug "cantbemorethanthirtyninecharacterslongthatswaytolongofaslug"
|> Expect.equal False
|> Expect.onFail "Expected long slugs to fail validation"
, test "Can't start with a hyphen" <|
\_ ->
Slug.isValidSlug "-cant-start-with-a-hyphen"
|> Expect.equal False
|> Expect.onFail "Expected - prefixed slugs to fail validation"
, test "Can't end with a hyphen" <|
\_ ->
Slug.isValidSlug "can-end-with-a-hyphen-"
|> Expect.equal False
|> Expect.onFail "Expected - suffixed slugs to fail validation"
]

0 comments on commit d9d6788

Please sign in to comment.