summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-ui/modules/directives/showhide/test/showhideSpec.js
blob: 6f9959911d9aedc9042fca9b245db3e6237dc2a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*global beforeEach, describe, it, inject, expect, module, spyOn*/

(function () {
    'use strict';

    describe('uiShow', function () {

        var scope, $compile;
        beforeEach(module('ui.directives'));
        beforeEach(inject(function (_$rootScope_, _$compile_) {
            scope = _$rootScope_.$new();
            $compile = _$compile_;
        }));

        describe('linking the directive', function () {
            it('should call scope.$watch', function () {
                spyOn(scope, '$watch');
                $compile('<div ui-show="foo"></div>')(scope);
                expect(scope.$watch).toHaveBeenCalled();
            });
        });

        describe('executing the watcher', function () {
            it('should add the ui-show class if true', function () {
                var element = $compile('<div ui-show="foo"></div>')(scope);
                scope.foo = true;
                scope.$apply();
                expect(element.hasClass('ui-show')).toBe(true);
            });
            it('should remove the ui-show class if false', function () {
                var element = $compile('<div ui-show="foo"></div>')(scope);
                scope.foo = false;
                scope.$apply();
                expect(element.hasClass('ui-show')).toBe(false);
            });
        });
    });

    describe('uiHide', function () {

        var scope, $compile;
        beforeEach(module('ui.directives'));
        beforeEach(inject(function (_$rootScope_, _$compile_) {
            scope = _$rootScope_.$new();
            $compile = _$compile_;
        }));

        describe('when the directive is linked', function () {
            it('should call scope.$watch', function () {
                spyOn(scope, '$watch');
                $compile('<div ui-hide="foo"></div>')(scope);
                expect(scope.$watch).toHaveBeenCalled();
            });
        });

        describe('executing the watcher', function () {
            it('should add the ui-hide class if true', function () {
                var element = $compile('<div ui-hide="foo"></div>')(scope);
                scope.foo = true;
                scope.$apply();
                expect(element.hasClass('ui-hide')).toBe(true);
            });
            it('should remove the ui-hide class if false', function () {
                var element = $compile('<div ui-hide="foo"></div>')(scope);
                scope.foo = false;
                scope.$apply();
                expect(element.hasClass('ui-hide')).toBe(false);
            });
        });
    });

    describe('uiToggle', function () {

        var scope, $compile;
        beforeEach(module('ui.directives'));
        beforeEach(inject(function (_$rootScope_, _$compile_) {
            scope = _$rootScope_.$new();
            $compile = _$compile_;
        }));

        describe('when the directive is linked', function () {
            it('should call scope.$watch', function () {
                spyOn(scope, '$watch');
                $compile('<div ui-toggle="foo"></div>')(scope);
                expect(scope.$watch).toHaveBeenCalled();
            });
        });

        describe('executing the watcher', function () {
            it('should remove the ui-hide class and add the ui-show class if true', function () {
                var element = $compile('<div ui-toggle="foo"></div>')(scope);
                scope.foo = true;
                scope.$apply();
                expect(element.hasClass('ui-show') && !element.hasClass('ui-hide')).toBe(true);
            });
            it('should remove the ui-hide class and add the ui-show class if false', function () {
                var element = $compile('<div ui-toggle="foo"></div>')(scope);
                scope.foo = false;
                scope.$apply();
                expect(!element.hasClass('ui-show') && element.hasClass('ui-hide')).toBe(true);
            });
        });
    });
})();