Files
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

29 lines
877 B
JavaScript

/**
* The Nuxt/happy-dom vitest environment does not provide localStorage. Install
* a minimal in-memory implementation on the global scope for tests that need it.
*/
export function installLocalStorageMock() {
if (globalThis.localStorage) {
return
}
// Null-prototype store so keys like `toString` or `__proto__` behave like
// real localStorage entries instead of hitting inherited properties.
const store = Object.create(null)
globalThis.localStorage = {
getItem: (key) => (key in store ? store[key] : null),
setItem: (key, value) => {
store[key] = String(value)
},
removeItem: (key) => {
delete store[key]
},
clear: () => {
Object.keys(store).forEach((key) => delete store[key])
},
key: (index) => Object.keys(store)[index] ?? null,
get length() {
return Object.keys(store).length
},
}
}