Pass network and connection tests

This commit is contained in:
49lf
2024-11-28 12:44:08 -05:00
parent faae28b025
commit 3e435bebf4

View File

@ -1,242 +1,212 @@
import { test, expect } from '@playwright/test' import { test, expect } from './zoo-test'
import { commonPoints, getUtils, setup, tearDown } from './test-utils' import { commonPoints, getUtils } from './test-utils'
test.beforeEach(async ({ context, page }, testInfo) => {
await setup(context, page, testInfo)
})
test.afterEach(async ({ page }, testInfo) => {
await tearDown(page, testInfo)
})
test.describe('Test network and connection issues', () => { test.describe('Test network and connection issues', () => {
test('simulate network down and network little widget', async ({ test('simulate network down and network little widget', async ({ page, homePage }) => { const u = await getUtils(page)
page, await page.setBodyDimensions({ width: 1200, height: 500 })
browserName,
}) => { await homePage.goToModelingScene()
// TODO: Don't skip Mac for these. After `window.tearDown` is working in Safari, these should work on webkit
test.skip( const networkToggle = page.getByTestId('network-toggle')
browserName === 'webkit',
'Skip on Safari until `window.tearDown` is working there' // This is how we wait until the stream is online
) await expect(
const u = await getUtils(page) page.getByRole('button', { name: 'Start Sketch' })
await page.setViewportSize({ width: 1200, height: 500 }) ).not.toBeDisabled({ timeout: 15000 })
await u.waitForAuthSkipAppStart() const networkWidget = page.locator('[data-testid="network-toggle"]')
await expect(networkWidget).toBeVisible()
const networkToggle = page.getByTestId('network-toggle') await networkWidget.hover()
// This is how we wait until the stream is online const networkPopover = page.locator('[data-testid="network-popover"]')
await expect( await expect(networkPopover).not.toBeVisible()
page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled({ timeout: 15000 }) // (First check) Expect the network to be up
await expect(networkToggle).toContainText('Connected')
const networkWidget = page.locator('[data-testid="network-toggle"]')
await expect(networkWidget).toBeVisible() // Click the network widget
await networkWidget.hover() await networkWidget.click()
const networkPopover = page.locator('[data-testid="network-popover"]') // Check the modal opened.
await expect(networkPopover).not.toBeVisible() await expect(networkPopover).toBeVisible()
// (First check) Expect the network to be up // Click off the modal.
await expect(networkToggle).toContainText('Connected') await page.mouse.click(100, 100)
await expect(networkPopover).not.toBeVisible()
// Click the network widget
await networkWidget.click() // Turn off the network
await u.emulateNetworkConditions({
// Check the modal opened. offline: true,
await expect(networkPopover).toBeVisible() // values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0,
// Click off the modal. downloadThroughput: -1,
await page.mouse.click(100, 100) uploadThroughput: -1,
await expect(networkPopover).not.toBeVisible()
// Turn off the network
await u.emulateNetworkConditions({
offline: true,
// values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0,
downloadThroughput: -1,
uploadThroughput: -1,
})
// Expect the network to be down
await expect(networkToggle).toContainText('Offline')
// Click the network widget
await networkWidget.click()
// Check the modal opened.
await expect(networkPopover).toBeVisible()
// Click off the modal.
await page.mouse.click(0, 0)
await expect(networkPopover).not.toBeVisible()
// Turn back on the network
await u.emulateNetworkConditions({
offline: false,
// values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0,
downloadThroughput: -1,
uploadThroughput: -1,
})
await expect(
page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled({ timeout: 15000 })
// (Second check) expect the network to be up
await expect(networkToggle).toContainText('Connected')
}) })
// Expect the network to be down
await expect(networkToggle).toContainText('Problem')
// Click the network widget
await networkWidget.click()
// Check the modal opened.
await expect(networkPopover).toBeVisible()
// Click off the modal.
await page.mouse.click(0, 0)
await expect(networkPopover).not.toBeVisible()
// Turn back on the network
await u.emulateNetworkConditions({
offline: false,
// values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0,
downloadThroughput: -1,
uploadThroughput: -1,
})
await expect(
page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled({ timeout: 15000 })
// (Second check) expect the network to be up
await expect(networkToggle).toContainText('Connected') })
test('Engine disconnect & reconnect in sketch mode', async ({ test('Engine disconnect & reconnect in sketch mode', async ({ page, browserName, homePage }) => { // TODO: Don't skip Mac for these. After `window.tearDown` is working in Safari, these should work on webkit
page, const networkToggle = page.getByTestId('network-toggle')
browserName,
}) => { const u = await getUtils(page)
// TODO: Don't skip Mac for these. After `window.tearDown` is working in Safari, these should work on webkit await page.setBodyDimensions({ width: 1200, height: 500 })
test.skip( const PUR = 400 / 37.5 //pixeltoUnitRatio
browserName === 'webkit',
'Skip on Safari until `window.tearDown` is working there' await homePage.goToModelingScene()
) await u.waitForPageLoad()
const networkToggle = page.getByTestId('network-toggle')
await u.openDebugPanel()
const u = await getUtils(page) // click on "Start Sketch" button
await page.setViewportSize({ width: 1200, height: 500 }) await u.clearCommandLogs()
const PUR = 400 / 37.5 //pixeltoUnitRatio await page.getByRole('button', { name: 'Start Sketch' }).click()
await page.waitForTimeout(100)
await u.waitForAuthSkipAppStart()
await u.openDebugPanel() // select a plane
await page.mouse.click(700, 200)
await expect(
page.getByRole('button', { name: 'Start Sketch' }) await expect(page.locator('.cm-content')).toHaveText(
).not.toBeDisabled({ timeout: 15000 }) `sketch001 = startSketchOn('XZ')`
)
// click on "Start Sketch" button await u.closeDebugPanel()
await u.clearCommandLogs()
await page.getByRole('button', { name: 'Start Sketch' }).click() await page.waitForTimeout(500) // TODO detect animation ending, or disable animation
await page.waitForTimeout(100)
const startXPx = 600
// select a plane await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
await page.mouse.click(700, 200) await expect(page.locator('.cm-content'))
.toHaveText(`sketch001 = startSketchOn('XZ')
await expect(page.locator('.cm-content')).toHaveText( |> startProfileAt(${commonPoints.startAt}, %)`)
`sketch001 = startSketchOn('XZ')` await page.waitForTimeout(100)
)
await u.closeDebugPanel() await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
await page.waitForTimeout(100)
await page.waitForTimeout(500) // TODO detect animation ending, or disable animation
await expect(page.locator('.cm-content'))
const startXPx = 600 .toHaveText(`sketch001 = startSketchOn('XZ')
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10) |> startProfileAt(${commonPoints.startAt}, %)
await expect(page.locator('.cm-content')) |> xLine(${commonPoints.num1}, %)`)
.toHaveText(`sketch001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)`) // Expect the network to be up
await page.waitForTimeout(100) await expect(networkToggle).toContainText('Connected')
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10) // simulate network down
await page.waitForTimeout(100) await u.emulateNetworkConditions({
offline: true,
await expect(page.locator('.cm-content')) // values of 0 remove any active throttling. crbug.com/456324#c9
.toHaveText(`sketch001 = startSketchOn('XZ') latency: 0,
|> startProfileAt(${commonPoints.startAt}, %) downloadThroughput: -1,
|> xLine(${commonPoints.num1}, %)`) uploadThroughput: -1,
})
// Expect the network to be up
await expect(networkToggle).toContainText('Connected') // Expect the network to be down
await expect(networkToggle).toContainText('Problem')
// simulate network down
await u.emulateNetworkConditions({ // Ensure we are not in sketch mode
offline: true, await expect(
// values of 0 remove any active throttling. crbug.com/456324#c9 page.getByRole('button', { name: 'Exit Sketch' })
latency: 0, ).not.toBeVisible()
downloadThroughput: -1, await expect(
uploadThroughput: -1, page.getByRole('button', { name: 'Start Sketch' })
}) ).toBeVisible()
// Expect the network to be down // simulate network up
await expect(networkToggle).toContainText('Offline') await u.emulateNetworkConditions({
offline: false,
// Ensure we are not in sketch mode // values of 0 remove any active throttling. crbug.com/456324#c9
await expect( latency: 0,
page.getByRole('button', { name: 'Exit Sketch' }) downloadThroughput: -1,
).not.toBeVisible() uploadThroughput: -1,
await expect( })
page.getByRole('button', { name: 'Start Sketch' })
).toBeVisible() // Wait for the app to be ready for use
await expect(
// simulate network up page.getByRole('button', { name: 'Start Sketch' })
await u.emulateNetworkConditions({ ).not.toBeDisabled({ timeout: 15000 })
offline: false,
// values of 0 remove any active throttling. crbug.com/456324#c9 // Expect the network to be up
latency: 0, await expect(networkToggle).toContainText('Connected')
downloadThroughput: -1, await expect(page.getByTestId('loading-stream')).not.toBeAttached()
uploadThroughput: -1,
}) // Click off the code pane.
await page.mouse.click(100, 100)
// Wait for the app to be ready for use
await expect( // select a line
page.getByRole('button', { name: 'Start Sketch' }) await page.getByText(`startProfileAt(${commonPoints.startAt}, %)`).click()
).not.toBeDisabled({ timeout: 15000 })
// enter sketch again
// Expect the network to be up await u.doAndWaitForCmd(
await expect(networkToggle).toContainText('Connected') () => page.getByRole('button', { name: 'Edit Sketch' }).click(),
await expect(page.getByTestId('loading-stream')).not.toBeAttached() 'default_camera_get_settings'
)
// Click off the code pane. await page.waitForTimeout(150)
await page.mouse.click(100, 100)
// Click the line tool
// select a line await page.getByRole('button', { name: 'line Line', exact: true }).click()
await page.getByText(`startProfileAt(${commonPoints.startAt}, %)`).click()
await page.waitForTimeout(150)
// enter sketch again
await u.doAndWaitForCmd( // Ensure we can continue sketching
() => page.getByRole('button', { name: 'Edit Sketch' }).click(), await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
'default_camera_get_settings' await expect.poll(u.normalisedEditorCode)
) .toBe(`sketch001 = startSketchOn('XZ')
await page.waitForTimeout(150)
// Click the line tool
await page.getByRole('button', { name: 'line Line', exact: true }).click()
await page.waitForTimeout(150)
// Ensure we can continue sketching
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
await expect.poll(u.normalisedEditorCode)
.toBe(`sketch001 = startSketchOn('XZ')
|> startProfileAt([12.34, -12.34], %) |> startProfileAt([12.34, -12.34], %)
|> xLine(12.34, %) |> xLine(12.34, %)
|> line([-12.34, 12.34], %) |> line([-12.34, 12.34], %)
`) `)
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.mouse.click(startXPx, 500 - PUR * 20) await page.mouse.click(startXPx, 500 - PUR * 20)
await expect.poll(u.normalisedEditorCode) await expect.poll(u.normalisedEditorCode)
.toBe(`sketch001 = startSketchOn('XZ') .toBe(`sketch001 = startSketchOn('XZ')
|> startProfileAt([12.34, -12.34], %) |> startProfileAt([12.34, -12.34], %)
|> xLine(12.34, %) |> xLine(12.34, %)
|> line([-12.34, 12.34], %) |> line([-12.34, 12.34], %)
|> xLine(-12.34, %) |> xLine(-12.34, %)
`) `)
// Unequip line tool // Unequip line tool
await page.keyboard.press('Escape') await page.keyboard.press('Escape')
// Make sure we didn't pop out of sketch mode. // Make sure we didn't pop out of sketch mode.
await expect( await expect(
page.getByRole('button', { name: 'Exit Sketch' }) page.getByRole('button', { name: 'Exit Sketch' })
).toBeVisible() ).toBeVisible()
await expect( await expect(
page.getByRole('button', { name: 'line Line', exact: true }) page.getByRole('button', { name: 'line Line', exact: true })
).not.toHaveAttribute('aria-pressed', 'true') ).not.toHaveAttribute('aria-pressed', 'true')
// Exit sketch // Exit sketch
await page.keyboard.press('Escape') await page.keyboard.press('Escape')
await expect( await expect(
page.getByRole('button', { name: 'Exit Sketch' }) page.getByRole('button', { name: 'Exit Sketch' })
).not.toBeVisible() ).not.toBeVisible() })
})
}) })