@@ -21,9 +21,9 @@ describe('usePhraseCycler', () => {
2121 vi . restoreAllMocks ( ) ;
2222 } ) ;
2323
24- it ( 'should initialize with the first witty phrase when not active and not waiting' , ( ) => {
24+ it ( 'should initialize with a witty phrase when not active and not waiting' , ( ) => {
2525 const { result } = renderHook ( ( ) => usePhraseCycler ( false , false ) ) ;
26- expect ( result . current ) . toBe ( WITTY_LOADING_PHRASES [ 0 ] ) ;
26+ expect ( WITTY_LOADING_PHRASES ) . toContain ( result . current ) ;
2727 } ) ;
2828
2929 it ( 'should show "Waiting for user confirmation..." when isWaiting is true' , ( ) => {
@@ -37,10 +37,11 @@ describe('usePhraseCycler', () => {
3737
3838 it ( 'should not cycle phrases if isActive is false and not waiting' , ( ) => {
3939 const { result } = renderHook ( ( ) => usePhraseCycler ( false , false ) ) ;
40+ const initialPhrase = result . current ;
4041 act ( ( ) => {
4142 vi . advanceTimersByTime ( PHRASE_CHANGE_INTERVAL_MS * 2 ) ;
4243 } ) ;
43- expect ( result . current ) . toBe ( WITTY_LOADING_PHRASES [ 0 ] ) ;
44+ expect ( result . current ) . toBe ( initialPhrase ) ;
4445 } ) ;
4546
4647 it ( 'should cycle through witty phrases when isActive is true and not waiting' , ( ) => {
@@ -99,7 +100,7 @@ describe('usePhraseCycler', () => {
99100
100101 // Set to inactive - should reset to the default initial phrase
101102 rerender ( { isActive : false , isWaiting : false } ) ;
102- expect ( result . current ) . toBe ( WITTY_LOADING_PHRASES [ 0 ] ) ;
103+ expect ( WITTY_LOADING_PHRASES ) . toContain ( result . current ) ;
103104
104105 // Set back to active - should pick a random witty phrase (which our mock controls)
105106 act ( ( ) => {
@@ -116,6 +117,56 @@ describe('usePhraseCycler', () => {
116117 expect ( clearIntervalSpy ) . toHaveBeenCalledOnce ( ) ;
117118 } ) ;
118119
120+ it ( 'should use custom phrases when provided' , ( ) => {
121+ const customPhrases = [ 'Custom Phrase 1' , 'Custom Phrase 2' ] ;
122+ let callCount = 0 ;
123+ vi . spyOn ( Math , 'random' ) . mockImplementation ( ( ) => {
124+ const val = callCount % 2 ;
125+ callCount ++ ;
126+ return val / customPhrases . length ;
127+ } ) ;
128+
129+ const { result, rerender } = renderHook (
130+ ( { isActive, isWaiting, customPhrases : phrases } ) =>
131+ usePhraseCycler ( isActive , isWaiting , phrases ) ,
132+ {
133+ initialProps : {
134+ isActive : true ,
135+ isWaiting : false ,
136+ customPhrases,
137+ } ,
138+ } ,
139+ ) ;
140+
141+ expect ( result . current ) . toBe ( customPhrases [ 0 ] ) ;
142+
143+ act ( ( ) => {
144+ vi . advanceTimersByTime ( PHRASE_CHANGE_INTERVAL_MS ) ;
145+ } ) ;
146+
147+ expect ( result . current ) . toBe ( customPhrases [ 1 ] ) ;
148+
149+ rerender ( { isActive : true , isWaiting : false , customPhrases : undefined } ) ;
150+
151+ expect ( WITTY_LOADING_PHRASES ) . toContain ( result . current ) ;
152+ } ) ;
153+
154+ it ( 'should fall back to witty phrases if custom phrases are an empty array' , ( ) => {
155+ const { result } = renderHook (
156+ ( { isActive, isWaiting, customPhrases : phrases } ) =>
157+ usePhraseCycler ( isActive , isWaiting , phrases ) ,
158+ {
159+ initialProps : {
160+ isActive : true ,
161+ isWaiting : false ,
162+ customPhrases : [ ] ,
163+ } ,
164+ } ,
165+ ) ;
166+
167+ expect ( WITTY_LOADING_PHRASES ) . toContain ( result . current ) ;
168+ } ) ;
169+
119170 it ( 'should reset to a witty phrase when transitioning from waiting to active' , ( ) => {
120171 const { result, rerender } = renderHook (
121172 ( { isActive, isWaiting } ) => usePhraseCycler ( isActive , isWaiting ) ,
0 commit comments