|
| 1 | +import { expect, test } from '@playwright/test' |
| 2 | +import { ANIMATION_DURATION } from './constants' |
| 3 | +import { openDrawer } from './helpers' |
| 4 | + |
| 5 | +test.describe('Direction tests', () => { |
| 6 | + test.describe('default direction (bottom)', () => { |
| 7 | + test.beforeEach(async ({ page }) => { |
| 8 | + await page.goto('/test/direction') |
| 9 | + }) |
| 10 | + |
| 11 | + test('should close when dragged down', async ({ page }) => { |
| 12 | + await openDrawer(page) |
| 13 | + await page.hover('[vaul-drawer]') |
| 14 | + await page.mouse.down() |
| 15 | + await page.mouse.move(0, 800) |
| 16 | + await page.mouse.up() |
| 17 | + await page.waitForTimeout(ANIMATION_DURATION) |
| 18 | + await expect(page.getByTestId('content')).not.toBeVisible() |
| 19 | + }) |
| 20 | + |
| 21 | + test('should not close when dragged up', async ({ page }) => { |
| 22 | + await openDrawer(page) |
| 23 | + await page.hover('[vaul-drawer]') |
| 24 | + await page.mouse.down() |
| 25 | + await page.mouse.move(0, -800) |
| 26 | + await page.mouse.up() |
| 27 | + await page.waitForTimeout(ANIMATION_DURATION) |
| 28 | + await expect(page.getByTestId('content')).toBeVisible() |
| 29 | + }) |
| 30 | + }) |
| 31 | + |
| 32 | + test.describe('direction - left', () => { |
| 33 | + test.beforeEach(async ({ page }) => { |
| 34 | + await page.goto('/test/direction?direction=left') |
| 35 | + }) |
| 36 | + |
| 37 | + test('should close when dragged left', async ({ page }) => { |
| 38 | + await openDrawer(page) |
| 39 | + await page.hover('[vaul-drawer]') |
| 40 | + await page.mouse.down() |
| 41 | + await page.mouse.move(-800, 0) |
| 42 | + await page.mouse.up() |
| 43 | + await page.waitForTimeout(ANIMATION_DURATION) |
| 44 | + await expect(page.getByTestId('content')).not.toBeVisible() |
| 45 | + }) |
| 46 | + |
| 47 | + test('should not close when dragged right', async ({ page }) => { |
| 48 | + await openDrawer(page) |
| 49 | + await page.hover('[vaul-drawer]') |
| 50 | + await page.mouse.down() |
| 51 | + await page.mouse.move(800, 0) |
| 52 | + await page.mouse.up() |
| 53 | + await page.waitForTimeout(ANIMATION_DURATION) |
| 54 | + await expect(page.getByTestId('content')).toBeVisible() |
| 55 | + }) |
| 56 | + }) |
| 57 | + |
| 58 | + test.describe('direction - right', () => { |
| 59 | + test.beforeEach(async ({ page }) => { |
| 60 | + await page.goto('/test/direction?direction=right') |
| 61 | + }) |
| 62 | + |
| 63 | + test('should close when dragged right', async ({ page }) => { |
| 64 | + await openDrawer(page) |
| 65 | + await page.hover('[vaul-drawer]') |
| 66 | + await page.mouse.down() |
| 67 | + await page.mouse.move(1600, 0) |
| 68 | + await page.mouse.up() |
| 69 | + await page.waitForTimeout(ANIMATION_DURATION) |
| 70 | + await expect(page.getByTestId('content')).not.toBeVisible() |
| 71 | + }) |
| 72 | + |
| 73 | + test('should not close when dragged left', async ({ page }) => { |
| 74 | + await openDrawer(page) |
| 75 | + await page.hover('[vaul-drawer]') |
| 76 | + await page.mouse.down() |
| 77 | + await page.mouse.move(-1600, 0) |
| 78 | + await page.mouse.up() |
| 79 | + await page.waitForTimeout(ANIMATION_DURATION) |
| 80 | + await expect(page.getByTestId('content')).toBeVisible() |
| 81 | + }) |
| 82 | + }) |
| 83 | + |
| 84 | + test.describe('direction - top', () => { |
| 85 | + test.beforeEach(async ({ page }) => { |
| 86 | + await page.goto('/test/direction?direction=top') |
| 87 | + }) |
| 88 | + |
| 89 | + test('should close when dragged top', async ({ page }) => { |
| 90 | + await openDrawer(page) |
| 91 | + await page.hover('[vaul-drawer]') |
| 92 | + await page.mouse.down() |
| 93 | + await page.mouse.move(0, -800) |
| 94 | + await page.mouse.up() |
| 95 | + await page.waitForTimeout(ANIMATION_DURATION) |
| 96 | + await expect(page.getByTestId('content')).not.toBeVisible() |
| 97 | + }) |
| 98 | + |
| 99 | + test('should not close when dragged down', async ({ page }) => { |
| 100 | + await openDrawer(page) |
| 101 | + await page.hover('[vaul-drawer]') |
| 102 | + await page.mouse.down() |
| 103 | + await page.mouse.move(0, 800) |
| 104 | + await page.mouse.up() |
| 105 | + await page.waitForTimeout(ANIMATION_DURATION) |
| 106 | + await expect(page.getByTestId('content')).toBeVisible() |
| 107 | + }) |
| 108 | + }) |
| 109 | +}) |
0 commit comments