Files
creator-hub/web/tests/responsive.e2e.js
T

50 lines
2.3 KiB
JavaScript

import { expect, test } from '@playwright/test'
const runtime = {
id: 'container-a',
alias: 'account-a',
name: 'account-a',
state: 'running',
status: 'Up',
image_version: '148.0.0.1',
fingerprint: { seed: 1000 },
profile: 'creatorhub-profile-account-a',
endpoint: 'http://account-a:9222',
}
test('keeps the create form inside a 900px viewport', async ({ page }) => {
await page.route('**/api/browsers', route => route.fulfill({ json: [] }))
await page.route('**/api/gateways', route => route.fulfill({ json: [] }))
await page.route('**/api/browser-images', route => route.fulfill({ json: [] }))
await page.route('**/api/phase-a/accounts', route => route.fulfill({ json: [] }))
await page.route('**/api/network-exits', route => route.fulfill({ json: [] }))
await page.setViewportSize({ width: 900, height: 800 })
await page.goto('/')
await expect(page.getByRole('button', { name: '收起导航' }).first()).toBeVisible()
const createButton = page.getByRole('button', { name: '创建环境' })
await expect(createButton).toBeVisible()
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(900)
const box = await createButton.boundingBox()
expect(box).not.toBeNull()
expect(box.x + box.width).toBeLessThanOrEqual(900)
})
test('shows the CDP endpoint only in the active branch at 900px and 599px', async ({ page }) => {
await page.route('**/api/browsers', route => route.fulfill({ json: [runtime] }))
await page.route('**/api/gateways', route => route.fulfill({ json: [] }))
await page.route('**/api/browser-images', route => route.fulfill({ json: [] }))
await page.route('**/api/phase-a/accounts', route => route.fulfill({ json: [] }))
await page.route('**/api/network-exits', route => route.fulfill({ json: [] }))
const endpoint = page.getByText('http://account-a:9222')
await page.setViewportSize({ width: 900, height: 800 })
await page.goto('/')
await expect(page.getByRole('cell', { name: 'http://account-a:9222' })).toBeVisible()
await expect(endpoint.filter({ visible: true })).toHaveCount(1)
await page.setViewportSize({ width: 599, height: 800 })
await expect(page.getByRole('cell', { name: 'http://account-a:9222' })).toBeHidden()
await expect(endpoint.filter({ visible: true })).toHaveCount(1)
})