Akron | defa5e8 | 2018-07-10 12:09:46 +0200 | [diff] [blame^] | 1 | define(['buttongroup'], function (buttonGroupClass) { |
| 2 | |
| 3 | var FunObj = { |
| 4 | count : 0, |
| 5 | create : function () { |
| 6 | return Object.create(this); |
| 7 | }, |
| 8 | incr : function () { |
| 9 | this.count++; |
| 10 | } |
| 11 | }; |
| 12 | |
| 13 | describe('KorAP.ButtonGroup', function () { |
| 14 | |
| 15 | it('should be initializable', function () { |
| 16 | var group = buttonGroupClass.create(['action', 'bottom']); |
| 17 | var el = group.element(); |
| 18 | expect(el.tagName).toEqual('DIV'); |
| 19 | expect(el.firstChild).toBeNull(); |
| 20 | expect(el.classList.contains('action')).toBeTruthy(); |
| 21 | expect(el.classList.contains('bottom')).toBeTruthy(); |
| 22 | expect(el.classList.contains('button-group')).toBeTruthy(); |
| 23 | }); |
| 24 | |
| 25 | it('should be expandable', function () { |
| 26 | var group = buttonGroupClass.create(); |
| 27 | expect(group.element().classList.contains('button-group')).toBeTruthy(); |
| 28 | |
| 29 | group.add('Meta', ['meta', 'top'], function (e) {}); |
| 30 | |
| 31 | var btn = group.element().firstChild; |
| 32 | expect(btn.tagName).toEqual('SPAN'); |
| 33 | expect(btn.classList.contains('meta')).toBeTruthy(); |
| 34 | expect(btn.classList.contains('top')).toBeTruthy(); |
| 35 | expect(btn.innerText).toEqual('Meta'); |
| 36 | }); |
| 37 | |
| 38 | it('should listen to button clicks', function () { |
| 39 | var group = buttonGroupClass.create(); |
| 40 | |
| 41 | var count = 0; |
| 42 | |
| 43 | group.add('Meta', undefined, function () { |
| 44 | count++; |
| 45 | }); |
| 46 | |
| 47 | expect(count).toEqual(0); |
| 48 | |
| 49 | // Click on the button |
| 50 | group.element().firstChild.click(); |
| 51 | |
| 52 | expect(count).toEqual(1); |
| 53 | }); |
| 54 | |
| 55 | it('should respect binds', function () { |
| 56 | var group = buttonGroupClass.create(); |
| 57 | fun = FunObj.create(); |
| 58 | expect(fun.count).toEqual(0); |
| 59 | |
| 60 | // Bind group to another object |
| 61 | group.bind(fun); |
| 62 | |
| 63 | group.add('Incr', undefined, function (e) { |
| 64 | // increment on bind object |
| 65 | this.incr() |
| 66 | }); |
| 67 | |
| 68 | // Click on the button |
| 69 | group.element().firstChild.click(); |
| 70 | expect(fun.count).toEqual(1); |
| 71 | }); |
| 72 | }); |
| 73 | }); |