string-wrapping-store.client.spec.ts 854 B

1234567891011121314151617181920212223242526
  1. // @vitest-environment jsdom
  2. import { afterEach, beforeEach, expect, it } from 'vitest'
  3. import { createTrajectoryStringWrappingStore } from '../src/client/string-wrapping-store.ts'
  4. const key = 'dsh.trajectory.jsonStringWrapping'
  5. let original: string | null
  6. beforeEach(() => {
  7. original = localStorage.getItem(key)
  8. localStorage.removeItem(key)
  9. })
  10. afterEach(() => {
  11. if (original === null) localStorage.removeItem(key)
  12. else localStorage.setItem(key, original)
  13. })
  14. it('restores the last wrapping choice when the view is recreated', () => {
  15. const first = createTrajectoryStringWrappingStore()
  16. expect(first.getSnapshot()).toBe(false)
  17. first.set(true)
  18. const second = createTrajectoryStringWrappingStore()
  19. expect(second.getSnapshot()).toBe(true)
  20. second.set(false)
  21. expect(createTrajectoryStringWrappingStore().getSnapshot()).toBe(false)
  22. })