|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { useQueryClient } from '@tanstack/react-query'; |
| 4 | +import { UserVote } from '@dailydotdev/shared/src/graphql/posts'; |
| 5 | +import type { PostBootData } from '@dailydotdev/shared/src/lib/boot'; |
| 6 | +import { CompanionEngagements } from './CompanionEngagements'; |
| 7 | + |
| 8 | +const mockUseConditionalFeature = jest.fn(); |
| 9 | +const mockUseAuthContext = jest.fn(); |
| 10 | +const mockUseQueryClient = useQueryClient as jest.Mock; |
| 11 | + |
| 12 | +jest.mock('@dailydotdev/shared/src/hooks/useConditionalFeature', () => ({ |
| 13 | + useConditionalFeature: () => mockUseConditionalFeature(), |
| 14 | +})); |
| 15 | + |
| 16 | +jest.mock('@dailydotdev/shared/src/contexts/AuthContext', () => ({ |
| 17 | + useAuthContext: () => mockUseAuthContext(), |
| 18 | +})); |
| 19 | + |
| 20 | +jest.mock('@dailydotdev/shared/src/hooks/companion', () => ({ |
| 21 | + useRawBackgroundRequest: jest.fn(), |
| 22 | +})); |
| 23 | + |
| 24 | +jest.mock('@tanstack/react-query', () => ({ |
| 25 | + ...jest.requireActual('@tanstack/react-query'), |
| 26 | + useQueryClient: jest.fn(), |
| 27 | +})); |
| 28 | + |
| 29 | +describe('CompanionEngagements', () => { |
| 30 | + beforeEach(() => { |
| 31 | + jest.clearAllMocks(); |
| 32 | + mockUseAuthContext.mockReturnValue({ user: { id: 'user-id' } }); |
| 33 | + mockUseConditionalFeature.mockReturnValue({ |
| 34 | + value: { |
| 35 | + threshold: 3, |
| 36 | + belowThresholdLabel: 'New', |
| 37 | + newWindowHours: 24, |
| 38 | + }, |
| 39 | + }); |
| 40 | + mockUseQueryClient.mockReturnValue({ |
| 41 | + setQueryData: jest.fn(), |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + it('does not render below-threshold label in companion', () => { |
| 46 | + const post = { |
| 47 | + id: 'post-id', |
| 48 | + createdAt: new Date().toISOString(), |
| 49 | + numUpvotes: 1, |
| 50 | + numComments: 2, |
| 51 | + userState: { |
| 52 | + vote: UserVote.None, |
| 53 | + }, |
| 54 | + } as PostBootData; |
| 55 | + |
| 56 | + render(<CompanionEngagements post={post} />); |
| 57 | + |
| 58 | + expect(screen.queryByText('New')).not.toBeInTheDocument(); |
| 59 | + }); |
| 60 | +}); |
0 commit comments