-
-
Notifications
You must be signed in to change notification settings - Fork 229
/
GrapherPage.jsdom.test.tsx
executable file
·100 lines (87 loc) · 2.71 KB
/
GrapherPage.jsdom.test.tsx
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /usr/bin/env jest
import { GrapherInterface } from "@ourworldindata/types"
import {
DimensionProperty,
KeyChartLevel,
RelatedChart,
} from "@ourworldindata/utils"
import React from "react"
import { ChartListItemVariant } from "./ChartListItemVariant.js"
import { GrapherPage } from "./GrapherPage.js"
import { SiteFooter } from "./SiteFooter.js"
import { SiteHeader } from "./SiteHeader.js"
import Enzyme, { ShallowWrapper } from "enzyme"
import Adapter from "@wojtekmaj/enzyme-adapter-react-17"
Enzyme.configure({ adapter: new Adapter() })
const mockGrapher: GrapherInterface = {
version: 5,
slug: "share-of-children-with-a-weight-too-low-for-their-height-wasting",
originUrl: "https://ourworldindata.org/hunger-and-undernourishment/",
dimensions: [
{
variableId: 3512,
property: DimensionProperty.y,
},
],
}
let grapher: GrapherInterface
let relatedCharts: RelatedChart[]
beforeAll(() => {
grapher = mockGrapher
relatedCharts = [
{
title: "Chart 1",
slug: "chart-1",
keyChartLevel: KeyChartLevel.Middle,
},
{
title: "Chart 2",
slug: "chart-2",
keyChartLevel: KeyChartLevel.Top,
},
]
})
describe("when the page is rendered", () => {
let view: ShallowWrapper
beforeAll(
() =>
(view = Enzyme.shallow(
<GrapherPage
grapher={grapher}
relatedCharts={relatedCharts}
baseGrapherUrl={"/grapher/"}
baseUrl={""}
/>
))
)
it("preloads the data", () => {
expect(
view
.find(`link[rel="preload"]`)
.filterWhere((element: any): boolean =>
element.prop("href").endsWith("/3512.data.json")
)
).toHaveLength(1)
expect(
view
.find(`link[rel="preload"]`)
.filterWhere((element: any): boolean =>
element.prop("href").endsWith("/3512.metadata.json")
)
).toHaveLength(1)
})
it("renders a site header", () => {
expect(view.find(SiteHeader)).toHaveLength(1)
})
it("renders a figure", () => {
const selector =
'figure[data-grapher-src="/grapher/share-of-children-with-a-weight-too-low-for-their-height-wasting"]'
expect(view.find(selector)).toHaveLength(1)
})
it("renders a related content block", () => {
expect(view.find(ChartListItemVariant)).toHaveLength(2)
})
it("renders a site footer", () => {
expect(view.find(SiteFooter)).toHaveLength(1)
})
})