settings-store.spec.ts 1.1 KB

12345678910111213141516171819202122232425262728
  1. /** Appearance row store: snapshot-mirror action and the revision guard. */
  2. import { describe, expect, it } from 'vitest'
  3. import { createAppearanceRowStore } from '../src/client/settings-store.ts'
  4. describe('createAppearanceRowStore', () => {
  5. it('init shape: system preference with revision at -1', () => {
  6. const store = createAppearanceRowStore().create()
  7. expect(store.getSnapshot()).toEqual({ preference: 'system', revision: -1 })
  8. })
  9. it('sync mirrors the preference and advances the revision', () => {
  10. const store = createAppearanceRowStore().create()
  11. store.actions.sync('dark', 0)
  12. expect(store.getSnapshot()).toEqual({ preference: 'dark', revision: 0 })
  13. store.actions.sync('light', 2)
  14. expect(store.getSnapshot().preference).toBe('light')
  15. expect(store.getSnapshot().revision).toBe(2)
  16. })
  17. it('revision guard drops stale and duplicate writes', () => {
  18. const store = createAppearanceRowStore().create()
  19. store.actions.sync('dark', 3)
  20. store.actions.sync('system', 2)
  21. store.actions.sync('system', 3)
  22. expect(store.getSnapshot().preference).toBe('dark')
  23. expect(store.getSnapshot().revision).toBe(3)
  24. })
  25. })