优化
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import {
|
||||
preferenceStorageKey,
|
||||
readLayoutPreference,
|
||||
reconcileOrder,
|
||||
removeLayoutPreference,
|
||||
writeLayoutPreference,
|
||||
} from './uiLayoutPreference'
|
||||
|
||||
describe('UI layout preferences', () => {
|
||||
beforeEach(() => localStorage.clear())
|
||||
|
||||
it('reconciles stored order with the current stable keys', () => {
|
||||
expect(reconcileOrder(['actions', 'name', 'status', 'createdAt'], ['status', 'removed', 'name', 'status']))
|
||||
.toEqual(['status', 'name', 'actions', 'createdAt'])
|
||||
})
|
||||
|
||||
it('falls back safely when cached JSON is invalid', () => {
|
||||
localStorage.setItem(preferenceStorageKey('table', 'user-1', 'customers'), '{broken')
|
||||
expect(readLayoutPreference('table', 'user-1', 'customers', ['actions', 'name'], ['name']))
|
||||
.toEqual({ version: 1, order: ['actions', 'name'], hidden: ['name'] })
|
||||
})
|
||||
|
||||
it('keeps preferences isolated by user and removes them on reset', () => {
|
||||
writeLayoutPreference('query', 'user-1', 'orders', { version: 1, order: ['status', 'keyword'], hidden: [] })
|
||||
expect(readLayoutPreference('query', 'user-1', 'orders', ['keyword', 'status']).order).toEqual(['status', 'keyword'])
|
||||
expect(readLayoutPreference('query', 'user-2', 'orders', ['keyword', 'status']).order).toEqual(['keyword', 'status'])
|
||||
|
||||
removeLayoutPreference('query', 'user-1', 'orders')
|
||||
expect(readLayoutPreference('query', 'user-1', 'orders', ['keyword', 'status']).order).toEqual(['keyword', 'status'])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user