AIstudioProxyAPI / static /frontend /src /contexts /SettingsContext.test.ts
peijun1's picture
Deploy AI Studio Proxy API to Hugging Face Spaces
a5784e9
Raw
History Blame Contribute Delete
1.48 kB
/**
* Settings Schema Tests
*/
import { describe, it, expect, beforeEach } from 'vitest';
// Schema version for reference
const SCHEMA_VERSION = 2;
describe('Settings Schema', () => {
beforeEach(() => {
localStorage.clear();
});
it('should have version 2 as current schema', () => {
expect(SCHEMA_VERSION).toBe(2);
});
describe('Storage format', () => {
it('stores settings with _version field', () => {
const mockSettings = {
_version: SCHEMA_VERSION,
temperature: 0.8,
maxOutputTokens: 4096,
topP: 0.9,
enableGoogleSearch: true,
};
localStorage.setItem('modelSettings', JSON.stringify(mockSettings));
const stored = JSON.parse(localStorage.getItem('modelSettings') || '{}');
expect(stored._version).toBe(2);
expect(stored.temperature).toBe(0.8);
});
});
describe('Migration', () => {
it('v1 settings (no version) should be migrated', () => {
// v1 format: no _version field
const v1Settings = {
temperature: 0.7,
maxOutputTokens: 2048,
};
localStorage.setItem('modelSettings', JSON.stringify(v1Settings));
const stored = JSON.parse(localStorage.getItem('modelSettings') || '{}');
// Migration logic would add version
expect(stored._version).toBeUndefined(); // Before migration
// After loading through SettingsContext, version would be added
});
});
});