forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GrapherBakingUtils.test.ts
70 lines (62 loc) · 2.39 KB
/
GrapherBakingUtils.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {
grapherSlugToExportFileKey,
grapherUrlToSlugAndQueryStr,
} from "./GrapherBakingUtils.js"
describe(grapherUrlToSlugAndQueryStr, () => {
it("can extract a slug", () => {
const grapherUrl = "https://ourworldindata.org/grapher/soil-lifespans"
const { slug, queryStr } = grapherUrlToSlugAndQueryStr(grapherUrl)
expect(slug).toEqual("soil-lifespans")
expect(queryStr).toEqual("")
})
it("can extract slug and queryStr", () => {
const grapherUrl =
"https://ourworldindata.org/grapher/soil-lifespans?tab=map"
const { slug, queryStr } = grapherUrlToSlugAndQueryStr(grapherUrl)
expect(slug).toEqual("soil-lifespans")
expect(queryStr).toEqual("?tab=map")
})
it("ignores empty query string", () => {
const grapherUrl = "https://ourworldindata.org/grapher/soil-lifespans?"
const { slug, queryStr } = grapherUrlToSlugAndQueryStr(grapherUrl)
expect(slug).toEqual("soil-lifespans")
expect(queryStr).toEqual("")
})
it("can handle slugs with uppercase letters", () => {
const grapherUrl =
"https://ourworldindata.org/grapher/real-gdp-per-capita-pennWT"
const { slug, queryStr } = grapherUrlToSlugAndQueryStr(grapherUrl)
expect(slug).toEqual("real-gdp-per-capita-pennWT")
expect(queryStr).toEqual("")
})
})
describe(grapherSlugToExportFileKey, () => {
it("can handle empty query string", () => {
const slug = "soil-lifespans"
const queryStr = ""
expect(grapherSlugToExportFileKey(slug, queryStr)).toEqual(
"soil-lifespans"
)
})
it("can handle undefined query string", () => {
const slug = "soil-lifespans"
const queryStr = undefined
expect(grapherSlugToExportFileKey(slug, queryStr)).toEqual(
"soil-lifespans"
)
})
it("can handle non-empty query string", () => {
const slug = "soil-lifespans"
const queryStr = "?tab=map"
expect(grapherSlugToExportFileKey(slug, queryStr)).toEqual(
"soil-lifespans-a42c8357c168ebd03c90930b9d3c439b"
)
})
it("can handle slugs with uppercase letters", () => {
const slug = "real-gdp-per-capita-pennWT"
const queryStr = ""
expect(grapherSlugToExportFileKey(slug, queryStr)).toEqual(
"real-gdp-per-capita-pennWT"
)
})
})