Skip to content

Commit

Permalink
Consolidate CommandPalette tests and refactor swipe helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Dec 3, 2024
1 parent eb5cf1b commit 23052b3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
34 changes: 24 additions & 10 deletions src/e2e/puppeteer/__tests__/commandPalette.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import path from 'path'
import { KnownDevices } from 'puppeteer'
import { isMac } from '../../../browser'
import sleep from '../../../util/sleep'
import configureSnapshots from '../configureSnapshots'
import paste from '../helpers/paste'
import press from '../helpers/press'
import screenshot from '../helpers/screenshot'
import setTheme from '../helpers/setTheme'
import swipe from '../helpers/swipe'
import { page } from '../setup'

expect.extend({
Expand All @@ -12,23 +16,33 @@ expect.extend({

vi.setConfig({ testTimeout: 20000, hookTimeout: 20000 })

/** Open sidebar and wait for it to slide all the way open. */
const openCommandPalette = async () => {
it('open with keyboard', async () => {
// Simulate pressing Ctrl + P or Command + P
// process.platform === 'darwin'
const modifierKey = isMac ? 'Meta' : 'Control' // Use Meta for macOS, Control for others

await page.keyboard.down(modifierKey) // Press the modifier key
await press('P') // Press the 'P' key
await page.keyboard.up(modifierKey) // Release the modifier key
await page.keyboard.down(modifierKey)
await press('P')
await page.keyboard.up(modifierKey)

await new Promise(resolve => setTimeout(resolve, 200))
}

it('command palette', async () => {
await openCommandPalette()
// TODO: Replace sleep with wait
await sleep(200)

expect(await screenshot()).toMatchImageSnapshot({ customSnapshotIdentifier: 'commandPalette' })
await setTheme('Light')
expect(await screenshot()).toMatchImageSnapshot({ customSnapshotIdentifier: 'commandPalette-light' })
})

it('open with gesture', async () => {
const importText = `
- Hello`

await page.emulate(KnownDevices['iPhone 15 Pro'])
await paste(importText)

await swipe('r')

// the command palette should open
const popupValue = await page.locator('[data-testid=popup-value]').wait()
expect(popupValue).toBeTruthy()
})
24 changes: 0 additions & 24 deletions src/e2e/puppeteer/__tests__/gestures.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { page } from '../setup'

/** Draw a gesture on the screen. */
const gesture = async (points: { x: number; y: number }[], complete: boolean = true) => {
const swipePoints = async (points: { x: number; y: number }[], complete: boolean = true) => {
const start = points[0]

await page.touchscreen.touchStart(start.x, start.y)

for (let i = 1; i < points.length; i++) await page.touchscreen.touchMove(points[i].x, points[i].y)
for (let i = 1; i < points.length; i++) {
await page.touchscreen.touchMove(points[i].x, points[i].y)
}

if (complete) await page.touchscreen.touchEnd()
if (complete) {
await page.touchscreen.touchEnd()
}
}

export default gesture

/** Draw a horizontal line gesture at a certain y coordinate on the touch screen. */
export const drawHorizontalLineGesture = (y: number = 100) =>
gesture(
/** Swipe right. */
// TODO: Support other directions and multiple swipes.
const swipe = async (direction: 'r') => {
const y = 100
await swipePoints(
[
{ x: 100, y },
{ x: 110, y },
Expand All @@ -41,3 +45,6 @@ export const drawHorizontalLineGesture = (y: number = 100) =>
],
false,
)
}

export default swipe

0 comments on commit 23052b3

Please sign in to comment.