-
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathBlogArticle_.test.res
More file actions
202 lines (167 loc) · 6.43 KB
/
BlogArticle_.test.res
File metadata and controls
202 lines (167 loc) · 6.43 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
open ReactRouter
open Vitest
let mockAuthor: BlogFrontmatter.author = {
username: "test-author",
fullname: "Test Author",
role: "Developer",
imgUrl: "https://rescript-lang.org/brand/rescript-brandmark.svg",
social: X("testauthor"),
}
let mockFrontmatter: BlogFrontmatter.t = {
author: mockAuthor,
co_authors: [],
date: DateStr.fromString("2025-01-15"),
previewImg: Nullable.null,
articleImg: Nullable.null,
title: "Test Blog Post Title",
badge: Nullable.null,
description: Nullable.Value("A short description of the blog post for testing."),
}
test("desktop blog article renders header, author, date, and body", async () => {
await viewport(1440, 900)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-article-wrapper">
<BlogArticle frontmatter=mockFrontmatter isArchived=false path="/blog/test-article">
<div> {React.string("This is the blog post body content for testing.")} </div>
</BlogArticle>
</div>
</BrowserRouter>,
)
let title = await screen->getByText("Test Blog Post Title")
await element(title)->toBeVisible
let authorName = await screen->getByText("Test Author")
await element(authorName)->toBeVisible
let description = await screen->getByText("A short description of the blog post for testing.")
await element(description)->toBeVisible
let wrapper = await screen->getByTestId("blog-article-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-blog-article")
})
test("desktop archived blog article shows warning banner", async () => {
await viewport(1440, 900)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-article-wrapper">
<BlogArticle frontmatter=mockFrontmatter isArchived=true path="/blog/test-article">
<div> {React.string("This is the blog post body content for testing.")} </div>
</BlogArticle>
</div>
</BrowserRouter>,
)
let important = await screen->getByText("Important:")
await element(important)->toBeVisible
let wrapper = await screen->getByTestId("blog-article-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-blog-article-archived")
})
test("mobile blog article", async () => {
await viewport(600, 1200)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-article-wrapper">
<BlogArticle frontmatter=mockFrontmatter isArchived=false path="/blog/test-article">
<div> {React.string("This is the blog post body content for testing.")} </div>
</BlogArticle>
</div>
</BrowserRouter>,
)
let title = await screen->getByText("Test Blog Post Title")
await element(title)->toBeVisible
let authorName = await screen->getByText("Test Author")
await element(authorName)->toBeVisible
let description = await screen->getByText("A short description of the blog post for testing.")
await element(description)->toBeVisible
let wrapper = await screen->getByTestId("blog-article-wrapper")
await element(wrapper)->toMatchScreenshot("mobile-blog-article")
})
let mockCoAuthor: BlogFrontmatter.author = {
username: "co-author",
fullname: "Co Author",
role: "Contributor",
imgUrl: "https://rescript-lang.org/brand/rescript-brandmark.svg",
social: Bluesky("coauthor.bsky.social"),
}
let mockFrontmatterWithCoAuthors: BlogFrontmatter.t = {
author: mockAuthor,
co_authors: [mockCoAuthor],
date: DateStr.fromString("2025-03-20"),
previewImg: Nullable.null,
articleImg: Nullable.null,
title: "Collaborative Blog Post",
badge: Nullable.Value(Release),
description: Nullable.Value("A post written by multiple authors."),
}
test("desktop blog article with co-authors shows all authors", async () => {
await viewport(1440, 900)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-article-wrapper">
<BlogArticle
frontmatter=mockFrontmatterWithCoAuthors isArchived=false path="/blog/collab-post"
>
<div> {React.string("Collaborative content.")} </div>
</BlogArticle>
</div>
</BrowserRouter>,
)
let mainAuthor = await screen->getByText("Test Author")
await element(mainAuthor)->toBeVisible
let coAuthor = await screen->getByText("Co Author")
await element(coAuthor)->toBeVisible
let wrapper = await screen->getByTestId("blog-article-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-blog-article-coauthors")
})
let mockFrontmatterWithArticleImg: BlogFrontmatter.t = {
author: mockAuthor,
co_authors: [],
date: DateStr.fromString("2025-06-01"),
previewImg: Nullable.null,
articleImg: Nullable.Value("/brand/rescript-brandmark.svg"),
title: "Blog Post With Article Image",
badge: Nullable.Value(Release),
description: Nullable.Value("A post with an article image."),
}
test("desktop blog article with article image shows image", async () => {
await viewport(1440, 900)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-article-wrapper">
<BlogArticle
frontmatter=mockFrontmatterWithArticleImg isArchived=false path="/blog/image-post"
>
<div> {React.string("Content below the article image.")} </div>
</BlogArticle>
</div>
</BrowserRouter>,
)
let title = await screen->getByText("Blog Post With Article Image")
await element(title)->toBeVisible
let wrapper = await screen->getByTestId("blog-article-wrapper")
await waitForImages("[data-testid='blog-article-wrapper']")
await element(wrapper)->toMatchScreenshot("desktop-blog-article-with-image")
})
let mockFrontmatterNoDescription: BlogFrontmatter.t = {
author: mockAuthor,
co_authors: [],
date: DateStr.fromString("2025-02-10"),
previewImg: Nullable.null,
articleImg: Nullable.null,
title: "Blog Post Without Description",
badge: Nullable.null,
description: Nullable.null,
}
test("desktop blog article without description", async () => {
await viewport(1440, 900)
let screen = await render(
<BrowserRouter>
<div dataTestId="blog-article-wrapper">
<BlogArticle frontmatter=mockFrontmatterNoDescription isArchived=false path="/blog/no-desc">
<div> {React.string("Content without a description above.")} </div>
</BlogArticle>
</div>
</BrowserRouter>,
)
let title = await screen->getByText("Blog Post Without Description")
await element(title)->toBeVisible
let wrapper = await screen->getByTestId("blog-article-wrapper")
await element(wrapper)->toMatchScreenshot("desktop-blog-article-no-description")
})