|
| 1 | +import { render } from '@testing-library/react'; |
| 2 | +import { ProfileStoreProvider } from 'src/stores/Profile/profile.store'; |
| 3 | +import { FactoryUser } from 'src/test/factories/User'; |
| 4 | +import { describe, expect, it, vi } from 'vitest'; |
| 5 | + |
| 6 | +import { PremiumTierWrapper } from './PremiumTierWrapper'; |
| 7 | + |
| 8 | +vi.mock('src/stores/Profile/profile.store', () => ({ |
| 9 | + useProfileStore: () => ({ |
| 10 | + profile: FactoryUser({ |
| 11 | + badges: [ |
| 12 | + { |
| 13 | + id: 1, |
| 14 | + name: 'supporter', |
| 15 | + displayName: 'Supporter', |
| 16 | + imageUrl: 'https://example.com/icons/supporter.svg', |
| 17 | + }, |
| 18 | + { |
| 19 | + id: 2, |
| 20 | + name: 'pro', |
| 21 | + displayName: 'PRO', |
| 22 | + imageUrl: 'https://example.com/icons/pro.svg', |
| 23 | + premiumTier: 1, |
| 24 | + }, |
| 25 | + ], |
| 26 | + }), |
| 27 | + }), |
| 28 | + ProfileStoreProvider: ({ children }: { children: React.ReactNode }) => children, |
| 29 | +})); |
| 30 | + |
| 31 | +describe('PremiumTierWrapper', () => { |
| 32 | + it('renders fallback when user does not have required tier', () => { |
| 33 | + const { getByText } = render( |
| 34 | + <ProfileStoreProvider> |
| 35 | + <PremiumTierWrapper tierRequired={2} fallback={<div>Fallback Content</div>}> |
| 36 | + <div>Test Content</div> |
| 37 | + </PremiumTierWrapper> |
| 38 | + </ProfileStoreProvider>, |
| 39 | + ); |
| 40 | + expect(getByText('Fallback Content')).toBeTruthy(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('renders child components when user has required tier', () => { |
| 44 | + const { getByText } = render( |
| 45 | + <ProfileStoreProvider> |
| 46 | + <PremiumTierWrapper tierRequired={1}> |
| 47 | + <div>Test Content</div> |
| 48 | + </PremiumTierWrapper> |
| 49 | + </ProfileStoreProvider>, |
| 50 | + ); |
| 51 | + expect(getByText('Test Content')).toBeTruthy(); |
| 52 | + }); |
| 53 | + |
| 54 | + it('renders child components when tierRequired is 0', () => { |
| 55 | + const { getByText } = render( |
| 56 | + <ProfileStoreProvider> |
| 57 | + <PremiumTierWrapper tierRequired={0}> |
| 58 | + <div>Test Content</div> |
| 59 | + </PremiumTierWrapper> |
| 60 | + </ProfileStoreProvider>, |
| 61 | + ); |
| 62 | + expect(getByText('Test Content')).toBeTruthy(); |
| 63 | + }); |
| 64 | +}); |
0 commit comments