Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
Bloc A - Code mort:
- Suppression Studio (components, views, features)
- Suppression gamification + services mock (projectService, storageService, gamificationService)
- Mise à jour Sidebar, Navbar, locales
Bloc B - Frontend:
- Suppression modal.tsx deprecated, Modal.stories (doublon Dialog)
- Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true
- Suppression 19 tests orphelins, retrait exclusions vitest.config
Bloc C - Backend:
- Extraction routes_auth.go depuis router.go
Bloc D - Rust:
- Suppression security_legacy.rs (code mort, patterns déjà dans security/)
2026-02-14 16:23:32 +00:00
|
|
|
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
|
2025-12-03 21:56:50 +00:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
|
import userEvent from '@testing-library/user-event';
|
feat: Visual masterpiece - true light mode & premium UI
🎨 **True Light/Dark Mode**
- Implemented proper light mode with inverted color scheme
- Smooth theme transitions (0.3s ease)
- Light mode colors: white backgrounds, dark text, vibrant accents
- System theme detection with proper class application
🌈 **Enhanced Theme System**
- 4 color themes work in both light and dark modes
- Cyber (cyan/magenta), Ocean (blue/teal), Forest (green/lime), Sunset (orange/purple)
- Theme-specific glassmorphism effects
- Proper contrast in light mode
✨ **Premium Animations**
- Float, glow-pulse, slide-in, scale-in, rotate-in animations
- Smooth page transitions
- Hover effects with depth (lift, glow, scale)
- Micro-interactions on all interactive elements
🎯 **Visual Polish**
- Enhanced glassmorphism for light/dark modes
- Custom scrollbar with theme colors
- Beautiful text selection
- Focus indicators for accessibility
- Premium utility classes
🔧 **Technical Improvements**
- Updated UIStore to properly apply light/dark classes
- Added data-theme attribute for CSS targeting
- Smooth scroll behavior
- Optimized transitions
The app is now a visual masterpiece with perfect light/dark mode support!
2026-01-11 01:32:21 +00:00
|
|
|
import '@testing-library/jest-dom/vitest';
|
|
|
|
|
import { Dialog, DialogBody, DialogFooter, DialogHeader } from './dialog';
|
2025-12-03 21:56:50 +00:00
|
|
|
|
|
|
|
|
describe('Dialog Component', () => {
|
|
|
|
|
const mockOnClose = vi.fn();
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks();
|
|
|
|
|
document.body.style.overflow = '';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders nothing when open is false', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={false} onClose={mockOnClose} title="Test Dialog">
|
|
|
|
|
<div>Dialog content</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.queryByText('Dialog content')).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders dialog when open is true', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose} title="Test Dialog">
|
|
|
|
|
<div>Dialog content</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('Dialog content')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Test Dialog')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('displays title when provided', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose} title="Test Dialog">
|
|
|
|
|
<div>Dialog content</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('Test Dialog')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders DialogHeader correctly', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose} title="Test Dialog">
|
|
|
|
|
<div>Dialog content</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const header = screen.getByText('Test Dialog').closest('.border-b');
|
|
|
|
|
expect(header).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders DialogBody correctly', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose} title="Test Dialog">
|
|
|
|
|
<div>Dialog content</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('Dialog content')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders custom footer when provided', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
title="Test Dialog"
|
|
|
|
|
footer={<button>Custom Footer</button>}
|
|
|
|
|
>
|
|
|
|
|
<div>Dialog content</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('Custom Footer')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows default footer with confirm and cancel buttons for confirm variant', () => {
|
|
|
|
|
const mockOnConfirm = vi.fn();
|
|
|
|
|
render(
|
|
|
|
|
<Dialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
title="Confirm Dialog"
|
|
|
|
|
variant="confirm"
|
|
|
|
|
onConfirm={mockOnConfirm}
|
|
|
|
|
showCancel={true}
|
|
|
|
|
>
|
|
|
|
|
<div>Are you sure?</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('Confirm')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Cancel')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('calls onConfirm when confirm button is clicked', async () => {
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
const mockOnConfirm = vi.fn();
|
|
|
|
|
render(
|
|
|
|
|
<Dialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
title="Confirm Dialog"
|
|
|
|
|
variant="confirm"
|
|
|
|
|
onConfirm={mockOnConfirm}
|
|
|
|
|
>
|
|
|
|
|
<div>Are you sure?</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const confirmButton = screen.getByText('Confirm');
|
|
|
|
|
await user.click(confirmButton);
|
|
|
|
|
|
|
|
|
|
expect(mockOnConfirm).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(mockOnClose).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('calls onCancel when cancel button is clicked', async () => {
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
const mockOnCancel = vi.fn();
|
|
|
|
|
render(
|
|
|
|
|
<Dialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
title="Confirm Dialog"
|
|
|
|
|
variant="confirm"
|
|
|
|
|
onCancel={mockOnCancel}
|
|
|
|
|
showCancel={true}
|
|
|
|
|
>
|
|
|
|
|
<div>Are you sure?</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const cancelButton = screen.getByText('Cancel');
|
|
|
|
|
await user.click(cancelButton);
|
|
|
|
|
|
|
|
|
|
expect(mockOnCancel).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(mockOnClose).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows alert icon for alert variant', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
title="Alert Dialog"
|
|
|
|
|
variant="alert"
|
|
|
|
|
>
|
|
|
|
|
<div>Alert message</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
2025-12-13 02:34:34 +00:00
|
|
|
const icon = screen
|
|
|
|
|
.getByText('Alert Dialog')
|
|
|
|
|
.closest('.border-b')
|
|
|
|
|
?.querySelector('svg');
|
2025-12-03 21:56:50 +00:00
|
|
|
expect(icon).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows info icon for info variant', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
title="Info Dialog"
|
|
|
|
|
variant="info"
|
|
|
|
|
>
|
|
|
|
|
<div>Info message</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
2025-12-13 02:34:34 +00:00
|
|
|
const icon = screen
|
|
|
|
|
.getByText('Info Dialog')
|
|
|
|
|
.closest('.border-b')
|
|
|
|
|
?.querySelector('svg');
|
2025-12-03 21:56:50 +00:00
|
|
|
expect(icon).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('applies destructive variant to confirm button for alert', () => {
|
|
|
|
|
const mockOnConfirm = vi.fn();
|
|
|
|
|
render(
|
|
|
|
|
<Dialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
title="Alert Dialog"
|
|
|
|
|
variant="alert"
|
|
|
|
|
onConfirm={mockOnConfirm}
|
|
|
|
|
>
|
|
|
|
|
<div>Alert message</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const confirmButton = screen.getByText('Confirm');
|
|
|
|
|
const buttonElement = confirmButton.closest('button');
|
2026-02-07 14:08:52 +00:00
|
|
|
// Design: destructive variant uses text-destructive / bg-destructive
|
|
|
|
|
expect(buttonElement?.className).toMatch(/text-destructive|bg-destructive/);
|
2025-12-03 21:56:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('uses custom confirm and cancel labels', () => {
|
|
|
|
|
const mockOnConfirm = vi.fn();
|
|
|
|
|
render(
|
|
|
|
|
<Dialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
title="Confirm Dialog"
|
|
|
|
|
variant="confirm"
|
|
|
|
|
onConfirm={mockOnConfirm}
|
|
|
|
|
confirmLabel="Yes"
|
|
|
|
|
cancelLabel="No"
|
|
|
|
|
showCancel={true}
|
|
|
|
|
>
|
|
|
|
|
<div>Are you sure?</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('Yes')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('No')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('hides cancel button when showCancel is false', () => {
|
|
|
|
|
const mockOnConfirm = vi.fn();
|
|
|
|
|
render(
|
|
|
|
|
<Dialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
title="Confirm Dialog"
|
|
|
|
|
variant="confirm"
|
|
|
|
|
onConfirm={mockOnConfirm}
|
|
|
|
|
showCancel={false}
|
|
|
|
|
>
|
|
|
|
|
<div>Are you sure?</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.queryByText('Cancel')).not.toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Confirm')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not show footer for default variant without footer or actions', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose} title="Default Dialog">
|
|
|
|
|
<div>Dialog content</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const footer = document.querySelector('.border-t');
|
|
|
|
|
expect(footer).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
Bloc A - Code mort:
- Suppression Studio (components, views, features)
- Suppression gamification + services mock (projectService, storageService, gamificationService)
- Mise à jour Sidebar, Navbar, locales
Bloc B - Frontend:
- Suppression modal.tsx deprecated, Modal.stories (doublon Dialog)
- Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true
- Suppression 19 tests orphelins, retrait exclusions vitest.config
Bloc C - Backend:
- Extraction routes_auth.go depuis router.go
Bloc D - Rust:
- Suppression security_legacy.rs (code mort, patterns déjà dans security/)
2026-02-14 16:23:32 +00:00
|
|
|
it('calls onClose when clicking overlay (default variant)', async () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose} title="Test Dialog">
|
|
|
|
|
<div>Dialog content</div>
|
|
|
|
|
</Dialog>,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const dialog = screen.getByRole('dialog');
|
|
|
|
|
const overlay = dialog.closest('.fixed.inset-0');
|
|
|
|
|
expect(overlay).toBeInTheDocument();
|
|
|
|
|
if (overlay) fireEvent.click(overlay);
|
|
|
|
|
expect(mockOnClose).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('calls onClose when pressing Escape', async () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose} title="Test Dialog">
|
|
|
|
|
<div>Dialog content</div>
|
|
|
|
|
</Dialog>,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fireEvent.keyDown(document, { key: 'Escape' });
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(mockOnClose).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('calls onClose when clicking close button', async () => {
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose} title="Test Dialog">
|
|
|
|
|
<div>Dialog content</div>
|
|
|
|
|
</Dialog>,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const closeButton = screen.getByLabelText('Fermer');
|
|
|
|
|
await user.click(closeButton);
|
|
|
|
|
expect(mockOnClose).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('prevents body scroll when open and restores when closed', () => {
|
|
|
|
|
const { rerender } = render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose} title="Test Dialog">
|
|
|
|
|
<div>Content</div>
|
|
|
|
|
</Dialog>,
|
|
|
|
|
);
|
|
|
|
|
expect(document.body.style.overflow).toBe('hidden');
|
|
|
|
|
|
|
|
|
|
rerender(
|
|
|
|
|
<Dialog open={false} onClose={mockOnClose} title="Test Dialog">
|
|
|
|
|
<div>Content</div>
|
|
|
|
|
</Dialog>,
|
|
|
|
|
);
|
|
|
|
|
expect(document.body.style.overflow).toBe('');
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-03 21:56:50 +00:00
|
|
|
it('handles async onConfirm', async () => {
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
const mockOnConfirm = vi.fn().mockResolvedValue(undefined);
|
|
|
|
|
render(
|
|
|
|
|
<Dialog
|
|
|
|
|
open={true}
|
|
|
|
|
onClose={mockOnClose}
|
|
|
|
|
title="Confirm Dialog"
|
|
|
|
|
variant="confirm"
|
|
|
|
|
onConfirm={mockOnConfirm}
|
|
|
|
|
>
|
|
|
|
|
<div>Are you sure?</div>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const confirmButton = screen.getByText('Confirm');
|
|
|
|
|
await user.click(confirmButton);
|
|
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(mockOnConfirm).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(mockOnClose).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('DialogHeader', () => {
|
|
|
|
|
it('renders DialogHeader correctly', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose}>
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<div>Header content</div>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<DialogBody>
|
|
|
|
|
<div>Body content</div>
|
|
|
|
|
</DialogBody>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('Header content')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('DialogBody', () => {
|
|
|
|
|
it('renders DialogBody correctly', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose}>
|
|
|
|
|
<DialogBody>
|
|
|
|
|
<div>Body content</div>
|
|
|
|
|
</DialogBody>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('Body content')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('DialogFooter', () => {
|
|
|
|
|
it('renders DialogFooter correctly', () => {
|
|
|
|
|
render(
|
|
|
|
|
<Dialog open={true} onClose={mockOnClose}>
|
|
|
|
|
<DialogBody>
|
|
|
|
|
<div>Body content</div>
|
|
|
|
|
</DialogBody>
|
|
|
|
|
<DialogFooter>
|
|
|
|
|
<button>Footer button</button>
|
|
|
|
|
</DialogFooter>
|
2025-12-13 02:34:34 +00:00
|
|
|
</Dialog>,
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('Footer button')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|