90 lines
3.7 KiB
TypeScript
90 lines
3.7 KiB
TypeScript
import { test, expect } from '@playwright/test'
|
|
import { getUrls, httpStatus, httpGetJson, snap } from './helpers'
|
|
|
|
const urls = getUrls()
|
|
|
|
// -- Explorer API ---------------------------------------------------------
|
|
test.describe('Zoo Explorer API', () => {
|
|
test('stats endpoint returns blocks', async ({ request }) => {
|
|
const data = await httpGetJson(request, `${urls.apiExploreZoo}/api/v2/stats`) as Record<string, unknown>
|
|
const blocks = Number(data.total_blocks || 0)
|
|
console.log(` Zoo explorer: ${blocks} blocks, ${data.total_transactions || 0} txs, ${data.total_addresses || 0} addrs`)
|
|
expect(blocks).toBeGreaterThan(0)
|
|
})
|
|
|
|
test('search API accessible', async ({ request }) => {
|
|
const status = await httpStatus(request, `${urls.apiExploreZoo}/api/v2/search?q=0x0000000000000000000000000000000000000000`)
|
|
expect([200, 404]).toContain(status)
|
|
})
|
|
|
|
test('blocks API returns data', async ({ request }) => {
|
|
const data = await httpGetJson(request, `${urls.apiExploreZoo}/api/v2/blocks`) as Record<string, unknown>
|
|
const items = data.items as unknown[] | undefined
|
|
console.log(` blocks API: ${items?.length || 0} items`)
|
|
expect(items).toBeDefined()
|
|
expect(Array.isArray(items)).toBe(true)
|
|
})
|
|
|
|
test('transactions API accessible', async ({ request }) => {
|
|
const status = await httpStatus(request, `${urls.apiExploreZoo}/api/v2/transactions`)
|
|
console.log(` txs API: HTTP ${status}`)
|
|
expect([200, 404]).toContain(status)
|
|
})
|
|
})
|
|
|
|
// -- Explorer Frontend ----------------------------------------------------
|
|
test.describe('Zoo Explorer Frontend', () => {
|
|
test('explorer loads', async ({ page }) => {
|
|
const res = await page.goto(urls.exploreZoo, { timeout: 60_000, waitUntil: 'domcontentloaded' })
|
|
expect(res?.status()).toBe(200)
|
|
await page.waitForTimeout(2000)
|
|
const bodyLen = (await page.textContent('body'))?.length || 0
|
|
expect(bodyLen).toBeGreaterThan(0)
|
|
await snap(page, 'zoo-explorer-home')
|
|
})
|
|
|
|
test('homepage shows blocks', async ({ page }) => {
|
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
await page.goto(urls.exploreZoo, { waitUntil: 'domcontentloaded' })
|
|
const blocksSection = page.locator('text=/block/i').first()
|
|
const visible = await blocksSection.isVisible({ timeout: 15_000 }).catch(() => false)
|
|
if (visible) break
|
|
if (attempt === 0) await page.reload({ waitUntil: 'domcontentloaded' })
|
|
}
|
|
const blocksSection = page.locator('text=/block/i').first()
|
|
await expect(blocksSection).toBeVisible({ timeout: 15_000 })
|
|
await snap(page, 'zoo-explorer-blocks')
|
|
})
|
|
|
|
test('blocks page loads', async ({ page }) => {
|
|
await page.goto(`${urls.exploreZoo}/blocks`, { waitUntil: 'domcontentloaded' })
|
|
await page.waitForTimeout(3000)
|
|
await snap(page, 'zoo-explorer-blocks-page')
|
|
const bodyLen = (await page.textContent('body'))?.length || 0
|
|
expect(bodyLen).toBeGreaterThan(0)
|
|
})
|
|
|
|
test('transactions page loads', async ({ page }) => {
|
|
await page.goto(`${urls.exploreZoo}/txs`, { waitUntil: 'domcontentloaded' })
|
|
await page.waitForTimeout(3000)
|
|
await snap(page, 'zoo-explorer-txs')
|
|
})
|
|
|
|
test('address lookup works (zero address)', async ({ page }) => {
|
|
await page.goto(
|
|
`${urls.exploreZoo}/address/0x0000000000000000000000000000000000000000`,
|
|
{ waitUntil: 'domcontentloaded' }
|
|
)
|
|
await page.waitForTimeout(3000)
|
|
await snap(page, 'zoo-explorer-address')
|
|
const content = await page.textContent('body')
|
|
expect(content?.toLowerCase()).toContain('0x0000')
|
|
})
|
|
|
|
test('API docs page loads', async ({ page }) => {
|
|
await page.goto(`${urls.exploreZoo}/api-docs`, { waitUntil: 'domcontentloaded' })
|
|
await page.waitForTimeout(2000)
|
|
await snap(page, 'zoo-explorer-api-docs')
|
|
})
|
|
})
|