* feat(PBI-76): extend UserSettings schema with layout Adds layout.splitPanePositions and layout.activeSprints. These will hold values currently kept in client-side and server-side cookies (Phase 2). Two new tests cover the shape. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(PBI-76): migrate SplitPane positions to user-settings store Outside of a drag the store is the source of truth (cross-tab updates flow in for free). During a drag we keep splits in local state so mousemove does not round-trip through the store. On mouseup we persist the final splits via setPref. Removes document.cookie reads/writes — cookieKey is reused as the store-key for backwards compat. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(PBI-76): resolveActiveSprint reads from User.settings lib/active-sprint: - New helpers: getActiveSprintIdFromSettings, setActiveSprintInSettings, clearActiveSprintInSettings — all read/write user.settings.layout.activeSprints. - resolveActiveSprint(productId, userId) — userId now required, falls back to first OPEN, then most recent CLOSED sprint. - Cookie helpers (getActiveSprintIdFromCookie/setActiveSprintCookie/ clearActiveSprintCookie) removed. Callers updated to pass session.userId. The cookie-based fallback path is gone — `actions/active-sprint.ts` and `actions/sprints.ts` will be updated in the next commit (T-917). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(PBI-76): rewrite setActiveSprint callers to use settings setActiveSprintAction, syncActiveSprintCookieAction, and the two sprint-creation paths in actions/sprints.ts now write through setActiveSprintInSettings (which also emits pg_notify for cross-tab sync) instead of dropping a cookie. The action names keep the 'cookie' suffix in the user-visible API for now — clean rename can come later. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(PBI-76): migration helper v2 — handle legacy cookies Bumps marker version to 'v2'. buildMigrationPatch now also scans document.cookie for `sp:*` (split-pane positions) and `active_sprint_*` (active sprint per product) and lifts them into layout.splitPanePositions / layout.activeSprints. clearLegacyStorage replaces clearLegacyLocalStorage and clears both keys and cookies. clearLegacyLocalStorage stays as a deprecated alias so the bridge upgrade is a single rename. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * 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> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
234 lines
7.1 KiB
TypeScript
234 lines
7.1 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
|
import { render, screen, fireEvent } from '@testing-library/react'
|
|
|
|
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 resetStore() {
|
|
useUserSettingsStore.setState((s) => {
|
|
s.entities.settings = {}
|
|
s.context.hydrated = false
|
|
s.context.isDemo = false
|
|
})
|
|
}
|
|
|
|
describe('SplitPane', () => {
|
|
beforeEach(() => {
|
|
resetStore()
|
|
// Default: desktop viewport
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 1440 })
|
|
window.dispatchEvent(new Event('resize'))
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
it('renders 2 panes', () => {
|
|
render(
|
|
<SplitPane
|
|
panes={[<div key="a">Pane A</div>, <div key="b">Pane B</div>]}
|
|
defaultSplit={[30, 70]}
|
|
cookieKey="test-2pane"
|
|
/>
|
|
)
|
|
expect(screen.getByText('Pane A')).toBeTruthy()
|
|
expect(screen.getByText('Pane B')).toBeTruthy()
|
|
})
|
|
|
|
it('renders 3 panes with 2 dividers', () => {
|
|
const { container } = render(
|
|
<SplitPane
|
|
panes={[
|
|
<div key="a">Left</div>,
|
|
<div key="b">Middle</div>,
|
|
<div key="c">Right</div>,
|
|
]}
|
|
defaultSplit={[28, 35, 37]}
|
|
cookieKey="test-3pane"
|
|
/>
|
|
)
|
|
expect(screen.getByText('Left')).toBeTruthy()
|
|
expect(screen.getByText('Middle')).toBeTruthy()
|
|
expect(screen.getByText('Right')).toBeTruthy()
|
|
// 2 dividers: cursor-col-resize elements
|
|
const dividers = container.querySelectorAll('.cursor-col-resize')
|
|
expect(dividers).toHaveLength(2)
|
|
})
|
|
|
|
it('restores splits from user-settings store on mount', () => {
|
|
seedPositions('test-restore', [40, 60])
|
|
|
|
const { container } = render(
|
|
<SplitPane
|
|
panes={[<div key="a">A</div>, <div key="b">B</div>]}
|
|
defaultSplit={[20, 80]}
|
|
cookieKey="test-restore"
|
|
/>
|
|
)
|
|
|
|
// Left pane should have width 40%, not the default 20%
|
|
const paneDiv = container.querySelector<HTMLElement>('[style*="40%"]')
|
|
expect(paneDiv).toBeTruthy()
|
|
})
|
|
|
|
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
|
|
panes={[<div key="a">A</div>, <div key="b">B</div>]}
|
|
defaultSplit={[25, 75]}
|
|
cookieKey="test-invalid"
|
|
/>
|
|
)
|
|
|
|
const paneDiv = container.querySelector<HTMLElement>('[style*="25%"]')
|
|
expect(paneDiv).toBeTruthy()
|
|
})
|
|
|
|
it('renders tabs on mobile viewport', () => {
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 768 })
|
|
window.dispatchEvent(new Event('resize'))
|
|
|
|
render(
|
|
<SplitPane
|
|
panes={[<div key="a">Content A</div>, <div key="b">Content B</div>]}
|
|
defaultSplit={[50, 50]}
|
|
cookieKey="test-mobile"
|
|
tabLabels={['Tab A', 'Tab B']}
|
|
/>
|
|
)
|
|
|
|
expect(screen.getByText('Tab A')).toBeTruthy()
|
|
expect(screen.getByText('Tab B')).toBeTruthy()
|
|
// Only first tab content visible by default
|
|
expect(screen.getByText('Content A')).toBeTruthy()
|
|
expect(screen.queryByText('Content B')).toBeNull()
|
|
})
|
|
|
|
it('switches tab content on mobile', () => {
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 600 })
|
|
window.dispatchEvent(new Event('resize'))
|
|
|
|
render(
|
|
<SplitPane
|
|
panes={[<div key="a">Content A</div>, <div key="b">Content B</div>]}
|
|
defaultSplit={[50, 50]}
|
|
cookieKey="test-mobile-switch"
|
|
tabLabels={['Tab A', 'Tab B']}
|
|
/>
|
|
)
|
|
|
|
// Click second tab
|
|
fireEvent.click(screen.getByText('Tab B'))
|
|
expect(screen.queryByText('Content A')).toBeNull()
|
|
expect(screen.getByText('Content B')).toBeTruthy()
|
|
})
|
|
|
|
it('back button not visible on tab 0 in mobile', () => {
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 600 })
|
|
window.dispatchEvent(new Event('resize'))
|
|
|
|
render(
|
|
<SplitPane
|
|
panes={[<div key="a">A</div>, <div key="b">B</div>, <div key="c">C</div>]}
|
|
defaultSplit={[33, 33, 34]}
|
|
cookieKey="test-back-hidden"
|
|
tabLabels={['T1', 'T2', 'T3']}
|
|
/>
|
|
)
|
|
|
|
// On tab 0, no back button
|
|
expect(screen.queryByLabelText('Terug')).toBeNull()
|
|
})
|
|
|
|
it('back button visible on tab > 0 and navigates back', () => {
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 600 })
|
|
window.dispatchEvent(new Event('resize'))
|
|
|
|
render(
|
|
<SplitPane
|
|
panes={[<div key="a">A</div>, <div key="b">B</div>, <div key="c">C</div>]}
|
|
defaultSplit={[33, 33, 34]}
|
|
cookieKey="test-back-nav"
|
|
tabLabels={['T1', 'T2', 'T3']}
|
|
/>
|
|
)
|
|
|
|
// Switch to tab 2
|
|
fireEvent.click(screen.getByText('T3'))
|
|
expect(screen.getByText('C')).toBeTruthy()
|
|
expect(screen.getByLabelText('Terug')).toBeTruthy()
|
|
|
|
// Click back → tab 1
|
|
fireEvent.click(screen.getByLabelText('Terug'))
|
|
expect(screen.getByText('B')).toBeTruthy()
|
|
|
|
// Click back again → tab 0, no back button
|
|
fireEvent.click(screen.getByLabelText('Terug'))
|
|
expect(screen.getByText('A')).toBeTruthy()
|
|
expect(screen.queryByLabelText('Terug')).toBeNull()
|
|
})
|
|
|
|
it('controlled activeTab prop switches the active pane', () => {
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 600 })
|
|
window.dispatchEvent(new Event('resize'))
|
|
|
|
const { rerender } = render(
|
|
<SplitPane
|
|
panes={[<div key="a">A</div>, <div key="b">B</div>, <div key="c">C</div>]}
|
|
defaultSplit={[33, 33, 34]}
|
|
cookieKey="test-controlled"
|
|
tabLabels={['T1', 'T2', 'T3']}
|
|
activeTab={0}
|
|
onActiveTabChange={vi.fn()}
|
|
/>
|
|
)
|
|
expect(screen.getByText('A')).toBeTruthy()
|
|
|
|
rerender(
|
|
<SplitPane
|
|
panes={[<div key="a">A</div>, <div key="b">B</div>, <div key="c">C</div>]}
|
|
defaultSplit={[33, 33, 34]}
|
|
cookieKey="test-controlled"
|
|
tabLabels={['T1', 'T2', 'T3']}
|
|
activeTab={2}
|
|
onActiveTabChange={vi.fn()}
|
|
/>
|
|
)
|
|
expect(screen.getByText('C')).toBeTruthy()
|
|
})
|
|
|
|
it('does not render dividers on mobile', () => {
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 600 })
|
|
window.dispatchEvent(new Event('resize'))
|
|
|
|
const { container } = render(
|
|
<SplitPane
|
|
panes={[<div key="a">A</div>, <div key="b">B</div>]}
|
|
defaultSplit={[50, 50]}
|
|
cookieKey="test-no-dividers"
|
|
/>
|
|
)
|
|
|
|
const dividers = container.querySelectorAll('.cursor-col-resize')
|
|
expect(dividers).toHaveLength(0)
|
|
})
|
|
})
|