53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
/**
|
|
* regionStore (src/store/regionStore.ts).
|
|
*
|
|
* The browsing region is deliberately NOT persisted — it is re-derived on every
|
|
* launch — so this pins the in-memory contract and the generation bump.
|
|
*/
|
|
|
|
import { useRegionStore } from '@/src/store/regionStore'
|
|
|
|
const REGION = { id: 2, name: 'Region B', description: null, effectiveBoundId: 7 }
|
|
|
|
describe('regionStore', () => {
|
|
beforeEach(() => {
|
|
useRegionStore.setState({
|
|
selectedRegionId: null,
|
|
selectedRegion: null,
|
|
selectedBoundId: null,
|
|
regionGeneration: 0,
|
|
})
|
|
})
|
|
|
|
it('stores the selected region and bound and bumps the generation', () => {
|
|
useRegionStore.getState().setRegion(REGION, 7)
|
|
|
|
const state = useRegionStore.getState()
|
|
expect(state.selectedRegionId).toBe(2)
|
|
expect(state.selectedRegion).toMatchObject({ id: 2, name: 'Region B' })
|
|
expect(state.selectedBoundId).toBe(7)
|
|
expect(state.regionGeneration).toBe(1)
|
|
})
|
|
|
|
it('does not bump the generation for an identical selection', () => {
|
|
useRegionStore.getState().setRegion(REGION, 7)
|
|
useRegionStore.getState().setRegion(REGION, 7)
|
|
|
|
expect(useRegionStore.getState().regionGeneration).toBe(1)
|
|
})
|
|
|
|
it('clears the region and bumps the generation', () => {
|
|
useRegionStore.getState().setRegion(REGION, 7)
|
|
useRegionStore.getState().clearRegion()
|
|
|
|
const state = useRegionStore.getState()
|
|
expect(state.selectedRegionId).toBeNull()
|
|
expect(state.selectedRegion).toBeNull()
|
|
expect(state.selectedBoundId).toBeNull()
|
|
expect(state.regionGeneration).toBe(2)
|
|
})
|
|
|
|
it('is memory-only (no persist middleware)', () => {
|
|
expect((useRegionStore as unknown as { persist?: unknown }).persist).toBeUndefined()
|
|
})
|
|
})
|