|
| 1 | +import { afterEach, beforeEach, describe, expect, it } from 'vitest' |
| 2 | + |
| 3 | +describe('useSettings - keyboardShortcuts', () => { |
| 4 | + beforeEach(() => { |
| 5 | + localStorage.clear() |
| 6 | + }) |
| 7 | + |
| 8 | + afterEach(() => { |
| 9 | + // Reset the singleton so the next test gets a fresh instance |
| 10 | + localStorage.clear() |
| 11 | + }) |
| 12 | + |
| 13 | + describe('default value', () => { |
| 14 | + it('should default keyboardShortcuts to true', () => { |
| 15 | + const { settings } = useSettings() |
| 16 | + expect(settings.value.keyboardShortcuts).toBe(true) |
| 17 | + }) |
| 18 | + }) |
| 19 | + |
| 20 | + describe('useKeyboardShortcuts composable', () => { |
| 21 | + it('should return true by default', () => { |
| 22 | + const enabled = useKeyboardShortcuts() |
| 23 | + expect(enabled.value).toBe(true) |
| 24 | + }) |
| 25 | + |
| 26 | + it('should reflect changes made via settings', () => { |
| 27 | + const { settings } = useSettings() |
| 28 | + const enabled = useKeyboardShortcuts() |
| 29 | + |
| 30 | + settings.value.keyboardShortcuts = false |
| 31 | + expect(enabled.value).toBe(false) |
| 32 | + |
| 33 | + settings.value.keyboardShortcuts = true |
| 34 | + expect(enabled.value).toBe(true) |
| 35 | + }) |
| 36 | + |
| 37 | + it('should be reactive', () => { |
| 38 | + const { settings } = useSettings() |
| 39 | + const enabled = useKeyboardShortcuts() |
| 40 | + |
| 41 | + expect(enabled.value).toBe(true) |
| 42 | + |
| 43 | + settings.value.keyboardShortcuts = false |
| 44 | + expect(enabled.value).toBe(false) |
| 45 | + }) |
| 46 | + }) |
| 47 | + |
| 48 | + describe('persistence', () => { |
| 49 | + it('should persist keyboardShortcuts=false to localStorage', () => { |
| 50 | + const { settings } = useSettings() |
| 51 | + settings.value.keyboardShortcuts = false |
| 52 | + |
| 53 | + const stored = JSON.parse(localStorage.getItem('npmx-settings') ?? '{}') |
| 54 | + expect(stored.keyboardShortcuts).toBe(false) |
| 55 | + }) |
| 56 | + |
| 57 | + it('should persist keyboardShortcuts=true to localStorage', () => { |
| 58 | + const { settings } = useSettings() |
| 59 | + settings.value.keyboardShortcuts = false |
| 60 | + settings.value.keyboardShortcuts = true |
| 61 | + |
| 62 | + const stored = JSON.parse(localStorage.getItem('npmx-settings') ?? '{}') |
| 63 | + expect(stored.keyboardShortcuts).toBe(true) |
| 64 | + }) |
| 65 | + }) |
| 66 | +}) |
0 commit comments