-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add base tests * Add tests for scaled background * Add tests for dismiss button * More tests * Start snap points test * Add tests for nested drawers * Rename
- Loading branch information
1 parent
9a26d57
commit a73a8c7
Showing
15 changed files
with
223 additions
and
26 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { ANIMATION_DURATION } from './constants'; | ||
import { openDrawer } from './helpers'; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/without-scaled-background'); | ||
}); | ||
|
||
test.describe('Base tests', () => { | ||
test('should open drawer', async ({ page }) => { | ||
await expect(page.getByTestId('content')).not.toBeVisible(); | ||
|
||
await page.getByTestId('trigger').click(); | ||
|
||
await expect(page.getByTestId('content')).toBeVisible(); | ||
}); | ||
|
||
test('should close on background interaction', async ({ page }) => { | ||
await openDrawer(page); | ||
// Click on the background | ||
await page.mouse.click(0, 0); | ||
|
||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('content')).not.toBeVisible(); | ||
}); | ||
|
||
test('should close when `Drawer.Close` is clicked', async ({ page }) => { | ||
await openDrawer(page); | ||
|
||
await page.getByTestId('drawer-close').click(); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('content')).not.toBeVisible(); | ||
}); | ||
|
||
test('should close when controlled', async ({ page }) => { | ||
await openDrawer(page); | ||
|
||
await page.getByTestId('controlled-close').click(); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('content')).not.toBeVisible(); | ||
}); | ||
|
||
test('should close when dragged down', async ({ page }) => { | ||
await openDrawer(page); | ||
await page.hover('[vaul-drawer]'); | ||
await page.mouse.down(); | ||
await page.mouse.move(0, 800); | ||
await page.mouse.up(); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('content')).not.toBeVisible(); | ||
}); | ||
|
||
test('should not close when dragged up', async ({ page }) => { | ||
await openDrawer(page); | ||
await page.hover('[vaul-drawer]'); | ||
await page.mouse.down(); | ||
await page.mouse.move(0, -800); | ||
await page.mouse.up(); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('content')).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ANIMATION_DURATION = 500; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect, Page } from '@playwright/test'; | ||
import { ANIMATION_DURATION } from './constants'; | ||
|
||
export async function openDrawer(page: Page) { | ||
await expect(page.getByTestId('content')).not.toBeVisible(); | ||
await page.getByTestId('trigger').click(); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('content')).toBeVisible(); | ||
} | ||
|
||
export async function dragWithSpeed( | ||
page: Page, | ||
selector: string, | ||
startY: number, | ||
endY: number, | ||
speed: number = 10, | ||
): Promise<void> { | ||
const startX = 0; | ||
const distance = Math.abs(endY - startY); | ||
const steps = distance / speed; | ||
const delayPerStep = 10; // in milliseconds | ||
const yOffset = (endY - startY) / steps; | ||
|
||
await page.hover(selector); | ||
await page.mouse.down(); | ||
await page.mouse.move(0, -200); | ||
await page.mouse.up(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { ANIMATION_DURATION } from './constants'; | ||
import { openDrawer } from './helpers'; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/nested-drawers'); | ||
}); | ||
|
||
test.describe.only('Nested tests', () => { | ||
test('should open and close nested drawer', async ({ page }) => { | ||
await openDrawer(page); | ||
await page.getByTestId('nested-trigger').click(); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('nested-content')).toBeVisible(); | ||
await page.getByTestId('nested-close').click(); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('nested-content')).not.toBeVisible(); | ||
await await expect(page.getByTestId('content')).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { openDrawer } from './helpers'; | ||
import { ANIMATION_DURATION } from './constants'; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/non-dismissible'); | ||
}); | ||
|
||
test.describe('Non-dismissible', () => { | ||
test('should not close on background interaction', async ({ page }) => { | ||
await openDrawer(page); | ||
// Click on the background | ||
await page.mouse.click(0, 0); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('content')).toBeVisible(); | ||
}); | ||
|
||
test('should not close when dragged down', async ({ page }) => { | ||
await openDrawer(page); | ||
await page.hover('[vaul-drawer]'); | ||
await page.mouse.down(); | ||
await page.mouse.move(0, 800); | ||
await page.mouse.up(); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('content')).toBeVisible(); | ||
}); | ||
|
||
test('should close when the dismiss button is clicked', async ({ page }) => { | ||
await openDrawer(page); | ||
|
||
await page.getByTestId('dismiss-button').click(); | ||
await page.waitForTimeout(ANIMATION_DURATION); | ||
await expect(page.getByTestId('content')).not.toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// import { test, expect } from '@playwright/test'; | ||
// import { ANIMATION_DURATION } from './constants'; | ||
// import { openDrawer } from './helpers'; | ||
|
||
// test.beforeEach(async ({ page }) => { | ||
// await page.goto('/with-snap-points'); | ||
// }); | ||
|
||
// test.describe.only('Base tests', () => { | ||
// test('should change active snap point', async ({ page }) => { | ||
// await openDrawer(page); | ||
// await page.hover('[vaul-drawer]'); | ||
// await page.mouse.down(); | ||
// await page.mouse.move(0, -800); | ||
// await page.mouse.up(); | ||
// const activeSnap = await page.getByTestId('active-snap-index').innerText(); | ||
// await page.waitForTimeout(ANIMATION_DURATION); | ||
// expect(activeSnap).toBe('2'); | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters