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) <noreply@anthropic.com>
This commit is contained in:
Janpeter Visser 2026-05-10 15:28:56 +02:00
parent 58dcb03420
commit aa7523c7bc
3 changed files with 36 additions and 19 deletions

View file

@ -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),
},
}))

View file

@ -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'

View file

@ -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(
<SplitPane
@ -81,8 +87,9 @@ describe('SplitPane', () => {
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(
<SplitPane