blob: d05899d24bfe9c7ba77fc6e5b619be78fb026830 [file] [log] [blame]
Max Chu886c89f2017-08-24 15:44:27 -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
19import * as angular from 'angular';
20import 'angular-mocks';
21import {IXosConfirm, XosConfirm} from './confirm.service';
22
23let service: IXosConfirm;
24let modal;
25let modalInstance;
Max Chu7d32b1e2017-08-25 15:51:18 -070026let q;
27let scope;
Max Chu886c89f2017-08-24 15:44:27 -070028
29describe('The XosConfirm service', () => {
30
31 beforeEach(() => {
32 angular.module('XosConfirmTest', ['ui.bootstrap.modal'])
33 .service('XosConfirm', XosConfirm);
34 angular.mock.module('XosConfirmTest');
35
36 angular.mock.inject((
37 XosConfirm: IXosConfirm,
Max Chu7d32b1e2017-08-25 15:51:18 -070038 $uibModal: any,
39 $q: ng.IQService,
40 $rootScope: ng.IScope
Max Chu886c89f2017-08-24 15:44:27 -070041 ) => {
42 service = XosConfirm;
43 modal = $uibModal;
Max Chu7d32b1e2017-08-25 15:51:18 -070044 q = $q;
45 scope = $rootScope;
Max Chu886c89f2017-08-24 15:44:27 -070046 });
47 });
48
49 describe('the open method', () => {
50
51 let test1 = {
52 header: 'Test Header',
53 text: 'Test body',
54 actions: [{
55 label: 'Action',
56 cb: () => {
57 return;
58 },
59 class: 'btn-success'
60 }]
61 };
62
Max Chu7d32b1e2017-08-25 15:51:18 -070063 it('should open the modal', () => {
64 spyOn(modal, 'open').and.returnValue('fake');
Max Chu886c89f2017-08-24 15:44:27 -070065 modalInstance = service.open(test1);
66 expect(modal.open).toHaveBeenCalled();
Max Chu7d32b1e2017-08-25 15:51:18 -070067 expect(modalInstance).toEqual('fake');
68 expect(service.modalInstance).toEqual('fake');
Max Chu886c89f2017-08-24 15:44:27 -070069 });
Max Chu886c89f2017-08-24 15:44:27 -070070
Max Chu7d32b1e2017-08-25 15:51:18 -070071 it('should close the modal', (done) => {
72 const p = q.defer();
73 const cb = jasmine.createSpy('cb').and.returnValue(p.promise);
74 service.modalInstance = {
75 close: jasmine.createSpy('close')
76 };
77
78 service.close(cb);
79 expect(cb).toHaveBeenCalled();
80 p.resolve();
81 scope.$apply();
82 expect(service.modalInstance.close).toHaveBeenCalled();
83 done();
84 });
85
86
87
88 });
Max Chu886c89f2017-08-24 15:44:27 -070089
90});