Added tests
This commit is contained in:
parent
742ba505c6
commit
dd9c95f72d
1180
package-lock.json
generated
1180
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -6,12 +6,20 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview --host 0.0.0.0"
|
"preview": "vite preview --host 0.0.0.0",
|
||||||
|
"test": "vitest",
|
||||||
|
"test:run": "vitest run",
|
||||||
|
"test:ui": "vitest --ui"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/vite-plugin-svelte": "^7.1.2",
|
"@sveltejs/vite-plugin-svelte": "^7.1.2",
|
||||||
|
"@testing-library/svelte": "^5.3.1",
|
||||||
|
"@vitest/ui": "^4.1.6",
|
||||||
|
"fake-indexeddb": "^6.2.5",
|
||||||
|
"jsdom": "^29.1.1",
|
||||||
"svelte": "^5.55.5",
|
"svelte": "^5.55.5",
|
||||||
"vite": "^8.0.12"
|
"vite": "^8.0.12",
|
||||||
|
"vitest": "^4.1.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"idb": "^8.0.3"
|
"idb": "^8.0.3"
|
||||||
|
|||||||
54
tests/lib/stores/app.test.js
Normal file
54
tests/lib/stores/app.test.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { describe, it, expect, beforeEach } from 'vitest'
|
||||||
|
import { app } from '../../../src/lib/stores/app.svelte.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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
70
tests/lib/stores/search.test.js
Normal file
70
tests/lib/stores/search.test.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
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')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
14
tests/setup.js
Normal file
14
tests/setup.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import 'fake-indexeddb/auto'
|
||||||
|
|
||||||
|
// jsdom does not provide crypto.subtle — polyfill it with the real Web Crypto API
|
||||||
|
// (available in Node 19+ as `node:crypto.webcrypto`)
|
||||||
|
if (typeof globalThis.crypto === 'undefined' || !globalThis.crypto.subtle) {
|
||||||
|
const { webcrypto } = await import('node:crypto')
|
||||||
|
globalThis.crypto = webcrypto
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mock window/document APIs used by security store
|
||||||
|
Object.defineProperty(globalThis, 'navigator', {
|
||||||
|
value: {},
|
||||||
|
writable: true,
|
||||||
|
})
|
||||||
@ -6,5 +6,11 @@ export default defineConfig({
|
|||||||
plugins: [svelte()],
|
plugins: [svelte()],
|
||||||
preview: {
|
preview: {
|
||||||
allowedHosts: ["dev.thecookiejar.me"]
|
allowedHosts: ["dev.thecookiejar.me"]
|
||||||
}
|
},
|
||||||
|
test: {
|
||||||
|
environment: 'jsdom',
|
||||||
|
globals: true,
|
||||||
|
setupFiles: ['./tests/setup.js'],
|
||||||
|
include: ['src/**/*.test.js', 'tests/**/*.test.js'],
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user