forked from FlowwStar/FlowStar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.spec.ts
More file actions
113 lines (98 loc) · 4.32 KB
/
Copy pathanalytics.spec.ts
File metadata and controls
113 lines (98 loc) · 4.32 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
import { test, expect, type Page } from '@playwright/test'
// The app ships with a built-in mock data store (lib/mock-data.ts) used
// whenever no on-chain contract id is configured. Its streams are keyed to
// DEMO_ADDRESS as sender/recipient, so connecting a mock wallet with this
// exact address surfaces deterministic "mock data" for chart rendering —
// the same convention e2e/visual.spec.ts uses for dashboard screenshots.
const DEMO_ADDRESS = 'GBQ2X7KFY3R4VZ6N5LJ7WQH3M2PD8C9SAUTV4EXAMPLE0WALLET00ADDR'
async function withWallet(page: Page, address: string = DEMO_ADDRESS) {
await page.addInitScript((walletAddress) => {
localStorage.setItem('walletId', 'xbull')
;(window as any).xBullSDK = {
connect: async () => ({ publicKey: walletAddress }),
signXDR: async () => 'AAAAAgAAAAA...dummy-signature...',
}
}, address)
}
test.describe('Analytics page — unauthenticated (no data)', () => {
test('renders page structure with zero-state stats', async ({ page }) => {
await page.goto('/app/analytics')
await expect(page.locator('h1:has-text("Platform analytics")')).toBeVisible()
await expect(page.locator('text=Total volume streamed')).toBeVisible()
await expect(page.locator('text=Active streams')).toBeVisible()
await expect(page.locator('text=Total streams created')).toBeVisible()
await expect(page.locator('text=Average duration')).toBeVisible()
})
test('shows empty-state copy in the charts when there is no stream activity', async ({
page,
}) => {
await page.goto('/app/analytics')
await expect(page.locator('text=No stream activity yet for this period.')).toBeVisible()
await expect(page.locator('text=No volume data yet.')).toBeVisible()
})
test('"Back to dashboard" link navigates to /app', async ({ page }) => {
await page.goto('/app/analytics')
await page.locator('a:has-text("Back to dashboard")').click()
await expect(page).toHaveURL(/\/app$/)
})
})
test.describe('Analytics page — chart rendering with mock data', () => {
test.beforeEach(async ({ page }) => {
await withWallet(page)
await page.goto('/app/analytics')
await page.waitForLoadState('networkidle')
})
test('default 30-day range reflects the mock streams within that window', async ({
page,
}) => {
// Of the 5 seeded mock streams, only 3 fall within the last 30 days
// (one is +90d old, one is +120d old); 2 of those 3 are active (one is
// cancelled).
const totalCard = page
.locator('div')
.filter({ has: page.locator('text=Total streams created') })
.last()
await expect(totalCard.locator('text=3')).toBeVisible()
const activeCard = page
.locator('div')
.filter({ has: page.locator('text=Active streams') })
.last()
await expect(activeCard.locator('text=2')).toBeVisible()
})
test('switching range to "All time" includes all seeded mock streams', async ({
page,
}) => {
await page.locator('button:has-text("30 days")').click()
await page.locator('text=All time').click()
const totalCard = page
.locator('div')
.filter({ has: page.locator('text=Total streams created') })
.last()
await expect(totalCard.locator('text=5')).toBeVisible()
const activeCard = page
.locator('div')
.filter({ has: page.locator('text=Active streams') })
.last()
await expect(activeCard.locator('text=3')).toBeVisible()
})
test('renders the "Streams created over time" chart with data bars', async ({
page,
}) => {
await expect(page.locator('text=Streams created over time')).toBeVisible()
await expect(page.locator('text=No stream activity yet for this period.')).not.toBeVisible()
})
test('renders "Top tokens by volume" with the seeded token symbols', async ({
page,
}) => {
await expect(page.locator('text=Top tokens by volume')).toBeVisible()
// The default 30d window includes USDC and XLM denominated streams.
await expect(page.locator('text=USDC').first()).toBeVisible()
})
test('renders "Token distribution" section', async ({ page }) => {
await expect(page.locator('text=Token distribution')).toBeVisible()
})
test('network context card lists available tokens', async ({ page }) => {
await expect(page.locator('text=Network context')).toBeVisible()
await expect(page.locator('text=XLM').first()).toBeVisible()
})
})