test(05-01): add failing tests for dashboard grid and clock widget

- DashboardGrid test: empty state, widget rendering, edit mode affordances
- ClockWidget test: timezone rendering, showDate toggle behavior

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-24 11:15:18 +02:00
parent 950eebbc15
commit 792b7661d8
2 changed files with 219 additions and 0 deletions
@@ -0,0 +1,68 @@
import { cleanup, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
// Mock next-intl
vi.mock('next-intl', () => ({
useTranslations: (ns: string) => (key: string) => {
const map: Record<string, Record<string, string>> = {
widgets: {
'clock.name': 'Clock',
'clock.description': 'Shows the current time',
'clock.dateHint': 'Show date',
},
};
return map[ns]?.[key] ?? key;
},
}));
afterEach(() => {
cleanup();
vi.useRealTimers();
});
describe('ClockWidget', () => {
it('renders a time string with timezone config', async () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-06-24T12:30:00Z'));
const { ClockWidget } = await import('./clock-widget');
render(
<ClockWidget
instanceId="clock-1"
config={{ timezone: 'Europe/Berlin', showDate: true }}
isEditMode={false}
/>,
);
// Should render a time element
const timeEl = screen.getByRole('time');
expect(timeEl).toBeInTheDocument();
// Time text should be non-empty
expect(timeEl.textContent).toBeTruthy();
// Should render a date element when showDate is true
const dateEl = screen.getByTestId('clock-date');
expect(dateEl).toBeInTheDocument();
expect(dateEl.textContent).toBeTruthy();
vi.useRealTimers();
});
it('does not render date element when showDate is false', async () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-06-24T12:30:00Z'));
const { ClockWidget } = await import('./clock-widget');
render(
<ClockWidget
instanceId="clock-2"
config={{ timezone: 'Europe/Berlin', showDate: false }}
isEditMode={false}
/>,
);
expect(screen.queryByTestId('clock-date')).not.toBeInTheDocument();
vi.useRealTimers();
});
});