| 
									
										
										
										
											2018-03-02 15:05:04 +00:00
										 |  |  | //////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // pgAdmin 4 - PostgreSQL Tools
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-01-02 15:54:12 +05:30
										 |  |  | // Copyright (C) 2013 - 2019, The pgAdmin Development Team
 | 
					
						
							| 
									
										
										
										
											2018-03-02 15:05:04 +00:00
										 |  |  | // This software is released under the PostgreSQL Licence
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-29 15:20:33 +01:00
										 |  |  | import { | 
					
						
							|  |  |  |   setFocusToDebuggerEditor, | 
					
						
							|  |  |  |   getProcedureId, | 
					
						
							|  |  |  | } from '../../pgadmin/tools/debugger/static/js/debugger_utils'; | 
					
						
							| 
									
										
										
										
											2018-03-02 15:05:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-29 15:20:33 +01:00
										 |  |  | describe('setFocusToDebuggerEditor', function () { | 
					
						
							| 
									
										
										
										
											2018-03-02 15:05:04 +00:00
										 |  |  |   let editor; | 
					
						
							|  |  |  |   editor = jasmine.createSpyObj('editor', ['focus']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let tab_key = { | 
					
						
							|  |  |  |     which: 9, | 
					
						
							|  |  |  |     keyCode: 9, | 
					
						
							| 
									
										
										
										
											2018-04-30 17:51:57 +05:30
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-03-02 15:05:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   let enter_key = { | 
					
						
							|  |  |  |     which: 13, | 
					
						
							|  |  |  |     keyCode: 13, | 
					
						
							| 
									
										
										
										
											2018-04-30 17:51:57 +05:30
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-03-02 15:05:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-29 15:20:33 +01:00
										 |  |  |   describe('setFocusToDebuggerEditor', function () { | 
					
						
							| 
									
										
										
										
											2018-03-02 15:05:04 +00:00
										 |  |  |     it('returns undefined if no command is passed', function () { | 
					
						
							|  |  |  |       expect(setFocusToDebuggerEditor(editor, null)).toEqual(undefined); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-29 15:20:33 +01:00
										 |  |  |   describe('setFocusToDebuggerEditor', function () { | 
					
						
							| 
									
										
										
										
											2018-03-02 15:05:04 +00:00
										 |  |  |     it('should call focus on editor', function () { | 
					
						
							| 
									
										
										
										
											2018-04-30 17:51:57 +05:30
										 |  |  |       setFocusToDebuggerEditor(editor, enter_key); | 
					
						
							| 
									
										
										
										
											2018-03-02 15:05:04 +00:00
										 |  |  |       expect(editor.focus).toHaveBeenCalled(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-29 15:20:33 +01:00
										 |  |  |   describe('setFocusToDebuggerEditor', function () { | 
					
						
							| 
									
										
										
										
											2018-03-02 15:05:04 +00:00
										 |  |  |     it('should not call focus on editor and returns undefined', function () { | 
					
						
							|  |  |  |       expect(setFocusToDebuggerEditor(editor, tab_key)).toEqual(undefined); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2018-06-29 15:20:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('getProcedureId', function () { | 
					
						
							|  |  |  |   let treeInfroProc = { | 
					
						
							|  |  |  |     'procedure': { | 
					
						
							|  |  |  |       '_id': 123, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   let treeInfroInvalidProcId = { | 
					
						
							|  |  |  |     'procedure': { | 
					
						
							|  |  |  |       '_id': null, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   let treeInfroEdbProc = { | 
					
						
							|  |  |  |     'edbproc': { | 
					
						
							|  |  |  |       '_id': 321, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   let fakeTreeInfro; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('Should return proper object id', function () { | 
					
						
							|  |  |  |     it('returns valid procedure id', function () { | 
					
						
							| 
									
										
										
										
											2019-03-14 15:11:16 +00:00
										 |  |  |       expect(getProcedureId(treeInfroProc)).toEqual(123); | 
					
						
							| 
									
										
										
										
											2018-06-29 15:20:33 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('returns valid edbproc id', function () { | 
					
						
							| 
									
										
										
										
											2019-03-14 15:11:16 +00:00
										 |  |  |       expect(getProcedureId(treeInfroEdbProc)).toEqual(321); | 
					
						
							| 
									
										
										
										
											2018-06-29 15:20:33 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('returns undefined for fake tree info', function () { | 
					
						
							| 
									
										
										
										
											2019-03-14 15:11:16 +00:00
										 |  |  |       expect(getProcedureId(fakeTreeInfro)).toEqual(undefined); | 
					
						
							| 
									
										
										
										
											2018-06-29 15:20:33 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('returns undefined for invalid procedure id', function () { | 
					
						
							| 
									
										
										
										
											2019-03-14 15:11:16 +00:00
										 |  |  |       expect(getProcedureId(treeInfroInvalidProcId)).toEqual(undefined); | 
					
						
							| 
									
										
										
										
											2018-06-29 15:20:33 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 |