import { describe, expect, it } from 'vitest' import { ref } from 'vue' import { useSelectionLimit } from '../../composables/useSelectionLimit' describe('useSelectionLimit', () => { it('tracks unlimited selections', () => { const count = ref(4) const limit = useSelectionLimit({ count }) expect(limit.isLimited.value).toBe(false) expect(limit.canAddMore.value).toBe(true) expect(limit.remaining.value).toBeUndefined() expect(limit.canAdd(100)).toBe(true) }) it('tracks remaining capacity from reactive count and max values', () => { const count = ref(1) const max = ref(3) const limit = useSelectionLimit({ count, max }) expect(limit.isLimited.value).toBe(true) expect(limit.remaining.value).toBe(2) expect(limit.canAdd(2)).toBe(true) expect(limit.canAdd(3)).toBe(false) count.value = 3 expect(limit.canAddMore.value).toBe(false) expect(limit.isAtLimit.value).toBe(true) max.value = undefined expect(limit.isLimited.value).toBe(false) expect(limit.canAdd(3)).toBe(true) }) it('can evaluate a candidate count without mutating the current count', () => { const limit = useSelectionLimit({ count: 1, max: 3 }) expect(limit.canAdd(1, 2)).toBe(true) expect(limit.canAdd(1, 3)).toBe(false) }) })