GUI -- Refactored ToolbarService to have only new toolbar functions.
Change-Id: I0319335915f37d3a63b3ac734d8f8e00ebed20ae
Showing
3 changed files
with
53 additions
and
380 deletions
| ... | @@ -33,7 +33,7 @@ | ... | @@ -33,7 +33,7 @@ |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | function button(div, id, gid, cb, tooltip) { | 35 | function button(div, id, gid, cb, tooltip) { |
| 36 | - if (!div || div.empty()) { | 36 | + if (!div) { |
| 37 | $log.warn('Button cannot append to div'); | 37 | $log.warn('Button cannot append to div'); |
| 38 | return null; | 38 | return null; |
| 39 | } | 39 | } |
| ... | @@ -53,7 +53,7 @@ | ... | @@ -53,7 +53,7 @@ |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | function toggle(div, id, gid, initState, cb, tooltip) { | 55 | function toggle(div, id, gid, initState, cb, tooltip) { |
| 56 | - if (!div || div.empty()) { | 56 | + if (!div) { |
| 57 | $log.warn('Toggle cannot append to div'); | 57 | $log.warn('Toggle cannot append to div'); |
| 58 | return null; | 58 | return null; |
| 59 | } | 59 | } |
| ... | @@ -84,7 +84,7 @@ | ... | @@ -84,7 +84,7 @@ |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | function radioSet(div, id, rset) { | 86 | function radioSet(div, id, rset) { |
| 87 | - if (!div || div.empty()) { | 87 | + if (!div) { |
| 88 | $log.warn('Radio buttons cannot append to div'); | 88 | $log.warn('Radio buttons cannot append to div'); |
| 89 | return null; | 89 | return null; |
| 90 | } | 90 | } | ... | ... |
| ... | @@ -22,80 +22,16 @@ | ... | @@ -22,80 +22,16 @@ |
| 22 | 22 | ||
| 23 | var $log, fs, ps, bns; | 23 | var $log, fs, ps, bns; |
| 24 | 24 | ||
| 25 | - var toolBtnIds = {}, | ||
| 26 | - toolbarPanel, | ||
| 27 | - toolbarDiv; | ||
| 28 | - | ||
| 29 | var ids = [], | 25 | var ids = [], |
| 30 | tbarId, | 26 | tbarId, |
| 31 | tbarPanel, | 27 | tbarPanel, |
| 32 | - tbarDiv; | 28 | + tbarDiv, |
| 29 | + tbarArrowDiv; | ||
| 33 | 30 | ||
| 34 | function init() { | 31 | function init() { |
| 35 | - toolBtnIds = {}; | ||
| 36 | ids = []; | 32 | ids = []; |
| 37 | } | 33 | } |
| 38 | 34 | ||
| 39 | - function addButton(btn) { | ||
| 40 | - // pass in button object and pass separate the pieces in this function, | ||
| 41 | - // to be passed to ButtonService | ||
| 42 | - var btndiv = toolbarDiv.append('div').attr('class', 'btn'); | ||
| 43 | - // use ButtonService to create btn with other arguments and btndiv | ||
| 44 | - } | ||
| 45 | - | ||
| 46 | - function addToggle(tog) { | ||
| 47 | - var togdiv = toolbarDiv.append('div').attr('class', 'tog'); | ||
| 48 | - // use ButtonService to create btn with other arguments and togdiv | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - function addRadio(rad) { | ||
| 52 | - var raddiv = toolbarDiv.append('div').attr('class', 'rad'); | ||
| 53 | - // use ButtonService to create btn with other arguments and raddiv | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - function addSeparator() { | ||
| 57 | - toolbarDiv.append('div') | ||
| 58 | - .attr('class', 'sep') | ||
| 59 | - .style({'width': '2px', | ||
| 60 | - 'border-width': '1px', | ||
| 61 | - 'border-style': 'solid'}); | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - function makeButton(id, gid, cb) { | ||
| 65 | - return { | ||
| 66 | - t: 'btn', | ||
| 67 | - id: id, | ||
| 68 | - gid: gid, | ||
| 69 | - cb: cb | ||
| 70 | - }; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - function makeToggle(id, gid, cb) { | ||
| 74 | - return { | ||
| 75 | - t: 'tog', | ||
| 76 | - id: id, | ||
| 77 | - gid: gid, | ||
| 78 | - cb: cb | ||
| 79 | - }; | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - function makeRadio(id, gid, cb) { | ||
| 83 | - (id in toolBtnIds) ? toolBtnIds[id] += 1 : toolBtnIds[id] = 0; | ||
| 84 | - return { | ||
| 85 | - t: 'rad', | ||
| 86 | - id: id + '-' + toolBtnIds[id], | ||
| 87 | - rid: toolBtnIds[id] + '', | ||
| 88 | - gid: gid, | ||
| 89 | - cb: cb | ||
| 90 | - }; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - function separator() { | ||
| 94 | - return { | ||
| 95 | - t: 'sep' | ||
| 96 | - }; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | function validId(id, caller) { | 35 | function validId(id, caller) { |
| 100 | if (fs.inArray(id, ids) !== -1) { | 36 | if (fs.inArray(id, ids) !== -1) { |
| 101 | $log.warn(caller + ': ID already exists'); | 37 | $log.warn(caller + ': ID already exists'); |
| ... | @@ -104,39 +40,38 @@ | ... | @@ -104,39 +40,38 @@ |
| 104 | return true; | 40 | return true; |
| 105 | } | 41 | } |
| 106 | 42 | ||
| 107 | - function addButton1(id, gid, cb, tooltip) { | 43 | + function addButton(id, gid, cb, tooltip) { |
| 108 | var btnId = tbarId + '-' + id; | 44 | var btnId = tbarId + '-' + id; |
| 109 | - if (!validId(btnId, 'addButton')) { | 45 | + if (!validId(btnId, 'addButton')) { return null; } |
| 110 | - return null; | ||
| 111 | - } | ||
| 112 | ids.push(btnId); | 46 | ids.push(btnId); |
| 113 | return bns.button(tbarDiv, btnId, gid, cb, tooltip); | 47 | return bns.button(tbarDiv, btnId, gid, cb, tooltip); |
| 114 | } | 48 | } |
| 115 | 49 | ||
| 116 | - function addToggle1(id, gid, initState, cb, tooltip) { | 50 | + function addToggle(id, gid, initState, cb, tooltip) { |
| 117 | var togId = tbarId + '-' + id; | 51 | var togId = tbarId + '-' + id; |
| 118 | - if (!validId(togId, 'addToggle')) { | 52 | + if (!validId(togId, 'addToggle')) { return null; } |
| 119 | - return null; | ||
| 120 | - } | ||
| 121 | ids.push(togId); | 53 | ids.push(togId); |
| 122 | return bns.toggle(tbarDiv, togId, gid, initState, cb, tooltip); | 54 | return bns.toggle(tbarDiv, togId, gid, initState, cb, tooltip); |
| 123 | } | 55 | } |
| 124 | 56 | ||
| 125 | function addRadioSet(id, rset) { | 57 | function addRadioSet(id, rset) { |
| 126 | var radId = tbarId + '-' + id; | 58 | var radId = tbarId + '-' + id; |
| 127 | - if (!validId(radId, 'addRadioSet')) { | 59 | + if (!validId(radId, 'addRadioSet')) { return null; } |
| 128 | - return null; | ||
| 129 | - } | ||
| 130 | ids.push(radId); | 60 | ids.push(radId); |
| 131 | return bns.radioSet(tbarDiv, radId, rset); | 61 | return bns.radioSet(tbarDiv, radId, rset); |
| 132 | } | 62 | } |
| 133 | 63 | ||
| 134 | - // TODO: finish this and remove unneeded code | 64 | + function addSeparator() { |
| 135 | - function addSeparator1() { | 65 | + if (!tbarDiv) { |
| 136 | - | 66 | + $log.warn('Separator cannot append to div'); |
| 67 | + return null; | ||
| 68 | + } | ||
| 69 | + tbarArrowDiv = tbarDiv.append('div') | ||
| 70 | + .classed('sep', true) | ||
| 71 | + .style('width', '2px'); | ||
| 137 | } | 72 | } |
| 138 | 73 | ||
| 139 | - function createToolbar1(id, settings) { | 74 | + function createToolbar(id, settings) { |
| 140 | if (!id) { | 75 | if (!id) { |
| 141 | $log.warn('createToolbar: no ID given'); | 76 | $log.warn('createToolbar: no ID given'); |
| 142 | return null; | 77 | return null; |
| ... | @@ -144,78 +79,23 @@ | ... | @@ -144,78 +79,23 @@ |
| 144 | tbarId = 'tbar-' + id; | 79 | tbarId = 'tbar-' + id; |
| 145 | var opts = fs.isO(settings) || {}; // default settings should be put here | 80 | var opts = fs.isO(settings) || {}; // default settings should be put here |
| 146 | 81 | ||
| 147 | - if (!validId(tbarId, 'createToolbar')) { | 82 | + if (!validId(tbarId, 'createToolbar')) { return null; } |
| 148 | - return null; | ||
| 149 | - } | ||
| 150 | ids.push(tbarId); | 83 | ids.push(tbarId); |
| 151 | 84 | ||
| 152 | tbarPanel = ps.createPanel(tbarId, opts); | 85 | tbarPanel = ps.createPanel(tbarId, opts); |
| 153 | tbarDiv = tbarPanel.classed('toolbar', true); | 86 | tbarDiv = tbarPanel.classed('toolbar', true); |
| 154 | 87 | ||
| 155 | - // TODO: change names of functions | ||
| 156 | return { | 88 | return { |
| 157 | - addButton1: addButton1, | 89 | + addButton: addButton, |
| 158 | - addToggle1: addToggle1, | 90 | + addToggle: addToggle, |
| 159 | addRadioSet: addRadioSet, | 91 | addRadioSet: addRadioSet, |
| 160 | - addSeparator1: addSeparator1 | 92 | + addSeparator: addSeparator |
| 161 | } | 93 | } |
| 162 | } | 94 | } |
| 163 | 95 | ||
| 164 | - // function currently not working | 96 | + //function currently not working |
| 165 | function destroyToolbar(id) { | 97 | function destroyToolbar(id) { |
| 166 | - ps.destroyPanel(id); | 98 | + //ps.destroyPanel(id); |
| 167 | - } | ||
| 168 | - | ||
| 169 | - function createToolbar(tbarId, tools) { | ||
| 170 | - var api; | ||
| 171 | - | ||
| 172 | - if (!tbarId) { | ||
| 173 | - $log.warn('createToolbar: no ID given'); | ||
| 174 | - return null; | ||
| 175 | - } | ||
| 176 | - if (!tools || tools.constructor !== Array || !tools.length) { | ||
| 177 | - $log.warn('createToolbar: no tools given'); | ||
| 178 | - return null; | ||
| 179 | - } | ||
| 180 | - | ||
| 181 | - for (var i = 0; i < tools.length; i += 1) { | ||
| 182 | - if (tools[i].t === 'rad' || tools[i].t === 'sep') { | ||
| 183 | - continue; | ||
| 184 | - } else { | ||
| 185 | - if (tools[i].id in toolBtnIds) { | ||
| 186 | - $log.warn('createToolbar: item with id ' | ||
| 187 | - + tools[i].id + ' already exists'); | ||
| 188 | - return null; | ||
| 189 | - } | ||
| 190 | - toolBtnIds[tools[i].id] = 1; | ||
| 191 | - } | ||
| 192 | - } | ||
| 193 | - | ||
| 194 | - // need to pass in an object with settings for where the toolbar will go | ||
| 195 | - toolbarPanel = ps.createPanel(tbarId, {}); | ||
| 196 | - toolbarPanel.classed('toolbar', true); | ||
| 197 | - toolbarDiv = toolbarPanel.el(); | ||
| 198 | - | ||
| 199 | - tools.forEach(function (tool) { | ||
| 200 | - switch (tool['t']) { | ||
| 201 | - case 'btn': addButton(tool); break; | ||
| 202 | - case 'tog': addToggle(tool); break; | ||
| 203 | - case 'rad': addRadio(tool); break; | ||
| 204 | - default: addSeparator(); break; | ||
| 205 | - } | ||
| 206 | - }); | ||
| 207 | - | ||
| 208 | - // api functions to be returned defined here | ||
| 209 | - | ||
| 210 | - function size(arr) { | ||
| 211 | - return arr.length; | ||
| 212 | - } | ||
| 213 | - | ||
| 214 | - api = { | ||
| 215 | - size: size | ||
| 216 | - }; | ||
| 217 | - | ||
| 218 | - return api; | ||
| 219 | } | 99 | } |
| 220 | 100 | ||
| 221 | angular.module('onosWidget') | 101 | angular.module('onosWidget') |
| ... | @@ -229,14 +109,8 @@ | ... | @@ -229,14 +109,8 @@ |
| 229 | 109 | ||
| 230 | return { | 110 | return { |
| 231 | init: init, | 111 | init: init, |
| 232 | - makeButton: makeButton, | ||
| 233 | - makeToggle: makeToggle, | ||
| 234 | - makeRadio: makeRadio, | ||
| 235 | - separator: separator, | ||
| 236 | createToolbar: createToolbar, | 112 | createToolbar: createToolbar, |
| 237 | - createToolbar1: createToolbar1, | ||
| 238 | destroyToolbar: destroyToolbar | 113 | destroyToolbar: destroyToolbar |
| 239 | }; | 114 | }; |
| 240 | }]); | 115 | }]); |
| 241 | - | ||
| 242 | }()); | 116 | }()); | ... | ... |
| ... | @@ -53,243 +53,31 @@ describe('factory: fw/widget/toolbar.js', function () { | ... | @@ -53,243 +53,31 @@ describe('factory: fw/widget/toolbar.js', function () { |
| 53 | 53 | ||
| 54 | it('should define api functions', function () { | 54 | it('should define api functions', function () { |
| 55 | expect(fs.areFunctions(tbs, [ | 55 | expect(fs.areFunctions(tbs, [ |
| 56 | - 'init', 'makeButton', 'makeToggle', 'makeRadio', 'separator', | 56 | + 'init', |
| 57 | - 'createToolbar', 'createToolbar1', 'destroyToolbar' | 57 | + 'createToolbar', 'destroyToolbar' |
| 58 | ])).toBeTruthy(); | 58 | ])).toBeTruthy(); |
| 59 | }); | 59 | }); |
| 60 | 60 | ||
| 61 | - function toolbarSelection() { | ||
| 62 | - return d3Elem.selectAll('.toolbar'); | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - it('should have no toolbars to start', function () { | ||
| 66 | - expect(toolbarSelection().size()).toBe(0); | ||
| 67 | - }); | ||
| 68 | - | ||
| 69 | - it('should log a warning if no ID is given', function () { | ||
| 70 | - spyOn($log, 'warn'); | ||
| 71 | - var tbar = tbs.createToolbar(); | ||
| 72 | - expect(tbar).toBeNull(); | ||
| 73 | - expect($log.warn).toHaveBeenCalledWith('createToolbar: no ID given'); | ||
| 74 | - expect(toolbarSelection().size()).toBe(0); | ||
| 75 | - }); | ||
| 76 | - | ||
| 77 | - it('should log a warning if no tools are given', function () { | ||
| 78 | - spyOn($log, 'warn'); | ||
| 79 | - var tbar = tbs.createToolbar(true); | ||
| 80 | - expect(tbar).toBeNull(); | ||
| 81 | - expect($log.warn).toHaveBeenCalledWith('createToolbar: no tools given'); | ||
| 82 | - expect(toolbarSelection().size()).toBe(0); | ||
| 83 | - }); | ||
| 84 | - | ||
| 85 | - it('should log a warning if tools are not an array', function () { | ||
| 86 | - spyOn($log, 'warn'); | ||
| 87 | - var tbar = tbs.createToolbar(true, {}); | ||
| 88 | - expect(tbar).toBeNull(); | ||
| 89 | - expect($log.warn).toHaveBeenCalledWith('createToolbar: no tools given'); | ||
| 90 | - expect(toolbarSelection().size()).toBe(0); | ||
| 91 | - }); | ||
| 92 | - | ||
| 93 | - it('should log a warning if tools array is empty', function () { | ||
| 94 | - spyOn($log, 'warn'); | ||
| 95 | - var tbar = tbs.createToolbar(true, []); | ||
| 96 | - expect(tbar).toBeNull(); | ||
| 97 | - expect($log.warn).toHaveBeenCalledWith('createToolbar: no tools given'); | ||
| 98 | - expect(toolbarSelection().size()).toBe(0); | ||
| 99 | - }); | ||
| 100 | - | ||
| 101 | - it("should verify makeButton's returned object", function () { | ||
| 102 | - var button = tbs.makeButton('foo', 'glyph-bar', function () {}); | ||
| 103 | - | ||
| 104 | - expect(button.t).toBe('btn'); | ||
| 105 | - expect(button.id).toBe('foo'); | ||
| 106 | - expect(button.gid).toBe('glyph-bar'); | ||
| 107 | - expect(fs.isF(button.cb)).toBeTruthy(); | ||
| 108 | - }); | ||
| 109 | - | ||
| 110 | - it("should verify makeToggle's returned object", function () { | ||
| 111 | - var toggle = tbs.makeToggle('foo', 'glyph-bar', function () {}); | ||
| 112 | - | ||
| 113 | - expect(toggle.t).toBe('tog'); | ||
| 114 | - expect(toggle.id).toBe('foo'); | ||
| 115 | - expect(toggle.gid).toBe('glyph-bar'); | ||
| 116 | - expect(fs.isF(toggle.cb)).toBeTruthy(); | ||
| 117 | - }); | ||
| 118 | - | ||
| 119 | - it("should verify makeRadio's returned object", function () { | ||
| 120 | - var rFoo0 = tbs.makeRadio('foo', 'glyph-foo0', function () {}); | ||
| 121 | - var rFoo1 = tbs.makeRadio('foo', 'glyph-foo1', function () {}); | ||
| 122 | - var rFoo2 = tbs.makeRadio('foo', 'glyph-foo2', function () {}); | ||
| 123 | - var rBar0 = tbs.makeRadio('bar', 'glyph-bar0', function () {}); | ||
| 124 | - var rBar1 = tbs.makeRadio('bar', 'glyph-bar1', function () {}); | ||
| 125 | - var rFoo3 = tbs.makeRadio('foo', 'glyph-foo3', function () {}); | ||
| 126 | - | ||
| 127 | - expect(rFoo0.t).toBe('rad'); | ||
| 128 | - expect(rFoo0.id).toBe('foo-0'); | ||
| 129 | - expect(rFoo0.rid).toBe('0'); | ||
| 130 | - expect(rFoo0.gid).toBe('glyph-foo0'); | ||
| 131 | - expect(fs.isF(rFoo0.cb)).toBeTruthy(); | ||
| 132 | - | ||
| 133 | - expect(rFoo1.t).toBe('rad'); | ||
| 134 | - expect(rFoo1.id).toBe('foo-1'); | ||
| 135 | - expect(rFoo1.rid).toBe('1'); | ||
| 136 | - expect(rFoo1.gid).toBe('glyph-foo1'); | ||
| 137 | - expect(fs.isF(rFoo1.cb)).toBeTruthy(); | ||
| 138 | - | ||
| 139 | - expect(rFoo2.t).toBe('rad'); | ||
| 140 | - expect(rFoo2.id).toBe('foo-2'); | ||
| 141 | - expect(rFoo2.rid).toBe('2'); | ||
| 142 | - expect(rFoo2.gid).toBe('glyph-foo2'); | ||
| 143 | - expect(fs.isF(rFoo2.cb)).toBeTruthy(); | ||
| 144 | - | ||
| 145 | - expect(rFoo3.t).toBe('rad'); | ||
| 146 | - expect(rFoo3.id).toBe('foo-3'); | ||
| 147 | - expect(rFoo3.rid).toBe('3'); | ||
| 148 | - expect(rFoo3.gid).toBe('glyph-foo3'); | ||
| 149 | - expect(fs.isF(rFoo3.cb)).toBeTruthy(); | ||
| 150 | - | ||
| 151 | - expect(rBar0.t).toBe('rad'); | ||
| 152 | - expect(rBar0.id).toBe('bar-0'); | ||
| 153 | - expect(rBar0.rid).toBe('0'); | ||
| 154 | - expect(rBar0.gid).toBe('glyph-bar0'); | ||
| 155 | - expect(fs.isF(rBar0.cb)).toBeTruthy(); | ||
| 156 | - | ||
| 157 | - expect(rBar1.t).toBe('rad'); | ||
| 158 | - expect(rBar1.id).toBe('bar-1'); | ||
| 159 | - expect(rBar1.rid).toBe('1'); | ||
| 160 | - expect(rBar1.gid).toBe('glyph-bar1'); | ||
| 161 | - expect(fs.isF(rBar1.cb)).toBeTruthy(); | ||
| 162 | - }); | ||
| 163 | - | ||
| 164 | - it("should verify separator's returned object", function () { | ||
| 165 | - var separator = tbs.separator(); | ||
| 166 | - expect(separator.t).toBe('sep'); | ||
| 167 | - }); | ||
| 168 | - | ||
| 169 | - it('should log a warning if btn id is already in use', function () { | ||
| 170 | - var tools = [ | ||
| 171 | - tbs.makeButton('id0', 'glyph-id0', function () {}), | ||
| 172 | - tbs.makeButton('id0', 'glyph-id0', function () {}) | ||
| 173 | - ]; | ||
| 174 | - | ||
| 175 | - spyOn($log, 'warn'); | ||
| 176 | - var tbar = tbs.createToolbar('someId', tools); | ||
| 177 | - expect(tbar).toBeNull(); | ||
| 178 | - expect($log.warn).toHaveBeenCalledWith('createToolbar: item with id ' + | ||
| 179 | - 'id0 already exists'); | ||
| 180 | - expect(toolbarSelection().size()).toBe(0); | ||
| 181 | - }); | ||
| 182 | - | ||
| 183 | - it('should log a warning if tog id is already in use', function () { | ||
| 184 | - var tools = [ | ||
| 185 | - tbs.makeToggle('id0', 'glyph-id0', function () {}), | ||
| 186 | - tbs.makeToggle('id1', 'glyph-id1', function () {}), | ||
| 187 | - tbs.makeToggle('id0', 'glyph-id0', function () {}) | ||
| 188 | - ]; | ||
| 189 | - | ||
| 190 | - spyOn($log, 'warn'); | ||
| 191 | - var tbar = tbs.createToolbar('someId', tools); | ||
| 192 | - expect(tbar).toBeNull(); | ||
| 193 | - expect($log.warn).toHaveBeenCalledWith('createToolbar: item with id ' + | ||
| 194 | - 'id0 already exists'); | ||
| 195 | - expect(toolbarSelection().size()).toBe(0); | ||
| 196 | - }); | ||
| 197 | - | ||
| 198 | - it('should create a toolbar', function () { | ||
| 199 | - // need to create a button so it does not throw errors | ||
| 200 | - var tools = [ | ||
| 201 | - tbs.makeButton('btn0', 'glyph0', function () {}) | ||
| 202 | - ]; | ||
| 203 | - spyOn($log, 'warn'); | ||
| 204 | - var tbar = tbs.createToolbar('test', tools); | ||
| 205 | - expect($log.warn).not.toHaveBeenCalled(); | ||
| 206 | - expect(toolbarSelection().size()).toBe(1); | ||
| 207 | - }); | ||
| 208 | - | ||
| 209 | - it('should test multiple separators in a row', function () { | ||
| 210 | - var tools = [ | ||
| 211 | - tbs.separator(), | ||
| 212 | - tbs.separator(), | ||
| 213 | - tbs.separator() | ||
| 214 | - ]; | ||
| 215 | - spyOn($log, 'warn'); | ||
| 216 | - var tbar = tbs.createToolbar('test', tools); | ||
| 217 | - expect($log.warn).not.toHaveBeenCalled(); | ||
| 218 | - expect(toolbarSelection().size()).toBe(1); | ||
| 219 | - }); | ||
| 220 | - | ||
| 221 | - it('should create a button div', function () { | ||
| 222 | - var tools = [ | ||
| 223 | - tbs.makeButton('btn0', 'glyph0', function () {}) | ||
| 224 | - ]; | ||
| 225 | - spyOn($log, 'warn'); | ||
| 226 | - var tbar = tbs.createToolbar('test', tools); | ||
| 227 | - expect($log.warn).not.toHaveBeenCalled(); | ||
| 228 | - expect(toolbarSelection().size()).toBe(1); | ||
| 229 | - | ||
| 230 | - expect(d3Elem.select('.btn')).toBeTruthy(); | ||
| 231 | - }); | ||
| 232 | - | ||
| 233 | - it('should create a toggle div', function () { | ||
| 234 | - var tools = [ | ||
| 235 | - tbs.makeToggle('tog0', 'glyph0', function () {}) | ||
| 236 | - ]; | ||
| 237 | - spyOn($log, 'warn'); | ||
| 238 | - var tbar = tbs.createToolbar('test', tools); | ||
| 239 | - expect($log.warn).not.toHaveBeenCalled(); | ||
| 240 | - expect(toolbarSelection().size()).toBe(1); | ||
| 241 | - | ||
| 242 | - expect(d3Elem.select('.tog')).toBeTruthy(); | ||
| 243 | - }); | ||
| 244 | - | ||
| 245 | - it('should create a radio btn div', function () { | ||
| 246 | - var tools = [ | ||
| 247 | - tbs.makeRadio('rad0', 'glyph0', function () {}) | ||
| 248 | - ]; | ||
| 249 | - spyOn($log, 'warn'); | ||
| 250 | - var tbar = tbs.createToolbar('test', tools); | ||
| 251 | - expect($log.warn).not.toHaveBeenCalled(); | ||
| 252 | - expect(toolbarSelection().size()).toBe(1); | ||
| 253 | - | ||
| 254 | - expect(d3Elem.select('.rad')).toBeTruthy(); | ||
| 255 | - }); | ||
| 256 | - | ||
| 257 | - | ||
| 258 | - it('should create a separator div', function () { | ||
| 259 | - var tools = [ | ||
| 260 | - tbs.separator() | ||
| 261 | - ]; | ||
| 262 | - tbs.createToolbar('test', tools); | ||
| 263 | - | ||
| 264 | - var sepDiv = d3Elem.select('.sep'); | ||
| 265 | - expect(sepDiv).toBeTruthy(); | ||
| 266 | - expect(sepDiv.style('width')).toBe('2px'); | ||
| 267 | - expect(sepDiv.style('border-width')).toBe('1px'); | ||
| 268 | - expect(sepDiv.style('border-style')).toBe('solid'); | ||
| 269 | - }); | ||
| 270 | - | ||
| 271 | - // ==== new Toolbar Unit tests -------------------------------------------- | ||
| 272 | - | ||
| 273 | it('should warn if createToolbar id is invalid', function () { | 61 | it('should warn if createToolbar id is invalid', function () { |
| 274 | spyOn($log, 'warn'); | 62 | spyOn($log, 'warn'); |
| 275 | - expect(tbs.createToolbar1()).toBeNull(); | 63 | + expect(tbs.createToolbar()).toBeNull(); |
| 276 | expect($log.warn).toHaveBeenCalledWith('createToolbar: no ID given'); | 64 | expect($log.warn).toHaveBeenCalledWith('createToolbar: no ID given'); |
| 277 | 65 | ||
| 278 | - expect(tbs.createToolbar1('test')).toBeTruthy(); | 66 | + expect(tbs.createToolbar('test')).toBeTruthy(); |
| 279 | - expect(tbs.createToolbar1('test')).toBeNull(); | 67 | + expect(tbs.createToolbar('test')).toBeNull(); |
| 280 | expect($log.warn).toHaveBeenCalledWith('createToolbar: ID already exists'); | 68 | expect($log.warn).toHaveBeenCalledWith('createToolbar: ID already exists'); |
| 281 | }); | 69 | }); |
| 282 | 70 | ||
| 283 | it('should create an unpopulated toolbar', function () { | 71 | it('should create an unpopulated toolbar', function () { |
| 284 | spyOn($log, 'warn'); | 72 | spyOn($log, 'warn'); |
| 285 | - expect(tbs.createToolbar1('test')).toBeTruthy(); | 73 | + expect(tbs.createToolbar('test')).toBeTruthy(); |
| 286 | expect($log.warn).not.toHaveBeenCalled(); | 74 | expect($log.warn).not.toHaveBeenCalled(); |
| 287 | }); | 75 | }); |
| 288 | 76 | ||
| 289 | it('should create a button', function () { | 77 | it('should create a button', function () { |
| 290 | spyOn($log, 'warn'); | 78 | spyOn($log, 'warn'); |
| 291 | - var toolbar = tbs.createToolbar1('test'), | 79 | + var toolbar = tbs.createToolbar('test'), |
| 292 | - btn = toolbar.addButton1('btn0', 'gid', function () {}); | 80 | + btn = toolbar.addButton('btn0', 'gid', function () {}); |
| 293 | expect(btn).not.toBeNull(); | 81 | expect(btn).not.toBeNull(); |
| 294 | expect(btn.id).toBe('tbar-test-btn0'); | 82 | expect(btn.id).toBe('tbar-test-btn0'); |
| 295 | expect($log.warn).not.toHaveBeenCalled(); | 83 | expect($log.warn).not.toHaveBeenCalled(); |
| ... | @@ -297,9 +85,9 @@ describe('factory: fw/widget/toolbar.js', function () { | ... | @@ -297,9 +85,9 @@ describe('factory: fw/widget/toolbar.js', function () { |
| 297 | 85 | ||
| 298 | it('should not create a button with a duplicate id', function () { | 86 | it('should not create a button with a duplicate id', function () { |
| 299 | spyOn($log, 'warn'); | 87 | spyOn($log, 'warn'); |
| 300 | - var toolbar = tbs.createToolbar1('test'), | 88 | + var toolbar = tbs.createToolbar('test'), |
| 301 | - btn = toolbar.addButton1('btn0', 'gid', function () {}), | 89 | + btn = toolbar.addButton('btn0', 'gid', function () {}), |
| 302 | - btn1 = toolbar.addButton1('btn0', 'gid', function () {}); | 90 | + btn1 = toolbar.addButton('btn0', 'gid', function () {}); |
| 303 | expect(btn).not.toBeNull(); | 91 | expect(btn).not.toBeNull(); |
| 304 | expect(btn.id).toBe('tbar-test-btn0'); | 92 | expect(btn.id).toBe('tbar-test-btn0'); |
| 305 | expect($log.warn).toHaveBeenCalledWith('addButton: ID already exists'); | 93 | expect($log.warn).toHaveBeenCalledWith('addButton: ID already exists'); |
| ... | @@ -308,8 +96,8 @@ describe('factory: fw/widget/toolbar.js', function () { | ... | @@ -308,8 +96,8 @@ describe('factory: fw/widget/toolbar.js', function () { |
| 308 | 96 | ||
| 309 | it('should create a toggle', function () { | 97 | it('should create a toggle', function () { |
| 310 | spyOn($log, 'warn'); | 98 | spyOn($log, 'warn'); |
| 311 | - var toolbar = tbs.createToolbar1('test'), | 99 | + var toolbar = tbs.createToolbar('test'), |
| 312 | - tog = toolbar.addButton1('tog0', 'gid', false, function () {}); | 100 | + tog = toolbar.addButton('tog0', 'gid', false, function () {}); |
| 313 | expect(tog).not.toBeNull(); | 101 | expect(tog).not.toBeNull(); |
| 314 | expect(tog.id).toBe('tbar-test-tog0'); | 102 | expect(tog.id).toBe('tbar-test-tog0'); |
| 315 | expect($log.warn).not.toHaveBeenCalled(); | 103 | expect($log.warn).not.toHaveBeenCalled(); |
| ... | @@ -317,9 +105,9 @@ describe('factory: fw/widget/toolbar.js', function () { | ... | @@ -317,9 +105,9 @@ describe('factory: fw/widget/toolbar.js', function () { |
| 317 | 105 | ||
| 318 | it('should not create a toggle with a duplicate id', function () { | 106 | it('should not create a toggle with a duplicate id', function () { |
| 319 | spyOn($log, 'warn'); | 107 | spyOn($log, 'warn'); |
| 320 | - var toolbar = tbs.createToolbar1('test'), | 108 | + var toolbar = tbs.createToolbar('test'), |
| 321 | - tog = toolbar.addToggle1('tog0', 'gid', false, function () {}), | 109 | + tog = toolbar.addToggle('tog0', 'gid', false, function () {}), |
| 322 | - tog1 = toolbar.addToggle1('tog0', 'gid', true, function () {}); | 110 | + tog1 = toolbar.addToggle('tog0', 'gid', true, function () {}); |
| 323 | expect(tog).not.toBeNull(); | 111 | expect(tog).not.toBeNull(); |
| 324 | expect(tog.id).toBe('tbar-test-tog0'); | 112 | expect(tog.id).toBe('tbar-test-tog0'); |
| 325 | expect($log.warn).toHaveBeenCalledWith('addToggle: ID already exists'); | 113 | expect($log.warn).toHaveBeenCalledWith('addToggle: ID already exists'); |
| ... | @@ -329,7 +117,7 @@ describe('factory: fw/widget/toolbar.js', function () { | ... | @@ -329,7 +117,7 @@ describe('factory: fw/widget/toolbar.js', function () { |
| 329 | 117 | ||
| 330 | it('should create a radio button set', function () { | 118 | it('should create a radio button set', function () { |
| 331 | spyOn($log, 'warn'); | 119 | spyOn($log, 'warn'); |
| 332 | - var toolbar = tbs.createToolbar1('test'), | 120 | + var toolbar = tbs.createToolbar('test'), |
| 333 | rset = [ | 121 | rset = [ |
| 334 | { gid: 'crown', cb: function () {}, tooltip: 'nothing' }, | 122 | { gid: 'crown', cb: function () {}, tooltip: 'nothing' }, |
| 335 | { gid: 'bird', cb: function () {}, tooltip: 'nothing' } | 123 | { gid: 'bird', cb: function () {}, tooltip: 'nothing' } |
| ... | @@ -341,6 +129,17 @@ describe('factory: fw/widget/toolbar.js', function () { | ... | @@ -341,6 +129,17 @@ describe('factory: fw/widget/toolbar.js', function () { |
| 341 | expect($log.warn).not.toHaveBeenCalled(); | 129 | expect($log.warn).not.toHaveBeenCalled(); |
| 342 | }); | 130 | }); |
| 343 | 131 | ||
| 132 | + it('should create a separator div', function () { | ||
| 133 | + spyOn($log, 'warn'); | ||
| 134 | + var toolbar = tbs.createToolbar('test'), | ||
| 135 | + sep = toolbar.addSeparator(); | ||
| 136 | + expect(sep).not.toBeNull(); | ||
| 137 | + expect($log.warn).not.toHaveBeenCalled(); | ||
| 138 | + | ||
| 139 | + expect(d3Elem.select('.sep')).toBeTruthy(); | ||
| 140 | + expect(d3Elem.select('.sep').style('width')).toBe('2px'); | ||
| 141 | + }); | ||
| 142 | + | ||
| 344 | //it('should not append to a destroyed toolbar', function () { | 143 | //it('should not append to a destroyed toolbar', function () { |
| 345 | // spyOn($log, 'warn'); | 144 | // spyOn($log, 'warn'); |
| 346 | // var toolbar = tbs.createToolbar1('test'); | 145 | // var toolbar = tbs.createToolbar1('test'); | ... | ... |
-
Please register or login to post a comment