Files
goodgo-platform/apps/web/components/ui/__tests__/dialog.spec.tsx
Ho Ngoc Hai ccb82fddf8 feat(cache): implement Redis caching for search & analytics hot paths
- Add TTL-specific cache durations: district stats (5min), market report (15min), heatmap (5min)
- Add Redis caching to GeoSearch handler with 60s TTL
- Add cache invalidation on listing.approved, listing.updated, listing.deactivated, listing.sold events
- Invalidate search, geo_search, and all analytics cache prefixes on listing state changes
- Update tests for new CacheService dependency in event handler and geo-search handler

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-08 22:51:16 +07:00

72 lines
2.2 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from '../dialog';
describe('Dialog', () => {
it('renders nothing when open is false', () => {
render(
<Dialog open={false} onOpenChange={() => {}}>
<DialogContent>
<DialogTitle>Hidden</DialogTitle>
</DialogContent>
</Dialog>,
);
expect(screen.queryByText('Hidden')).not.toBeInTheDocument();
});
it('renders content when open is true', () => {
render(
<Dialog open={true} onOpenChange={() => {}}>
<DialogContent>
<DialogHeader>
<DialogTitle>Test Dialog</DialogTitle>
<DialogDescription>Dialog description</DialogDescription>
</DialogHeader>
<p>Body content</p>
<DialogFooter>
<button>OK</button>
</DialogFooter>
</DialogContent>
</Dialog>,
);
expect(screen.getByText('Test Dialog')).toBeInTheDocument();
expect(screen.getByText('Dialog description')).toBeInTheDocument();
expect(screen.getByText('Body content')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'OK' })).toBeInTheDocument();
});
it('calls onOpenChange when backdrop is clicked', async () => {
const onOpenChange = vi.fn();
render(
<Dialog open={true} onOpenChange={onOpenChange}>
<DialogContent>
<DialogTitle>Closeable</DialogTitle>
</DialogContent>
</Dialog>,
);
// Click the backdrop (the overlay div)
const backdrop = document.querySelector('.bg-black\\/80');
if (backdrop) {
await userEvent.click(backdrop);
}
expect(onOpenChange).toHaveBeenCalledWith(false);
});
it('does not close when clicking inside content', async () => {
const onOpenChange = vi.fn();
render(
<Dialog open={true} onOpenChange={onOpenChange}>
<DialogContent>
<DialogTitle>Stay Open</DialogTitle>
</DialogContent>
</Dialog>,
);
await userEvent.click(screen.getByText('Stay Open'));
expect(onOpenChange).not.toHaveBeenCalled();
});
});