blob: 6825c9e35c1f6a8c2e829addb5acc140fa464f40 [file] [log] [blame]
Matteo Scandolofb46ae62017-08-08 09:10:50 -07001
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 Scandoloa4a47112016-12-16 10:06:13 -080019import * as angular from 'angular';
20import 'angular-mocks';
21import 'angular-ui-router';
22import {xosCore} from '../index';
23import {IXosPageTitleService} from './page-title';
24import IWindowService = angular.IWindowService;
Matteo Scandoloa4a47112016-12-16 10:06:13 -080025
26let service: IXosPageTitleService, $window: IWindowService;
Matteo Scandolo828d1e82017-01-17 14:49:38 -080027
28const MockStyleConfig = {
29 projectName: 'CORD'
30};
31
Matteo Scandoloa4a47112016-12-16 10:06:13 -080032describe('The PageTitle service', () => {
33
Matteo Scandolo828d1e82017-01-17 14:49:38 -080034 beforeEach(() => {
35 angular.module(xosCore)
36 .constant('StyleConfig', MockStyleConfig);
37 angular.mock.module(xosCore);
38 });
Matteo Scandoloa4a47112016-12-16 10:06:13 -080039
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 Scandolo828d1e82017-01-17 14:49:38 -080055 expect($window.document.title).toEqual(`${MockStyleConfig.projectName} - sample`);
Matteo Scandoloa4a47112016-12-16 10:06:13 -080056 });
Matteo Scandoloee655a12016-12-19 15:38:43 -080057
58 it('should convert dots to >', () => {
59 service.set('core.sample.bread.crumb');
Matteo Scandolo828d1e82017-01-17 14:49:38 -080060 expect($window.document.title).toEqual(`${MockStyleConfig.projectName} - core > sample > bread > crumb`);
Matteo Scandoloee655a12016-12-19 15:38:43 -080061 });
Matteo Scandoloa4a47112016-12-16 10:06:13 -080062});