mirror of
https://github.com/ghndrx/k8s-game-2048.git
synced 2026-02-10 06:45:07 +00:00
feat: add comprehensive Playwright testing suite with visual regression
- Add Playwright configuration with multi-browser testing - Create basic functionality tests for game mechanics - Add gameplay tests with keyboard and touch interactions - Implement visual regression testing with screenshots - Add environment-specific tests for dev/staging/prod - Include health endpoint and security header validation - Set up test infrastructure for CI/CD pipeline
This commit is contained in:
58
tests/basic.spec.ts
Normal file
58
tests/basic.spec.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('2048 Game - Basic Functionality', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
test('should load the game successfully', async ({ page }) => {
|
||||
// Check title
|
||||
await expect(page).toHaveTitle(/2048/);
|
||||
|
||||
// Check main elements are present
|
||||
await expect(page.locator('h1')).toContainText('2048');
|
||||
await expect(page.locator('.game-container')).toBeVisible();
|
||||
await expect(page.locator('.grid-container')).toBeVisible();
|
||||
|
||||
// Check score displays
|
||||
await expect(page.locator('#score')).toBeVisible();
|
||||
await expect(page.locator('#best')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should show environment badge', async ({ page }) => {
|
||||
const envBadge = page.locator('#env-badge');
|
||||
await expect(envBadge).toBeVisible();
|
||||
|
||||
// Should have one of the environment classes
|
||||
const badgeClass = await envBadge.getAttribute('class');
|
||||
expect(badgeClass).toMatch(/(development|staging|production)/);
|
||||
});
|
||||
|
||||
test('should have initial tiles on game start', async ({ page }) => {
|
||||
// Should have at least 2 tiles initially
|
||||
const tiles = page.locator('.tile');
|
||||
await expect(tiles).toHaveCount(2);
|
||||
|
||||
// Tiles should have values 2 or 4
|
||||
const tileTexts = await tiles.allTextContents();
|
||||
tileTexts.forEach(text => {
|
||||
expect(['2', '4']).toContain(text);
|
||||
});
|
||||
});
|
||||
|
||||
test('should restart game when restart button is clicked', async ({ page }) => {
|
||||
const restartButton = page.locator('#restart-button');
|
||||
await expect(restartButton).toBeVisible();
|
||||
|
||||
// Click restart
|
||||
await restartButton.click();
|
||||
|
||||
// Should have exactly 2 tiles after restart
|
||||
const tiles = page.locator('.tile');
|
||||
await expect(tiles).toHaveCount(2);
|
||||
|
||||
// Score should be reset to 0
|
||||
await expect(page.locator('#score')).toHaveText('0');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user