@@ -32,21 +32,32 @@ describe("<WelcomeView />", () => {
3232 commandline : { command : "button8" } ,
3333 }
3434
35+ const sessions = [
36+ {
37+ name : "test" ,
38+ id : "test-1" ,
39+ file : "/test/dir" ,
40+ directory : "/test/dir" ,
41+ workspace : "/test/dir" ,
42+ } ,
43+ ]
44+
45+ const restoreSession = jest . fn ( )
3546 const executeCommand = jest . fn ( )
3647 const inputEvent = new Event < IWelcomeInputEvent > ( "handleInputTestEvent" )
37- let handleInputSpy : jest . SpyInstance < WelcomeView [ "handleInput" ] >
3848
3949 afterEach ( ( ) => {
40- if ( handleInputSpy ) {
41- handleInputSpy . mockClear ( )
42- }
4350 instance . setState ( { selectedId : "button1" , currentIndex : 0 } )
4451 } )
4552
53+ const ids = [ ...buttons , ...sessions . map ( ( { id } ) => id ) ]
4654 const wrapper = mount < WelcomeViewProps , WelcomeViewState > (
4755 < WelcomeView
4856 active
49- buttonIds = { buttons }
57+ restoreSession = { restoreSession }
58+ ids = { ids }
59+ sections = { [ buttons . length , sessions . length ] }
60+ sessions = { sessions }
5061 inputEvent = { inputEvent }
5162 commands = { commands }
5263 executeCommand = { executeCommand }
@@ -63,25 +74,39 @@ describe("<WelcomeView />", () => {
6374 } )
6475
6576 it ( "should correctly update selection based on input" , ( ) => {
66- instance . handleInput ( { direction : 1 , select : false } )
77+ instance . handleInput ( { vertical : 1 , select : false } )
6778 expect ( instance . state . selectedId ) . toBe ( "button2" )
6879 } )
6980
70- it ( "should loop back to button if user navigates upwards at the first button" , ( ) => {
71- instance . handleInput ( { direction : - 1 , select : false } )
72- expect ( instance . state . currentIndex ) . toBe ( 7 )
73- expect ( instance . state . selectedId ) . toBe ( "button8 " )
81+ it ( "should loop back to last button if user navigates upwards at the first button" , ( ) => {
82+ instance . handleInput ( { vertical : - 1 , select : false } )
83+ expect ( instance . state . currentIndex ) . toBe ( ids . length - 1 )
84+ expect ( instance . state . selectedId ) . toBe ( "test-1 " )
7485 } )
7586
76- it ( "should loop back to button if user navigates downwards at the last button" , ( ) => {
77- instance . setState ( { currentIndex : 7 , selectedId : "button8 " } )
78- instance . handleInput ( { direction : 1 , select : false } )
87+ it ( "should loop back to first button if user navigates downwards at the last button" , ( ) => {
88+ instance . setState ( { currentIndex : ids . length - 1 , selectedId : "test-1 " } )
89+ instance . handleInput ( { vertical : 1 , select : false } )
7990 expect ( instance . state . currentIndex ) . toBe ( 0 )
8091 expect ( instance . state . selectedId ) . toBe ( "button1" )
8192 } )
8293
8394 it ( "should trigger a command on enter event" , ( ) => {
84- instance . handleInput ( { direction : 0 , select : true } )
95+ instance . handleInput ( { vertical : 0 , select : true } )
8596 expect ( executeCommand . mock . calls [ 0 ] [ 0 ] ) . toBe ( "button1" )
8697 } )
98+
99+ it ( "should navigate right if horizontal is 1" , ( ) => {
100+ instance . setState ( { currentIndex : 7 , selectedId : "button8" } )
101+ instance . handleInput ( { vertical : 0 , horizontal : 1 , select : false } )
102+ expect ( instance . state . currentIndex ) . toBe ( 8 )
103+ expect ( instance . state . selectedId ) . toBe ( "test-1" )
104+ } )
105+
106+ it ( "should navigate left if horizontal is -1" , ( ) => {
107+ instance . setState ( { currentIndex : ids . length - 1 , selectedId : "test-1" } )
108+ instance . handleInput ( { vertical : 0 , horizontal : - 1 , select : false } )
109+ expect ( instance . state . currentIndex ) . toBe ( 0 )
110+ expect ( instance . state . selectedId ) . toBe ( "button1" )
111+ } )
87112} )
0 commit comments