Skip to content

Commit

Permalink
dragAndDropThought: Reintroduce sleep after mouseUp (#2669)
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine authored Dec 3, 2024
1 parent d56e643 commit a378795
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.

5 changes: 5 additions & 0 deletions src/e2e/puppeteer/helpers/dragAndDropThought.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sleep from '../../../util/sleep'
import { page } from '../setup'
import getEditable from './getEditable'
import hide from './hide'
Expand Down Expand Up @@ -97,6 +98,10 @@ const dragAndDropThought = async (
if (mouseUp) {
await page.mouse.up()
await waitUntil(() => !document.querySelector('[data-drag-in-progress="true"]'))

// TODO: Why does drop/DragAndDropThought test fails intermittently without a small delay?
// QuickDropPanel and bullet highlight are visible.
await sleep(500)
}

// Hide QuickDropPanel by defafult.
Expand Down
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 a378795

Please sign in to comment.