password_manager/tests/lib/stores/search.test.js
2026-05-11 23:35:52 +00:00

71 lines
1.8 KiB
JavaScript

import { describe, it, expect, beforeEach } from 'vitest'
import { search } from '../../../src/lib/stores/search.svelte.js'
describe('SearchStore', () => {
beforeEach(() => {
search.clear()
})
describe('initial state', () => {
it('should have empty query', () => {
expect(search.query).toBe('')
})
it('should have activeGroupId set to "all"', () => {
expect(search.activeGroupId).toBe('all')
})
})
describe('query', () => {
it('should update query', () => {
search.query = 'test'
expect(search.query).toBe('test')
})
it('should handle unicode query', () => {
search.query = 'тест'
expect(search.query).toBe('тест')
})
})
describe('activeGroupId', () => {
it('should update activeGroupId', () => {
search.activeGroupId = 'group-123'
expect(search.activeGroupId).toBe('group-123')
})
it('should allow setting back to "all"', () => {
search.activeGroupId = 'group-123'
search.activeGroupId = 'all'
expect(search.activeGroupId).toBe('all')
})
it('should allow empty string for ungrouped', () => {
search.activeGroupId = ''
expect(search.activeGroupId).toBe('')
})
})
describe('clear()', () => {
it('should reset query to empty string', () => {
search.query = 'some search'
search.clear()
expect(search.query).toBe('')
})
it('should reset activeGroupId to "all"', () => {
search.activeGroupId = 'group-123'
search.clear()
expect(search.activeGroupId).toBe('all')
})
it('should reset both fields simultaneously', () => {
search.query = 'some search'
search.activeGroupId = 'group-123'
search.clear()
expect(search.query).toBe('')
expect(search.activeGroupId).toBe('all')
})
})
})