Steven Burrows | 202034f | 2017-08-11 12:08:01 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Layer -- Dialog Service - Unit Tests |
| 19 | */ |
| 20 | |
| 21 | describe('factory: fw/layer/dialog.js', function () { |
| 22 | |
| 23 | var $log, $timeout, fs, ps, d3Elem, dialog; |
| 24 | |
| 25 | beforeEach(module('onosLayer', 'onosNav', 'onosSvg', 'onosRemote')); |
| 26 | |
| 27 | beforeEach(inject(function (_$log_, _$timeout_, FnService, PanelService, DialogService) { |
| 28 | $log = _$log_; |
| 29 | $timeout = _$timeout_; |
| 30 | fs = FnService; |
| 31 | ps = PanelService; |
| 32 | dialog = DialogService; |
| 33 | |
| 34 | spyOn(fs, 'debugOn').and.returnValue(true); |
| 35 | d3Elem = d3.select('body').append('div').attr('id', 'floatpanels'); |
| 36 | ps.init(); |
| 37 | })); |
| 38 | |
| 39 | afterEach(function () { |
| 40 | d3.select('#floatpanels').remove(); |
| 41 | ps.init(); |
| 42 | }); |
| 43 | |
| 44 | it('should define DialogService', function () { |
| 45 | expect(dialog).toBeDefined(); |
| 46 | }); |
| 47 | |
| 48 | it('should define api functions', function () { |
| 49 | expect(fs.areFunctions(dialog, [ |
| 50 | 'openDialog', 'closeDialog', 'createDiv', |
| 51 | ])).toBe(true); |
| 52 | }); |
| 53 | |
| 54 | it('should create div', function () { |
| 55 | var div = dialog.createDiv(); |
| 56 | expect(div).toBeDefined(); |
| 57 | }); |
| 58 | |
| 59 | it('should create div with class', function () { |
| 60 | var div = dialog.createDiv('test-dialog'); |
| 61 | expect(div.classed('test-dialog')).toBe(true); |
| 62 | }); |
| 63 | |
| 64 | it('should openDialog and return API', function () { |
| 65 | |
| 66 | var dialogOptions = { |
| 67 | edge: 'right', |
| 68 | width: 400, |
| 69 | cssCls: 'test-dialog', |
| 70 | }; |
| 71 | |
| 72 | var d = dialog.openDialog('test-dialog', dialogOptions); |
| 73 | |
| 74 | expect(fs.areFunctions(d, [ |
| 75 | 'setTitle', 'addContent', 'addButton', 'addOk', 'addOkChained', 'addCancel', 'bindKeys', |
| 76 | ])).toBe(true); |
| 77 | }); |
| 78 | |
| 79 | it('should append elements, reset and destroy', function () { |
| 80 | |
| 81 | var okCallback = jasmine.createSpy('cb'); |
| 82 | var cancelCallback = jasmine.createSpy('cb'); |
| 83 | |
| 84 | var dialogOptions = { |
| 85 | edge: 'right', |
| 86 | width: 400, |
| 87 | cssCls: 'test-dialog', |
| 88 | }; |
| 89 | |
| 90 | var d = dialog.openDialog('test-dialog', dialogOptions); |
| 91 | // Title |
| 92 | d.setTitle('Dialog Title'); |
| 93 | |
| 94 | // Content |
| 95 | var content = dialog.createDiv(); |
| 96 | content.append('p').text('Dialog Content'); |
| 97 | d.addContent(content); |
| 98 | |
| 99 | d.addOk(okCallback); |
| 100 | d.addOk(okCallback, 'Ok'); |
| 101 | |
| 102 | d.addCancel(cancelCallback); |
| 103 | d.addCancel(cancelCallback, 'Cancel'); |
| 104 | |
| 105 | // TODO: Test elements have been correctly added |
| 106 | // Resets dialog |
| 107 | d = dialog.openDialog('test-dialog', dialogOptions); |
| 108 | |
| 109 | d.addContent('content'); |
| 110 | d.addOkChained(okCallback, 'ok'); |
| 111 | dialog.closeDialog(); |
| 112 | }); |
| 113 | |
| 114 | }); |