aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/directive/ngSwitchSpec.js
diff options
context:
space:
mode:
authorMisko Hevery2013-03-20 16:24:23 -0700
committerMisko Hevery2013-04-02 14:05:06 -0700
commit0b6f1ce5f89f47f9302ff1e8cd8f4b92f837c413 (patch)
tree8cbc0c86024dd4f97d0aa54e0c9b7df9b0d56b86 /test/ng/directive/ngSwitchSpec.js
parent4bfb66ce0be46d3a0e9da2f80f3e1d0c2b559828 (diff)
downloadangular.js-0b6f1ce5f89f47f9302ff1e8cd8f4b92f837c413.tar.bz2
feat(ngAnimate): add support for animation
Diffstat (limited to 'test/ng/directive/ngSwitchSpec.js')
-rw-r--r--test/ng/directive/ngSwitchSpec.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/test/ng/directive/ngSwitchSpec.js b/test/ng/directive/ngSwitchSpec.js
index 85240b19..9d3eceaa 100644
--- a/test/ng/directive/ngSwitchSpec.js
+++ b/test/ng/directive/ngSwitchSpec.js
@@ -213,3 +213,121 @@ describe('ngSwitch', function() {
// afterwards a global afterEach will check for leaks in jq data cache object
}));
});
+
+describe('ngSwitch ngAnimate', function() {
+ var element, vendorPrefix, window;
+
+ beforeEach(module(function($animationProvider, $provide) {
+ $provide.value('$window', window = angular.mock.createMockWindow());
+ return function($sniffer) {
+ vendorPrefix = '-' + $sniffer.vendorPrefix + '-';
+ };
+ }));
+
+ afterEach(function(){
+ dealoc(element);
+ });
+
+ it('should fire off the enter animation + set and remove the classes',
+ inject(function($compile, $rootScope, $sniffer) {
+ var $scope = $rootScope.$new();
+ var style = vendorPrefix + 'transition: 1s linear all';
+ element = $compile(
+ '<div ng-switch on="val" ng-animate="{enter: \'cool-enter\', leave: \'cool-leave\'}">' +
+ '<div ng-switch-when="one" style="' + style + '">one</div>' +
+ '<div ng-switch-when="two" style="' + style + '">two</div>' +
+ '<div ng-switch-when="three" style="' + style + '">three</div>' +
+ '</div>'
+ )($scope);
+
+ $scope.val = 'one';
+ $scope.$digest();
+
+ expect(element.children().length).toBe(1);
+ var first = element.children()[0];
+
+ if ($sniffer.supportsTransitions) {
+ expect(first.className).toContain('cool-enter-setup');
+ window.setTimeout.expect(1).process();
+
+ expect(first.className).toContain('cool-enter-start');
+ window.setTimeout.expect(1000).process();
+ } else {
+ expect(window.setTimeout.queue).toEqual([]);
+ }
+
+ expect(first.className).not.toContain('cool-enter-setup');
+ expect(first.className).not.toContain('cool-enter-start');
+ }));
+
+
+ it('should fire off the leave animation + set and remove the classes',
+ inject(function($compile, $rootScope, $sniffer) {
+ var $scope = $rootScope.$new();
+ var style = vendorPrefix + 'transition: 1s linear all';
+ element = $compile(
+ '<div ng-switch on="val" ng-animate="{enter: \'cool-enter\', leave: \'cool-leave\'}">' +
+ '<div ng-switch-when="one" style="' + style + '">one</div>' +
+ '<div ng-switch-when="two" style="' + style + '">two</div>' +
+ '<div ng-switch-when="three" style="' + style + '">three</div>' +
+ '</div>'
+ )($scope);
+
+ $scope.val = 'two';
+ $scope.$digest();
+
+ if ($sniffer.supportsTransitions) {
+ window.setTimeout.expect(1).process();
+ window.setTimeout.expect(1000).process();
+ } else {
+ expect(window.setTimeout.queue).toEqual([]);
+ }
+
+ $scope.val = 'three';
+ $scope.$digest();
+
+ expect(element.children().length).toBe($sniffer.supportsTransitions ? 2 : 1);
+ var first = element.children()[0];
+
+
+ if ($sniffer.supportsTransitions) {
+ expect(first.className).toContain('cool-leave-setup');
+ window.setTimeout.expect(1).process();
+ window.setTimeout.expect(1).process();
+ } else {
+ expect(window.setTimeout.queue).toEqual([]);
+ }
+
+
+ if ($sniffer.supportsTransitions) {
+ expect(first.className).toContain('cool-leave-start');
+ window.setTimeout.expect(1000).process();
+ window.setTimeout.expect(1000).process();
+ } else {
+ expect(window.setTimeout.queue).toEqual([]);
+ }
+
+ expect(first.className).not.toContain('cool-leave-setup');
+ expect(first.className).not.toContain('cool-leave-start');
+ }));
+
+ it('should catch and use the correct duration for animation',
+ inject(function($compile, $rootScope, $sniffer) {
+ element = $compile(
+ '<div ng-switch on="val" ng-animate="{enter: \'cool-enter\', leave: \'cool-leave\'}">' +
+ '<div ng-switch-when="one" style="' + vendorPrefix + 'transition: 0.5s linear all">one</div>' +
+ '</div>'
+ )($rootScope);
+
+ $rootScope.val = 'one';
+ $rootScope.$digest();
+
+ if ($sniffer.supportsTransitions) {
+ window.setTimeout.expect(1).process();
+ window.setTimeout.expect(500).process();
+ } else {
+ expect(window.setTimeout.queue).toEqual([]);
+ }
+ }));
+
+});