mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
feat: add survey registry for feature survey configurations
This commit is contained in:
50
src/platform/surveys/surveyRegistry.test.ts
Normal file
50
src/platform/surveys/surveyRegistry.test.ts
Normal file
@@ -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)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
29
src/platform/surveys/surveyRegistry.ts
Normal file
29
src/platform/surveys/surveyRegistry.ts
Normal file
@@ -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<string, FeatureSurveyConfig> = {
|
||||
// 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)
|
||||
}
|
||||
Reference in New Issue
Block a user