import { BaseExtension } from './extension' import { SettingComponentProps } from '../types' jest.mock('./core') jest.mock('./fs') class TestBaseExtension extends BaseExtension { onLoad(): void {} onUnload(): void {} } describe('BaseExtension', () => { let baseExtension: TestBaseExtension beforeEach(() => { baseExtension = new TestBaseExtension('https://example.com', 'TestExtension') }) afterEach(() => { jest.resetAllMocks() }) it('should have the correct properties', () => { expect(baseExtension.name).toBe('TestExtension') expect(baseExtension.productName).toBeUndefined() expect(baseExtension.url).toBe('https://example.com') expect(baseExtension.active).toBeUndefined() expect(baseExtension.description).toBeUndefined() expect(baseExtension.version).toBeUndefined() }) it('should return undefined for type()', () => { expect(baseExtension.type()).toBeUndefined() }) it('should have abstract methods onLoad() and onUnload()', () => { expect(baseExtension.onLoad).toBeDefined() expect(baseExtension.onUnload).toBeDefined() }) it('should install the extension', async () => { await baseExtension.install() // Add your assertions here }) }) describe('BaseExtension', () => { class TestBaseExtension extends BaseExtension { onLoad(): void {} onUnload(): void {} } let baseExtension: TestBaseExtension beforeEach(() => { baseExtension = new TestBaseExtension('https://example.com', 'TestExtension') }) afterEach(() => { jest.resetAllMocks() }) it('should have the correct properties', () => { expect(baseExtension.name).toBe('TestExtension') expect(baseExtension.productName).toBeUndefined() expect(baseExtension.url).toBe('https://example.com') expect(baseExtension.active).toBeUndefined() expect(baseExtension.description).toBeUndefined() expect(baseExtension.version).toBeUndefined() }) it('should return undefined for type()', () => { expect(baseExtension.type()).toBeUndefined() }) it('should have abstract methods onLoad() and onUnload()', () => { expect(baseExtension.onLoad).toBeDefined() expect(baseExtension.onUnload).toBeDefined() }) it('should install the extension', async () => { await baseExtension.install() // Add your assertions here }) it('should register settings', async () => { const settings: SettingComponentProps[] = [ { key: 'setting1', controllerProps: { value: 'value1' } } as any, { key: 'setting2', controllerProps: { value: 'value2' } } as any, ] const localStorageMock = (() => { let store: Record = {} return { getItem: (key: string) => store[key] || null, setItem: (key: string, value: string) => { store[key] = value }, removeItem: (key: string) => { delete store[key] }, clear: () => { store = {} }, } })() Object.defineProperty(global, 'localStorage', { value: localStorageMock, }) const mock = jest.spyOn(localStorage, 'setItem') await baseExtension.registerSettings(settings) expect(mock).toHaveBeenCalledWith( 'TestExtension', JSON.stringify(settings) ) }) it('should get setting with default value', async () => { const settings: SettingComponentProps[] = [ { key: 'setting1', controllerProps: { value: 'value1' } } as any, ] jest.spyOn(baseExtension, 'getSettings').mockResolvedValue(settings) const value = await baseExtension.getSetting('setting1', 'defaultValue') expect(value).toBe('value1') const defaultValue = await baseExtension.getSetting('setting2', 'defaultValue') expect(defaultValue).toBe('defaultValue') }) it('should update settings', async () => { const settings: SettingComponentProps[] = [ { key: 'setting1', controllerProps: { value: 'value1' } } as any, ] jest.spyOn(baseExtension, 'getSettings').mockResolvedValue(settings) const mockSetItem = jest.spyOn(localStorage, 'setItem') await baseExtension.updateSettings([ { key: 'setting1', controllerProps: { value: 'newValue' } } as any, ]) expect(mockSetItem).toHaveBeenCalledWith( 'TestExtension', JSON.stringify([{ key: 'setting1', controllerProps: { value: 'newValue' } }]) ) }) })