|
1
|
|
|
import { test, expect } from '@playwright/test'; |
|
2
|
|
|
|
|
3
|
|
|
test.describe('Disabled Boxes - UI Interactions', () => { |
|
4
|
|
|
test.beforeEach(async ({ page }) => { |
|
5
|
|
|
await page.goto('/'); |
|
6
|
|
|
await page.waitForSelector('.grid'); |
|
7
|
|
|
}); |
|
8
|
|
|
|
|
9
|
|
|
test('should not allow clicking disabled 2048 box', async ({ page }) => { |
|
10
|
|
|
const boxes = page.locator('.box'); |
|
11
|
|
|
const box2048 = boxes.nth(0); |
|
12
|
|
|
const box1024 = boxes.nth(1); |
|
13
|
|
|
const indexDisplay = page.locator('#index'); |
|
14
|
|
|
|
|
15
|
|
|
await box1024.click(); |
|
16
|
|
|
await expect(indexDisplay).toHaveText('1024'); |
|
17
|
|
|
|
|
18
|
|
|
await box2048.click({ force: true }); |
|
19
|
|
|
|
|
20
|
|
|
await expect(indexDisplay).toHaveText('1024'); |
|
21
|
|
|
await expect(box2048).not.toHaveClass(/active/); |
|
22
|
|
|
}); |
|
23
|
|
|
|
|
24
|
|
|
test('should not allow clicking other disabled boxes when 2048 is active', async ({ page }) => { |
|
25
|
|
|
const boxes = page.locator('.box'); |
|
26
|
|
|
const box2048 = boxes.nth(0); |
|
27
|
|
|
const box1024 = boxes.nth(1); |
|
28
|
|
|
const wordDisplay = page.locator('#word-input'); |
|
29
|
|
|
|
|
30
|
|
|
await box2048.click(); |
|
31
|
|
|
|
|
32
|
|
|
await expect(wordDisplay).not.toHaveClass(/error/); |
|
33
|
|
|
|
|
34
|
|
|
await box1024.click({ force: true }); |
|
35
|
|
|
|
|
36
|
|
|
await expect(box1024).not.toHaveClass(/active/); |
|
37
|
|
|
await expect(box2048).toHaveClass(/active/); |
|
38
|
|
|
}); |
|
39
|
|
|
|
|
40
|
|
|
test('should enable all boxes after reset', async ({ page }) => { |
|
41
|
|
|
const boxes = page.locator('.box'); |
|
42
|
|
|
const resetButton = page.locator('#reset'); |
|
43
|
|
|
|
|
44
|
|
|
await boxes.nth(0).click(); |
|
45
|
|
|
|
|
46
|
|
|
await expect(boxes.nth(1)).toHaveClass(/disabled/); |
|
47
|
|
|
|
|
48
|
|
|
await resetButton.click(); |
|
49
|
|
|
|
|
50
|
|
|
for (let i = 0; i < 12; i++) { |
|
51
|
|
|
await expect(boxes.nth(i)).not.toHaveClass(/disabled/); |
|
52
|
|
|
} |
|
53
|
|
|
}); |
|
54
|
|
|
|
|
55
|
|
|
test('should not allow keyboard navigation to trigger disabled boxes', async ({ page }) => { |
|
56
|
|
|
const boxes = page.locator('.box'); |
|
57
|
|
|
const box2048 = boxes.nth(0); |
|
58
|
|
|
const box1024 = boxes.nth(1); |
|
59
|
|
|
|
|
60
|
|
|
await box1024.click(); |
|
61
|
|
|
|
|
62
|
|
|
await box2048.focus(); |
|
63
|
|
|
await page.keyboard.press('Enter'); |
|
64
|
|
|
|
|
65
|
|
|
await expect(box2048).not.toHaveClass(/active/); |
|
66
|
|
|
await expect(box1024).toHaveClass(/active/); // 1024 should still be active |
|
67
|
|
|
}); |
|
68
|
|
|
|
|
69
|
|
|
test('should allow keyboard navigation through enabled boxes only', async ({ page }) => { |
|
70
|
|
|
const boxes = page.locator('.box'); |
|
71
|
|
|
|
|
72
|
|
|
await boxes.nth(0).click(); |
|
73
|
|
|
|
|
74
|
|
|
await boxes.nth(0).focus(); |
|
75
|
|
|
await page.keyboard.press('ArrowRight'); |
|
76
|
|
|
|
|
77
|
|
|
await page.keyboard.press('Enter'); |
|
78
|
|
|
|
|
79
|
|
|
await expect(boxes.nth(1)).not.toHaveClass(/active/); |
|
80
|
|
|
}); |
|
81
|
|
|
|
|
82
|
|
|
test('should have visual disabled state (disabled class)', async ({ page }) => { |
|
83
|
|
|
const boxes = page.locator('.box'); |
|
84
|
|
|
const box2048 = boxes.nth(0); |
|
85
|
|
|
const box1024 = boxes.nth(1); |
|
86
|
|
|
|
|
87
|
|
|
await box1024.click(); |
|
88
|
|
|
|
|
89
|
|
|
await expect(box2048).toHaveClass(/disabled/); |
|
90
|
|
|
|
|
91
|
|
|
await expect(box2048).toHaveAttribute('aria-disabled', 'true'); |
|
92
|
|
|
}); |
|
93
|
|
|
|
|
94
|
|
|
test('should show not-allowed cursor on disabled boxes', async ({ page }) => { |
|
95
|
|
|
const box2048 = page.locator('.box').nth(0); |
|
96
|
|
|
const box1024 = page.locator('.box').nth(1); |
|
97
|
|
|
|
|
98
|
|
|
await box1024.click(); |
|
99
|
|
|
|
|
100
|
|
|
await expect(box2048).toHaveClass(/disabled/); |
|
101
|
|
|
|
|
102
|
|
|
const cursor = await box2048.evaluate((el) => |
|
103
|
|
|
window.getComputedStyle(el).cursor |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
expect(cursor).toBe('not-allowed'); |
|
107
|
|
|
}); |
|
108
|
|
|
}); |
|
109
|
|
|
|