-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy path427-highlight-created-words.spec.ts
More file actions
72 lines (61 loc) · 3.29 KB
/
Copy path427-highlight-created-words.spec.ts
File metadata and controls
72 lines (61 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { expect, type Page, test } from '@playwright/test';
import * as Lib from '../lib';
/*
* @see https://github.com/kamilmielnik/scrabble-solver/issues/427
*/
test.describe('#427 - Highlight created words on board on hover', () => {
test('highlights the hovered word only at its own position', async ({ page }) => {
await Lib.visitIndex(page);
await Lib.typeBoard(page, 'cat', 'horizontal', { x: 3, y: 3 });
await Lib.typeBoard(page, 'cat', 'vertical', { x: 8, y: 8 });
await openWordsModal(page);
await Lib.hoverWord(page, 3, 3, 'horizontal');
await Lib.expectTileHighlighted(Lib.getBoardTile(page, 3, 3));
await Lib.expectTileHighlighted(Lib.getBoardTile(page, 4, 3));
await Lib.expectTileHighlighted(Lib.getBoardTile(page, 5, 3));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 8, 8));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 8, 9));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 8, 10));
await Lib.hoverWord(page, 8, 8, 'vertical');
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 3, 3));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 4, 3));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 5, 3));
await Lib.expectTileHighlighted(Lib.getBoardTile(page, 8, 8));
await Lib.expectTileHighlighted(Lib.getBoardTile(page, 8, 9));
await Lib.expectTileHighlighted(Lib.getBoardTile(page, 8, 10));
await Lib.moveMouseAway(page);
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 3, 3));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 4, 3));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 5, 3));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 8, 8));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 8, 9));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 8, 10));
});
test('highlights a hovered invalid word', async ({ page }) => {
await Lib.visitIndex(page);
await Lib.typeBoard(page, 'zvq', 'horizontal', { x: 5, y: 5 });
await openWordsModal(page);
await expect(page.getByTestId('word-5-5-horizontal').getByLabel('Invalid', { exact: true })).toBeVisible();
await Lib.hoverWord(page, 5, 5, 'horizontal');
await Lib.expectTileHighlighted(Lib.getBoardTile(page, 5, 5));
await Lib.expectTileHighlighted(Lib.getBoardTile(page, 6, 5));
await Lib.expectTileHighlighted(Lib.getBoardTile(page, 7, 5));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 8, 5));
});
test('clears the highlight when the modal closes', async ({ page }) => {
await Lib.visitIndex(page);
await Lib.typeBoard(page, 'cat', 'horizontal', { x: 3, y: 3 });
await openWordsModal(page);
await Lib.hoverWord(page, 3, 3, 'horizontal');
await Lib.expectTileHighlighted(Lib.getBoardTile(page, 3, 3));
await page.keyboard.press('Escape');
await expect(Lib.getOpenModal(page)).toHaveCount(0);
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 3, 3));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 4, 3));
await Lib.expectTileNotHighlighted(Lib.getBoardTile(page, 5, 3));
});
});
async function openWordsModal(page: Page) {
await page.getByLabel('Created words', { exact: true }).click();
await expect(Lib.getOpenModal(page)).toBeVisible();
}