Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
chore(modal): fix tests for Angular 1.4.4
Browse files Browse the repository at this point in the history
Closes #4207
  • Loading branch information
Foxandxss authored and wesleycho committed Aug 14, 2015
1 parent cd4822d commit 8e84567
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ describe('$modal', function () {
var $animate, $controllerProvider, $rootScope, $document, $compile, $templateCache, $timeout, $q;
var $modal, $modalProvider;

var triggerKeyDown = function(element, keyCode, shiftKey) {
var e = $.Event('keydown');
e.srcElement = element[0];
e.which = keyCode;
e.shiftKey = shiftKey;
element.trigger(e);
};

beforeEach(module('ngAnimateMock'));
beforeEach(module('ui.bootstrap.modal'));
beforeEach(module('template/modal/backdrop.html'));
Expand Down Expand Up @@ -143,6 +135,14 @@ describe('$modal', function () {
body.removeClass('modal-open');
});

function triggerKeyDown(element, keyCode, shiftKey) {
var e = $.Event('keydown');
e.srcElement = element[0];
e.which = keyCode;
e.shiftKey = shiftKey;
element.trigger(e);
}

function open(modalOptions) {
var modal = $modal.open(modalOptions);
$rootScope.$digest();
Expand All @@ -155,6 +155,7 @@ describe('$modal', function () {
$rootScope.$digest();
if (!noFlush) {
$animate.triggerCallbacks();
$animate.triggerCallbacks();
}
return closed;
}
Expand All @@ -164,6 +165,7 @@ describe('$modal', function () {
$rootScope.$digest();
if (!noFlush) {
$animate.triggerCallbacks();
$animate.triggerCallbacks();
}
return closed;
}
Expand Down Expand Up @@ -232,6 +234,7 @@ describe('$modal', function () {

triggerKeyDown($document, 27);
$animate.triggerCallbacks();
$animate.triggerCallbacks();
$rootScope.$digest();

expect($document).toHaveModalsOpen(0);
Expand All @@ -252,6 +255,7 @@ describe('$modal', function () {

triggerKeyDown(button, 27);
$animate.triggerCallbacks();
$animate.triggerCallbacks();
$rootScope.$digest();

expect($document).toHaveModalsOpen(0);
Expand All @@ -267,6 +271,7 @@ describe('$modal', function () {

$document.find('body > div.modal').click();
$animate.triggerCallbacks();
$animate.triggerCallbacks();
$rootScope.$digest();

expect($document).toHaveModalsOpen(0);
Expand All @@ -285,6 +290,7 @@ describe('$modal', function () {

triggerKeyDown($document, 27);
$animate.triggerCallbacks();
$animate.triggerCallbacks();
$rootScope.$digest();

expect(document.activeElement.tagName).toBe('A');
Expand All @@ -309,6 +315,7 @@ describe('$modal', function () {
element[0].focus = undefined;
triggerKeyDown($document, 27);
$animate.triggerCallbacks();
$animate.triggerCallbacks();
$rootScope.$digest();

expect(document.activeElement.tagName).toBe('BODY');
Expand Down Expand Up @@ -338,6 +345,7 @@ describe('$modal', function () {

expect(modal.result).toBeRejectedWith('$uibUnscheduledDestruction');

$animate.triggerCallbacks();
$animate.triggerCallbacks();
expect($document).toHaveModalsOpen(0);
});
Expand Down Expand Up @@ -663,12 +671,14 @@ describe('$modal', function () {

it('should contain backdrop in classes on each modal opening', function() {
var modal = open({ template: '<div>With backdrop</div>' });
$animate.triggerCallbacks();
var backdropEl = $document.find('body > div.modal-backdrop');
expect(backdropEl).toHaveClass('in');

dismiss(modal);

modal = open({ template: '<div>With backdrop</div>' });
$animate.triggerCallbacks();
backdropEl = $document.find('body > div.modal-backdrop');
expect(backdropEl).toHaveClass('in');

Expand Down

0 comments on commit 8e84567

Please sign in to comment.