blob: 34281efd959309e2cbf838339ceaf47fa52a4afd [file] [log] [blame]
Simon Hunt9d286562015-03-09 13:53:50 -07001/*
2 * Copyright 2014,2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 ONOS GUI -- Util -- Theme Service - Unit Tests
19 */
20describe('factory: fw/nav/nav.js', function() {
21 var ns, $log, fs;
22 var d3Elem;
23
24 beforeEach(module('onosNav', 'onosUtil'));
25
26 beforeEach(inject(function (NavService, _$log_, FnService) {
27 ns = NavService;
28 $log = _$log_;
29 fs = FnService;
30 d3Elem = d3.select('body').append('div').attr('id', 'nav');
31 ns.hideNav();
32 }));
33
34 afterEach(function () {
35 d3.select('#nav').remove();
36 });
37
38 it('should define NavService', function () {
39 expect(ns).toBeDefined();
40 });
41
42 it('should define api functions', function () {
43 expect(fs.areFunctions(ns, [
44 'showNav', 'hideNav', 'toggleNav', 'hideIfShown'
45 ])).toBeTruthy();
46 });
47
48 function checkHidden(b) {
49 var what = b ? 'hidden' : 'visible';
50 expect(d3.select('#nav').style('visibility')).toEqual(what);
51 }
52
53 it('should start hidden', function () {
54 checkHidden(true);
55 });
56
57 it('should be shown then hidden', function () {
58 ns.showNav();
59 checkHidden(false);
60 ns.hideNav();
61 checkHidden(true);
62 });
63
64 it('should toggle hidden', function () {
65 ns.toggleNav();
66 checkHidden(false);
67 ns.toggleNav();
68 checkHidden(true);
69 });
70
71 it('should show idempotently', function () {
72 checkHidden(true);
73 ns.showNav();
74 checkHidden(false);
75 ns.showNav();
76 checkHidden(false);
77 });
78
79 it('should hide idempotently', function () {
80 checkHidden(true);
81 ns.hideNav();
82 checkHidden(true);
83 });
84
85 it('should be a noop if already hidden', function () {
86 checkHidden(true);
87 expect(ns.hideIfShown()).toBe(false);
88 checkHidden(true);
89 });
90
91 it('should hide if shown', function () {
92 ns.showNav();
93 checkHidden(false);
94 expect(ns.hideIfShown()).toBe(true);
95 checkHidden(true);
96 });
97
98});