|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +/** |
| 4 | + * Simulates a pull-to-refresh gesture by dragging from the top of |
| 5 | + * the content element downward with intermediate steps so the |
| 6 | + * gesture recognizer detects the movement. |
| 7 | + */ |
| 8 | +const pullDown = async (page: import('@playwright/test').Page, distance: number) => { |
| 9 | + const content = page.locator('ion-content'); |
| 10 | + const box = await content.boundingBox(); |
| 11 | + if (!box) throw new Error('ion-content not visible'); |
| 12 | + |
| 13 | + const startX = box.x + box.width / 2; |
| 14 | + const startY = box.y + 30; |
| 15 | + |
| 16 | + await page.mouse.move(startX, startY); |
| 17 | + await page.mouse.down(); |
| 18 | + await page.mouse.move(startX, startY + distance, { steps: 20 }); |
| 19 | + await page.mouse.up(); |
| 20 | +}; |
| 21 | + |
| 22 | +test.describe('refresher: angular standalone', () => { |
| 23 | + test.beforeEach(async ({ page }) => { |
| 24 | + await page.goto('/standalone/refresher'); |
| 25 | + }); |
| 26 | + |
| 27 | + test('should emit ionPullStart and ionPullEnd with cancel reason', async ({ page }) => { |
| 28 | + // Small drag that doesn't reach the refresh threshold |
| 29 | + await pullDown(page, 60); |
| 30 | + |
| 31 | + await page.waitForTimeout(500); |
| 32 | + |
| 33 | + await expect(page.locator('#pull-start-count')).toHaveText('1'); |
| 34 | + await expect(page.locator('#refresh-count')).toHaveText('0'); |
| 35 | + await expect(page.locator('#pull-end-count')).toHaveText('1'); |
| 36 | + await expect(page.locator('#pull-end-reason')).toHaveText('cancel'); |
| 37 | + }); |
| 38 | + |
| 39 | + test('should emit ionPullStart, ionRefresh, and ionPullEnd with complete reason', async ({ page }) => { |
| 40 | + // Large drag past the refresh threshold |
| 41 | + await pullDown(page, 300); |
| 42 | + |
| 43 | + await page.waitForTimeout(1000); |
| 44 | + |
| 45 | + await expect(page.locator('#pull-start-count')).toHaveText('1'); |
| 46 | + await expect(page.locator('#refresh-count')).toHaveText('1'); |
| 47 | + await expect(page.locator('#pull-end-count')).toHaveText('1'); |
| 48 | + await expect(page.locator('#pull-end-reason')).toHaveText('complete'); |
| 49 | + }); |
| 50 | +}); |
0 commit comments