summaryrefslogtreecommitdiff
path: root/src/fauxton/app/addons/fauxton/tests/navbarSpec.js
blob: 3eca6f6ce9a9351a2c6bf330f57234d388a1da14 (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
105
106
107
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
define([
       'addons/fauxton/base',
      'testUtils'
], function (Fauxton, testUtils) {
  var assert = testUtils.assert,
      NavBar = Fauxton.NavBar;

  describe('NavBar', function () {

    describe('adding links', function () {
      var navBar;

      beforeEach(function () {
        navBar = new NavBar();
        navBar.navLinks = [];
        navBar.bottomNavLinks = [];
        navBar.footerNavLinks = [];
      });

      it('Should add link to navlinks', function () {
        navBar.addLink({href: '#/test', title: 'Test Title'});

        assert.equal(navBar.navLinks.length, 1);
        assert.equal(navBar.footerNavLinks.length, 0);
        assert.equal(navBar.bottomNavLinks.length, 0);
      });

      it('Should add link to bottom links', function () {
        navBar.addLink({href: '#/test', bottomNav: true, title: 'Test Title'});

        assert.equal(navBar.bottomNavLinks.length, 1);
        assert.equal(navBar.navLinks.length, 0);
        assert.equal(navBar.footerNavLinks.length, 0);
      });

      it('Should add link to footer links', function () {
        navBar.addLink({href: '#/test', footerNav: true, title: 'Test Title'});

        assert.equal(navBar.footerNavLinks.length, 1);
        assert.equal(navBar.bottomNavLinks.length, 0);
        assert.equal(navBar.navLinks.length, 0);
      });
    });

    describe('removing links', function () {
      var navBar;

      beforeEach(function () {
        navBar = new NavBar();
        navBar.navLinks = [];
        navBar.bottomNavLinks = [];
        navBar.footerNavLinks = [];
        navBar.addLink({
          href: '#/test', 
          footerNav: true, 
          title: 'Test Title Footer'
        });

        navBar.addLink({
          href: '#/test', 
          bottomNav: true, 
          title: 'Test Title Bottom'
        });

        navBar.addLink({
          href: '#/test', 
          title: 'Test Title'
        });
      });

      it("should remove links from list", function () {
        navBar.removeLink({
          title: 'Test Title Footer',
          footerNav: true
        });

        assert.equal(navBar.footerNavLinks.length, 0);
        assert.equal(navBar.bottomNavLinks.length, 1);
        assert.equal(navBar.navLinks.length, 1);
      });

      it("Should call render after removing links", function () {
        var renderSpy = sinon.stub(navBar,'render');

        navBar.removeLink({
          title: 'Test Title Footer',
          footerNav: true
        });

        assert.ok(renderSpy.calledOnce);
      });

    });
  });

});