-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhistory.spec.ts
More file actions
117 lines (98 loc) · 4.68 KB
/
Copy pathhistory.spec.ts
File metadata and controls
117 lines (98 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* E2E Test: History Page
*
* Tests the reading history workflow on the live site:
* US-05: View reading history, navigate to articles from history
*/
import { test, expect } from '@playwright/test';
const TEST_FEED_URL = 'https://tailwindcss.com/feeds/feed.xml';
/**
* Helper to ensure a feed is subscribed before test.
*/
async function ensureFeedSubscribed(page: import('@playwright/test').Page) {
await page.goto('/');
await page.waitForURL(/\/#\/feeds/, { timeout: 15_000 });
await page.waitForLoadState('networkidle');
const existingFeed = page.locator('a[href*="/feeds/"]').first();
if (!(await existingFeed.isVisible({ timeout: 3_000 }).catch(() => false))) {
const addButton = page.locator('button').filter({ hasText: /Add Feed|添加订阅/ });
const fabButton = page.locator('button.fixed, button[class*="fixed"]').last();
const targetButton = (await addButton.count()) > 0 ? addButton.first() : fabButton;
await targetButton.click();
const dialog = page.locator('[role="dialog"]');
await expect(dialog).toBeVisible({ timeout: 5_000 });
await dialog.locator('input#feed-url').fill(TEST_FEED_URL);
await dialog.locator('button[type="submit"]').click();
await expect(dialog).not.toBeVisible({ timeout: 30_000 });
}
}
test.describe('Reading History', () => {
test('should display history page with heading', async ({ page }) => {
await page.goto('/#/history');
await page.waitForLoadState('networkidle');
// Verify page heading
const heading = page.locator('h1').first();
await expect(heading).toBeVisible({ timeout: 10_000 });
const headingText = await heading.textContent();
expect(headingText).toMatch(/History|历史|Reading History/);
});
test('should show articles in history after reading them', async ({ page }) => {
await ensureFeedSubscribed(page);
// Navigate to a feed and read an article
const feedLink = page.locator('a[href*="/feeds/"]').first();
await expect(feedLink).toBeVisible({ timeout: 10_000 });
await feedLink.click();
await page.waitForLoadState('networkidle');
const articleLink = page.locator('a[href*="/articles/"]').first();
await expect(articleLink).toBeVisible({ timeout: 10_000 });
await articleLink.click();
await page.waitForLoadState('networkidle');
// Verify article page loaded (reading it auto-marks as read)
const articleTitle = page.locator('h1').first();
await expect(articleTitle).toBeVisible({ timeout: 10_000 });
// Navigate to history page
await page.goto('/#/history');
// Wait for the loading spinner to disappear before checking content
await page.waitForSelector('.animate-spin', { state: 'hidden', timeout: 10_000 }).catch(() => {});
await page.waitForLoadState('networkidle');
// Verify history page shows the read article
const heading = page.locator('h1').first();
await expect(heading).toBeVisible({ timeout: 10_000 });
const headingText = await heading.textContent();
expect(headingText).toMatch(/History|历史|Reading History/);
// Should have at least one article in history (the one we just read)
const historyArticles = page.locator('a[href*="/articles/"]');
await expect(historyArticles.first()).toBeVisible({ timeout: 15_000 });
const count = await historyArticles.count();
expect(count).toBeGreaterThan(0);
});
test('should navigate from history to article detail', async ({ page }) => {
await page.goto('/#/history');
await page.waitForLoadState('networkidle');
// Check if there are history articles
const articleLinks = page.locator('a[href*="/articles/"]');
if ((await articleLinks.count()) > 0) {
// Click the first article
await articleLinks.first().click();
await page.waitForLoadState('networkidle');
// Verify article detail page loads
const articleTitle = page.locator('h1').first();
await expect(articleTitle).toBeVisible({ timeout: 10_000 });
const titleText = await articleTitle.textContent();
expect(titleText).toBeTruthy();
expect(titleText!.length).toBeGreaterThan(0);
}
});
test('should display read time information for history articles', async ({ page }) => {
await page.goto('/#/history');
await page.waitForLoadState('networkidle');
// Check if there are history articles with read time info
const articleLinks = page.locator('a[href*="/articles/"]');
if ((await articleLinks.count()) > 0) {
// History items should show read time like "Read Xm ago", "Just now", etc.
const bodyText = await page.textContent('body');
// The history page shows "Read" followed by relative time
expect(bodyText).toMatch(/Read|Just now|ago|历史/);
}
});
});