Some checks failed
This commit fixes two bugs: 1. Issue #7: Missing status message DOM element - Added #status-message div to index.html - Added CSS styling with type-based classes (info, success, error) - Enhanced showMessage() to apply type classes for visual styling - Messages auto-hide after 3 seconds with fade-in animation 2. Column resizing visual bug: - Changed grid-template-columns from flexible (1fr 3fr 1fr) - To fixed minimum widths: minmax(200px, 250px) minmax(600px, 3fr) minmax(200px, 250px) - Prevents columns from resizing when content changes (captured pieces, move history) - Maintains stable layout throughout gameplay Tests: - Added status-message.test.js with 10 test cases - Added column-resize.test.js with 8 test cases - Tests verify DOM element existence, CSS styling, auto-hide behavior, and layout stability 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
148 lines
5.2 KiB
JavaScript
148 lines
5.2 KiB
JavaScript
/**
|
|
* Status Message Display Tests - Issue #7
|
|
* Tests for the status message element and its functionality
|
|
*/
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('Status Message Display', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('http://localhost:8080');
|
|
await page.waitForLoadState('networkidle');
|
|
});
|
|
|
|
test('status message element exists in DOM', async ({ page }) => {
|
|
const statusMessage = await page.locator('#status-message');
|
|
await expect(statusMessage).toBeAttached();
|
|
});
|
|
|
|
test('status message is hidden by default', async ({ page }) => {
|
|
const statusMessage = await page.locator('#status-message');
|
|
await expect(statusMessage).toHaveCSS('display', 'none');
|
|
});
|
|
|
|
test('new game shows status message', async ({ page }) => {
|
|
const newGameBtn = await page.locator('#btn-new-game');
|
|
|
|
// Accept the confirm dialog
|
|
page.on('dialog', dialog => dialog.accept());
|
|
await newGameBtn.click();
|
|
|
|
const statusMessage = await page.locator('#status-message');
|
|
await expect(statusMessage).toBeVisible();
|
|
await expect(statusMessage).toContainText('New game started!');
|
|
});
|
|
|
|
test('status message auto-hides after 3 seconds', async ({ page }) => {
|
|
const newGameBtn = await page.locator('#btn-new-game');
|
|
|
|
// Accept the confirm dialog
|
|
page.on('dialog', dialog => dialog.accept());
|
|
await newGameBtn.click();
|
|
|
|
const statusMessage = await page.locator('#status-message');
|
|
await expect(statusMessage).toBeVisible();
|
|
|
|
// Wait for message to auto-hide
|
|
await page.waitForTimeout(3100);
|
|
await expect(statusMessage).toHaveCSS('display', 'none');
|
|
});
|
|
|
|
test('check message displays with info styling', async ({ page }) => {
|
|
// Create a check situation (this would require setting up a specific board state)
|
|
// For now, we'll test that the element can receive the info class
|
|
await page.evaluate(() => {
|
|
const app = window.app;
|
|
if (app && app.showMessage) {
|
|
app.showMessage('Check! black king is in check', 'info');
|
|
}
|
|
});
|
|
|
|
const statusMessage = await page.locator('#status-message');
|
|
await expect(statusMessage).toBeVisible();
|
|
await expect(statusMessage).toHaveClass(/info/);
|
|
await expect(statusMessage).toContainText('Check!');
|
|
});
|
|
|
|
test('checkmate message displays with success styling', async ({ page }) => {
|
|
await page.evaluate(() => {
|
|
const app = window.app;
|
|
if (app && app.showMessage) {
|
|
app.showMessage('Checkmate! white wins!', 'success');
|
|
}
|
|
});
|
|
|
|
const statusMessage = await page.locator('#status-message');
|
|
await expect(statusMessage).toBeVisible();
|
|
await expect(statusMessage).toHaveClass(/success/);
|
|
await expect(statusMessage).toContainText('Checkmate!');
|
|
});
|
|
|
|
test('error messages display with error styling', async ({ page }) => {
|
|
await page.evaluate(() => {
|
|
const app = window.app;
|
|
if (app && app.showMessage) {
|
|
app.showMessage('Invalid move!', 'error');
|
|
}
|
|
});
|
|
|
|
const statusMessage = await page.locator('#status-message');
|
|
await expect(statusMessage).toBeVisible();
|
|
await expect(statusMessage).toHaveClass(/error/);
|
|
});
|
|
|
|
test('multiple messages display sequentially', async ({ page }) => {
|
|
// Show first message
|
|
await page.evaluate(() => {
|
|
const app = window.app;
|
|
if (app && app.showMessage) {
|
|
app.showMessage('First message', 'info');
|
|
}
|
|
});
|
|
|
|
const statusMessage = await page.locator('#status-message');
|
|
await expect(statusMessage).toContainText('First message');
|
|
|
|
// Show second message (should replace first)
|
|
await page.evaluate(() => {
|
|
const app = window.app;
|
|
if (app && app.showMessage) {
|
|
app.showMessage('Second message', 'success');
|
|
}
|
|
});
|
|
|
|
await expect(statusMessage).toContainText('Second message');
|
|
await expect(statusMessage).toHaveClass(/success/);
|
|
});
|
|
|
|
test('status message has correct CSS classes', async ({ page }) => {
|
|
await page.evaluate(() => {
|
|
const app = window.app;
|
|
if (app && app.showMessage) {
|
|
app.showMessage('Test message', 'info');
|
|
}
|
|
});
|
|
|
|
const statusMessage = await page.locator('#status-message');
|
|
await expect(statusMessage).toHaveClass('status-message info');
|
|
});
|
|
|
|
test('console warning not shown when element exists', async ({ page }) => {
|
|
const consoleWarnings = [];
|
|
page.on('console', msg => {
|
|
if (msg.type() === 'warning') {
|
|
consoleWarnings.push(msg.text());
|
|
}
|
|
});
|
|
|
|
await page.evaluate(() => {
|
|
const app = window.app;
|
|
if (app && app.showMessage) {
|
|
app.showMessage('Test message', 'info');
|
|
}
|
|
});
|
|
|
|
expect(consoleWarnings.filter(w => w.includes('Status message element not found'))).toHaveLength(0);
|
|
});
|
|
});
|