From 37afd3b3a03ce1f3035e0b5365e082feb65a105a Mon Sep 17 00:00:00 2001 From: Dale Alexander Webb Date: Fri, 6 Nov 2015 11:28:30 +0000 Subject: [PATCH] test(modal): added unit tests for aside and modal z-index values --- src/aside/test/aside.spec.js | 22 ++++++++++++++++++++++ src/modal/modal.js | 6 ++++-- src/modal/test/modal.spec.js | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/aside/test/aside.spec.js b/src/aside/test/aside.spec.js index 882758939..ee69baa58 100644 --- a/src/aside/test/aside.spec.js +++ b/src/aside/test/aside.spec.js @@ -256,6 +256,28 @@ describe('aside', function () { expect(bodyEl.find('.aside-backdrop').length).toBe(0); }); + it('should show backdrop above a previous aside dialog using the z-index value', function() { + var elm1 = compileDirective('default'); + var elm2 = compileDirective('default'); + + expect(bodyEl.find('.aside-backdrop').length).toBe(0); + + angular.element(elm1[0]).triggerHandler('click'); + expect(bodyEl.find('.aside-backdrop').length).toBe(1); + var backdrop1 = bodyEl.find('.aside-backdrop')[0]; + var aside1 = bodyEl.find('.aside')[0]; + + angular.element(elm2[0]).triggerHandler('click'); + expect(bodyEl.find('.aside-backdrop').length).toBe(2); + var backdrop2 = bodyEl.find('.aside-backdrop')[0]; + var aside2 = bodyEl.find('.aside')[1]; + + expect(angular.element(backdrop1).css('z-index')).toBe('1040'); + expect(angular.element(aside1).css('z-index')).toBe('1050'); + expect(angular.element(backdrop2).css('z-index')).toBe('1060'); + expect(angular.element(aside2).css('z-index')).toBe('1070'); + }); + }); describe('keyboard', function() { diff --git a/src/modal/modal.js b/src/modal/modal.js index 87c2152d8..8b94d0562 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -197,8 +197,10 @@ angular.module('mgcrea.ngStrap.modal', ['mgcrea.ngStrap.core', 'mgcrea.ngStrap.h $modal.hide = function() { if(!$modal.$isShown) return; - // decrement number of modals - backdropCount--; + if(options.backdrop) { + // decrement number of modals + backdropCount--; + } if(scope.$emit(options.prefixEvent + '.hide.before', $modal).defaultPrevented) { return; diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 3aa4dc82c..a0c175eac 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -671,6 +671,28 @@ describe('modal', function() { expect(bodyEl.find('.modal-backdrop').length).toBe(0); }); + it('should show backdrop above a previous modal dialog using the z-index value', function() { + var elm1 = compileDirective('default'); + var elm2 = compileDirective('default'); + + expect(bodyEl.find('.modal-backdrop').length).toBe(0); + + angular.element(elm1[0]).triggerHandler('click'); + expect(bodyEl.find('.modal-backdrop').length).toBe(1); + var backdrop1 = bodyEl.find('.modal-backdrop')[0]; + var modal1 = bodyEl.find('.modal')[0]; + + angular.element(elm2[0]).triggerHandler('click'); + expect(bodyEl.find('.modal-backdrop').length).toBe(2); + var backdrop2 = bodyEl.find('.modal-backdrop')[0]; + var modal2 = bodyEl.find('.modal')[1]; + + expect(angular.element(backdrop1).css('z-index')).toBe('1040'); + expect(angular.element(modal1).css('z-index')).toBe('1050'); + expect(angular.element(backdrop2).css('z-index')).toBe('1060'); + expect(angular.element(modal2).css('z-index')).toBe('1070'); + }); + });