Files
baserow/web-frontend/test/unit/database/utils/rowEditModalSidebar.spec.js
alamin-br 633f1c4b7d feat: remember last-opened row sidebar tab (comments/history) (#5687)
* 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
2026-07-09 15:56:41 +02:00

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()
})
})