-
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathBlog_.test.res
More file actions
223 lines (191 loc) · 5.99 KB
/
Blog_.test.res
File metadata and controls
223 lines (191 loc) · 5.99 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
open ReactRouter
open Vitest
let mockAuthor: BlogFrontmatter.author = {
username: "rescript-team",
fullname: "ReScript Team",
role: "Core Development",
imgUrl: "https://rescript-lang.org/brand/rescript-brandmark.svg",
social: X("rescriptlang"),
}
let mockPosts: array<BlogApi.post> = [
{
path: "blog/release-12-0-0",
archived: false,
frontmatter: {
author: mockAuthor,
co_authors: [],
date: DateStr.fromString("2025-11-25"),
previewImg: Nullable.null,
articleImg: Nullable.null,
title: "Announcing ReScript 12",
badge: Nullable.Value(Release),
description: Nullable.Value("ReScript 12 arrives with a redesigned build toolchain."),
},
},
{
path: "blog/release-11-1-0",
archived: false,
frontmatter: {
author: mockAuthor,
co_authors: [],
date: DateStr.fromString("2024-06-15"),
previewImg: Nullable.null,
articleImg: Nullable.null,
title: "ReScript 11.1",
badge: Nullable.Value(Release),
description: Nullable.Value("Tagged template literals, import attributes, and more."),
},
},
{
path: "blog/improving-interop",
archived: false,
frontmatter: {
author: mockAuthor,
co_authors: [],
date: DateStr.fromString("2024-03-01"),
previewImg: Nullable.null,
articleImg: Nullable.null,
title: "Improving Interop",
badge: Nullable.null,
description: Nullable.Value("Better JavaScript interoperability in ReScript."),
},
},
]
test("desktop blog index shows featured post and cards", async () => {
await viewport(1440, 900)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-wrapper">
<Blog posts=mockPosts category=All />
</div>
</BrowserRouter>,
)
let featured = await screen->getByText("Announcing ReScript 12")
await element(featured)->toBeVisible
let card1 = await screen->getByText("ReScript 11.1")
await element(card1)->toBeVisible
let card2 = await screen->getByText("Improving Interop")
await element(card2)->toBeVisible
let wrapper = await screen->getByTestId("blog-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-blog-index")
})
test("desktop blog shows category selector", async () => {
await viewport(1440, 900)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-wrapper">
<Blog posts=mockPosts category=All />
</div>
</BrowserRouter>,
)
let allTab = await screen->getByText("All")
await element(allTab)->toBeVisible
let archivedTab = await screen->getByText("Archived")
await element(archivedTab)->toBeVisible
let wrapper = await screen->getByTestId("blog-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-blog-category-selector")
})
test("mobile blog index", async () => {
await viewport(600, 1200)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-wrapper">
<Blog posts=mockPosts category=All />
</div>
</BrowserRouter>,
)
let featured = await screen->getByText("Announcing ReScript 12")
await element(featured)->toBeVisible
let wrapper = await screen->getByTestId("blog-wrapper")
await element(wrapper)->toMatchScreenshot("mobile-blog-index")
})
test("blog shows empty state when no posts", async () => {
await viewport(1440, 900)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-empty-wrapper">
<Blog posts=[] category=All />
</div>
</BrowserRouter>,
)
let emptyMsg = await screen->getByText("Blog not yet available")
await element(emptyMsg)->toBeVisible
let wrapper = await screen->getByTestId("blog-empty-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-blog-empty")
})
let mockArchivedPosts: array<BlogApi.post> = [
{
path: "blog/old-post-2020",
archived: true,
frontmatter: {
author: mockAuthor,
co_authors: [],
date: DateStr.fromString("2020-03-15"),
previewImg: Nullable.null,
articleImg: Nullable.null,
title: "An Old Archived Post",
badge: Nullable.null,
description: Nullable.Value("This post is from the archives."),
},
},
{
path: "blog/old-post-2019",
archived: true,
frontmatter: {
author: mockAuthor,
co_authors: [],
date: DateStr.fromString("2019-11-01"),
previewImg: Nullable.null,
articleImg: Nullable.null,
title: "Another Archived Post",
badge: Nullable.null,
description: Nullable.Value("Another old post from the archives."),
},
},
]
test("desktop blog shows archived posts", async () => {
await viewport(1440, 900)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-wrapper">
<Blog posts=mockArchivedPosts category=Archived />
</div>
</BrowserRouter>,
)
let post1 = await screen->getByText("An Old Archived Post")
await element(post1)->toBeVisible
let post2 = await screen->getByText("Another Archived Post")
await element(post2)->toBeVisible
let wrapper = await screen->getByTestId("blog-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-blog-archived")
})
test("desktop blog with single post", async () => {
await viewport(1440, 900)
let singlePost: array<BlogApi.post> = [
{
path: "blog/only-post",
archived: false,
frontmatter: {
author: mockAuthor,
co_authors: [],
date: DateStr.fromString("2025-12-01"),
previewImg: Nullable.null,
articleImg: Nullable.null,
title: "The Only Post",
badge: Nullable.Value(Release),
description: Nullable.Value("This is the only blog post."),
},
},
]
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-wrapper">
<Blog posts=singlePost category=All />
</div>
</BrowserRouter>,
)
let post = await screen->getByText("The Only Post")
await element(post)->toBeVisible
let wrapper = await screen->getByTestId("blog-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-blog-single-post")
})