105 lines
4.2 KiB
TypeScript
105 lines
4.2 KiB
TypeScript
import { test, expect } from '@playwright/test'
|
|
import { getUrls, httpStatus, snap } from './helpers'
|
|
|
|
const urls = getUrls()
|
|
|
|
/** Skip page tests if exchange is unreachable */
|
|
async function skipIfUnreachable(request: any) {
|
|
const status = await httpStatus(request, urls.exchange, 10_000)
|
|
if (status === 0) {
|
|
test.skip(true, 'zoo.exchange is unreachable (connection refused/timeout)')
|
|
}
|
|
}
|
|
|
|
// -- Exchange Reachability ------------------------------------------------
|
|
test.describe('Exchange — Reachability', () => {
|
|
test('zoo.exchange responds (skip if not deployed)', async ({ request }) => {
|
|
const status = await httpStatus(request, urls.exchange, 15_000)
|
|
console.log(` Exchange HTTP: ${status}`)
|
|
if (status === 0) {
|
|
test.skip(true, 'zoo.exchange is not yet deployed or unreachable')
|
|
return
|
|
}
|
|
expect(status).toBeGreaterThan(0)
|
|
})
|
|
})
|
|
|
|
// -- Exchange Frontend ----------------------------------------------------
|
|
test.describe('Exchange — Frontend', () => {
|
|
test('zoo.exchange loads', async ({ request, page }) => {
|
|
await skipIfUnreachable(request)
|
|
const res = await page.goto(urls.exchange, { timeout: 30_000, waitUntil: 'domcontentloaded' })
|
|
expect(res?.status()).toBe(200)
|
|
await snap(page, 'zoo-exchange-home')
|
|
})
|
|
|
|
test('exchange has visible header/nav', async ({ request, page }) => {
|
|
await skipIfUnreachable(request)
|
|
await page.goto(urls.exchange, { timeout: 30_000, waitUntil: 'domcontentloaded' })
|
|
await page.waitForTimeout(3000)
|
|
const header = page.locator('header, nav, [class*="header"], [class*="nav"]').first()
|
|
await expect(header).toBeVisible({ timeout: 15_000 })
|
|
await snap(page, 'zoo-exchange-header')
|
|
})
|
|
})
|
|
|
|
// -- Exchange Swap UI -----------------------------------------------------
|
|
test.describe('Exchange — Swap Interface', () => {
|
|
test('swap page loads', async ({ request, page }) => {
|
|
await skipIfUnreachable(request)
|
|
await page.goto(`${urls.exchange}/swap`, { timeout: 30_000, waitUntil: 'domcontentloaded' })
|
|
await page.waitForTimeout(3000)
|
|
await snap(page, 'zoo-exchange-swap')
|
|
const content = await page.textContent('body')
|
|
expect(content?.length).toBeGreaterThan(0)
|
|
})
|
|
|
|
test('swap has token selectors', async ({ request, page }) => {
|
|
await skipIfUnreachable(request)
|
|
await page.goto(`${urls.exchange}/swap`, { timeout: 30_000, waitUntil: 'domcontentloaded' })
|
|
await page.waitForTimeout(5000)
|
|
const swapUI = page.locator(
|
|
'button:has-text("Select"), button:has-text("ZOO"), [class*="token"], [class*="swap"], [class*="Swap"]'
|
|
).first()
|
|
const visible = await swapUI.isVisible({ timeout: 10_000 }).catch(() => false)
|
|
if (visible) {
|
|
await snap(page, 'zoo-exchange-swap-tokens')
|
|
}
|
|
expect(await page.title()).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
// -- Exchange Pool UI -----------------------------------------------------
|
|
test.describe('Exchange — Liquidity Pools', () => {
|
|
test('pool page loads', async ({ request, page }) => {
|
|
await skipIfUnreachable(request)
|
|
await page.goto(`${urls.exchange}/pool`, { timeout: 30_000, waitUntil: 'domcontentloaded' })
|
|
await page.waitForTimeout(3000)
|
|
await snap(page, 'zoo-exchange-pool')
|
|
expect(await page.title()).toBeTruthy()
|
|
})
|
|
|
|
test('add liquidity page accessible', async ({ request, page }) => {
|
|
await skipIfUnreachable(request)
|
|
await page.goto(`${urls.exchange}/add`, { timeout: 30_000, waitUntil: 'domcontentloaded' })
|
|
await page.waitForTimeout(3000)
|
|
await snap(page, 'zoo-exchange-add-liquidity')
|
|
expect(await page.title()).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
// -- Exchange Network Detection -------------------------------------------
|
|
test.describe('Exchange — Network Configuration', () => {
|
|
test('exchange references Zoo network', async ({ request, page }) => {
|
|
await skipIfUnreachable(request)
|
|
await page.goto(urls.exchange, { timeout: 30_000, waitUntil: 'domcontentloaded' })
|
|
await page.waitForTimeout(5000)
|
|
const content = await page.textContent('body')
|
|
const hasNetwork = content?.toLowerCase().includes('zoo') ||
|
|
content?.toLowerCase().includes('200200') ||
|
|
content?.toLowerCase().includes('swap')
|
|
expect(hasNetwork).toBeTruthy()
|
|
await snap(page, 'zoo-exchange-network')
|
|
})
|
|
})
|