-
Notifications
You must be signed in to change notification settings - Fork 24
/
url_helper.test.ts
28 lines (24 loc) · 1.02 KB
/
url_helper.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { formatUrlSlug, listingUrlSlug } from "../../src/lib/url_helper"
import { Listing } from "@bloom-housing/core"
import triton from "../../listings/triton.json"
describe("formatUrlSlug", () => {
test("reformats strings properly", () => {
expect(formatUrlSlug("snake_case")).toEqual("snake_case")
expect(formatUrlSlug("SnakeCase")).toEqual("snake_case")
expect(formatUrlSlug("Mix of spaces_and-hyphens")).toEqual("mix_of_spaces_and_hyphens")
expect(formatUrlSlug("Lots@of&weird spaces&^&!@^*&AND OTHER_CHARS")).toEqual(
"lots_of_weird_spaces_and_other_chars"
)
})
test("with an empty string", () => {
expect(formatUrlSlug("")).toEqual("")
})
})
describe("listingUrlSlug", () => {
// Force cast to listing - should we add a dependency to `listingsLoader` instead?
const listing = (triton as unknown) as Listing
test("Generates a URL slug for a Listing", () => {
const slug = listingUrlSlug(listing)
expect(slug).toEqual("the_triton_55_triton_park_lane_foster_city_ca")
})
})