diff --git a/components/grid.tsx b/components/grid.tsx index 60cd705..0633d4d 100644 --- a/components/grid.tsx +++ b/components/grid.tsx @@ -17,7 +17,7 @@ export default function Grid() { const [drawMessageDisplay, setDrawMessageDisplay] = useState(false); type CellValue = 'X' | 'O' | null; const [board, setBoard] = useState(Array(9).fill(null)); - const gridArray = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + const gridArray: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const winningPatterns = [ [1, 2, 3], [4, 5, 6], @@ -91,7 +91,7 @@ export default function Grid() { const drawScenario = () => { setDrawMessageDisplay(true); }; - + /* const mapGrid = gridArray.map((fieldValue) => { const index = fieldValue - 1; const cellValue = board[index]; @@ -104,6 +104,8 @@ export default function Grid() { [&:nth-child(3n+1)_button]:border-l-0 [&:nth-child(3n)_button]:border-r-0' key={fieldValue} + role='gridcell' + aria-label={`Cell ${fieldValue}`} > + + ); + })} + + )); return (
-
- {mapGrid} -
+
{mapGrid}
+ {winningMessageDisplay || drawMessageDisplay === true ? (
diff --git a/tests/example.spec.ts b/tests/example.spec.ts index fa12220..127cad7 100644 --- a/tests/example.spec.ts +++ b/tests/example.spec.ts @@ -1,7 +1,19 @@ import { expect } from '@playwright/test'; import { test } from './base-test'; -//do fixtures - array of al board cells - then all one by one? +test('Verify that the board is a 3x3 grid', async ({ page, board }) => { + const { tictacBoard } = board; + + await page.goto('http://localhost:3000/'); + //expect 3 rows in grid + const cellRows = tictacBoard.getByRole('row'); + await expect(cellRows).toHaveCount(3); + //expect 3 cells in each row + const count = await cellRows.count(); + for (let i = 0; i < count; i++) { + await expect(cellRows.nth(i).getByRole('gridcell')).toHaveCount(3); + } +}); test('Verify that there is 9 cells and that all are enabled', async ({ page, @@ -32,7 +44,6 @@ test('Verify that valid moves (empty cells) are accepted', async ({ await cellOne.click(); await tictacBoard.getByRole('button', { name: 'Cell 2' }).click(); await tictacBoard.getByRole('button', { name: 'Cell 3' }).click(); - //await page.getByRole('image', { name: 'X' }) // Expect a image called "X" await expect(cellOne.getByAltText('X')).toBeVisible();