fix: bug
This commit is contained in:
@@ -89,6 +89,10 @@ jest.mock('expo-image', () => ({
|
||||
|
||||
const mockRefetch = jest.fn()
|
||||
const mockLoadMore = jest.fn()
|
||||
const mockFavoritesRefetch = jest.fn()
|
||||
const mockFavoritesLoadMore = jest.fn()
|
||||
const mockLikesRefetch = jest.fn()
|
||||
const mockLikesLoadMore = jest.fn()
|
||||
|
||||
jest.mock('@/hooks', () => ({
|
||||
useTemplateGenerations: jest.fn(() => ({
|
||||
@@ -99,6 +103,22 @@ jest.mock('@/hooks', () => ({
|
||||
loadMore: mockLoadMore,
|
||||
hasMore: true,
|
||||
})),
|
||||
useUserFavorites: jest.fn(() => ({
|
||||
favorites: [],
|
||||
loading: false,
|
||||
loadingMore: false,
|
||||
refetch: mockFavoritesRefetch,
|
||||
loadMore: mockFavoritesLoadMore,
|
||||
hasMore: false,
|
||||
})),
|
||||
useUserLikes: jest.fn(() => ({
|
||||
likes: [],
|
||||
loading: false,
|
||||
loadingMore: false,
|
||||
refetch: mockLikesRefetch,
|
||||
loadMore: mockLikesLoadMore,
|
||||
hasMore: false,
|
||||
})),
|
||||
}))
|
||||
|
||||
describe('My Page - Pagination', () => {
|
||||
@@ -257,4 +277,81 @@ describe('My Page - Pagination', () => {
|
||||
expect(mockRefetch).toHaveBeenCalledWith({ page: 1, limit: 20 })
|
||||
})
|
||||
})
|
||||
|
||||
describe('Tab Navigation', () => {
|
||||
it('should render tab navigation with 3 tabs', async () => {
|
||||
const { getByTestId } = render(<My />)
|
||||
|
||||
await waitFor(() => {
|
||||
const tabNavigation = getByTestId('tab-navigation')
|
||||
expect(tabNavigation).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
it('should display works tab as active by default', async () => {
|
||||
const { getByTestId, getByText } = render(<My />)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByTestId('tab-0')).toBeTruthy()
|
||||
})
|
||||
|
||||
const activeTab = getByTestId('tab-0')
|
||||
expect(activeTab).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should switch to favorites tab when pressed', async () => {
|
||||
const { getByTestId, getByText } = render(<My />)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByTestId('tab-1')).toBeTruthy()
|
||||
})
|
||||
|
||||
const favoritesTab = getByTestId('tab-1')
|
||||
fireEvent.press(favoritesTab)
|
||||
|
||||
// After pressing, the favorites tab should become active
|
||||
await waitFor(() => {
|
||||
expect(favoritesTab).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
it('should switch to likes tab when pressed', async () => {
|
||||
const { getByTestId } = render(<My />)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByTestId('tab-2')).toBeTruthy()
|
||||
})
|
||||
|
||||
const likesTab = getByTestId('tab-2')
|
||||
fireEvent.press(likesTab)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(likesTab).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
it('should show empty state for favorites when no favorites', async () => {
|
||||
const { getByTestId, getByText } = render(<My />)
|
||||
|
||||
// Switch to favorites tab
|
||||
const favoritesTab = getByTestId('tab-1')
|
||||
fireEvent.press(favoritesTab)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('my.noFavorites')).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
it('should show empty state for likes when no likes', async () => {
|
||||
const { getByTestId, getByText } = render(<My />)
|
||||
|
||||
// Switch to likes tab
|
||||
const likesTab = getByTestId('tab-2')
|
||||
fireEvent.press(likesTab)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('my.noLikes')).toBeTruthy()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user