blob: c8dffe745d575a7f2ea7fa28463848e9e8610cec [file] [log] [blame]
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08001/// <reference path="../../../../typings/index.d.ts" />
2
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -08003import * as $ from 'jquery';
4import 'jasmine-jquery';
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08005import * as angular from 'angular';
6import 'angular-mocks';
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -08007import {xosHeader, INotification} from './header';
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08008import {StyleConfig} from '../../config/style.config';
Matteo Scandolo63e43eb2016-12-14 14:18:53 -08009import {Subject} from 'rxjs';
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080010
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -080011let element, scope: angular.IRootScopeService, compile: ng.ICompileService, isolatedScope;
12const events = new Subject();
13const sendEvent = (event: INotification): void => {
14 events.next(event);
15};
16const MockStore = function() {
17 this.query = () => {
18 return events.asObservable();
19 };
20};
Matteo Scandolo266907e2016-12-20 13:41:42 -080021
22interface ImockToastr {
23 info(msg: string, title: string): void;
24}
25
26const MockToastr: ImockToastr = {
27 info: jasmine.createSpy('info')
28};
29
30const MockToastrConfig = {};
31
32const infoNotification = {
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -080033 model: 'TestModel',
34 msg: {
35 changed_fields: ['backend_status'],
36 pk: 1,
37 object: {
38 name: 'TestName',
Matteo Scandolo266907e2016-12-20 13:41:42 -080039 backend_status: '1 - Test Status'
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -080040 }
41 }
42};
43
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080044describe('header component', () => {
45 beforeEach(() => {
46 angular
47 .module('xosHeader', ['app/core/header/header.html'])
Matteo Scandolo63e43eb2016-12-14 14:18:53 -080048 .component('xosHeader', xosHeader)
Matteo Scandolo266907e2016-12-20 13:41:42 -080049 .service('SynchronizerStore', MockStore)
50 .value('toastr', MockToastr)
51 .value('toastrConfig', MockToastrConfig);
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080052 angular.mock.module('xosHeader');
53 });
54
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -080055 beforeEach(angular.mock.inject(($rootScope: ng.IRootScopeService, $compile: ng.ICompileService) => {
56 scope = $rootScope;
57 compile = $compile;
58 element = $compile('<xos-header></xos-header>')($rootScope);
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080059 $rootScope.$digest();
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -080060 isolatedScope = element.isolateScope();
61
62 // clear notifications
63 isolatedScope.notifications = [];
64 }));
65
66 it('should render the appropriate title', () => {
Matteo Scandolo266907e2016-12-20 13:41:42 -080067 const header = $('a.navbar-brand .brand-title', element).text();
68 expect(header.trim()).toEqual(StyleConfig.projectName);
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -080069 });
70
Matteo Scandolo99fface2016-12-21 15:37:23 -080071 it('should set the appropriate favicon', () => {
72 console.log($('#favicon').attr('href'));
73 });
74
Matteo Scandolo266907e2016-12-20 13:41:42 -080075 it('should configure toastr', () => {
76 expect(MockToastrConfig).toEqual({
77 newestOnTop: false,
78 positionClass: 'toast-top-right',
79 preventDuplicates: false,
80 preventOpenDuplicates: false,
81 progressBar: true,
82 });
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -080083 });
84
Matteo Scandolo266907e2016-12-20 13:41:42 -080085 it('should display a toastr for a new notification', () => {
86 sendEvent(infoNotification);
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -080087 scope.$digest();
88
Matteo Scandolo266907e2016-12-20 13:41:42 -080089 expect(MockToastr.info).toHaveBeenCalledWith('Synchronization started for: TestName', 'TestModel');
Matteo Scandolo52fa5cb2016-12-16 10:06:13 -080090 });
91
Matteo Scandolo266907e2016-12-20 13:41:42 -080092 // TODO test error and success toaster call
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080093});