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