96 lines
5.2 KiB
JavaScript
96 lines
5.2 KiB
JavaScript
const sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds))
|
|
const origin = process.argv[2] || 'http://localhost:5173'
|
|
const route = '/pages/genealogy/g05-genealogy-overview'
|
|
|
|
const connect = async () => {
|
|
const pages = await (await fetch('http://127.0.0.1:9222/json/list')).json()
|
|
const page = pages.find((item) => item.type === 'page' && item.url.startsWith(`${origin}/`))
|
|
if (!page) throw new Error(`Chrome debugging has no ${origin} application page`)
|
|
const socket = new WebSocket(page.webSocketDebuggerUrl)
|
|
await new Promise((resolve, reject) => {
|
|
socket.addEventListener('open', resolve, { once: true })
|
|
socket.addEventListener('error', reject, { once: true })
|
|
})
|
|
let id = 0
|
|
const pending = new Map()
|
|
const exceptions = []
|
|
socket.addEventListener('message', (event) => {
|
|
const message = JSON.parse(event.data)
|
|
if (message.method === 'Runtime.exceptionThrown') exceptions.push(message.params.exceptionDetails.text)
|
|
const request = pending.get(message.id)
|
|
if (!request) return
|
|
pending.delete(message.id)
|
|
message.error ? request.reject(new Error(message.error.message)) : request.resolve(message.result)
|
|
})
|
|
const send = (method, params = {}) => new Promise((resolve, reject) => {
|
|
id += 1
|
|
pending.set(id, { resolve, reject })
|
|
socket.send(JSON.stringify({ id, method, params }))
|
|
})
|
|
return { socket, send, exceptions }
|
|
}
|
|
|
|
const valueOf = async (send, expression) => {
|
|
const result = await send('Runtime.evaluate', { expression, returnByValue: true })
|
|
if (result.exceptionDetails) throw new Error(result.exceptionDetails.exception?.description || result.exceptionDetails.text)
|
|
return result.result?.value
|
|
}
|
|
const waitFor = async (send, expression, message) => {
|
|
for (let attempt = 0; attempt < 40; attempt += 1) {
|
|
if (await valueOf(send, expression)) return
|
|
await sleep(100)
|
|
}
|
|
throw new Error(message)
|
|
}
|
|
const open = async (send, query, selector) => {
|
|
const url = `${origin}/#${route}${query}`
|
|
await send('Page.navigate', { url })
|
|
await waitFor(send, `location.href === ${JSON.stringify(url)}`, 'G05 navigation failed')
|
|
const documentTimeOrigin = await valueOf(send, 'performance.timeOrigin')
|
|
await send('Page.reload')
|
|
await waitFor(send, `performance.timeOrigin !== ${JSON.stringify(documentTimeOrigin)}`, `G05 ${query} did not reload into a fresh document`)
|
|
await waitFor(send, `Boolean(document.querySelector(${JSON.stringify(selector)}))`, `G05 ${query} did not render`)
|
|
}
|
|
|
|
const run = async () => {
|
|
const { socket, send, exceptions } = await connect()
|
|
try {
|
|
await send('Page.enable')
|
|
await send('Runtime.enable')
|
|
await open(send, '?state=empty', '.overview-state--empty')
|
|
await open(send, '?state=error&genealogyId=1001', '.overview-state--error')
|
|
await open(send, '?state=no-permission&genealogyId=1001', '.overview-state--no-permission')
|
|
await open(send, '?mode=public&genealogyId=2001', '.overview-public')
|
|
if ((await valueOf(send, "document.querySelectorAll('.overview-public__details > uni-view').length")) !== 5) throw new Error('G05 public preview is missing identity details')
|
|
if (await valueOf(send, "Boolean(document.querySelector('.overview-actions'))")) throw new Error('G05 public preview exposed member actions')
|
|
await valueOf(send, "document.querySelector('.overview-public__action').click()")
|
|
await waitFor(send, "location.href.includes('/pages/genealogy/g08-join-application?source=search&genealogyId=2001')", 'G05 public apply action did not open G08 search source')
|
|
|
|
await open(send, '?role=member&genealogyId=1001', '.overview-ready')
|
|
if ((await valueOf(send, "document.querySelectorAll('.overview-action').length")) !== 2) throw new Error('G05 member overview exposed owner actions')
|
|
if (await valueOf(send, "document.querySelector('.header-action')?.textContent.trim().length > 0")) throw new Error('G05 member overview exposed management action')
|
|
|
|
await open(send, '?genealogyId=1001', '.overview-ready')
|
|
if ((await valueOf(send, "document.querySelectorAll('.overview-action').length")) !== 4) throw new Error('G05 owner overview is missing management actions')
|
|
await valueOf(send, "document.querySelector('.overview-action--ancestor')?.click()")
|
|
await waitFor(send, "location.href.includes('/pages/genealogy/g03-create-genealogy?step=ancestor&genealogyId=1001')", 'G05 ancestor action did not open the G03 ancestor step')
|
|
|
|
for (const size of [{ width: 320, height: 568 }, { width: 360, height: 800 }, { width: 412, height: 915 }]) {
|
|
await send('Emulation.setDeviceMetricsOverride', { ...size, deviceScaleFactor: 1, mobile: true })
|
|
await open(send, '?mode=public&genealogyId=2001', '.overview-public')
|
|
const width = await valueOf(send, 'document.documentElement.scrollWidth')
|
|
if (width > size.width + 1) throw new Error(`G05 has horizontal overflow at ${size.width}x${size.height}`)
|
|
}
|
|
if (exceptions.length) throw new Error(`G05 raised browser exceptions: ${exceptions.join('; ')}`)
|
|
process.stdout.write('G05-OVERVIEW-RUNTIME-SMOKE PASS\n')
|
|
} finally {
|
|
try { await send('Emulation.clearDeviceMetricsOverride') } catch (_) {}
|
|
socket.close()
|
|
}
|
|
}
|
|
|
|
run().catch((error) => {
|
|
process.stderr.write(`${error.stack || error.message}\n`)
|
|
process.exit(1)
|
|
})
|