Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added more tests

  • Loading branch information...
commit 8f100ce8876efb7dd497f50863d95523900df2a7 1 parent d1fdc0e
@jpdery authored
View
7 Specs/SpecRunner.html
@@ -85,7 +85,14 @@
<!-- include spec files here... -->
<script type="text/javascript" src="spec/Class/Class.Instantiate.js"></script>
+ <script type="text/javascript" src="spec/Types/Array.js"></script>
+ <script type="text/javascript" src="spec/Types/String.js"></script>
<script type="text/javascript" src="spec/Component/Component.js"></script>
+ <script type="text/javascript" src="spec/Control/Control.js"></script>
+ <script type="text/javascript" src="spec/Control/Bar.js"></script>
+ <script type="text/javascript" src="spec/Control/BarItem.js"></script>
+ <script type="text/javascript" src="spec/Control/Button.js"></script>
+ <script type="text/javascript" src="spec/Control/ButtonGroup.js"></script>
<script type="text/javascript">
View
38 Specs/spec/Component/Component.js
@@ -31,7 +31,7 @@ describe('Component/Component', function() {
});
it('should add a child', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
p.addChild(c1);
expect(p.getChildren()[0]).toEqual(c1);
@@ -87,21 +87,21 @@ describe('Component/Component', function() {
});
it('should find a child using its name', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component(null, null, 'me');
p.addChild(c1);
expect(p.getChild('me')).toEqual(c1);
});
it('should find a child using its index', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
p.addChild(c1);
expect(p.getChildAt(0)).toEqual(c1);
});
it('should find a child of a given type using its index', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
var c2 = new MyComponent();
p.addChild(c1);
@@ -110,14 +110,14 @@ describe('Component/Component', function() {
});
it('should find the index of a child', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
p.addChild(c1);
expect(p.getChildIndex(c1)).toEqual(0);
});
it('should return all children', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
var c2 = new Moobile.Component();
p.addChild(c1);
@@ -128,7 +128,7 @@ describe('Component/Component', function() {
});
it('should return all children of a given type', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
var c2 = new Moobile.Component();
var c3 = new MyComponent();
@@ -140,14 +140,14 @@ describe('Component/Component', function() {
});
it('should know if a child exists', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
p.addChild(c1);
expect(p.hasChild(c1)).toEqual(true);
});
it('should know if a child of a given type exists', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
var c2 = new MyComponent();
p.addChild(c1);
@@ -156,7 +156,7 @@ describe('Component/Component', function() {
});
it('should replace a child', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
var c2 = new Moobile.Component();
p.addChild(c1);
@@ -165,7 +165,7 @@ describe('Component/Component', function() {
});
it('should a child be replaced with another', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
var c2 = new Moobile.Component();
p.addChild(c1);
@@ -174,7 +174,7 @@ describe('Component/Component', function() {
});
it('should remove a child', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
p.addChild(c1);
p.removeChild(c1);
@@ -182,7 +182,7 @@ describe('Component/Component', function() {
});
it('should remove all children', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
var c2 = new Moobile.Component();
p.addChild(c1);
@@ -192,7 +192,7 @@ describe('Component/Component', function() {
});
it('should remove all children of a given type', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
var c2 = new MyComponent();
p.addChild(c1);
@@ -202,7 +202,7 @@ describe('Component/Component', function() {
});
it('should a child remove itself', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
p.addChild(c1);
c1.removeFromParent();
@@ -210,7 +210,7 @@ describe('Component/Component', function() {
});
it('should set/get/has parent', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
c1.setParent(p);
expect(c1.getParent()).toEqual(p);
@@ -218,8 +218,8 @@ describe('Component/Component', function() {
});
it('should set the window through all child', function() {
- var w = new Moobile.Window();
- var p = new Moobile.Component();
+ var w = new Moobile.Window();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
var c2 = new Moobile.Component();
p.addChild(c1);
@@ -232,7 +232,7 @@ describe('Component/Component', function() {
});
it('should set the ready flag through all child', function() {
- var p = new Moobile.Component();
+ var p = new Moobile.Component();
var c1 = new Moobile.Component();
var c2 = new Moobile.Component();
p.addChild(c1);
View
19 Specs/spec/Control/Bar.js
@@ -0,0 +1,19 @@
+
+describe('Control/Bar', function() {
+
+ it('should create a bar item on initialization', function() {
+ var bar = new Moobile.Bar();
+ expect(bar.getItem() instanceof Moobile.BarItem).toEqual(true);
+ });
+
+ it('should assign, replace and retrieve the bar item', function() {
+ var bar = new Moobile.Bar();
+ var curItem = bar.getItem();
+ var newItem = new Moobile.BarItem();
+ spyOn(curItem, 'destroy');
+ bar.setItem(newItem);
+ expect(curItem.destroy).toHaveBeenCalled();
+ expect(bar.getItem()).toEqual(newItem);
+ });
+
+});
View
4 Specs/spec/Control/BarItem.js
@@ -0,0 +1,4 @@
+
+describe('Control/BarItem', function() {
+
+});
View
30 Specs/spec/Control/Button.js
@@ -0,0 +1,30 @@
+
+describe('Control/Button', function() {
+
+ it('should create a label on initialization', function() {
+ var button = new Moobile.Button();
+ expect(button.getLabel() instanceof Moobile.Text).toEqual(true);
+ });
+
+ it('should set/get the label created from a string', function() {
+ var button = new Moobile.Button();
+ button.setLabel('foo');
+ expect(button.getLabel().getText()).toEqual('foo');
+ });
+
+ it('should set/get the label created from a Moobile.Text instance', function() {
+ var button = new Moobile.Button();
+ var label = new Moobile.Text().setText('foo');
+ button.setLabel(label);
+ expect(button.getLabel().getText()).toEqual('foo');
+ });
+
+ it('should replace the current label when a new one is assigned', function() {
+ var button = new Moobile.Button();
+ var label = button.getLabel();
+ spyOn(label, 'destroy');
+ button.setLabel('foo');
+ expect(label.destroy).toHaveBeenCalled();
+ });
+
+});
View
135 Specs/spec/Control/ButtonGroup.js
@@ -0,0 +1,135 @@
+
+describe('Control/ButtonGroup', function() {
+
+ it('should add a button', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ g.addButton(b1);
+ expect(g.getChildren()[0]).toEqual(b1);
+ });
+
+ it('should add a button at the top', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ var b2 = new Moobile.Button();
+ g.addButton(b1);
+ g.addButton(b2, 'top');
+ expect(g.getButtonAt(0)).toEqual(b2);
+ expect(g.getElements('>')[0]).toEqual(b2.getElement());
+ });
+
+ it('should add a button at the bottom', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ var b2 = new Moobile.Button();
+ g.addButton(b1);
+ g.addButton(b2, 'bottom');
+ expect(g.getButtonAt(1)).toEqual(b2);
+ expect(g.getElements('>')[1]).toEqual(b2.getElement());
+ });
+
+ it('should add a button after another button', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ var b2 = new Moobile.Button();
+ g.addButton(b1);
+ g.addButtonAfter(b2, b1);
+ expect(g.getButtonAt(1)).toEqual(b2);
+ expect(g.getElements('>')[1]).toEqual(b2.getElement());
+ });
+
+ it('should add a button before another button', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ var b2 = new Moobile.Button();
+ g.addButton(b1);
+ g.addButtonBefore(b2, b1);
+ expect(g.getButtonAt(0)).toEqual(b2);
+ expect(g.getElements()[0]).toEqual(b2.getElement());
+ });
+
+ it('should return all buttons', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ var b2 = new Moobile.Button();
+ g.addChild(b1);
+ g.addChild(b2);
+ var children = g.getButtons();
+ expect(children[0]).toEqual(b1);
+ expect(children[1]).toEqual(b2);
+ });
+
+ it('should find a button using its name', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button(null, null, 'me');
+ g.addButton(b1);
+ expect(g.getButton('me')).toEqual(b1);
+ });
+
+ it('should find a button using its index', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ g.addButton(b1);
+ expect(g.getButtonAt(0)).toEqual(b1);
+ });
+
+ it('should remove a button', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ g.addButton(b1);
+ g.removeButton(b1);
+ expect(g.getButtonAt(0)).toEqual(null);
+ });
+
+ it('should remove all buttons', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ var b2 = new Moobile.Button();
+ g.addButton(b1);
+ g.addButton(b2);
+ g.removeAllButtons();
+ expect(g.getButtons().length).toEqual(0);
+ });
+
+ it('should call didAddChild when adding a button', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ spyOn(g, 'didAddChild');
+ g.addButton(b1);
+ expect(g.didAddChild).toHaveBeenCalled();
+ });
+
+ it('should call didRemoveChild when removing a button', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ spyOn(g, 'didRemoveChild');
+ g.addButton(b1);
+ g.removeButton(b1);
+ expect(g.didRemoveChild).toHaveBeenCalled();
+ });
+
+ it('should select a button using the button instance', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ var b2 = new Moobile.Button();
+ var b3 = new Moobile.Button();
+ g.addButton(b1);
+ g.addButton(b2);
+ g.addButton(b3);
+ g.setSelectedButton(b1);
+ expect(g.getSelectedButton()).toEqual(b1);
+ });
+
+ it('should select a button using the button index', function() {
+ var g = new Moobile.ButtonGroup();
+ var b1 = new Moobile.Button();
+ var b2 = new Moobile.Button();
+ var b3 = new Moobile.Button();
+ g.addButton(b1);
+ g.addButton(b2);
+ g.addButton(b3);
+ g.setSelectedButtonIndex(0);
+ expect(g.getSelectedButton()).toEqual(b1);
+ });
+
+});
View
41 Specs/spec/Control/Control.js
@@ -0,0 +1,41 @@
+
+describe('Control/Control', function() {
+
+ var control = null;
+
+ beforeEach(function() {
+ control = new Moobile.Control();
+// spyOn(control, 'shouldAllowState');
+ spyOn(control, 'willChangeState');
+ spyOn(control, 'didChangeState');
+ });
+
+ afterEach(function() {
+ control = null;
+ });
+
+ it('should set its state to disabled', function() {
+ control.setDisabled(true);
+ expect(control.isDisabled()).toEqual(true);
+// expect(control.shouldAlloState).toHaveBeenCalledWith('disabled');
+ expect(control.willChangeState).toHaveBeenCalledWith('disabled');
+ expect(control.didChangeState).toHaveBeenCalledWith('disabled');
+ });
+
+ it('should set its state to selected', function() {
+ control.setSelected(true);
+ expect(control.isSelected()).toEqual(true);
+// expect(control.shouldAlloState).toHaveBeenCalledWith('disabled');
+ expect(control.willChangeState).toHaveBeenCalledWith('selected');
+ expect(control.didChangeState).toHaveBeenCalledWith('selected');
+ });
+
+ it('should set its state to highlighted', function() {
+ control.setHighlighted(true);
+ expect(control.isHighlighted()).toEqual(true);
+// expect(control.shouldAlloState).toHaveBeenCalledWith('disabled');
+ expect(control.willChangeState).toHaveBeenCalledWith('highlighted');
+ expect(control.didChangeState).toHaveBeenCalledWith('highlighted');
+ });
+
+});
View
18 Specs/spec/Types/Array.js
@@ -0,0 +1,18 @@
+
+describe('Types/Array', function() {
+
+ var array = ['foo', 'bar', 'wat'];
+
+ it('should find a item from the array', function() {
+ expect(array.find(function(item) {
+ return item === 'wat';
+ })).toEqual('wat');
+ });
+
+ it('should return an item from the end of the array', function() {
+ expect(array.getLastItemAtOffset()).toEqual('wat');
+ expect(array.getLastItemAtOffset(0)).toEqual('wat');
+ expect(array.getLastItemAtOffset(1)).toEqual('bar');
+ });
+
+});
View
10 Specs/spec/Types/String.js
@@ -0,0 +1,10 @@
+
+describe('Types/String', function() {
+
+ it('should transform to camel casing', function() {
+ expect('foo bar wat'.toCamelCase()).toEqual('fooBarWat');
+ expect('foo-bar-wat'.toCamelCase()).toEqual('fooBarWat');
+ expect('foo_bar_wat'.toCamelCase()).toEqual('foo_bar_wat');
+ });
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.