Skip to content

Commit 82729cf

Browse files
committed
e2e testing improvement
1 parent 5f43e6c commit 82729cf

File tree

2 files changed

+19
-40
lines changed

2 files changed

+19
-40
lines changed

e2e/navigation.spec.ts

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { test, expect } from '@playwright/test';
2-
import { register, generateUniqueUser } from './helpers/auth';
2+
import { register, login, generateUniqueUser } from './helpers/auth';
33
import { createArticle, generateUniqueArticle } from './helpers/articles';
4+
import { registerUserViaAPI, createManyArticles } from './helpers/api';
45

56
test.describe('Navigation and Filtering', () => {
67
test.afterEach(async ({ context }) => {
@@ -73,7 +74,7 @@ test.describe('Navigation and Filtering', () => {
7374
await page.goto('/', { waitUntil: 'load' });
7475

7576
// 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 });
7778

7879
// Wait for the specific tag to appear in Popular Tags sidebar (or use first available tag)
7980
// Note: Custom tags might not appear immediately in Popular Tags
@@ -115,12 +116,12 @@ test.describe('Navigation and Filtering', () => {
115116
await page.goto('/', { waitUntil: 'load' });
116117

117118
// Wait for articles to load
118-
await page.waitForSelector('.article-preview', { timeout: 10000 });
119+
await page.waitForSelector('.article-preview', { timeout: 3000 });
119120

120121
// Should see our article and existing articles in Global Feed
121122
await page.click('a:has-text("Global Feed")');
122123
// 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 });
124125
await expect(page.locator(`h1:has-text("${article.title}")`).first()).toBeVisible();
125126

126127
// Also should see johndoe's articles from demo backend
@@ -152,41 +153,22 @@ test.describe('Navigation and Filtering', () => {
152153
await expect(page.locator('.sidebar .tag-list .tag-pill:has-text("trending")')).toBeVisible();
153154
});
154155

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()}`;
156159
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);
158162

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 });
180167

181168
// Count articles on first page (should be 10 or less)
182169
const firstPageCount = await page.locator('.article-preview').count();
183170
expect(firstPageCount).toBeGreaterThan(0);
184171
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);
190172
});
191173

192174
test('should navigate to article from author name', async ({ page }) => {
@@ -243,7 +225,7 @@ test.describe('Navigation and Filtering', () => {
243225
await page.goto(`/profile/${user.username}`, { waitUntil: 'load' });
244226

245227
// Wait for profile page to load
246-
await page.waitForSelector('.user-info, h4', { timeout: 10000 });
228+
await page.waitForSelector('.user-info, h4', { timeout: 3000 });
247229

248230
// Check if there are article previews (there might be none on empty profile)
249231
const articleCount = await page.locator('.article-preview').count();

e2e/social.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,12 @@ test.describe('Social Features', () => {
156156

157157
// Go to profile and click Favorited tab
158158
await page.goto(`/profile/${user.username}`, { waitUntil: 'load' });
159-
await page.waitForSelector('a:has-text("Favorited")', { timeout: 10000 });
159+
await page.waitForSelector('a:has-text("Favorited")', { timeout: 3000 });
160160
await page.click('a:has-text("Favorited")');
161161

162-
// Wait for articles to load - use Playwright's built-in retry logic
163-
await expect(page.locator('.article-preview').first()).toBeVisible({ timeout: 15000 });
164-
165-
// The favorited article should be visible (use more flexible matching)
166-
const articleVisible = await page.locator('.article-preview').first().isVisible();
167-
expect(articleVisible).toBe(true);
162+
// Wait for URL to change then for articles to load
163+
await expect(page).toHaveURL(`/profile/${user.username}/favorites`);
164+
await expect(page.locator('.article-preview').first()).toBeVisible({ timeout: 3000 });
168165
});
169166

170167
test('should display followed users articles in feed', async ({ page }) => {

0 commit comments

Comments
 (0)