Repository navigation
Expand file tree
/
Copy pathadmin.spec.ts
More file actions
160 lines (132 loc) · 5.55 KB
/
Copy pathadmin.spec.ts
File metadata and controls
160 lines (132 loc) · 5.55 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { test, expect } from "playwright/test";
import { loggedInAsUserOne, loggedInAsAdmin } from "./utils";
test.describe("Unauthenticated Admin Access", () => {
test("Should redirect unauthenticated users to home page", async ({
page,
}) => {
await page.goto("http://localhost:3000/admin");
// Should redirect to home page
await expect(page).toHaveURL("http://localhost:3000/");
});
});
test.describe("Non-Admin User Access", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsUserOne(page);
});
test("Should redirect non-admin users to home page", async ({ page }) => {
await page.goto("http://localhost:3000/admin");
// Should redirect to home page since user is not an admin
await expect(page).toHaveURL("http://localhost:3000/");
});
});
test.describe("Admin Dashboard", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsAdmin(page);
});
test("Should display admin dashboard for admin users", async ({ page }) => {
await page.goto("http://localhost:3000/admin");
await expect(page.locator("h1")).toContainText("Admin Dashboard");
});
test("Should show stats cards", async ({ page }) => {
await page.goto("http://localhost:3000/admin");
await expect(page.locator("h1")).toContainText("Admin Dashboard");
// Should show Total Users stat
await expect(page.getByText("Total Users")).toBeVisible();
// Should show Published Posts stat
await expect(page.getByText("Published Posts")).toBeVisible();
// Should show Active Feed Sources stat
await expect(page.getByText("Active Feed Sources")).toBeVisible();
// Should show Total Reports stat
await expect(page.getByText("Total Reports")).toBeVisible();
});
test("Should show moderation section", async ({ page }) => {
await page.goto("http://localhost:3000/admin");
await expect(
page.getByRole("heading", { name: "Moderation" }),
).toBeVisible();
// Should show moderation stats
await expect(page.getByText("Pending Reports")).toBeVisible();
await expect(page.getByText("Actioned Reports")).toBeVisible();
await expect(page.getByText("Banned Users")).toBeVisible();
await expect(page.getByText("Dismissed Reports")).toBeVisible();
});
test("Should show quick actions section", async ({ page }) => {
await page.goto("http://localhost:3000/admin");
await expect(
page.getByRole("heading", { name: "Quick Actions" }),
).toBeVisible();
// Should show quick action links
await expect(page.getByText("Moderation Queue")).toBeVisible();
await expect(page.getByText("User Management")).toBeVisible();
// Use role link to be more specific since "Feed Sources" appears multiple times
await expect(
page.getByRole("link", { name: /Feed Sources.*Manage RSS feed/i }),
).toBeVisible();
});
test("Should navigate to user management", async ({ page }) => {
await page.goto("http://localhost:3000/admin");
await page.getByText("User Management").click();
await expect(page).toHaveURL("http://localhost:3000/admin/users");
});
test("Should navigate to moderation queue", async ({ page }) => {
await page.goto("http://localhost:3000/admin");
await page.getByText("Moderation Queue").click();
await expect(page).toHaveURL("http://localhost:3000/admin/moderation");
});
test("Should navigate to feed sources", async ({ page }) => {
await page.goto("http://localhost:3000/admin");
await page.waitForLoadState("domcontentloaded");
// Use role link to be more specific since "Feed Sources" appears multiple times
const feedSourcesLink = page.getByRole("link", {
name: /Feed Sources.*Manage RSS feed/i,
});
await expect(feedSourcesLink).toBeVisible({ timeout: 10000 });
// Wait for navigation to complete after click
await Promise.all([
page.waitForURL("http://localhost:3000/admin/sources"),
feedSourcesLink.click(),
]);
await expect(page).toHaveURL("http://localhost:3000/admin/sources");
});
});
test.describe("Admin User Management", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsAdmin(page);
});
test("Should display user management page", async ({ page }) => {
await page.goto("http://localhost:3000/admin/users");
// User management page should have search functionality
await expect(page.getByPlaceholder(/search/i)).toBeVisible();
});
test("Should be able to search users", async ({ page }) => {
await page.goto("http://localhost:3000/admin/users");
// Search for a user
const searchInput = page.getByPlaceholder(/search/i);
await searchInput.fill("e2e");
await page.waitForTimeout(500); // Wait for debounced search
// Results should be displayed
await expect(page.locator("body")).toContainText(/e2e/i);
});
});
test.describe("Admin Moderation", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsAdmin(page);
});
test("Should display moderation page", async ({ page }) => {
await page.goto("http://localhost:3000/admin/moderation");
// Moderation page should show some indication of reports or empty state
const pageContent = await page.content();
expect(pageContent).toBeTruthy();
});
});
test.describe("Admin Feed Sources", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsAdmin(page);
});
test("Should display feed sources page", async ({ page }) => {
await page.goto("http://localhost:3000/admin/sources");
// Sources page should be accessible to admin
const pageContent = await page.content();
expect(pageContent).toBeTruthy();
});
});