Skip to content

Commit 16edfe7

Browse files
committed
test(web): extract shared test helpers for the three page tests
Adds apps/web/__tests__/helpers/test-utils.ts exporting reusable factories and a small UI helper: - mockCreatorProfile / defaultCreatorProfile - mockPlaylist / defaultPlaylist / mockMyPlaylistsList (envelope) / mockPlaylistEnvelope (envelope) - defaultFanProfile / defaultMeUser / mockMeResponse - defaultAuth (preserves explicit null via in-checks) - openCreateForm (UI helper) Rewrites consume from helpers: - creator-profile-page.test.tsx (12 tests, unchanged from previous commit) - playlists-page.test.tsx (12 tests) - edit-profile-page.test.tsx (10 tests) Bug fixes that fell out of the rewrite: - playlists-page mock module was exporting getMyPlaylists, but the page imports listMyPlaylists — rename to listMyPlaylists resolves "Failed to load playlists" on every data-load test. - mockCreatePlaylist now returns mockPlaylistEnvelope(...) to match the { data: PlaylistResponse } shape createPlaylist produces. - Edit-profile Loading test typed Promise<void> resolving undefined, which made the page access state.data.user on undefined. Now Promise<MeResponse> resolved with mockMeResponse(). - Edit-profile validation test changed to use a 1-char displayName ("X") that actually fails updateMeSchema.min(2) and asserts the error AFTER clicking submit (form only validates on submit). - Edit-profile empty-fields test disambiguates the Genre label with an exact match so it no longer matches "Genre Preferences". - Playlists load-error test drops name option from findByRole since <p role="alert"> computed accessible names are inconsistent. - Removes an unused eslint-disable directive on DEFAULT_GENRE_PREFS. Result: 50/50 tests pass across 6 files. Lint clean. Build clean.
1 parent d4509a7 commit 16edfe7

4 files changed

Lines changed: 430 additions & 403 deletions

File tree

apps/web/__tests__/creator-profile-page.test.tsx

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,7 @@ import { render, screen } from '@testing-library/react'
22
import type { CreatorProfileResponse } from '@universal-healthcare/shared'
33
import { describe, expect, it, vi } from 'vitest'
44
import CreatorProfilePage from '../app/creators/[slug]/page'
5-
6-
// ─────────────────────────────────────────────────────────────────────────────
7-
// Mock fixtures
8-
// ─────────────────────────────────────────────────────────────────────────────
9-
10-
const defaultCreatorProfile: CreatorProfileResponse = {
11-
id: 'cp-1',
12-
userId: 'u-1',
13-
displayName: 'Solar Vibes',
14-
slug: 'solar-vibes',
15-
bio: 'Indie producer from Lagos',
16-
avatarUrl: null,
17-
genre: 'Indie',
18-
location: 'Lagos',
19-
isVerified: true,
20-
followerCount: 0,
21-
trackCount: 0,
22-
createdAt: '2026-01-01T00:00:00.000Z',
23-
updatedAt: '2026-01-01T00:00:00.000Z',
24-
}
25-
26-
// Spread defaults first, then overrides — this preserves callers' explicit
27-
// `null` overrides (a `??`-based defaulting helper would silently coerce
28-
// `null` back to the default).
29-
const mockCreatorProfile = (
30-
overrides?: Partial<CreatorProfileResponse>
31-
): CreatorProfileResponse => ({ ...defaultCreatorProfile, ...overrides })
5+
import { mockCreatorProfile } from './helpers/test-utils'
326

337
// Hoisted so vi.mock factories can reference them.
348
const { mockGetCreatorBySlug, mockUseParams } = vi.hoisted(() => ({

0 commit comments

Comments
 (0)