test: add AddToCartButton and ToggleCartIcon integration tests, fix timer cleanup

This commit is contained in:
Kirill
2026-05-25 18:14:27 +05:00
parent c9e3917129
commit bedf98245b
4 changed files with 112 additions and 2 deletions
@@ -1,6 +1,6 @@
import { render, screen, fireEvent, act } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { cartAdded, cartDismissed } from '@/shared/model/cart-notifications'
import { CartSnackbar } from '@/shared/ui/CartSnackbar'
@@ -15,6 +15,10 @@ beforeEach(() => {
navigateMock.mockClear()
})
afterEach(() => {
vi.useRealTimers()
})
function renderWithRouter() {
render(
<MemoryRouter initialEntries={['/']}>
@@ -53,7 +57,6 @@ describe('CartSnackbar', () => {
vi.advanceTimersByTime(4000)
})
expect(screen.queryByText(/товар добавлен/i)).not.toBeInTheDocument()
vi.useRealTimers()
})
it('navigates to /cart and closes on "Перейти в корзину" click', () => {