55 lines
1.4 KiB
JavaScript

import { describe, it, expect, beforeEach } from 'vitest'
import { app } from '../../../src/lib/stores/app.js'
describe('AppStore', () => {
beforeEach(() => {
// Reset state before each test
app.isUnlocked = false
app.encryptionKey = null
app.salt = null
})
describe('initial state', () => {
it('should start locked', () => {
expect(app.isUnlocked).toBe(false)
})
it('should have no encryption key', () => {
expect(app.encryptionKey).toBe(null)
})
it('should have no salt', () => {
expect(app.salt).toBe(null)
})
})
describe('lockVault()', () => {
it('should clear the encryption key', () => {
app.encryptionKey = { mock: 'key' }
app.lockVault()
expect(app.encryptionKey).toBe(null)
})
it('should set isUnlocked to false', () => {
app.isUnlocked = true
app.lockVault()
expect(app.isUnlocked).toBe(false)
})
})
describe('unlock flow', () => {
it('should allow setting encryption key and unlocked state', () => {
app.encryptionKey = { mock: 'key' }
app.isUnlocked = true
expect(app.isUnlocked).toBe(true)
expect(app.encryptionKey).toEqual({ mock: 'key' })
})
it('should allow setting salt', () => {
const salt = new Uint8Array([1, 2, 3, 4])
app.salt = salt
expect(app.salt).toEqual(salt)
})
})
})