Skip to content

Commit 250053d

Browse files
authored
Merge pull request #520 from sylhare/category-test
Add categories test
2 parents d6ac61d + 53e8cd4 commit 250053d

File tree

4 files changed

+112
-3
lines changed

4 files changed

+112
-3
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
const { test, expect } = require('@playwright/test');
2+
3+
test.describe('Category Display Functionality @desktop', () => {
4+
test('should display categories on posts with category metadata', async ({ page }) => {
5+
await page.goto('/demo/2014/11/26/lorem-ipsum');
6+
7+
const categoryList = page.locator('[data-testid="category-list"]');
8+
await expect(categoryList).toBeVisible();
9+
10+
const categoryLink = page.locator('[data-testid="category-link"]');
11+
await expect(categoryLink).toBeVisible();
12+
13+
const categoryText = await categoryLink.textContent();
14+
expect(categoryText).toContain('Demo');
15+
});
16+
17+
test('should display empty category list on posts without categories', async ({ page }) => {
18+
await page.goto('/');
19+
20+
const categoryListDivs = page.locator('[data-testid="category-list"]');
21+
22+
await expect(page.locator('body')).toBeVisible();
23+
});
24+
25+
test('should have category links that navigate to categories page', async ({ page }) => {
26+
await page.goto('/demo/2014/11/26/lorem-ipsum');
27+
28+
const categoryLink = page.locator('[data-testid="category-link"]').first();
29+
await expect(categoryLink).toBeVisible();
30+
31+
await categoryLink.click();
32+
33+
await expect(page).toHaveURL(/\/categories(\/)?#/);
34+
});
35+
36+
test('should display category with folder icon', async ({ page }) => {
37+
await page.goto('/demo/2014/11/26/lorem-ipsum');
38+
39+
const categoryLink = page.locator('[data-testid="category-link"]').first();
40+
await expect(categoryLink).toBeVisible();
41+
42+
const icon = categoryLink.locator('i.fa-folder');
43+
await expect(icon).toBeVisible();
44+
});
45+
46+
test('should display both tags and categories on the same post', async ({ page }) => {
47+
await page.goto('/demo/2014/11/26/lorem-ipsum');
48+
49+
const tagList = page.locator('[data-testid="tag-list"]');
50+
await expect(tagList).toBeVisible();
51+
52+
const categoryList = page.locator('[data-testid="category-list"]');
53+
await expect(categoryList).toBeVisible();
54+
55+
const tagLinks = page.locator('[data-testid="tag-link"]');
56+
expect(await tagLinks.count()).toBeGreaterThan(0);
57+
58+
const categoryLinks = page.locator('[data-testid="category-link"]');
59+
expect(await categoryLinks.count()).toBeGreaterThan(0);
60+
});
61+
62+
test('should display singular "Category" for single category', async ({ page }) => {
63+
await page.goto('/demo/2014/11/26/lorem-ipsum');
64+
65+
const categoryList = page.locator('[data-testid="category-list"]');
66+
await expect(categoryList).toBeVisible();
67+
68+
const categoryMeta = categoryList.locator('li.meta');
69+
const metaText = await categoryMeta.textContent();
70+
expect(metaText).toContain('Category');
71+
});
72+
73+
test('should display categories on tutorial post', async ({ page }) => {
74+
await page.goto('/tutorial/2013/10/18/blogging-with-title');
75+
76+
const categoryList = page.locator('[data-testid="category-list"]');
77+
await expect(categoryList).toBeVisible();
78+
79+
const categoryLink = page.locator('[data-testid="category-link"]');
80+
await expect(categoryLink).toBeVisible();
81+
82+
const categoryText = await categoryLink.textContent();
83+
expect(categoryText).toContain('Tutorial');
84+
});
85+
86+
test('should display categories on example posts', async ({ page }) => {
87+
await page.goto('/example/2019/06/30/sample-post');
88+
89+
const categoryList = page.locator('[data-testid="category-list"]');
90+
await expect(categoryList).toBeVisible();
91+
92+
const categoryLink = page.locator('[data-testid="category-link"]');
93+
await expect(categoryLink).toBeVisible();
94+
95+
const categoryText = await categoryLink.textContent();
96+
expect(categoryText).toContain('Example');
97+
});
98+
99+
test('should have proper styling for category buttons', async ({ page }) => {
100+
await page.goto('/demo/2014/11/26/lorem-ipsum');
101+
102+
const categoryLink = page.locator('[data-testid="category-link"]').first();
103+
await expect(categoryLink).toBeVisible();
104+
105+
const hasButtonClass = await categoryLink.evaluate(el => el.classList.contains('button'));
106+
expect(hasButtonClass).toBe(true);
107+
});
108+
});
109+

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ jekyll-theme-type-on-strap.gemspec
4343
*copy.md
4444
test/*
4545
/type-on-strap*/*
46-
test-results/.last-run.json
46+
test-results/*

_posts/2013-10-18-blogging-with-title.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: post
33
title: >
44
Blogging with title
55
tags: [Test, Image]
6-
categories: Demo
6+
categories: Tutorial
77
---
88

99
# I am a BIG title

_posts/2019-06-30-sample-post.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Sample post
44
tags: [A Tag, Katex]
55
last_modified: "2025-05-30"
66
excerpt_separator: <!--more-->
7-
categories: Demo
7+
categories: Example
88
---
99

1010
Consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor.

0 commit comments

Comments
 (0)