@@ -33,16 +33,79 @@ describe('Editor component', () => {
3333 } ) ;
3434
3535 it ( 'should dispatch selected suggestion' , ( ) => {
36+ //S
3637 const spy = expect . createSpy ( ) ;
3738 const wraper = mount ( < Editor input = { document . createElement ( 'input' ) } onJsonPathChanged = { spy } jsonpath = 'abc' position = { { x : 0 , y :0 } } json = { { type : 'string' } } /> ) ;
39+ //E
3840 wraper . instance ( ) . onSelectSuggestion ( { value : 'test' , description : 'test' } ) ;
41+ //V
3942 expect ( spy ) . toHaveBeenCalledWith ( 'test' ) ;
4043 } ) ;
4144
4245 it ( 'should dispatch selected suggestion when suggestion has setCarretAt' , ( ) => {
46+ //S
4347 const spy = expect . createSpy ( ) ;
4448 const wraper = mount ( < Editor input = { document . createElement ( 'input' ) } onJsonPathChanged = { spy } jsonpath = 'abc' position = { { x : 0 , y :0 } } json = { { type : 'string' } } /> ) ;
49+ //E
4550 wraper . instance ( ) . onSelectSuggestion ( { value : 'test' , description : 'test' , setCarretAt : 1 } ) ;
51+ //V
4652 expect ( spy ) . toHaveBeenCalledWith ( 'test' ) ;
4753 } ) ;
54+
55+ it ( 'should set json path with suggestion value correctly when jsonpath ends with a part of the suggestion' , ( ) => {
56+ //S
57+ const spy = expect . createSpy ( ) ;
58+ const jsonPath = '$.te.es' ; // es is included in 'test' which is the value of the suggestion
59+ const input = document . createElement ( 'input' ) ;
60+ input . value = jsonPath ;
61+ const wraper = mount ( < Editor input = { input } onJsonPathChanged = { spy } jsonpath = { jsonPath } position = { { x : 0 , y :0 } } json = { { type : 'string' } } /> ) ;
62+ //E
63+ wraper . instance ( ) . onSelectSuggestion ( { value : 'test' , description : 'test' , setCarretAt : 1 } ) ;
64+ //V
65+ expect ( spy ) . toHaveBeenCalledWith ( '$.te.test' ) ;
66+ } ) ;
67+
68+ it ( 'should set json path with suggestion value correctly when jsonpath doesn\'t ends with a part of the suggestion' , ( ) => {
69+ //S
70+ const spy = expect . createSpy ( ) ;
71+ const jsonPath = '$.te.re' ;
72+ const input = document . createElement ( 'input' ) ;
73+ input . value = jsonPath ;
74+ const wraper = mount ( < Editor input = { input } onJsonPathChanged = { spy } jsonpath = { jsonPath } position = { { x : 0 , y :0 } } json = { { type : 'string' } } /> ) ;
75+ //E
76+ wraper . instance ( ) . onSelectSuggestion ( { value : 'test' , description : 'test' , setCarretAt : 1 } ) ;
77+ //V
78+ expect ( spy ) . toHaveBeenCalledWith ( '$.te.retest' ) ;
79+ } ) ;
80+
81+ it ( 'should evaluate suggestions when caret position is updated' , ( ) => {
82+ //S
83+ const wraper = mount ( < Editor input = { document . createElement ( 'input' ) } position = { { x : 0 , y :0 } } json = { { type : 'string' } } /> ) ;
84+ const spy = expect . spyOn ( wraper . instance ( ) , 'evalPathAndSuggestions' ) ;
85+ //E
86+ wraper . instance ( ) . onCaretChanged ( { code : 'ArrowLeft' } ) ;
87+ //V
88+ expect ( spy ) . toHaveBeenCalled ( ) ;
89+ } ) ;
90+
91+
92+ it ( 'should not evaluate suggestions when caret position is updated due to up arrow' , ( ) => {
93+ //S
94+ const wraper = mount ( < Editor input = { document . createElement ( 'input' ) } position = { { x : 0 , y :0 } } json = { { type : 'string' } } /> ) ;
95+ const spy = expect . spyOn ( wraper . instance ( ) , 'evalPathAndSuggestions' ) ;
96+ //E
97+ wraper . instance ( ) . onCaretChanged ( { code : 'ArrowUp' } ) ;
98+ //V
99+ expect ( spy ) . toNotHaveBeenCalled ( ) ;
100+ } ) ;
101+
102+ it ( 'should not evaluate suggestions when caret position is updated due to down arrow' , ( ) => {
103+ //S
104+ const wraper = mount ( < Editor input = { document . createElement ( 'input' ) } position = { { x : 0 , y :0 } } json = { { type : 'string' } } /> ) ;
105+ const spy = expect . spyOn ( wraper . instance ( ) , 'evalPathAndSuggestions' ) ;
106+ //E
107+ wraper . instance ( ) . onCaretChanged ( { code : 'ArrowDown' } ) ;
108+ //V
109+ expect ( spy ) . toNotHaveBeenCalled ( ) ;
110+ } ) ;
48111} ) ;
0 commit comments