|
1
|
|
|
import { test, expect } from '@playwright/test'; |
|
2
|
|
|
|
|
3
|
|
|
test.describe('Toast Notification Integration', () => { |
|
4
|
|
|
test.beforeEach(async ({ page }) => { |
|
5
|
|
|
await page.goto('/'); |
|
6
|
|
|
}); |
|
7
|
|
|
|
|
8
|
|
|
test('should show toast when using keyboard on disabled box', async ({ page }) => { |
|
9
|
|
|
const box1024 = page.locator('.box').nth(1); |
|
10
|
|
|
await box1024.click(); |
|
11
|
|
|
|
|
12
|
|
|
const box2048 = page.locator('.box').first(); |
|
13
|
|
|
await box2048.focus(); |
|
14
|
|
|
|
|
15
|
|
|
await page.keyboard.press('Enter'); |
|
16
|
|
|
await page.keyboard.press('Enter'); |
|
17
|
|
|
|
|
18
|
|
|
const toast = page.locator('#toast-notification'); |
|
19
|
|
|
await toast.waitFor({ state: 'attached', timeout: 5000 }); |
|
20
|
|
|
await expect(toast).toBeVisible(); |
|
21
|
|
|
}); |
|
22
|
|
|
|
|
23
|
|
|
test('should auto-hide toast after 3 seconds', async ({ page }) => { |
|
24
|
|
|
const box1024 = page.locator('.box').nth(1); |
|
25
|
|
|
await box1024.click(); |
|
26
|
|
|
|
|
27
|
|
|
const box2048 = page.locator('.box').first(); |
|
28
|
|
|
|
|
29
|
|
|
await box2048.click({ force: true }); |
|
30
|
|
|
await box2048.click({ force: true }); |
|
31
|
|
|
|
|
32
|
|
|
const toast = page.locator('#toast-notification'); |
|
33
|
|
|
await toast.waitFor({ state: 'attached', timeout: 5000 }); |
|
34
|
|
|
await expect(toast).toBeVisible(); |
|
35
|
|
|
await expect(toast).toContainText('Cannot select this number'); |
|
36
|
|
|
|
|
37
|
|
|
await toast.waitFor({ state: 'detached', timeout: 4000 }); |
|
38
|
|
|
await expect(toast).not.toBeVisible(); |
|
39
|
|
|
}); |
|
40
|
|
|
|
|
41
|
|
|
test('should be centered and visible on mobile', async ({ page }) => { |
|
42
|
|
|
await page.setViewportSize({ width: 375, height: 667 }); |
|
43
|
|
|
|
|
44
|
|
|
const box1024 = page.locator('.box').nth(1); |
|
45
|
|
|
await box1024.click(); |
|
46
|
|
|
|
|
47
|
|
|
const box2048 = page.locator('.box').first(); |
|
48
|
|
|
|
|
49
|
|
|
await box2048.click({ force: true }); |
|
50
|
|
|
await box2048.click({ force: true }); |
|
51
|
|
|
|
|
52
|
|
|
const toast = page.locator('#toast-notification'); |
|
53
|
|
|
await toast.waitFor({ state: 'attached', timeout: 5000 }); |
|
54
|
|
|
await expect(toast).toBeVisible(); |
|
55
|
|
|
|
|
56
|
|
|
const boundingBox = await toast.boundingBox(); |
|
57
|
|
|
const viewportSize = page.viewportSize(); |
|
58
|
|
|
|
|
59
|
|
|
if (boundingBox && viewportSize) { |
|
60
|
|
|
const centerX = boundingBox.x + boundingBox.width / 2; |
|
61
|
|
|
const viewportCenterX = viewportSize.width / 2; |
|
62
|
|
|
const horizontalDiff = Math.abs(centerX - viewportCenterX); |
|
63
|
|
|
|
|
64
|
|
|
expect(horizontalDiff).toBeLessThan(20); |
|
65
|
|
|
} |
|
66
|
|
|
}); |
|
67
|
|
|
}); |
|
68
|
|
|
|