From aa7523c7bcaaf1d912b8f6d0f03be4c1f0cdfcae Mon Sep 17 00:00:00 2001 From: Madhura68 Date: Sun, 10 May 2026 15:28:56 +0200 Subject: [PATCH] test(PBI-76): align tests with new SplitPane and active-sprint flow - split-pane.test.tsx: seed positions via Zustand store instead of document.cookie; mock @/actions/user-settings so the prisma client is not transitively initialised in jsdom. - backlog-split-pane.test.tsx: same action mock. - sprint-dates.test.ts: add user.findUnique/update + $executeRaw mocks because createSprintAction now writes to user-settings. Co-Authored-By: Claude Opus 4.7 (1M context) --- __tests__/actions/sprint-dates.test.ts | 5 +++ .../backlog/backlog-split-pane.test.tsx | 7 ++- __tests__/components/split-pane.test.tsx | 43 +++++++++++-------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/__tests__/actions/sprint-dates.test.ts b/__tests__/actions/sprint-dates.test.ts index 6adb153..af2474f 100644 --- a/__tests__/actions/sprint-dates.test.ts +++ b/__tests__/actions/sprint-dates.test.ts @@ -20,6 +20,11 @@ vi.mock('@/lib/prisma', () => ({ create: vi.fn(), update: vi.fn(), }, + user: { + findUnique: vi.fn().mockResolvedValue({ settings: {} }), + update: vi.fn().mockResolvedValue({}), + }, + $executeRaw: vi.fn().mockResolvedValue(1), }, })) diff --git a/__tests__/components/backlog/backlog-split-pane.test.tsx b/__tests__/components/backlog/backlog-split-pane.test.tsx index 4505a80..27d7626 100644 --- a/__tests__/components/backlog/backlog-split-pane.test.tsx +++ b/__tests__/components/backlog/backlog-split-pane.test.tsx @@ -1,6 +1,11 @@ // @vitest-environment jsdom -import { describe, it, expect, beforeEach } from 'vitest' +import { describe, it, expect, beforeEach, vi } from 'vitest' import { render, screen } from '@testing-library/react' + +vi.mock('@/actions/user-settings', () => ({ + updateUserSettingsAction: vi.fn().mockResolvedValue({ success: true, settings: {} }), +})) + import { useProductWorkspaceStore } from '@/stores/product-workspace/store' import { BacklogSplitPane } from '@/components/backlog/backlog-split-pane' diff --git a/__tests__/components/split-pane.test.tsx b/__tests__/components/split-pane.test.tsx index cd166c0..40cb515 100644 --- a/__tests__/components/split-pane.test.tsx +++ b/__tests__/components/split-pane.test.tsx @@ -1,28 +1,35 @@ // @vitest-environment jsdom import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' import { render, screen, fireEvent } from '@testing-library/react' -import { SplitPane } from '@/components/split-pane/split-pane' -// Helper to set a cookie -function setCookie(key: string, value: string) { - Object.defineProperty(document, 'cookie', { - writable: true, - configurable: true, - value: `sp:${key}=${encodeURIComponent(value)}`, +vi.mock('@/actions/user-settings', () => ({ + updateUserSettingsAction: vi.fn().mockResolvedValue({ success: true, settings: {} }), +})) + +import { SplitPane } from '@/components/split-pane/split-pane' +import { useUserSettingsStore } from '@/stores/user-settings/store' + +function seedPositions(key: string, positions: number[]) { + useUserSettingsStore.setState((s) => { + s.entities.settings = { + layout: { + splitPanePositions: { [key]: positions }, + }, + } }) } -function clearCookies() { - Object.defineProperty(document, 'cookie', { - writable: true, - configurable: true, - value: '', +function resetStore() { + useUserSettingsStore.setState((s) => { + s.entities.settings = {} + s.context.hydrated = false + s.context.isDemo = false }) } describe('SplitPane', () => { beforeEach(() => { - clearCookies() + resetStore() // Default: desktop viewport Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 1440 }) window.dispatchEvent(new Event('resize')) @@ -64,9 +71,8 @@ describe('SplitPane', () => { expect(dividers).toHaveLength(2) }) - it('restores splits from cookie on mount', () => { - const stored = JSON.stringify([40, 60]) - setCookie('test-restore', stored) + it('restores splits from user-settings store on mount', () => { + seedPositions('test-restore', [40, 60]) const { container } = render( { expect(paneDiv).toBeTruthy() }) - it('falls back to defaultSplit when cookie is invalid', () => { - setCookie('test-invalid', 'not-valid-json') + it('falls back to defaultSplit when persisted positions are invalid', () => { + // Wrong number of values for a 2-pane layout + seedPositions('test-invalid', [10, 30, 60]) const { container } = render(