Created
January 24, 2012 14:11
-
-
Save cromwellryan/1670359 to your computer and use it in GitHub Desktop.
Knockout & Jasmine not mixing well
This file contains hidden or 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
var TASKLISTMODULE = (function(module) { | |
module.Task = function (name, owner, duedate, status) { | |
var self = this; | |
self.name = ko.observable(name || ''); | |
self.owner = ko.observable(owner || ''); | |
self.duedate = ko.observable(duedate); | |
self.status = status || 'unassigned'; | |
self.duedate_readable = function() { | |
var formatting = 'm/d/Y H:i:s'; | |
var dd = self.duedate(); | |
if( system.istoday(dd) ) { formatting = 'H:i:s'; } | |
return dd.format(formatting); | |
}; | |
var statuses = { | |
'unassigned': 'Unassigned' | |
, 'assigned': 'Assigned' | |
, 'in_progress': 'In Progress' | |
, 'completed': 'Completed' }; | |
self.status_readable = function() { | |
return statuses[self.status]; | |
}; | |
}; | |
return module; | |
}(TASKLISTMODULE || {})); |
This file contains hidden or 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
describe('TaskModel', function() { | |
beforeEach(function() { | |
this.task = new TASKLISTMODULE.Task(); | |
}); | |
it('should default name to empty', function() { | |
expect(this.task.name()).toEqual(''); | |
}); | |
it('should default owner to empty', function() { | |
expect(this.task.owner()).toEqual(''); | |
}); | |
it('should default Due Date to null', function() { | |
expect(this.task.due).toEqual(); | |
}); | |
it('should default Status to unassigned', function() { | |
expect(this.task.status).toEqual('unassigned'); | |
}); | |
it('should hide date for duedate_readble when date is today', function() { | |
// year, month, day, hours, minutes, seconds, milliseconds | |
system.today = function() { return new Date(2012, 0, 2); }; | |
this.task.duedate( new Date(2012, 0, 2, 14,0,0) ); | |
expect(this.task.duedate_readable()).toEqual('14:00:00'); | |
}); | |
it('should show date for duedate_readble when date is not today', function() { | |
// year, month, day, hours, minutes, seconds, milliseconds | |
system.today = function() { return new Date(2012, 0, 1); }; | |
this.task.duedate( new Date(2012, 0, 2, 14,0,0) ); | |
expect(this.task.duedate_readable()).toEqual('01/02/2012 14:00:00'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment