mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
* feat: add helper to persist row edit modal sidebar tab * test: spy on real localStorage so error-path tests exercise the catch * feat: remember last-opened row edit modal sidebar tab (#2532) * fix: persist the genuinely last-opened row sidebar tab * chore: add changelog for remembered row sidebar tab * refactor: tidy sidebar tab snapshot and assert no write on default mount * refactor: address PR review — explicit no-op catch, shared localStorage test mock * refactor: harden localStorage test mock with null-prototype store * fix: keep sidebar tab preference when props deactivate it on a reused instance * refactor: simplify sidebar tab persistence to a single reactive property
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
import {
|
|
ROW_EDIT_MODAL_SIDEBAR_TAB_KEY,
|
|
getRowEditModalSidebarTab,
|
|
setRowEditModalSidebarTab,
|
|
} from '@baserow/modules/database/utils/rowEditModalSidebar'
|
|
import { installLocalStorageMock } from '@baserow/test/helpers/localStorage'
|
|
|
|
describe('rowEditModalSidebar utils', () => {
|
|
beforeAll(() => {
|
|
installLocalStorageMock()
|
|
})
|
|
|
|
afterEach(() => {
|
|
localStorage.clear()
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
test('returns null when nothing is stored', () => {
|
|
expect(getRowEditModalSidebarTab()).toBe(null)
|
|
})
|
|
|
|
test('round-trips a stored tab type', () => {
|
|
setRowEditModalSidebarTab('history')
|
|
expect(localStorage.getItem(ROW_EDIT_MODAL_SIDEBAR_TAB_KEY)).toBe('history')
|
|
expect(getRowEditModalSidebarTab()).toBe('history')
|
|
})
|
|
|
|
test('get returns null when localStorage throws', () => {
|
|
vi.spyOn(localStorage, 'getItem').mockImplementation(() => {
|
|
throw new Error('unavailable')
|
|
})
|
|
expect(getRowEditModalSidebarTab()).toBe(null)
|
|
})
|
|
|
|
test('set does not throw when localStorage throws', () => {
|
|
vi.spyOn(localStorage, 'setItem').mockImplementation(() => {
|
|
throw new Error('unavailable')
|
|
})
|
|
expect(() => setRowEditModalSidebarTab('comments')).not.toThrow()
|
|
})
|
|
})
|