|
| 1 | +import { mockNuxtImport, mountSuspended, registerEndpoint } from '@nuxt/test-utils/runtime' |
| 2 | +import { describe, expect, it, vi, beforeEach } from 'vitest' |
| 3 | + |
| 4 | +const { mockUseAtproto, mockUseProfileLikes } = vi.hoisted(() => ({ |
| 5 | + mockUseAtproto: vi.fn(), |
| 6 | + mockUseProfileLikes: vi.fn(), |
| 7 | +})) |
| 8 | + |
| 9 | +mockNuxtImport('useAtproto', () => mockUseAtproto) |
| 10 | +mockNuxtImport('useProfileLikes', () => mockUseProfileLikes) |
| 11 | + |
| 12 | +import ProfilePage from '~/pages/profile/[identity]/index.vue' |
| 13 | + |
| 14 | +registerEndpoint('/api/social/profile/test-handle', () => ({ |
| 15 | + displayName: 'Test User', |
| 16 | + description: '', |
| 17 | + website: '', |
| 18 | + handle: 'test-handle', |
| 19 | + recordExists: false, |
| 20 | +})) |
| 21 | + |
| 22 | +describe('Profile invite section', () => { |
| 23 | + beforeEach(() => { |
| 24 | + mockUseAtproto.mockReset() |
| 25 | + mockUseProfileLikes.mockReset() |
| 26 | + }) |
| 27 | + |
| 28 | + it('does not show invite section while auth is still loading', async () => { |
| 29 | + mockUseAtproto.mockReturnValue({ |
| 30 | + user: ref(null), |
| 31 | + pending: ref(true), |
| 32 | + logout: vi.fn(), |
| 33 | + }) |
| 34 | + |
| 35 | + mockUseProfileLikes.mockReturnValue({ |
| 36 | + data: ref({ records: [] }), |
| 37 | + status: ref('success'), |
| 38 | + }) |
| 39 | + |
| 40 | + const wrapper = await mountSuspended(ProfilePage, { |
| 41 | + route: '/profile/test-handle', |
| 42 | + }) |
| 43 | + |
| 44 | + expect(wrapper.text()).not.toContain("It doesn't look like they're using npmx yet") |
| 45 | + }) |
| 46 | + |
| 47 | + it('shows invite section after auth resolves for non-owner', async () => { |
| 48 | + mockUseAtproto.mockReturnValue({ |
| 49 | + user: ref({ handle: 'other-user' }), |
| 50 | + pending: ref(false), |
| 51 | + logout: vi.fn(), |
| 52 | + }) |
| 53 | + |
| 54 | + mockUseProfileLikes.mockReturnValue({ |
| 55 | + data: ref({ records: [] }), |
| 56 | + status: ref('success'), |
| 57 | + }) |
| 58 | + |
| 59 | + const wrapper = await mountSuspended(ProfilePage, { |
| 60 | + route: '/profile/test-handle', |
| 61 | + }) |
| 62 | + |
| 63 | + expect(wrapper.text()).toContain("It doesn't look like they're using npmx yet") |
| 64 | + }) |
| 65 | + |
| 66 | + it('does not show invite section for profile owner', async () => { |
| 67 | + mockUseAtproto.mockReturnValue({ |
| 68 | + user: ref({ handle: 'test-handle' }), |
| 69 | + pending: ref(false), |
| 70 | + logout: vi.fn(), |
| 71 | + }) |
| 72 | + |
| 73 | + mockUseProfileLikes.mockReturnValue({ |
| 74 | + data: ref({ records: [] }), |
| 75 | + status: ref('success'), |
| 76 | + }) |
| 77 | + |
| 78 | + const wrapper = await mountSuspended(ProfilePage, { |
| 79 | + route: '/profile/test-handle', |
| 80 | + }) |
| 81 | + |
| 82 | + expect(wrapper.text()).not.toContain("It doesn't look like they're using npmx yet") |
| 83 | + }) |
| 84 | +}) |
0 commit comments