feat: self-serve signup Phase 2 (frontend cutover) (#162)
Co-authored-by: Michael Chihlas <michael@resolutionflow.com> Co-committed-by: Michael Chihlas <michael@resolutionflow.com>
This commit was merged in pull request #162.
This commit is contained in:
44
frontend/src/hooks/useFeature.test.ts
Normal file
44
frontend/src/hooks/useFeature.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { renderHook, act } from '@testing-library/react'
|
||||
import { useFeature } from './useFeature'
|
||||
import { useBillingStore } from '@/store/billingStore'
|
||||
|
||||
describe('useFeature', () => {
|
||||
beforeEach(() => {
|
||||
useBillingStore.setState({
|
||||
subscription: null,
|
||||
planBilling: null,
|
||||
planLimits: {},
|
||||
enabledFeatures: {},
|
||||
isLoading: false,
|
||||
error: null,
|
||||
})
|
||||
})
|
||||
|
||||
it('returns false when flag absent', () => {
|
||||
const { result } = renderHook(() => useFeature('does_not_exist'))
|
||||
expect(result.current).toBe(false)
|
||||
})
|
||||
|
||||
it('returns true when flag is enabled', () => {
|
||||
useBillingStore.setState({ enabledFeatures: { ai_builder: true } })
|
||||
const { result } = renderHook(() => useFeature('ai_builder'))
|
||||
expect(result.current).toBe(true)
|
||||
})
|
||||
|
||||
it('returns false when flag is explicitly disabled', () => {
|
||||
useBillingStore.setState({ enabledFeatures: { ai_builder: false } })
|
||||
const { result } = renderHook(() => useFeature('ai_builder'))
|
||||
expect(result.current).toBe(false)
|
||||
})
|
||||
|
||||
it('updates when store changes (subscribes to store)', () => {
|
||||
const { result } = renderHook(() => useFeature('foo'))
|
||||
expect(result.current).toBe(false)
|
||||
|
||||
act(() => {
|
||||
useBillingStore.setState({ enabledFeatures: { foo: true } })
|
||||
})
|
||||
expect(result.current).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user