-
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathDocsLayout_.test.res
More file actions
160 lines (129 loc) · 5.41 KB
/
DocsLayout_.test.res
File metadata and controls
160 lines (129 loc) · 5.41 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
open ReactRouter
open Vitest
let mockCategories: array<SidebarLayout.Sidebar.Category.t> = [
{
name: "Overview",
items: [
{name: "Introduction", href: "/docs/manual/introduction"},
{name: "Installation", href: "/docs/manual/installation"},
],
},
{
name: "Language Features",
items: [
{name: "Primitive Types", href: "/docs/manual/primitive-types"},
{name: "Record", href: "/docs/manual/record"},
{name: "Object", href: "/docs/manual/object"},
],
},
]
let mockToc: TableOfContents.t = {
title: "Introduction",
entries: [
{header: "What is ReScript", href: "#what-is-rescript"},
{header: "Prerequisites", href: "#prerequisites"},
{header: "Getting Started", href: "#getting-started"},
],
}
test("desktop docs layout shows sidebar with categories", async () => {
await viewport(1440, 900)
let screen = await render(
<MemoryRouter initialEntries=["/docs/manual/introduction"]>
<div dataTestId="docs-layout-wrapper">
<DocsLayout categories=mockCategories activeToc=mockToc>
<div> {React.string("This is the documentation content.")} </div>
</DocsLayout>
</div>
</MemoryRouter>,
)
let overviewHeading = await screen->getByText("Overview")
await element(overviewHeading)->toBeVisible
let languageFeaturesHeading = await screen->getByText("Language Features")
await element(languageFeaturesHeading)->toBeVisible
let introItem = await screen->getByText("Introduction")
await element(introItem)->toBeVisible
let mainContent = await screen->getByTestId("side-layout-children")
await element(mainContent)->toBeVisible
let wrapper = await screen->getByTestId("docs-layout-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-docs-layout")
})
test("desktop docs layout shows table of contents entries", async () => {
await viewport(1440, 900)
let screen = await render(
<MemoryRouter initialEntries=["/docs/manual/introduction"]>
<div dataTestId="docs-layout-wrapper">
<DocsLayout categories=mockCategories activeToc=mockToc>
<div> {React.string("This is the documentation content.")} </div>
</DocsLayout>
</div>
</MemoryRouter>,
)
// The TOC entries render inside the sidebar under the active nav item.
// Since the test isn't at a matching route, the TOC appears for the first
// category item that matches the current location. Verify the layout
// renders with the activeToc data by checking sidebar and content are present.
let overviewHeading = await screen->getByText("Overview")
await element(overviewHeading)->toBeVisible
let mainContent = await screen->getByTestId("side-layout-children")
await element(mainContent)->toBeVisible
let wrapper = await screen->getByTestId("docs-layout-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-docs-layout-with-toc")
})
test("mobile docs layout hides sidebar by default", async () => {
await viewport(600, 1200)
let screen = await render(
<MemoryRouter initialEntries=["/docs/manual/introduction"]>
<div dataTestId="docs-layout-wrapper">
<DocsLayout categories=mockCategories activeToc=mockToc>
<div> {React.string("This is the documentation content.")} </div>
</DocsLayout>
</div>
</MemoryRouter>,
)
let introItem = await screen->getByText("Introduction")
await element(introItem)->notToBeVisible
let mainContent = await screen->getByTestId("side-layout-children")
await element(mainContent)->toBeVisible
let wrapper = await screen->getByTestId("docs-layout-wrapper")
await element(wrapper)->toMatchScreenshot("mobile-docs-layout")
})
test("desktop docs layout highlights active nav item", async () => {
await viewport(1440, 900)
let screen = await render(
<MemoryRouter initialEntries=["/docs/manual/installation"]>
<div dataTestId="docs-layout-wrapper">
<DocsLayout categories=mockCategories activeToc=mockToc>
<div> {React.string("This is the documentation content.")} </div>
</DocsLayout>
</div>
</MemoryRouter>,
)
let sidebar = await screen->getByTestId("sidebar-content")
let installItem = await sidebar->getByText("Installation")
await element(installItem)->toBeVisible
let introItem = await sidebar->getByText("Introduction")
await element(introItem)->toBeVisible
let wrapper = await screen->getByTestId("docs-layout-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-docs-layout-active-item")
})
test("desktop docs layout shows pagination (prev/next)", async () => {
await viewport(1440, 900)
let screen = await render(
<MemoryRouter initialEntries=["/docs/manual/installation"]>
<div dataTestId="docs-layout-wrapper">
<DocsLayout categories=mockCategories activeToc=mockToc>
<div> {React.string("Installation documentation content.")} </div>
</DocsLayout>
</div>
</MemoryRouter>,
)
// When at "Installation" (second item), there should be a "Previous" link to "Introduction"
// and a "Next" link to "Primitive Types"
let content = await screen->getByTestId("side-layout-children")
let prevLink = await content->getByText("Introduction")
await element(prevLink)->toBeVisible
let nextLink = await content->getByText("Primitive Types")
await element(nextLink)->toBeVisible
let wrapper = await screen->getByTestId("docs-layout-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-docs-layout-pagination")
})