blob: 026d4caf95d0b364f4e06cd237b21e382d219fea [file] [log] [blame]
Yuta HIGUCHI4f39bcd2014-12-18 20:46:14 -08001/*
Simon Hunt8ead3a22015-01-06 11:00:15 -08002 * Copyright 2014,2015 Open Networking Laboratory
Yuta HIGUCHI4f39bcd2014-12-18 20:46:14 -08003 *
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
Yuta HIGUCHI4f39bcd2014-12-18 20:46:14 -080019 */
20describe('factory: fw/util/theme.js', function() {
21 var ts, $log;
22
23 beforeEach(module('onosUtil'));
24
25 beforeEach(inject(function (ThemeService, _$log_) {
26 ts = ThemeService;
27 $log = _$log_;
28 ts.init();
29 }));
30
31 function verifyBodyClass(yes, no) {
32 function bodyHasClass(c) {
33 return d3.select('body').classed(c);
34 }
35 expect(bodyHasClass(yes)).toBeTruthy();
36 expect(bodyHasClass(no)).toBeFalsy();
37 }
38
39 it('should default to light theme', function () {
40 expect(ts.theme()).toEqual('light');
41 });
42
43 it('should toggle to dark, then to light again', function () {
44 // Note: re-work this once theme-change listeners are implemented
45 spyOn($log, 'debug');
46
47 expect(ts.toggleTheme()).toEqual('dark');
48 expect(ts.theme()).toEqual('dark');
49 expect($log.debug).toHaveBeenCalledWith('Theme-Change-(toggle): dark');
50 verifyBodyClass('dark', 'light');
51
52 expect(ts.toggleTheme()).toEqual('light');
53 expect(ts.theme()).toEqual('light');
54 expect($log.debug).toHaveBeenCalledWith('Theme-Change-(toggle): light');
55 verifyBodyClass('light', 'dark');
56 });
57
58 it('should let us set the theme by name', function () {
59 // Note: re-work this once theme-change listeners are implemented
60 spyOn($log, 'debug');
61
62 expect(ts.theme()).toEqual('light');
63 ts.theme('dark');
64 expect(ts.theme()).toEqual('dark');
65 expect($log.debug).toHaveBeenCalledWith('Theme-Change-(set): dark');
66 verifyBodyClass('dark', 'light');
67 });
68
69 it('should ignore unknown theme names', function () {
70 // Note: re-work this once theme-change listeners are implemented
71 spyOn($log, 'debug');
72
73 expect(ts.theme()).toEqual('light');
74 verifyBodyClass('light', 'dark');
75
76 ts.theme('turquoise');
77 expect(ts.theme()).toEqual('light');
78 expect($log.debug).not.toHaveBeenCalled();
79 verifyBodyClass('light', 'dark');
80 });
81});