Matteo Scandolo | fb46ae6 | 2017-08-08 09:10:50 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 19 | import * as angular from 'angular'; |
| 20 | import 'angular-mocks'; |
| 21 | import 'angular-ui-router'; |
| 22 | import {xosCore} from '../index'; |
| 23 | import {IXosPageTitleService} from './page-title'; |
| 24 | import IWindowService = angular.IWindowService; |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 25 | |
| 26 | let service: IXosPageTitleService, $window: IWindowService; |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 27 | |
| 28 | const MockStyleConfig = { |
| 29 | projectName: 'CORD' |
| 30 | }; |
| 31 | |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 32 | describe('The PageTitle service', () => { |
| 33 | |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 34 | beforeEach(() => { |
| 35 | angular.module(xosCore) |
| 36 | .constant('StyleConfig', MockStyleConfig); |
| 37 | angular.mock.module(xosCore); |
| 38 | }); |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 39 | |
| 40 | beforeEach(angular.mock.inject(( |
| 41 | PageTitle: IXosPageTitleService, |
| 42 | _$window_: IWindowService |
| 43 | ) => { |
| 44 | service = PageTitle; |
| 45 | $window = _$window_; |
| 46 | })); |
| 47 | |
| 48 | it('should get the page title', () => { |
| 49 | $window.document.title = 'test'; |
| 50 | expect(service.get()).toEqual('test'); |
| 51 | }); |
| 52 | |
| 53 | it('should set a page title', () => { |
| 54 | service.set('sample'); |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 55 | expect($window.document.title).toEqual(`${MockStyleConfig.projectName} - sample`); |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 56 | }); |
Matteo Scandolo | ee655a1 | 2016-12-19 15:38:43 -0800 | [diff] [blame] | 57 | |
| 58 | it('should convert dots to >', () => { |
| 59 | service.set('core.sample.bread.crumb'); |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 60 | expect($window.document.title).toEqual(`${MockStyleConfig.projectName} - core > sample > bread > crumb`); |
Matteo Scandolo | ee655a1 | 2016-12-19 15:38:43 -0800 | [diff] [blame] | 61 | }); |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 62 | }); |