Skip to content

Commit

Permalink
fix and simulate engine disconnect when in sketch mode (#2524)
Browse files Browse the repository at this point in the history
* fix and simulate engine disconnect when in sketch mode

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* Update e2e/playwright/test-utils.ts

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
  • Loading branch information
jessfraz committed May 24, 2024
1 parent 1b72c7d commit f735cdc
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 3 deletions.
127 changes: 127 additions & 0 deletions e2e/playwright/flow-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3684,3 +3684,130 @@ test('simulate network down and network little widget', async ({ page }) => {
// Expect the network to be up
await expect(page.getByText('Network Health (Connected)')).toBeVisible()
})

test('Engine disconnect & reconnect in sketch mode', async ({ page }) => {
const u = await getUtils(page)
await page.setViewportSize({ width: 1200, height: 500 })
const PUR = 400 / 37.5 //pixeltoUnitRatio
await page.goto('/')
await u.waitForAuthSkipAppStart()
await u.openDebugPanel()

await expect(
page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled()
await expect(page.getByRole('button', { name: 'Start Sketch' })).toBeVisible()

// click on "Start Sketch" button
await u.clearCommandLogs()
await page.getByRole('button', { name: 'Start Sketch' }).click()
await page.waitForTimeout(100)

// select a plane
await page.mouse.click(700, 200)

await expect(page.locator('.cm-content')).toHaveText(
`const part001 = startSketchOn('XZ')`
)
await u.closeDebugPanel()

await page.waitForTimeout(300) // TODO detect animation ending, or disable animation

const startXPx = 600
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
await expect(page.locator('.cm-content'))
.toHaveText(`const part001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)`)
await page.waitForTimeout(100)

await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
await page.waitForTimeout(100)

await expect(page.locator('.cm-content'))
.toHaveText(`const part001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)
|> line([${commonPoints.num1}, 0], %)`)

// Expect the network to be up
await expect(page.getByText('Network Health (Connected)')).toBeVisible()

// simulate network down
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(page.getByText('Network Health (Offline)')).toBeVisible()

// Ensure we are not in sketch mode
await expect(
page.getByRole('button', { name: 'Exit Sketch' })
).not.toBeVisible()
await expect(page.getByRole('button', { name: 'Start Sketch' })).toBeVisible()

// simulate network up
await u.emulateNetworkConditions({
offline: false,
// values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0,
downloadThroughput: -1,
uploadThroughput: -1,
})

// Wait for the app to be ready for use
// Expect the network to be up
await expect(page.getByText('Network Health (Connected)')).toBeVisible()

// Click off the code pane.
await page.mouse.click(100, 100)

// select a line
await page.getByText(`startProfileAt(${commonPoints.startAt}, %)`).click()

// enter sketch again
await u.doAndWaitForCmd(
() => page.getByRole('button', { name: 'Edit Sketch' }).click(),
'default_camera_get_settings'
)
await page.waitForTimeout(150)

// Click the line tool
await page.getByRole('button', { name: 'Line' }).click()

await page.waitForTimeout(150)

// Ensure we can continue sketching
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
await expect(page.locator('.cm-content'))
.toHaveText(`const part001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)
|> line([${commonPoints.num1}, 0], %)
|> line([-11.59, 11.1], %)`)
await page.waitForTimeout(100)
await page.mouse.click(startXPx, 500 - PUR * 20)
await expect(page.locator('.cm-content'))
.toHaveText(`const part001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)
|> line([${commonPoints.num1}, 0], %)
|> line([-11.59, 11.1], %)
|> line([-6.61, 0], %)`)

// Unequip line tool
await page.keyboard.press('Escape')
// Make sure we didn't pop out of sketch mode.
await expect(page.getByRole('button', { name: 'Exit Sketch' })).toBeVisible()
await expect(page.getByRole('button', { name: 'Line' })).not.toHaveAttribute(
'aria-pressed',
'true'
)

// Exit sketch
await page.keyboard.press('Escape')
await expect(
page.getByRole('button', { name: 'Exit Sketch' })
).not.toBeVisible()
})
6 changes: 3 additions & 3 deletions e2e/playwright/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ async function waitForCmdReceive(page: Page, commandType: string) {
}

export async function getUtils(page: Page) {
// Chrome devtools protocol session only works in Chromium
const browserType = page.context().browser()?.browserType().name()
const cdpSession =
process.platform === 'darwin'
? null
: await page.context().newCDPSession(page)
browserType !== 'chromium' ? null : await page.context().newCDPSession(page)

return {
waitForAuthSkipAppStart: () => waitForPageLoad(page),
Expand Down
17 changes: 17 additions & 0 deletions src/components/ModelingMachineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ import { useSearchParams } from 'react-router-dom'
import { letEngineAnimateAndSyncCamAfter } from 'clientSideScene/CameraControls'
import { getVarNameModal } from 'hooks/useToolbarGuards'
import useHotkeyWrapper from 'lib/hotkeyWrapper'
import {
EngineConnectionState,

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (macos-14)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (ubuntu-latest)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / playwright-ubuntu

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / playwright-macos

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (windows-latest)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (ubuntu-latest)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (windows-latest)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (macos-14)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (ubuntu-latest)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (macos-14)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (windows-latest)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (ubuntu-latest)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (macos-14)

'EngineConnectionState' is defined but never used

Check warning on line 77 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (windows-latest)

'EngineConnectionState' is defined but never used
EngineConnectionStateType,

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (macos-14)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (ubuntu-latest)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / playwright-ubuntu

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / playwright-macos

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (windows-latest)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (ubuntu-latest)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (windows-latest)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (macos-14)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (ubuntu-latest)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (macos-14)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (windows-latest)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (ubuntu-latest)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (macos-14)

'EngineConnectionStateType' is defined but never used

Check warning on line 78 in src/components/ModelingMachineProvider.tsx

View workflow job for this annotation

GitHub Actions / build-test-apps (windows-latest)

'EngineConnectionStateType' is defined but never used
} from 'lang/std/engineConnection'

type MachineContext<T extends AnyStateMachine> = {
state: StateFrom<T>
Expand Down Expand Up @@ -658,6 +662,19 @@ export const ModelingMachineProvider = ({
editorManager.selectionRanges = modelingState.context.selectionRanges
}, [modelingState.context.selectionRanges])

useEffect(() => {
const offlineCallback = () => {
// If we are in sketch mode we need to exit it.
// TODO: how do i check if we are in a sketch mode, I only want to call
// this then.
modelingSend({ type: 'Cancel' })
}
window.addEventListener('offline', offlineCallback)
return () => {
window.removeEventListener('offline', offlineCallback)
}
}, [modelingSend])

useStateMachineCommands({
machineId: 'modeling',
state: modelingState,
Expand Down

0 comments on commit f735cdc

Please sign in to comment.