diff --git a/src/platform/surveys/surveyRegistry.test.ts b/src/platform/surveys/surveyRegistry.test.ts new file mode 100644 index 000000000..054178bc3 --- /dev/null +++ b/src/platform/surveys/surveyRegistry.test.ts @@ -0,0 +1,50 @@ +import { describe, expect, it } from 'vitest' + +import { + FEATURE_SURVEYS, + getEnabledSurveys, + getSurveyConfig +} from './surveyRegistry' + +describe('surveyRegistry', () => { + describe('FEATURE_SURVEYS', () => { + it('is a valid record of survey configs', () => { + expect(typeof FEATURE_SURVEYS).toBe('object') + expect(FEATURE_SURVEYS).not.toBeNull() + }) + + it('all configs have required fields', () => { + for (const [key, config] of Object.entries(FEATURE_SURVEYS)) { + expect(config.featureId).toBe(key) + expect(typeof config.typeformId).toBe('string') + expect(config.typeformId.length).toBeGreaterThan(0) + } + }) + }) + + describe('getSurveyConfig', () => { + it('returns undefined for unknown feature', () => { + expect(getSurveyConfig('nonexistent-feature')).toBeUndefined() + }) + + it('returns config for known feature', () => { + const testFeatureId = Object.keys(FEATURE_SURVEYS)[0] + if (testFeatureId) { + const config = getSurveyConfig(testFeatureId) + expect(config).toBeDefined() + expect(config?.featureId).toBe(testFeatureId) + } + }) + }) + + describe('getEnabledSurveys', () => { + it('returns array of enabled surveys', () => { + const enabled = getEnabledSurveys() + expect(Array.isArray(enabled)).toBe(true) + + for (const config of enabled) { + expect(config.enabled).not.toBe(false) + } + }) + }) +}) diff --git a/src/platform/surveys/surveyRegistry.ts b/src/platform/surveys/surveyRegistry.ts new file mode 100644 index 000000000..6a87ea2e5 --- /dev/null +++ b/src/platform/surveys/surveyRegistry.ts @@ -0,0 +1,29 @@ +import type { FeatureSurveyConfig } from './useSurveyEligibility' + +/** + * Registry of all feature surveys. + * Add new surveys here when targeting specific features for feedback. + */ +export const FEATURE_SURVEYS: Record = { + // Example survey - replace with actual feature surveys + // 'simple-mode': { + // featureId: 'simple-mode', + // typeformId: 'abc123', + // triggerThreshold: 3, + // delayMs: 5000, + // enabled: true + // } +} + +/** @public */ +export type FeatureId = keyof typeof FEATURE_SURVEYS + +export function getSurveyConfig( + featureId: string +): FeatureSurveyConfig | undefined { + return FEATURE_SURVEYS[featureId] +} + +export function getEnabledSurveys(): FeatureSurveyConfig[] { + return Object.values(FEATURE_SURVEYS).filter((config) => config.enabled) +}