Introduce button group
Change-Id: Ic9d158e77f76aabfc92ce54093d768a0e92b3560
diff --git a/dev/js/spec/buttongroupSpec.js b/dev/js/spec/buttongroupSpec.js
new file mode 100644
index 0000000..fa5a888
--- /dev/null
+++ b/dev/js/spec/buttongroupSpec.js
@@ -0,0 +1,73 @@
+define(['buttongroup'], function (buttonGroupClass) {
+
+ var FunObj = {
+ count : 0,
+ create : function () {
+ return Object.create(this);
+ },
+ incr : function () {
+ this.count++;
+ }
+ };
+
+ describe('KorAP.ButtonGroup', function () {
+
+ it('should be initializable', function () {
+ var group = buttonGroupClass.create(['action', 'bottom']);
+ var el = group.element();
+ expect(el.tagName).toEqual('DIV');
+ expect(el.firstChild).toBeNull();
+ expect(el.classList.contains('action')).toBeTruthy();
+ expect(el.classList.contains('bottom')).toBeTruthy();
+ expect(el.classList.contains('button-group')).toBeTruthy();
+ });
+
+ it('should be expandable', function () {
+ var group = buttonGroupClass.create();
+ expect(group.element().classList.contains('button-group')).toBeTruthy();
+
+ group.add('Meta', ['meta', 'top'], function (e) {});
+
+ var btn = group.element().firstChild;
+ expect(btn.tagName).toEqual('SPAN');
+ expect(btn.classList.contains('meta')).toBeTruthy();
+ expect(btn.classList.contains('top')).toBeTruthy();
+ expect(btn.innerText).toEqual('Meta');
+ });
+
+ it('should listen to button clicks', function () {
+ var group = buttonGroupClass.create();
+
+ var count = 0;
+
+ group.add('Meta', undefined, function () {
+ count++;
+ });
+
+ expect(count).toEqual(0);
+
+ // Click on the button
+ group.element().firstChild.click();
+
+ expect(count).toEqual(1);
+ });
+
+ it('should respect binds', function () {
+ var group = buttonGroupClass.create();
+ fun = FunObj.create();
+ expect(fun.count).toEqual(0);
+
+ // Bind group to another object
+ group.bind(fun);
+
+ group.add('Incr', undefined, function (e) {
+ // increment on bind object
+ this.incr()
+ });
+
+ // Click on the button
+ group.element().firstChild.click();
+ expect(fun.count).toEqual(1);
+ });
+ });
+});