forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pageOverrides.test.ts
84 lines (72 loc) · 2.44 KB
/
pageOverrides.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { FullPost, WP_PostType } from "../clientUtils/owidTypes.js"
import { extractFormattingOptions } from "./formatting.js"
import * as pageOverrides from "./pageOverrides.js"
const mockCreatePost = (slug: string): FullPost => {
return {
id: 123,
type: WP_PostType.Post,
slug: slug,
path: "",
title: "",
date: new Date(0),
modifiedDate: new Date(0),
authors: [],
content: "",
glossary: false,
}
}
const forestLandingSlug = "forests-and-deforestation"
const getPostBySlugLogToSlackNoThrow = jest.spyOn(
pageOverrides,
"getPostBySlugLogToSlackNoThrow"
)
getPostBySlugLogToSlackNoThrow.mockImplementation((landingSlug) =>
Promise.resolve(mockCreatePost(landingSlug))
)
it("gets parent landing", async () => {
const formattingOptions = extractFormattingOptions(
"<!-- formatting-options subnavId:forests subnavCurrentId:forest-area -->"
)
await expect(
pageOverrides.getLandingOnlyIfParent(
mockCreatePost("forest-area"),
formattingOptions
)
).resolves.toEqual(mockCreatePost(forestLandingSlug))
})
it("does not get parent landing (subnavId invalid)", async () => {
const formattingOptions = extractFormattingOptions(
"<!-- formatting-options subnavId:invalid subnavCurrentId:forest-area -->"
)
await expect(
pageOverrides.getLandingOnlyIfParent(
mockCreatePost("forest-area"),
formattingOptions
)
).resolves.toEqual(undefined)
})
it("does not get parent landing (post is already a landing)", async () => {
const formattingOptions = extractFormattingOptions(
"<!-- formatting-options subnavId:forests subnavCurrentId:forest-area -->"
)
await expect(
pageOverrides.getLandingOnlyIfParent(
mockCreatePost(forestLandingSlug),
formattingOptions
)
).resolves.toEqual(undefined)
})
it("does not get parent landing and logs (landing post not found)", async () => {
const formattingOptions = extractFormattingOptions(
"<!-- formatting-options subnavId:forests subnavCurrentId:forest-area -->"
)
getPostBySlugLogToSlackNoThrow.mockImplementationOnce(() =>
Promise.resolve(undefined)
)
await expect(
pageOverrides.getLandingOnlyIfParent(
mockCreatePost("forest-area"),
formattingOptions
)
).resolves.toEqual(undefined)
})