forked from FlowwStar/FlowStar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisual.spec.ts
More file actions
256 lines (234 loc) · 8.73 KB
/
Copy pathvisual.spec.ts
File metadata and controls
256 lines (234 loc) · 8.73 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import { test, expect, type Page } from "@playwright/test";
const DEMO_ADDRESS =
"GBQ2X7KFY3R4VZ6N5LJ7WQH3M2PD8C9SAUTV4EXAMPLE0WALLET00ADDR";
const FIXED_NOW = 1720000000000; // 2024-10-?? UTC; keep dates stable for screenshots
async function preparePage(
page: Page,
options: { theme?: "light" | "dark"; connect?: boolean } = {},
) {
const theme = options.theme ?? "light";
await page.addInitScript(
({ theme, connect, walletAddress, now }) => {
localStorage.setItem("theme", theme);
if (connect) {
localStorage.setItem("walletId", "xbull");
(window as any).xBullSDK = {
connect: async () => ({ publicKey: walletAddress }),
signXDR: async () => "AAAAAgAAAAA...dummy-signature...",
};
}
const OriginalDate = Date;
class MockDate extends OriginalDate {
constructor(...args: any[]) {
if (args.length === 0) {
super(now);
} else {
// Date has multiple overloaded constructors; a variadic args array
// can't be typed as a fixed tuple, so this spread can't type-check.
// @ts-expect-error
super(...args);
}
}
static now() {
return now;
}
static parse(value: string) {
return OriginalDate.parse(value);
}
static UTC(...args: Parameters<typeof OriginalDate.UTC>) {
return OriginalDate.UTC(...args);
}
}
// @ts-ignore
window.Date = MockDate;
if (theme === "dark") {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
},
{
theme,
connect: options.connect ?? false,
walletAddress: DEMO_ADDRESS,
now: FIXED_NOW,
},
);
}
for (const theme of ["light", "dark"] as const) {
test(`landing page screenshot (${theme})`, async ({ page }) => {
await preparePage(page, { theme });
await page.goto("/");
await expect(page.locator("text=FlowStar")).toBeVisible();
await expect(page).toHaveScreenshot(`landing-${theme}.png`, {
fullPage: true,
});
});
}
test.describe("Dashboard visual states", () => {
test("dashboard empty state", async ({ page }) => {
await preparePage(page, { theme: "light" });
await page.goto("/app");
await expect(page.locator("text=Connect your wallet")).toBeVisible();
await expect(page).toHaveScreenshot("dashboard-empty.png", {
fullPage: true,
});
});
test("dashboard connected with streams", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app");
await expect(page.locator("text=Dashboard")).toBeVisible();
await expect(page.locator("text=New stream")).toBeVisible();
await expect(page).toHaveScreenshot("dashboard-with-streams.png", {
fullPage: true,
});
});
test("dashboard tabs: receiving and sent", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app");
await expect(page.locator("text=Dashboard")).toBeVisible();
await page.locator('button:has-text("Receiving")').first().click();
await expect(page.locator("text=Receiving")).toBeVisible();
await expect(page).toHaveScreenshot("dashboard-receiving-tab.png", {
fullPage: true,
});
await page.locator('button:has-text("Sending")').first().click();
await expect(page.locator("text=Sending")).toBeVisible();
await expect(page).toHaveScreenshot("dashboard-sent-tab.png", {
fullPage: true,
});
});
});
test.describe("Create stream form", () => {
test("empty form screenshot", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app/create");
await expect(page.locator("text=Create a stream")).toBeVisible();
await expect(page).toHaveScreenshot("create-stream-empty.png", {
fullPage: true,
});
});
test("filled form screenshot", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app/create");
await page.fill("#recipient", "GD7HQZX4...PAYROLL...4FJ2K");
await page.fill("#amount", "1234");
await page.fill("#startDate", "2025-01-01T00:00");
await page.fill("#endDate", "2025-12-31T23:59");
await page.click('button:has-text("Create stream")');
await expect(
page
.locator("text=Review transaction")
.or(page.locator("text=Create stream")),
).toBeVisible();
await expect(page).toHaveScreenshot("create-stream-filled.png", {
fullPage: true,
});
});
test("validation error screenshot", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app/create");
await page.fill("#recipient", "invalid-address");
await page.fill("#amount", "1234");
await page.click('button:has-text("Create stream")');
await expect(
page
.locator("text=Invalid recipient address")
.or(page.locator("text=invalid")),
).toBeVisible();
await expect(page).toHaveScreenshot("create-stream-validation.png", {
fullPage: true,
});
});
});
test.describe("Stream detail pages", () => {
test("active stream screenshot", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app/stream/2");
await expect(
page.locator("text=Stream details").or(page.locator("text=Withdraw")),
).toBeVisible();
await expect(page).toHaveScreenshot("stream-detail-active.png", {
fullPage: true,
});
});
test("completed stream screenshot", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app/stream/3");
await expect(page.locator("text=Stream not found")).not.toBeVisible();
await expect(
page.locator("text=Stream details").or(page.locator("text=Withdraw")),
).toBeVisible();
await expect(page).toHaveScreenshot("stream-detail-completed.png", {
fullPage: true,
});
});
test("cancelled stream screenshot", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app/stream/5");
await expect(
page.locator("text=Cancelled").or(page.locator("text=Stream details")),
).toBeVisible();
await expect(page).toHaveScreenshot("stream-detail-cancelled.png", {
fullPage: true,
});
});
});
test.describe("Batch create page", () => {
test("empty batch create screenshot", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app/create/batch");
await expect(page.locator("text=Batch create streams")).toBeVisible();
await expect(page).toHaveScreenshot("batch-create-empty.png", {
fullPage: true,
});
});
test("batch create with CSV screenshot", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app/create/batch");
const csv =
"recipient,amount,start_time,end_time,cliff_time,cliff_amount\nGD7HQZX4...PAYROLL...4FJ2K,100,2025-01-01T00:00,2025-12-31T23:59,2025-01-01T00:00,0\n";
await page.setInputFiles('input[type="file"]#csvFile', {
name: "batch-streams.csv",
mimeType: "text/csv",
buffer: Buffer.from(csv, "utf-8"),
});
await expect(
page
.locator("text=CSV parse warnings")
.or(page.locator("text=Preview rows")),
).toBeVisible();
await expect(page).toHaveScreenshot("batch-create-with-csv.png", {
fullPage: true,
});
});
});
test.describe("Wallet and modal dialogs", () => {
test("wallet connect dialog screenshot", async ({ page }) => {
await preparePage(page, { theme: "light" });
await page.goto("/app");
await page.click('button:has-text("Connect wallet")');
await expect(page.locator("text=Connect a wallet")).toBeVisible();
await expect(page).toHaveScreenshot("wallet-connect-dialog.png", {
fullPage: true,
});
});
test("withdraw dialog screenshot", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app/stream/2");
await page.locator('button:has-text("Withdraw")').first().click();
await expect(page.locator("text=Withdraw funds")).toBeVisible();
await expect(page).toHaveScreenshot("withdraw-dialog.png", {
fullPage: true,
});
});
test("cancel dialog screenshot", async ({ page }) => {
await preparePage(page, { theme: "light", connect: true });
await page.goto("/app/stream/1");
await page.locator('button:has-text("Cancel")').first().click();
await expect(page.locator("text=Cancel stream")).toBeVisible();
await expect(page).toHaveScreenshot("cancel-dialog.png", {
fullPage: true,
});
});
});