|
| 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 | + |
0 commit comments