Skip to content

Commit 2a75d16

Browse files
Fix snapshot test
1 parent 014b3cd commit 2a75d16

File tree

6 files changed

+41
-37
lines changed

6 files changed

+41
-37
lines changed

e2e/playwright/snapshot-tests.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ test.describe('Grid visibility', { tag: '@snapshot' }, () => {
10441044
})
10451045
})
10461046

1047-
test('theme persists', async ({ page, context }) => {
1047+
test('theme persists', async ({ page, context, homePage }) => {
10481048
const u = await getUtils(page)
10491049
await context.addInitScript(async () => {
10501050
localStorage.setItem(
@@ -1062,7 +1062,7 @@ test('theme persists', async ({ page, context }) => {
10621062

10631063
await page.setViewportSize({ width: 1200, height: 500 })
10641064

1065-
await u.waitForAuthSkipAppStart()
1065+
await homePage.goToModelingScene()
10661066
await page.waitForTimeout(500)
10671067

10681068
// await page.getByRole('link', { name: 'Settings Settings (tooltip)' }).click()
@@ -1090,7 +1090,7 @@ test('theme persists', async ({ page, context }) => {
10901090
// Disconnect and reconnect to check the theme persists through a reload
10911091

10921092
// Expect the network to be down
1093-
await expect(networkToggle).toContainText('Offline')
1093+
await expect(networkToggle).toContainText('Problem')
10941094

10951095
// simulate network up
10961096
await u.emulateNetworkConditions({
Loading

e2e/playwright/test-network-and-connection-issues.spec.ts

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ profile001 = startProfile(sketch001, at = [12.34, -12.34])
267267
async ({ page, homePage, scene, cmdBar, toolbar }) => {
268268
const u = await getUtils(page)
269269
const networkToggle = page.getByTestId('network-toggle')
270+
const networkToggleConnectedText = page.getByText('Connected')
271+
const networkToggleWeakText = page.getByText('Network health (Weak)')
270272
const userSettingsTab = page.getByRole('radio', { name: 'User' })
271273
const appStreamIdleModeSetting = page.getByTestId('app-streamIdleMode')
272274
const settingsCloseButton = page.getByTestId('settings-close-button')
@@ -275,44 +277,21 @@ profile001 = startProfile(sketch001, at = [12.34, -12.34])
275277
localStorage.setItem(
276278
'persistCode',
277279
`sketch001 = startSketchOn(XY)
278-
profile001 = startProfile(sketch001, at = [44.41, 59.65])
279-
|> line(end = [205.52, 251.67])
280-
|> line(end = [184.62, -219.45])
281-
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
280+
profile001 = startProfile(sketch001, at = [0.0, 0.0])
281+
|> line(end = [10.0, 0])
282+
|> line(end = [0, 10.0])
282283
|> close()`
283284
)
284285
})
285286

286-
const dim = { width: 1200, height: 800 }
287+
const dim = { width: 1200, height: 500 }
287288
await page.setBodyDimensions(dim)
288289

289290
await test.step('Go to modeling scene', async () => {
290291
await homePage.goToModelingScene()
291292
await scene.settled(cmdBar)
292293
})
293294

294-
// GRAB THE COORDINATES OF A POINT ON A LINE.
295-
// Use the right side of the square (not covered by panes)
296-
// Trigger highlight by hovering over the space
297-
await circleMove(page, dim.width / 2, dim.height / 2, 20, 10)
298-
299-
// Double click to edit sketch.
300-
await page.mouse.dblclick(dim.width / 2, dim.height / 2, { delay: 100 })
301-
await toolbar.waitUntilSketchingReady()
302-
303-
// We need to be in sketch mode to access this data.
304-
const line = await u.getBoundingBox('[data-overlay-index="0"]')
305-
const angle = await u.getAngle('[data-overlay-index="0"]')
306-
const midPoint = {
307-
x: line.x + (Math.sin((angle / 360) * Math.PI * 2) * line.width) / 2,
308-
// Different coordinate space, need to -1 to fix it up
309-
y:
310-
(line.y +
311-
(Math.cos((angle / 360) * Math.PI * 2) * line.height) / 2) *
312-
-1,
313-
}
314-
await page.getByRole('button', { name: 'Exit Sketch' }).click()
315-
316295
await test.step('Set stream idle pause time to 5s', async () => {
317296
await page.getByRole('link', { name: 'Settings' }).last().click()
318297
await expect(
@@ -333,25 +312,39 @@ profile001 = startProfile(sketch001, at = [44.41, 59.65])
333312

334313
// We should now be paused. To the user, it should appear we're still
335314
// connected.
336-
await expect(networkToggle).toContainText('Connected')
315+
await networkToggle.hover()
316+
await expect(networkToggleConnectedText.or(networkToggleWeakText)).toBeVisible()
317+
318+
const center = {
319+
x: dim.width / 2,
320+
y: dim.height / 2,
321+
}
322+
323+
let probe = { x: 0, y: 0 }
337324

338325
// ... and the model's still visibly there
339-
console.log(midPoint)
340-
await scene.expectPixelColor(TEST_COLORS.OFFWHITE, midPoint, 15)
326+
probe.x = center.x + (dim.width / 100)
327+
probe.y = center.y
328+
await scene.expectPixelColor(TEST_COLORS.GREY, probe, 15)
329+
probe = { ...center }
341330

342331
// Now move the mouse around to unpause!
343-
await circleMove(page, dim.width / 2, dim.height / 2, 20, 10)
332+
await circleMove(page, probe.x, probe.y, 20, 10)
344333

345334
// ONCE AGAIN! Check the view area hasn't changed at all.
346335
// Check the pixel a couple times as it reconnects.
347336
// NOTE: Remember, idle behavior is still on at this point -
348337
// if this test takes longer than 5s shit WILL go south!
349-
await scene.expectPixelColor(TEST_COLORS.OFFWHITE, midPoint, 15)
338+
probe.x = center.x + (dim.width / 100)
339+
probe.y = center.y
340+
await scene.expectPixelColor(TEST_COLORS.GREY, probe, 15)
350341
await page.waitForTimeout(1000)
351-
await scene.expectPixelColor(TEST_COLORS.OFFWHITE, midPoint, 15)
342+
await scene.expectPixelColor(TEST_COLORS.GREY, probe, 15)
343+
probe = { ...center }
352344

353345
// Ensure we're still connected
354-
await expect(networkToggle).toContainText('Connected')
346+
await networkToggle.hover()
347+
await expect(networkToggleConnectedText.or(networkToggleWeakText)).toBeVisible()
355348
})
356349
}
357350
)

e2e/playwright/test-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type TestColor = [number, number, number]
4343
export const TEST_COLORS: { [key: string]: TestColor } = {
4444
WHITE: [249, 249, 249],
4545
OFFWHITE: [237, 237, 237],
46+
GREY: [142, 142, 142],
4647
YELLOW: [255, 255, 0],
4748
BLUE: [0, 0, 255],
4849
DARK_MODE_BKGD: [27, 27, 27],

src/components/EngineStream.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TEST } from '@src/env'
12
import { useAppState } from '@src/AppState'
23
import { ClientSideScene } from '@src/clientSideScene/ClientSideSceneComp'
34
import { ViewControlContextMenu } from '@src/components/ViewControlMenu'
@@ -208,6 +209,10 @@ export const EngineStream = (props: {
208209
// Poll that we're connected. If not, send a reset signal.
209210
// Do not restart if we're in idle mode.
210211
const connectionCheckIntervalId = setInterval(() => {
212+
// SKIP DURING TESTS BECAUSE IT WILL MESS WITH REUSING THE
213+
// ELECTRON INSTANCE.
214+
if (TEST) { return }
215+
211216
// Don't try try to restart if we're already connected!
212217
const hasEngineConnectionInst = engineCommandManager.engineConnection
213218
const isDisconnected =

src/lang/std/engineConnection.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TEST } from '@src/env'
12
import type { Models } from '@kittycad/lib'
23
import { VITE_KC_API_WS_MODELING_URL, VITE_KC_DEV_TOKEN } from '@src/env'
34
import { jsAppSettings } from '@src/lib/settings/settingsUtils'
@@ -1449,6 +1450,10 @@ export class EngineCommandManager extends EventTarget {
14491450

14501451
private onOffline = () => {
14511452
console.log('Browser reported network is offline')
1453+
if (TEST) {
1454+
console.warn('DURING TESTS ENGINECONNECTION.ONOFFLINE WILL DO NOTHING.')
1455+
return
1456+
}
14521457
this.onEngineConnectionRestartRequest()
14531458
}
14541459

0 commit comments

Comments
 (0)