Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 1 | import * as angular from 'angular'; |
| 2 | import 'angular-mocks'; |
| 3 | import 'angular-ui-router'; |
| 4 | import {xosCore} from '../index'; |
| 5 | import {IXosPageTitleService} from './page-title'; |
| 6 | import IWindowService = angular.IWindowService; |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 7 | |
| 8 | let service: IXosPageTitleService, $window: IWindowService; |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 9 | |
| 10 | const MockStyleConfig = { |
| 11 | projectName: 'CORD' |
| 12 | }; |
| 13 | |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 14 | describe('The PageTitle service', () => { |
| 15 | |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 16 | beforeEach(() => { |
| 17 | angular.module(xosCore) |
| 18 | .constant('StyleConfig', MockStyleConfig); |
| 19 | angular.mock.module(xosCore); |
| 20 | }); |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 21 | |
| 22 | beforeEach(angular.mock.inject(( |
| 23 | PageTitle: IXosPageTitleService, |
| 24 | _$window_: IWindowService |
| 25 | ) => { |
| 26 | service = PageTitle; |
| 27 | $window = _$window_; |
| 28 | })); |
| 29 | |
| 30 | it('should get the page title', () => { |
| 31 | $window.document.title = 'test'; |
| 32 | expect(service.get()).toEqual('test'); |
| 33 | }); |
| 34 | |
| 35 | it('should set a page title', () => { |
| 36 | service.set('sample'); |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 37 | expect($window.document.title).toEqual(`${MockStyleConfig.projectName} - sample`); |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 38 | }); |
Matteo Scandolo | ee655a1 | 2016-12-19 15:38:43 -0800 | [diff] [blame] | 39 | |
| 40 | it('should convert dots to >', () => { |
| 41 | service.set('core.sample.bread.crumb'); |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 42 | expect($window.document.title).toEqual(`${MockStyleConfig.projectName} - core > sample > bread > crumb`); |
Matteo Scandolo | ee655a1 | 2016-12-19 15:38:43 -0800 | [diff] [blame] | 43 | }); |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame] | 44 | }); |