mirror of
				https://github.com/django/django.git
				synced 2025-10-28 08:06:09 +00:00 
			
		
		
		
	Refs #31170 -- Added JavaScript tests for RelatedObjectLookups.js.
This commit is contained in:
		
				
					committed by
					
						 Sarah Boyce
						Sarah Boyce
					
				
			
			
				
	
			
			
			
						parent
						
							727731d76d
						
					
				
				
					commit
					91bebf1adb
				
			| @@ -55,11 +55,11 @@ | |||||||
|         if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) { |         if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) { | ||||||
|             elem.value += ',' + chosenId; |             elem.value += ',' + chosenId; | ||||||
|         } else { |         } else { | ||||||
|             document.getElementById(name).value = chosenId; |             elem.value = chosenId; | ||||||
|         } |         } | ||||||
|         const index = relatedWindows.indexOf(win); |         const index = window.relatedWindows.indexOf(win); | ||||||
|         if (index > -1) { |         if (index > -1) { | ||||||
|             relatedWindows.splice(index, 1); |             window.relatedWindows.splice(index, 1); | ||||||
|         } |         } | ||||||
|         win.close(); |         win.close(); | ||||||
|     } |     } | ||||||
|   | |||||||
							
								
								
									
										38
									
								
								js_tests/admin/RelatedObjectLookups.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								js_tests/admin/RelatedObjectLookups.test.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | |||||||
|  | /* global QUnit, RelatedObjectLookups */ | ||||||
|  | 'use strict'; | ||||||
|  |  | ||||||
|  | QUnit.module('admin.RelatedObjectLookups', { | ||||||
|  |     beforeEach: function() { | ||||||
|  |         const $ = django.jQuery; | ||||||
|  |         $('#qunit-fixture').append(` | ||||||
|  |             <input type="text" id="test_id" name="test" /> | ||||||
|  |             <input type="text" id="many_test_id" name="many_test" class="vManyToManyRawIdAdminField" /> | ||||||
|  |         `); | ||||||
|  |         window.relatedWindows = window.relatedWindows || []; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | QUnit.test('dismissRelatedLookupPopup closes popup window', function(assert) { | ||||||
|  |     const testId = 'test_id'; | ||||||
|  |     let windowClosed = false; | ||||||
|  |     const mockWin = { | ||||||
|  |         name: testId, | ||||||
|  |         close: function() { | ||||||
|  |             windowClosed = true; | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |     window.dismissRelatedLookupPopup(mockWin, '123'); | ||||||
|  |     assert.true(windowClosed, 'Popup window should be closed'); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | QUnit.test('dismissRelatedLookupPopup removes window from relatedWindows array', function(assert) { | ||||||
|  |     const testId = 'test_id'; | ||||||
|  |     const mockWin = { | ||||||
|  |         name: testId, | ||||||
|  |         close: function() {} | ||||||
|  |     }; | ||||||
|  |     window.relatedWindows.push(mockWin); | ||||||
|  |     assert.equal(window.relatedWindows.indexOf(mockWin), 0, 'Window should be in relatedWindows array'); | ||||||
|  |     window.dismissRelatedLookupPopup(mockWin, '123'); | ||||||
|  |     assert.equal(window.relatedWindows.indexOf(mockWin), -1, 'Window should be removed from relatedWindows array'); | ||||||
|  | }); | ||||||
| @@ -125,6 +125,7 @@ | |||||||
|     <script src='./admin/navigation.test.js'></script> |     <script src='./admin/navigation.test.js'></script> | ||||||
|  |  | ||||||
|     <script src='../django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js' data-cover></script> |     <script src='../django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js' data-cover></script> | ||||||
|  |     <script src='./admin/RelatedObjectLookups.test.js'></script> | ||||||
|  |  | ||||||
|     <script src='./admin/DateTimeShortcuts.test.js'></script> |     <script src='./admin/DateTimeShortcuts.test.js'></script> | ||||||
|     <script src='../django/contrib/admin/static/admin/js/calendar.js' data-cover></script> |     <script src='../django/contrib/admin/static/admin/js/calendar.js' data-cover></script> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user