插件
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { loadConfig, saveConfig } from '../push/config.js';
|
||||
|
||||
describe('config', () => {
|
||||
beforeEach(() => {
|
||||
// 内存版 chrome.storage.local,验证 load/save 往返(不依赖真实 chrome)
|
||||
const store = {};
|
||||
globalThis.chrome = {
|
||||
storage: {
|
||||
local: {
|
||||
get: vi.fn(async key => {
|
||||
const k = typeof key === 'string' ? key : key[0];
|
||||
return k in store ? { [k]: store[k] } : {};
|
||||
}),
|
||||
set: vi.fn(async obj => { Object.assign(store, obj); }),
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('loadConfig returns disabled default when unset', async () => {
|
||||
const cfg = await loadConfig();
|
||||
expect(cfg.enabled).toBe(false);
|
||||
expect(cfg.serverUrl).toBe('');
|
||||
});
|
||||
|
||||
it('saveConfig then loadConfig round-trips', async () => {
|
||||
await saveConfig({ enabled: true, serverUrl: 'http://x', token: 't' });
|
||||
const cfg = await loadConfig();
|
||||
expect(cfg.enabled).toBe(true);
|
||||
expect(cfg.serverUrl).toBe('http://x');
|
||||
expect(cfg.token).toBe('t');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user