forked from SmartDropLabs/smartdrop-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend-retry.spec.ts
More file actions
93 lines (77 loc) · 2.91 KB
/
Copy pathbackend-retry.spec.ts
File metadata and controls
93 lines (77 loc) · 2.91 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
import { test, expect, type Page, type Route } from '@playwright/test';
// #96: Prices/Airdrops/Webhooks/Alerts pages must offer a visible Retry
// affordance on a failed backend query, and recovering from a transient
// failure must not require a full page reload. This spec exercises that
// against the Airdrops page (no wallet/Freighter dependency, simplest of
// the four) by intercepting its backend call directly — same page.route
// pattern e2e/farm.spec.ts uses for Horizon/Soroban RPC mocking, just
// against smartdrop-backend's plain JSON REST API instead of XDR-encoded
// Soroban RPC.
const AIRDROPS_SUCCESS_BODY = {
airdrops: [
{
id: 'a1',
name: 'Genesis Drop',
asset: 'XLM',
asset_issuer: '',
total_amount: 1000,
expiry_ledger: 123456,
status: 'completed',
created_at: '2024-01-01T00:00:00Z',
updated_at: '2024-01-01T00:00:00Z',
},
],
pagination: { page: 1, limit: 20, total: 1, total_pages: 1 },
};
async function mockAirdropsFailThenSucceed(page: Page): Promise<void> {
let callCount = 0;
await page.route('**/api/v1/airdrops**', async (route: Route) => {
callCount += 1;
if (callCount === 1) {
await route.fulfill({
status: 400,
contentType: 'application/json',
body: JSON.stringify({ error: { message: 'Bad request from mock' } }),
});
return;
}
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(AIRDROPS_SUCCESS_BODY),
});
});
}
test.describe('Backend-query retry affordance (#96)', () => {
test('Airdrops: Retry button recovers a failed query without a page reload', async ({
page,
}) => {
await mockAirdropsFailThenSucceed(page);
let navigationCount = 0;
page.on('load', () => {
navigationCount += 1;
});
await page.goto('/airdrops');
// Error state with a Retry button.
await expect(page.getByText('Bad request from mock')).toBeVisible();
const retryButton = page.getByRole('button', { name: /retry/i });
await expect(retryButton).toBeVisible();
// Full-page navigations after the initial goto('/airdrops') load would
// mean a reload happened — there must be none.
const loadCountBeforeRetry = navigationCount;
await retryButton.click();
// Success data renders in place.
await expect(page.getByText('Genesis Drop')).toBeVisible();
expect(navigationCount).toBe(loadCountBeforeRetry);
});
test('Retry button is keyboard-operable: Enter recovers the page', async ({ page }) => {
await mockAirdropsFailThenSucceed(page);
await page.goto('/airdrops');
const retryButton = page.getByRole('button', { name: /retry/i });
await expect(retryButton).toBeVisible();
await retryButton.focus();
await expect(retryButton).toBeFocused();
await page.keyboard.press('Enter');
await expect(page.getByText('Genesis Drop')).toBeVisible();
});
});