@@ -148,4 +148,63 @@ describe('test snippet manipulation', () => {
148148
149149 expect ( codeSnippetWidgetModel . snippets . length ) . toBe ( 0 ) ;
150150 } ) ;
151+
152+ it ( 'test add snippet with id = -1' , ( ) => {
153+ const insertSnippet = jest . spyOn (
154+ CodeSnippetWidgetModel . prototype as any ,
155+ 'insertSnippet'
156+ ) ;
157+
158+ const expectedId = codeSnippetWidgetModel . snippets . length ;
159+ const newSnippet = {
160+ name : 'test_snippet_three' ,
161+ description : 'testing code snippet widget model' ,
162+ language : 'Python' ,
163+ code : [ "print('testing')" ] ,
164+ id : - 1
165+ } ;
166+ codeSnippetWidgetModel . addSnippet ( newSnippet , newSnippet . id ) ;
167+
168+ expect (
169+ codeSnippetWidgetModel . snippets [
170+ codeSnippetWidgetModel . snippets . length - 1
171+ ] . id
172+ ) . toBe ( expectedId ) ;
173+
174+ expect ( insertSnippet ) . toHaveBeenCalled ( ) ;
175+ } ) ;
176+
177+ it ( 'test moveSnippets to same index' , ( ) => {
178+ const before = codeSnippetWidgetModel . snippets ;
179+ codeSnippetWidgetModel . moveSnippet ( 0 , 0 ) ;
180+ const after = codeSnippetWidgetModel . snippets ;
181+
182+ expect ( before ) . toEqual ( after ) ;
183+ } ) ;
184+
185+ it ( 'test addSnippet to the middle of list' , ( ) => {
186+ const insertSnippet = jest . spyOn (
187+ CodeSnippetWidgetModel . prototype as any ,
188+ 'insertSnippet'
189+ ) ;
190+
191+ const newSnippet2 = {
192+ name : 'test_snippet_three' ,
193+ description : 'testing code snippet widget model' ,
194+ language : 'Python' ,
195+ code : [ "print('testing')" ] ,
196+ id : 0
197+ } ;
198+
199+ codeSnippetWidgetModel . addSnippet ( newSnippet2 , newSnippet2 . id ) ;
200+ expect ( codeSnippetWidgetModel . snippets [ 0 ] ) . toBe ( newSnippet2 ) ;
201+
202+ expect ( insertSnippet ) . toHaveBeenCalled ( ) ;
203+ } ) ;
204+
205+ it ( 'test delete the first snippet' , ( ) => {
206+ codeSnippetWidgetModel . deleteSnippet ( 0 ) ;
207+
208+ expect ( codeSnippetWidgetModel . snippets . length ) . toBe ( 1 ) ;
209+ } ) ;
151210} ) ;
0 commit comments