feat(PBI-76): migrate cookie-based prefs to user-settings (Phase 2) (#189)
* 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>
This commit is contained in:
parent
852945efa3
commit
bf7162a5fc
17 changed files with 298 additions and 116 deletions
|
|
@ -2,15 +2,25 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|||
|
||||
import {
|
||||
buildMigrationPatch,
|
||||
clearLegacyLocalStorage,
|
||||
clearLegacyStorage,
|
||||
} from '@/lib/user-settings-migration'
|
||||
|
||||
function clearAllCookies() {
|
||||
for (const part of document.cookie.split(';')) {
|
||||
const eq = part.indexOf('=')
|
||||
const name = (eq < 0 ? part : part.slice(0, eq)).trim()
|
||||
if (name) document.cookie = `${name}=; max-age=0; path=/`
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
clearAllCookies()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
localStorage.clear()
|
||||
clearAllCookies()
|
||||
})
|
||||
|
||||
describe('buildMigrationPatch', () => {
|
||||
|
|
@ -21,11 +31,42 @@ describe('buildMigrationPatch', () => {
|
|||
expect(result.legacyKeys).toEqual([])
|
||||
})
|
||||
|
||||
it('skips after marker is set', () => {
|
||||
it('skips after marker is set to current version', () => {
|
||||
localStorage.setItem('scrum4me:sprint_pb_filter_status', 'all')
|
||||
localStorage.setItem('scrum4me:settings_migrated', 'v2')
|
||||
const result = buildMigrationPatch()
|
||||
expect(result.hasData).toBe(false)
|
||||
})
|
||||
|
||||
it('still runs when only the v1 marker is set (re-migration)', () => {
|
||||
localStorage.setItem('scrum4me:sprint_pb_filter_status', 'all')
|
||||
localStorage.setItem('scrum4me:settings_migrated', 'v1')
|
||||
const result = buildMigrationPatch()
|
||||
expect(result.hasData).toBe(false)
|
||||
expect(result.hasData).toBe(true)
|
||||
})
|
||||
|
||||
it('extracts split-pane cookies into layout', () => {
|
||||
document.cookie = `sp:backlog-p1=${encodeURIComponent(JSON.stringify([25, 35, 40]))}; path=/`
|
||||
const result = buildMigrationPatch()
|
||||
expect(result.patch.layout?.splitPanePositions).toEqual({ 'backlog-p1': [25, 35, 40] })
|
||||
expect(result.legacyCookies).toContain('sp:backlog-p1')
|
||||
})
|
||||
|
||||
it('ignores split-pane cookies that do not sum to 100', () => {
|
||||
document.cookie = `sp:bad=${encodeURIComponent(JSON.stringify([10, 20]))}; path=/`
|
||||
const result = buildMigrationPatch()
|
||||
expect(result.patch.layout).toBeUndefined()
|
||||
})
|
||||
|
||||
it('extracts active-sprint cookies into layout.activeSprints', () => {
|
||||
document.cookie = `active_sprint_prod-1=sprint-abc; path=/`
|
||||
document.cookie = `active_sprint_prod-2=sprint-xyz; path=/`
|
||||
const result = buildMigrationPatch()
|
||||
expect(result.patch.layout?.activeSprints).toEqual({
|
||||
'prod-1': 'sprint-abc',
|
||||
'prod-2': 'sprint-xyz',
|
||||
})
|
||||
expect(result.legacyCookies).toContain('active_sprint_prod-1')
|
||||
})
|
||||
|
||||
it('extracts sprint backlog prefs into nested patch', () => {
|
||||
|
|
@ -87,20 +128,20 @@ describe('buildMigrationPatch', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('clearLegacyLocalStorage', () => {
|
||||
it('removes given keys and sets the marker', () => {
|
||||
describe('clearLegacyStorage', () => {
|
||||
it('removes given keys and cookies and sets the v2 marker', () => {
|
||||
localStorage.setItem('scrum4me:sprint_pb_sort', 'code')
|
||||
localStorage.setItem('scrum4me:pbi_sort', 'priority')
|
||||
document.cookie = 'sp:x=foo; path=/'
|
||||
|
||||
clearLegacyLocalStorage(['scrum4me:sprint_pb_sort', 'scrum4me:pbi_sort'])
|
||||
clearLegacyStorage(['scrum4me:sprint_pb_sort'], ['sp:x'])
|
||||
|
||||
expect(localStorage.getItem('scrum4me:sprint_pb_sort')).toBeNull()
|
||||
expect(localStorage.getItem('scrum4me:pbi_sort')).toBeNull()
|
||||
expect(localStorage.getItem('scrum4me:settings_migrated')).toBe('v1')
|
||||
expect(document.cookie).not.toContain('sp:x=foo')
|
||||
expect(localStorage.getItem('scrum4me:settings_migrated')).toBe('v2')
|
||||
})
|
||||
|
||||
it('sets marker even with empty keys list (no-op migration)', () => {
|
||||
clearLegacyLocalStorage([])
|
||||
expect(localStorage.getItem('scrum4me:settings_migrated')).toBe('v1')
|
||||
it('sets marker even with empty lists (no-op migration)', () => {
|
||||
clearLegacyStorage([], [])
|
||||
expect(localStorage.getItem('scrum4me:settings_migrated')).toBe('v2')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -109,7 +109,17 @@ describe('UserSettingsSchema', () => {
|
|||
jobsColumns: { 'queue:active': { kinds: ['TASK_IMPLEMENTATION'], statuses: [] } },
|
||||
},
|
||||
devTools: { debugMode: true },
|
||||
layout: {
|
||||
splitPanePositions: { 'backlog-pid': [25, 35, 40] },
|
||||
activeSprints: { 'product-1': 'sprint-1' },
|
||||
},
|
||||
})
|
||||
expect(result.success).toBe(true)
|
||||
})
|
||||
|
||||
it('accepts layout-only settings', () => {
|
||||
expect(UserSettingsSchema.safeParse({
|
||||
layout: { splitPanePositions: { x: [50, 50] }, activeSprints: { p: 's' } },
|
||||
}).success).toBe(true)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue