fa0f1bdcad
- Add RightClickRestorer page with active unlock trigger - Content script with dual-world strategy (isolated + main world) - Monkey patch preventDefault/stopPropagation via background executeScript - Overlay penetration for pointer-events blocking layers - Delegated main-world injection to avoid CSP restrictions - Async message handling for reliable state updates - i18n translations (zh/en) and unit tests
132 lines
4.7 KiB
TypeScript
132 lines
4.7 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
FEATURES,
|
|
getAllFeatureKeys,
|
|
getDefaultPageOrder,
|
|
getDefaultVisibleFeatureKeys,
|
|
getFeatureByKey,
|
|
} from '@/config/features';
|
|
|
|
describe('features', () => {
|
|
describe('FEATURES', () => {
|
|
it('should have 11 features defined', () => {
|
|
expect(FEATURES).toHaveLength(11);
|
|
});
|
|
|
|
it('should have all required properties for each feature', () => {
|
|
FEATURES.forEach((feature) => {
|
|
expect(feature).toHaveProperty('key');
|
|
expect(feature).toHaveProperty('labelKey');
|
|
expect(feature).toHaveProperty('descriptionKey');
|
|
expect(feature).toHaveProperty('defaultVisible');
|
|
expect(feature).toHaveProperty('components');
|
|
expect(typeof feature.key).toBe('string');
|
|
expect(typeof feature.labelKey).toBe('string');
|
|
expect(typeof feature.descriptionKey).toBe('string');
|
|
expect(typeof feature.defaultVisible).toBe('boolean');
|
|
expect(typeof feature.components).toBe('object');
|
|
expect(feature.components).toHaveProperty('popup');
|
|
expect(feature.components).toHaveProperty('sidepanel');
|
|
expect(feature.components).toHaveProperty('tab');
|
|
|
|
// Optional UI properties for non-hidden features
|
|
if (feature.key !== 'dashboard') {
|
|
expect(feature).toHaveProperty('icon');
|
|
expect(feature).toHaveProperty('themeColorKey');
|
|
expect(typeof feature.themeColorKey).toBe('string');
|
|
}
|
|
});
|
|
});
|
|
|
|
it('should have unique keys for each feature', () => {
|
|
const keys = FEATURES.map((f) => f.key);
|
|
const uniqueKeys = new Set(keys);
|
|
expect(uniqueKeys.size).toBe(keys.length);
|
|
});
|
|
});
|
|
|
|
describe('getFeatureByKey', () => {
|
|
it('should return dashboard feature', () => {
|
|
const feature = getFeatureByKey('dashboard');
|
|
expect(feature).toBeDefined();
|
|
expect(feature?.key).toBe('dashboard');
|
|
expect(feature?.labelKey).toBe('features:dashboard.title');
|
|
});
|
|
|
|
it('should return timestamp feature', () => {
|
|
const feature = getFeatureByKey('timestamp');
|
|
expect(feature).toBeDefined();
|
|
expect(feature?.key).toBe('timestamp');
|
|
expect(feature?.labelKey).toBe('features:timestamp.title');
|
|
expect(feature?.themeColorKey).toBeDefined();
|
|
});
|
|
|
|
it('should return storageCleaner feature', () => {
|
|
const feature = getFeatureByKey('storageCleaner');
|
|
expect(feature).toBeDefined();
|
|
expect(feature?.key).toBe('storageCleaner');
|
|
expect(feature?.labelKey).toBe('features:storageCleaner.title');
|
|
});
|
|
|
|
it('should return undefined for invalid key', () => {
|
|
const feature = getFeatureByKey('invalid' as any);
|
|
expect(feature).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('getDefaultVisibleFeatureKeys', () => {
|
|
it('should return only visible features', () => {
|
|
const visibleKeys = getDefaultVisibleFeatureKeys();
|
|
visibleKeys.forEach((key) => {
|
|
const feature = getFeatureByKey(key);
|
|
expect(feature?.defaultVisible).toBe(true);
|
|
});
|
|
});
|
|
|
|
it('should include dashboard, timestamp, storageCleaner, qrCode', () => {
|
|
const visibleKeys = getDefaultVisibleFeatureKeys();
|
|
expect(visibleKeys).toContain('dashboard');
|
|
expect(visibleKeys).toContain('timestamp');
|
|
expect(visibleKeys).toContain('storageCleaner');
|
|
expect(visibleKeys).toContain('qrCode');
|
|
});
|
|
});
|
|
|
|
describe('getAllFeatureKeys', () => {
|
|
it('should return all feature keys', () => {
|
|
const allKeys = getAllFeatureKeys();
|
|
expect(allKeys).toHaveLength(11);
|
|
expect(allKeys).toContain('dashboard');
|
|
expect(allKeys).toContain('timestamp');
|
|
expect(allKeys).toContain('storageCleaner');
|
|
expect(allKeys).toContain('qrCode');
|
|
expect(allKeys).toContain('textStatistics');
|
|
expect(allKeys).toContain('jwt');
|
|
expect(allKeys).toContain('jsonDiff');
|
|
expect(allKeys).toContain('base64Converter');
|
|
expect(allKeys).toContain('markdownToHtml');
|
|
expect(allKeys).toContain('htmlToMarkdown');
|
|
expect(allKeys).toContain('rightClickRestorer');
|
|
});
|
|
});
|
|
|
|
describe('getDefaultPageOrder', () => {
|
|
it('should exclude dashboard from page order', () => {
|
|
const pageOrder = getDefaultPageOrder();
|
|
expect(pageOrder).not.toContain('dashboard');
|
|
});
|
|
|
|
it('should include timestamp, storageCleaner, qrCode in page order', () => {
|
|
const pageOrder = getDefaultPageOrder();
|
|
expect(pageOrder).toContain('timestamp');
|
|
expect(pageOrder).toContain('storageCleaner');
|
|
expect(pageOrder).toContain('qrCode');
|
|
});
|
|
|
|
it('should have 10 items in page order', () => {
|
|
const pageOrder = getDefaultPageOrder();
|
|
expect(pageOrder).toHaveLength(10);
|
|
});
|
|
});
|
|
});
|