-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from DataTorrent/improve_coverage
Improve coverage for models
- Loading branch information
Showing
3 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
describe('Factory: WidgetDataModel', function () { | ||
|
||
// load the service's module | ||
beforeEach(module('ui.dashboard')); | ||
|
||
// instantiate service | ||
var WidgetDataModel, m, widget, scope; | ||
|
||
beforeEach(inject(function (_WidgetDataModel_) { | ||
WidgetDataModel = _WidgetDataModel_; | ||
m = new WidgetDataModel(); | ||
widget = { | ||
dataAttrName: 'testing', | ||
dataModelOptions: { opt: true } | ||
}; | ||
scope = { | ||
fake: 'scope' | ||
}; | ||
})); | ||
|
||
it('should be a function', function() { | ||
expect(typeof WidgetDataModel).toEqual('function'); | ||
}); | ||
|
||
describe('setup method', function() { | ||
|
||
it('should set dataAttrName, dataModelOptions, and widgetScope from args', function() { | ||
m.setup(widget, scope); | ||
expect(m.dataAttrName).toEqual(widget.dataAttrName); | ||
expect(m.dataModelOptions).toEqual(widget.dataModelOptions); | ||
expect(m.widgetScope).toEqual(scope); | ||
}); | ||
|
||
}); | ||
|
||
describe('updateScope method', function() { | ||
|
||
it('should set scope.widgetData to passed data', function() { | ||
m.setup(widget, scope); | ||
var newData = []; | ||
m.updateScope(newData); | ||
expect(scope.widgetData).toEqual(newData); | ||
}); | ||
|
||
}); | ||
|
||
describe('init method', function() { | ||
it('should be an empty (noop) implementation', function() { | ||
expect(typeof m.init).toEqual('function'); | ||
expect(m.init).not.toThrow(); | ||
}); | ||
}); | ||
|
||
describe('destroy method', function() { | ||
it('should be an empty (noop) implementation', function() { | ||
expect(typeof m.destroy).toEqual('function'); | ||
expect(m.destroy).not.toThrow(); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
'use strict'; | ||
|
||
describe('Factory: WidgetModel', function () { | ||
|
||
// load the service's module | ||
beforeEach(module('ui.dashboard')); | ||
|
||
// instantiate service | ||
var WidgetModel; | ||
beforeEach(inject(function (_WidgetModel_) { | ||
WidgetModel = _WidgetModel_; | ||
})); | ||
|
||
it('should be a function', function() { | ||
expect(typeof WidgetModel).toEqual('function'); | ||
}); | ||
|
||
describe('the constructor', function() { | ||
var m, Class, Class2, overrides; | ||
|
||
beforeEach(function() { | ||
Class = { | ||
name: 'TestWidget', | ||
attrs: {}, | ||
dataAttrName: 'attr-name', | ||
dataModelType: function TestType() {}, | ||
dataModelOptions: {}, | ||
style: { width: '10em' } | ||
}; | ||
|
||
Class2 = { | ||
name: 'TestWidget2', | ||
attrs: {}, | ||
dataAttrName: 'attr-name', | ||
dataModelType: function TestType() {}, | ||
dataModelOptions: {}, | ||
style: { width: '10em' }, | ||
templateUrl: 'my/url.html', | ||
template: '<div>some template</div>' | ||
}; | ||
|
||
overrides = { | ||
style: { | ||
width: '15em' | ||
} | ||
}; | ||
spyOn(WidgetModel.prototype, 'setWidth'); | ||
m = new WidgetModel(Class, overrides); | ||
}); | ||
|
||
it('should copy class defaults, so that changes on an instance do not change the Class', function() { | ||
m.style.width = '20em'; | ||
expect(Class.style.width).toEqual('10em'); | ||
}); | ||
|
||
it('should call setWidth', function() { | ||
expect(WidgetModel.prototype.setWidth).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should take overrides as precedent over Class defaults', function() { | ||
expect(m.style.width).toEqual('15em'); | ||
}); | ||
|
||
it('should set templateUrl if and only if it is present on Class', function() { | ||
var m2 = new WidgetModel(Class2, overrides); | ||
expect(m2.templateUrl).toEqual('my/url.html'); | ||
}); | ||
|
||
it('should NOT set template if templateUrl was specified', function() { | ||
var m2 = new WidgetModel(Class2, overrides); | ||
expect(m2.template).toBeUndefined(); | ||
}); | ||
|
||
it('should set template if and only if it is present on Class', function() { | ||
delete Class2.templateUrl; | ||
var m2 = new WidgetModel(Class2, overrides); | ||
expect(m2.template).toEqual('<div>some template</div>'); | ||
}); | ||
|
||
it('should look for directive if neither templateUrl nor template is found on Class', function() { | ||
delete Class2.templateUrl; | ||
delete Class2.template; | ||
Class2.directive = 'ng-bind'; | ||
var m2 = new WidgetModel(Class2, overrides); | ||
expect(m2.directive).toEqual('ng-bind'); | ||
}); | ||
|
||
it('should set the name as directive if templateUrl, template, and directive are not defined', function() { | ||
delete Class2.templateUrl; | ||
delete Class2.template; | ||
var m2 = new WidgetModel(Class2, overrides); | ||
expect(m2.directive).toEqual('TestWidget2'); | ||
}); | ||
|
||
it('should not require overrides', function() { | ||
var fn = function() { | ||
var m2 = new WidgetModel(Class); | ||
} | ||
expect(fn).not.toThrow(); | ||
}); | ||
|
||
}); | ||
|
||
describe('setWidth method', function() { | ||
|
||
var context, setWidth; | ||
|
||
beforeEach(function() { | ||
context = { style: {} }; | ||
setWidth = WidgetModel.prototype.setWidth; | ||
}); | ||
|
||
it('should take one argument as a string with units', function() { | ||
setWidth.call(context, '100px'); | ||
expect(context.style.width).toEqual('100px'); | ||
}); | ||
|
||
it('should take two args as a number and string as units', function() { | ||
setWidth.call(context, 100, 'px'); | ||
expect(context.style.width).toEqual('100px'); | ||
}); | ||
|
||
it('should return false and not set anything if width is less than 0', function() { | ||
var result = setWidth.call(context, -100, 'em'); | ||
expect(result).toEqual(false); | ||
expect(context.style.width).not.toEqual('-100em'); | ||
}); | ||
|
||
it('should assume % if no unit is given', function() { | ||
setWidth.call(context, 50); | ||
expect(context.style.width).toEqual('50%'); | ||
}); | ||
|
||
it('should force greater than 0% and less than or equal 100%', function() { | ||
setWidth.call(context, '110%'); | ||
expect(context.style.width).toEqual('100%'); | ||
}); | ||
|
||
}); | ||
|
||
}); |