|
1 | 1 | import { test, expect } from '@playwright/test'; |
2 | | -import { register, generateUniqueUser } from './helpers/auth'; |
| 2 | +import { register, login, generateUniqueUser } from './helpers/auth'; |
3 | 3 | import { createArticle, generateUniqueArticle } from './helpers/articles'; |
| 4 | +import { registerUserViaAPI, createManyArticles } from './helpers/api'; |
4 | 5 |
|
5 | 6 | test.describe('Navigation and Filtering', () => { |
6 | 7 | test.afterEach(async ({ context }) => { |
@@ -73,7 +74,7 @@ test.describe('Navigation and Filtering', () => { |
73 | 74 | await page.goto('/', { waitUntil: 'load' }); |
74 | 75 |
|
75 | 76 | // Wait for the sidebar to be visible |
76 | | - await page.waitForSelector('.sidebar .tag-list', { timeout: 10000 }); |
| 77 | + await page.waitForSelector('.sidebar .tag-list', { timeout: 3000 }); |
77 | 78 |
|
78 | 79 | // Wait for the specific tag to appear in Popular Tags sidebar (or use first available tag) |
79 | 80 | // Note: Custom tags might not appear immediately in Popular Tags |
@@ -115,12 +116,12 @@ test.describe('Navigation and Filtering', () => { |
115 | 116 | await page.goto('/', { waitUntil: 'load' }); |
116 | 117 |
|
117 | 118 | // Wait for articles to load |
118 | | - await page.waitForSelector('.article-preview', { timeout: 10000 }); |
| 119 | + await page.waitForSelector('.article-preview', { timeout: 3000 }); |
119 | 120 |
|
120 | 121 | // Should see our article and existing articles in Global Feed |
121 | 122 | await page.click('a:has-text("Global Feed")'); |
122 | 123 | // Wait for articles to load after clicking Global Feed |
123 | | - await page.waitForSelector('.article-preview', { timeout: 10000 }); |
| 124 | + await page.waitForSelector('.article-preview', { timeout: 3000 }); |
124 | 125 | await expect(page.locator(`h1:has-text("${article.title}")`).first()).toBeVisible(); |
125 | 126 |
|
126 | 127 | // Also should see johndoe's articles from demo backend |
@@ -152,41 +153,22 @@ test.describe('Navigation and Filtering', () => { |
152 | 153 | await expect(page.locator('.sidebar .tag-list .tag-pill:has-text("trending")')).toBeVisible(); |
153 | 154 | }); |
154 | 155 |
|
155 | | - test('should paginate articles', async ({ page }) => { |
| 156 | + test('should paginate articles', async ({ page, request }) => { |
| 157 | + // Create user and 12 articles via API (much faster than UI) |
| 158 | + const uniqueTag = `pag${Date.now()}`; |
156 | 159 | const user = generateUniqueUser(); |
157 | | - await register(page, user.username, user.email, user.password); |
| 160 | + const token = await registerUserViaAPI(request, user); |
| 161 | + await createManyArticles(request, token, 12, uniqueTag); |
158 | 162 |
|
159 | | - // Create 12 articles to trigger pagination (default page size is typically 10) |
160 | | - const baseTimestamp = Date.now(); |
161 | | - const articles = Array.from({ length: 12 }, (_, i) => { |
162 | | - const article = generateUniqueArticle(); |
163 | | - article.title = `Pagination Test ${baseTimestamp}-${i}`; |
164 | | - return article; |
165 | | - }); |
166 | | - |
167 | | - for (let i = 0; i < articles.length; i++) { |
168 | | - await createArticle(page, articles[i]); |
169 | | - // Navigate back to editor for next article |
170 | | - if (i < articles.length - 1) { |
171 | | - await page.goto('/editor', { waitUntil: 'load' }); |
172 | | - // Wait for editor form to be ready |
173 | | - await page.waitForSelector('input[formControlName="title"]', { timeout: 10000 }); |
174 | | - } |
175 | | - } |
176 | | - |
177 | | - // Go to home and check pagination |
178 | | - await page.goto('/', { waitUntil: 'load' }); |
179 | | - await page.waitForSelector('.article-preview', { timeout: 10000 }); |
| 163 | + // Login and navigate to our tag to see only our articles |
| 164 | + await login(page, user.email, user.password); |
| 165 | + await page.goto(`/tag/${uniqueTag}`); |
| 166 | + await page.waitForSelector('.article-preview', { timeout: 3000 }); |
180 | 167 |
|
181 | 168 | // Count articles on first page (should be 10 or less) |
182 | 169 | const firstPageCount = await page.locator('.article-preview').count(); |
183 | 170 | expect(firstPageCount).toBeGreaterThan(0); |
184 | 171 | expect(firstPageCount).toBeLessThanOrEqual(10); |
185 | | - |
186 | | - // Verify pagination functionality - with 12+ articles created plus demo articles, |
187 | | - // we should have enough to trigger pagination |
188 | | - // Just verify the page structure is correct - articles are displayed properly |
189 | | - expect(firstPageCount).toBeGreaterThanOrEqual(1); |
190 | 172 | }); |
191 | 173 |
|
192 | 174 | test('should navigate to article from author name', async ({ page }) => { |
@@ -243,7 +225,7 @@ test.describe('Navigation and Filtering', () => { |
243 | 225 | await page.goto(`/profile/${user.username}`, { waitUntil: 'load' }); |
244 | 226 |
|
245 | 227 | // Wait for profile page to load |
246 | | - await page.waitForSelector('.user-info, h4', { timeout: 10000 }); |
| 228 | + await page.waitForSelector('.user-info, h4', { timeout: 3000 }); |
247 | 229 |
|
248 | 230 | // Check if there are article previews (there might be none on empty profile) |
249 | 231 | const articleCount = await page.locator('.article-preview').count(); |
|
0 commit comments