diff options
Diffstat (limited to 'js_tests/admin/RelatedObjectLookups.test.js')
| -rw-r--r-- | js_tests/admin/RelatedObjectLookups.test.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/js_tests/admin/RelatedObjectLookups.test.js b/js_tests/admin/RelatedObjectLookups.test.js new file mode 100644 index 0000000000..64433cb623 --- /dev/null +++ b/js_tests/admin/RelatedObjectLookups.test.js @@ -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'); +}); |
