Skip to content

Commit e0e22bc

Browse files
committed
Finished testing codeSnippetWidgetModel
1 parent d1ca5db commit e0e22bc

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/codeSnippetWidgetModel.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)