GUI -- Fixing broken Jasmine unit tests.
Change-Id: Ic0c9754c6fcf66d755067467be32d8275b7ffc3d
Showing
3 changed files
with
50 additions
and
41 deletions
| ... | @@ -73,7 +73,9 @@ describe('factory: fw/layer/panel.js', function () { | ... | @@ -73,7 +73,9 @@ describe('factory: fw/layer/panel.js', function () { |
| 73 | edge: 'right', | 73 | edge: 'right', |
| 74 | width: 200, | 74 | width: 200, |
| 75 | margin: 20, | 75 | margin: 20, |
| 76 | - xtnTime: 750 | 76 | + hideMargin: 20, |
| 77 | + xtnTime: 750, | ||
| 78 | + fade: true | ||
| 77 | }); | 79 | }); |
| 78 | 80 | ||
| 79 | // check basic properties | 81 | // check basic properties |
| ... | @@ -128,7 +130,9 @@ describe('factory: fw/layer/panel.js', function () { | ... | @@ -128,7 +130,9 @@ describe('factory: fw/layer/panel.js', function () { |
| 128 | edge: 'left', | 130 | edge: 'left', |
| 129 | width: 250, | 131 | width: 250, |
| 130 | margin: 20, | 132 | margin: 20, |
| 131 | - xtnTime: 750 | 133 | + hideMargin: 20, |
| 134 | + xtnTime: 750, | ||
| 135 | + fade: true | ||
| 132 | }); | 136 | }); |
| 133 | }); | 137 | }); |
| 134 | 138 | ... | ... |
| ... | @@ -18,28 +18,28 @@ | ... | @@ -18,28 +18,28 @@ |
| 18 | ONOS GUI -- Widget -- Button Service - Unit Tests | 18 | ONOS GUI -- Widget -- Button Service - Unit Tests |
| 19 | */ | 19 | */ |
| 20 | describe('factory: fw/widget/button.js', function () { | 20 | describe('factory: fw/widget/button.js', function () { |
| 21 | - var $log, fs, bns, gs, | 21 | + var $log, fs, bns, d3Elem; |
| 22 | - d3Elem; | ||
| 23 | 22 | ||
| 24 | beforeEach(module('onosWidget', 'onosSvg')); | 23 | beforeEach(module('onosWidget', 'onosSvg')); |
| 25 | 24 | ||
| 26 | - beforeEach(inject(function (_$log_, FnService, | 25 | + beforeEach(inject(function (_$log_, FnService, ButtonService) { |
| 27 | - ButtonService, GlyphService) { | ||
| 28 | $log = _$log_; | 26 | $log = _$log_; |
| 29 | fs = FnService; | 27 | fs = FnService; |
| 30 | bns = ButtonService; | 28 | bns = ButtonService; |
| 31 | - gs = GlyphService; | ||
| 32 | })); | 29 | })); |
| 33 | 30 | ||
| 34 | beforeEach(function () { | 31 | beforeEach(function () { |
| 35 | - gs.init(); | 32 | + d3Elem = d3.select('body').append('div').attr('id', 'testDiv'); |
| 36 | - d3Elem = d3.select('body').append('div').attr('id', 'testToolbar'); | ||
| 37 | }); | 33 | }); |
| 38 | 34 | ||
| 39 | afterEach(function () { | 35 | afterEach(function () { |
| 40 | - d3.select('#testToolbar').remove(); | 36 | + d3.select('#testDiv').remove(); |
| 41 | }); | 37 | }); |
| 42 | 38 | ||
| 39 | + | ||
| 40 | + // re-usable null function | ||
| 41 | + function nullFunc () {} | ||
| 42 | + | ||
| 43 | it('should define ButtonService', function () { | 43 | it('should define ButtonService', function () { |
| 44 | expect(bns).toBeDefined(); | 44 | expect(bns).toBeDefined(); |
| 45 | }); | 45 | }); |
| ... | @@ -51,19 +51,21 @@ describe('factory: fw/widget/button.js', function () { | ... | @@ -51,19 +51,21 @@ describe('factory: fw/widget/button.js', function () { |
| 51 | }); | 51 | }); |
| 52 | 52 | ||
| 53 | it('should verify button glyph', function () { | 53 | it('should verify button glyph', function () { |
| 54 | - var btn = bns.button(d3Elem, 'tbar0-btn-0', 'crown', function () {}); | 54 | + var btn = bns.button(d3Elem, 'foo-id', 'crown', nullFunc); |
| 55 | - expect((btn.el).classed('btn')).toBeTruthy(); | 55 | + var el = d3Elem.select('#foo-id'); |
| 56 | - expect((btn.el).attr('id')).toBe('tbar0-btn-0'); | 56 | + expect(el.classed('button')).toBeTruthy(); |
| 57 | - expect((btn.el).select('svg')).toBeTruthy(); | 57 | + expect(el.attr('id')).toBe('foo-id'); |
| 58 | - expect((btn.el).select('use')).toBeTruthy(); | 58 | + expect(el.select('svg')).toBeTruthy(); |
| 59 | - expect((btn.el).select('use').classed('glyph')).toBeTruthy(); | 59 | + expect(el.select('use')).toBeTruthy(); |
| 60 | - expect((btn.el).select('use').attr('xlink:href')).toBe('#crown'); | 60 | + expect(el.select('use').classed('glyph')).toBeTruthy(); |
| 61 | + expect(el.select('use').attr('xlink:href')).toBe('#crown'); | ||
| 61 | }); | 62 | }); |
| 62 | 63 | ||
| 64 | + | ||
| 63 | it('should not append button to an undefined div', function () { | 65 | it('should not append button to an undefined div', function () { |
| 64 | spyOn($log, 'warn'); | 66 | spyOn($log, 'warn'); |
| 65 | - expect(bns.button(undefined, 'id', 'gid', function () {})).toBeNull(); | 67 | + expect(bns.button(null, 'id', 'gid', nullFunc)).toBeNull(); |
| 66 | - expect($log.warn).toHaveBeenCalledWith('Button cannot append to div'); | 68 | + expect($log.warn).toHaveBeenCalledWith('div undefined (button)'); |
| 67 | }); | 69 | }); |
| 68 | 70 | ||
| 69 | it('should verify button callback', function () { | 71 | it('should verify button callback', function () { |
| ... | @@ -71,7 +73,7 @@ describe('factory: fw/widget/button.js', function () { | ... | @@ -71,7 +73,7 @@ describe('factory: fw/widget/button.js', function () { |
| 71 | function cb() { count++; } | 73 | function cb() { count++; } |
| 72 | var btn = bns.button(d3Elem, 'test', 'nothing', cb); | 74 | var btn = bns.button(d3Elem, 'test', 'nothing', cb); |
| 73 | expect(count).toBe(0); | 75 | expect(count).toBe(0); |
| 74 | - btn.click(); | 76 | + d3Elem.select('#test').on('click')(); |
| 75 | expect(count).toBe(1); | 77 | expect(count).toBe(1); |
| 76 | }); | 78 | }); |
| 77 | 79 | ||
| ... | @@ -79,26 +81,25 @@ describe('factory: fw/widget/button.js', function () { | ... | @@ -79,26 +81,25 @@ describe('factory: fw/widget/button.js', function () { |
| 79 | var count = 0; | 81 | var count = 0; |
| 80 | var btn = bns.button(d3Elem, 'test', 'nothing', 'foo'); | 82 | var btn = bns.button(d3Elem, 'test', 'nothing', 'foo'); |
| 81 | expect(count).toBe(0); | 83 | expect(count).toBe(0); |
| 82 | - btn.click(); | 84 | + d3Elem.select('#test').on('click')(); |
| 83 | expect(count).toBe(0); | 85 | expect(count).toBe(0); |
| 84 | }); | 86 | }); |
| 85 | 87 | ||
| 86 | it('should not append toggle to an undefined div', function () { | 88 | it('should not append toggle to an undefined div', function () { |
| 87 | spyOn($log, 'warn'); | 89 | spyOn($log, 'warn'); |
| 88 | - expect(bns.toggle(undefined, 'id', 'gid', false, | 90 | + expect(bns.toggle(undefined, 'id', 'gid', false, nullFunc)).toBeNull(); |
| 89 | - function () {})).toBeNull(); | 91 | + expect($log.warn).toHaveBeenCalledWith('div undefined (toggle button)'); |
| 90 | - expect($log.warn).toHaveBeenCalledWith('Toggle cannot append to div'); | ||
| 91 | }); | 92 | }); |
| 92 | 93 | ||
| 93 | it('should verify toggle glyph', function () { | 94 | it('should verify toggle glyph', function () { |
| 94 | - var tog = bns.toggle(d3Elem, 'tbar0-tog-0', 'crown', | 95 | + var tog = bns.toggle(d3Elem, 'foo-id', 'crown', false, nullFunc); |
| 95 | - false, function () {}); | 96 | + var el = d3Elem.select('#foo-id'); |
| 96 | - expect((tog.el).classed('tog')).toBeTruthy(); | 97 | + expect(el.classed('toggleButton')).toBeTruthy(); |
| 97 | - expect((tog.el).attr('id')).toBe('tbar0-tog-0'); | 98 | + expect(el.attr('id')).toBe('foo-id'); |
| 98 | - expect((tog.el).select('svg')).toBeTruthy(); | 99 | + expect(el.select('svg')).toBeTruthy(); |
| 99 | - expect((tog.el).select('use')).toBeTruthy(); | 100 | + expect(el.select('use')).toBeTruthy(); |
| 100 | - expect((tog.el).select('use').classed('glyph')).toBeTruthy(); | 101 | + expect(el.select('use').classed('glyph')).toBeTruthy(); |
| 101 | - expect((tog.el).select('use').attr('xlink:href')).toBe('#crown'); | 102 | + expect(el.select('use').attr('xlink:href')).toBe('#crown'); |
| 102 | }); | 103 | }); |
| 103 | 104 | ||
| 104 | it('should toggle the selected state', function () { | 105 | it('should toggle the selected state', function () { |
| ... | @@ -138,27 +139,31 @@ describe('factory: fw/widget/button.js', function () { | ... | @@ -138,27 +139,31 @@ describe('factory: fw/widget/button.js', function () { |
| 138 | it('should not append radio button set to an undefined div', function () { | 139 | it('should not append radio button set to an undefined div', function () { |
| 139 | spyOn($log, 'warn'); | 140 | spyOn($log, 'warn'); |
| 140 | expect(bns.radioSet(undefined, 'id', [])).toBeNull(); | 141 | expect(bns.radioSet(undefined, 'id', [])).toBeNull(); |
| 141 | - expect($log.warn).toHaveBeenCalledWith('Radio buttons cannot append ' + | 142 | + expect($log.warn).toHaveBeenCalledWith('div undefined (radio button set)'); |
| 142 | - 'to div'); | ||
| 143 | }); | 143 | }); |
| 144 | 144 | ||
| 145 | it('should not create radio button set from a non-array', function () { | 145 | it('should not create radio button set from a non-array', function () { |
| 146 | var rads = {test: 'test'}; | 146 | var rads = {test: 'test'}; |
| 147 | + var warning = 'invalid array (radio button set)'; | ||
| 148 | + | ||
| 147 | spyOn($log, 'warn'); | 149 | spyOn($log, 'warn'); |
| 148 | 150 | ||
| 149 | expect(bns.radioSet(d3Elem, 'test', rads)).toBeNull(); | 151 | expect(bns.radioSet(d3Elem, 'test', rads)).toBeNull(); |
| 150 | - expect($log.warn).toHaveBeenCalledWith('Radio button set is not ' + | 152 | + expect($log.warn).toHaveBeenCalledWith(warning); |
| 151 | - 'an array'); | ||
| 152 | rads = 'rads'; | 153 | rads = 'rads'; |
| 153 | expect(bns.radioSet(d3Elem, 'test', rads)).toBeNull(); | 154 | expect(bns.radioSet(d3Elem, 'test', rads)).toBeNull(); |
| 154 | - expect($log.warn).toHaveBeenCalledWith('Radio button set is not ' + | 155 | + expect($log.warn).toHaveBeenCalledWith(warning); |
| 155 | - 'an array'); | ||
| 156 | rads = {arr: [1, 2, 3]}; | 156 | rads = {arr: [1, 2, 3]}; |
| 157 | expect(bns.radioSet(d3Elem, 'test', rads)).toBeNull(); | 157 | expect(bns.radioSet(d3Elem, 'test', rads)).toBeNull(); |
| 158 | - expect($log.warn).toHaveBeenCalledWith('Radio button set is not ' + | 158 | + expect($log.warn).toHaveBeenCalledWith(warning); |
| 159 | - 'an array'); | ||
| 160 | }); | 159 | }); |
| 161 | 160 | ||
| 161 | + // =================================================================== | ||
| 162 | + // =================================================================== | ||
| 163 | + // =================================================================== | ||
| 164 | + | ||
| 165 | + | ||
| 166 | + | ||
| 162 | it('should not create radio button set from empty array', function () { | 167 | it('should not create radio button set from empty array', function () { |
| 163 | var rads = []; | 168 | var rads = []; |
| 164 | spyOn($log, 'warn'); | 169 | spyOn($log, 'warn'); | ... | ... |
| ... | @@ -24,7 +24,7 @@ module.exports = function(config) { | ... | @@ -24,7 +24,7 @@ module.exports = function(config) { |
| 24 | 24 | ||
| 25 | // production code... | 25 | // production code... |
| 26 | // make sure modules are defined first... | 26 | // make sure modules are defined first... |
| 27 | - '../app/onos.js', | 27 | + '../onos.js', |
| 28 | 28 | ||
| 29 | '../app/fw/util/util.js', | 29 | '../app/fw/util/util.js', |
| 30 | '../app/fw/svg/svg.js', | 30 | '../app/fw/svg/svg.js', | ... | ... |
-
Please register or login to post a comment