import { describe, expect, it } from 'vitest' import { getCompletedFeatureTipIds, getOrderedUnseenFeatureTips, normalizeFeatureTipIds, type FeatureTipId } from './feature-tips' describe('feature tips', () => { it('orders new unseen tips before older unseen tips', () => { const tips = getOrderedUnseenFeatureTips({ seenTipIds: new Set() }) expect(tips.map((tip) => tip.id)).toEqual([ 'native-chat-upgrade', 'agent-session-search', 'orca-cli', 'cmd-j-palette', 'voice-dictation' ]) }) it('treats the native chat upgrade tip as done for every profile outside its audience', () => { const base = { cliInstalled: true, voiceDictationEnabled: true, sessionSearchTipCompleted: true } expect( getCompletedFeatureTipIds({ ...base, inNativeChatUpgradeTipAudience: false }).has( 'native-chat-upgrade' ) ).toBe(true) expect( getCompletedFeatureTipIds({ ...base, inNativeChatUpgradeTipAudience: true }).has( 'native-chat-upgrade' ) ).toBe(false) }) it('skips tips the user has already seen', () => { const tips = getOrderedUnseenFeatureTips({ seenTipIds: new Set([ 'native-chat-upgrade', 'voice-dictation', 'orca-cli', 'cmd-j-palette', 'agent-session-search' ]) }) expect(tips.map((tip) => tip.id)).toEqual([]) }) it('skips tips for features the user has already completed', () => { const tips = getOrderedUnseenFeatureTips({ // cmd-j is a seen-based tip with no feature completion, so mark it seen here. seenTipIds: new Set(['cmd-j-palette']), completedTipIds: getCompletedFeatureTipIds({ cliInstalled: true, voiceDictationEnabled: true, sessionSearchTipCompleted: true, inNativeChatUpgradeTipAudience: false }) }) expect(tips.map((tip) => tip.id)).toEqual([]) }) it('skips the CLI tip when the CLI is already installed', () => { const tips = getOrderedUnseenFeatureTips({ seenTipIds: new Set(['voice-dictation', 'cmd-j-palette']), completedTipIds: getCompletedFeatureTipIds({ cliInstalled: true, voiceDictationEnabled: false, sessionSearchTipCompleted: true, inNativeChatUpgradeTipAudience: false }) }) expect(tips.map((tip) => tip.id)).toEqual([]) }) it('skips tips for features the user has already interacted with', () => { const tips = getOrderedUnseenFeatureTips({ seenTipIds: new Set(), completedTipIds: getCompletedFeatureTipIds({ cliInstalled: false, voiceDictationEnabled: false, sessionSearchTipCompleted: true, inNativeChatUpgradeTipAudience: false, featureInteractions: { 'voice-dictation': { firstInteractedAt: 100, interactionCount: 1 } } }) }) expect(tips.map((tip) => tip.id)).toEqual(['orca-cli', 'cmd-j-palette']) }) it('normalizes persisted tip ids', () => { expect( normalizeFeatureTipIds([ 'feature-tour', 'orca-cli', 'bogus', 'cmd-j-palette', 'voice-dictation' ]) ).toEqual(['orca-cli', 'cmd-j-palette', 'voice-dictation']) }) })