Skip to content

Commit 552a95e

Browse files
committed
Add another test
1 parent 7fa157e commit 552a95e

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

test/e2e/community-events.spec.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test, expect } from "@playwright/test"
1+
import { test, expect, type Locator } from "@playwright/test"
22

33
test.beforeEach(async ({ page }) => {
44
await page.goto("/community/events")
@@ -218,3 +218,70 @@ test("event type filters hide cards and lock the last active tag", async ({
218218
await workingGroupChip.click()
219219
await expect(meetupFilter).toBeEnabled()
220220
})
221+
222+
test("upcoming and past sections only show events on the correct side of now", async ({
223+
page,
224+
}) => {
225+
const upcomingSection = page
226+
.locator("section")
227+
.filter({
228+
has: page.getByRole("heading", { level: 2, name: /Upcoming events/i }),
229+
})
230+
.first()
231+
const pastEventsSection = page
232+
.locator("section")
233+
.filter({
234+
has: page.getByRole("heading", {
235+
level: 2,
236+
name: /Past events & meetups/i,
237+
}),
238+
})
239+
.first()
240+
241+
await Promise.all([
242+
upcomingSection.scrollIntoViewIfNeeded(),
243+
pastEventsSection.scrollIntoViewIfNeeded(),
244+
])
245+
246+
const now = Date.now()
247+
248+
const readSectionDates = async (section: Locator) => {
249+
const entries = await section.locator("a time").evaluateAll(elements =>
250+
elements.map(element => ({
251+
iso: element.getAttribute("datetime") ?? "",
252+
text: element.textContent?.trim() ?? "",
253+
})),
254+
)
255+
return entries
256+
}
257+
258+
const upcomingDates = await readSectionDates(upcomingSection)
259+
expect(upcomingDates.length).toBeGreaterThan(0)
260+
upcomingDates.forEach(({ iso, text }) => {
261+
expect(iso.length, `${text} is missing a datetime attribute`).toBeGreaterThan(0)
262+
const timestamp = Date.parse(iso)
263+
expect(
264+
Number.isNaN(timestamp),
265+
`${text} carries an invalid datetime attribute: ${iso}`,
266+
).toBe(false)
267+
expect(
268+
timestamp,
269+
`${text} should be in the future but resolved to ${iso}`,
270+
).toBeGreaterThanOrEqual(now)
271+
})
272+
273+
const pastDates = await readSectionDates(pastEventsSection)
274+
expect(pastDates.length).toBeGreaterThan(0)
275+
pastDates.forEach(({ iso, text }) => {
276+
expect(iso.length, `${text} is missing a datetime attribute`).toBeGreaterThan(0)
277+
const timestamp = Date.parse(iso)
278+
expect(
279+
Number.isNaN(timestamp),
280+
`${text} carries an invalid datetime attribute: ${iso}`,
281+
).toBe(false)
282+
expect(
283+
timestamp,
284+
`${text} should be in the past but resolved to ${iso}`,
285+
).toBeLessThan(now)
286+
})
287+
})

0 commit comments

Comments
 (0)