|
| 1 | +/* jasmine specs for primitives/SensingPrims.js go here */ |
| 2 | + |
| 3 | +describe ('SensingPrims', function() { |
| 4 | + var sensingPrims; |
| 5 | + beforeEach(function() { |
| 6 | + sensingPrims = SensingPrims; |
| 7 | + realDate = Date; |
| 8 | + }); |
| 9 | + |
| 10 | + afterEach(function () { |
| 11 | + Date = realDate; |
| 12 | + }); |
| 13 | + |
| 14 | + describe('primTimestamp', function(){ |
| 15 | + beforeEach(function() { |
| 16 | + /* MonkeyPatching the built-in Javascript Date */ |
| 17 | + var epochDate = new Date(2000, 0, 1); |
| 18 | + var nowDate = new Date(2014, 5, 16); |
| 19 | + Date = function () { |
| 20 | + return (arguments.length ? epochDate : nowDate); |
| 21 | + }; |
| 22 | + }); |
| 23 | + |
| 24 | + it('should return the days since 2000', function() { |
| 25 | + expect(sensingPrims.prototype.primTimestamp()).toEqual(5280.25); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('primTimeDate', function(){ |
| 30 | + beforeEach(function() { |
| 31 | + /* MonkeyPatching the built-in Javascript Date */ |
| 32 | + Date = function () { |
| 33 | + return { |
| 34 | + 'getFullYear' : function() { return 2014;}, |
| 35 | + 'getMonth' : function() { return 4;}, |
| 36 | + 'getDate' : function() { return 16;}, |
| 37 | + 'getDay' : function() { return 4;}, |
| 38 | + 'getHours' : function() { return 9;}, |
| 39 | + 'getMinutes' : function() { return 18;}, |
| 40 | + 'getSeconds' : function() { return 36;}, |
| 41 | + 'getTime' : function() {} |
| 42 | + }; |
| 43 | + }; |
| 44 | + }); |
| 45 | + |
| 46 | + it('should return the year', function() { |
| 47 | + var block = {'args' : ['year']}; |
| 48 | + expect(sensingPrims.prototype.primTimeDate(block)).toEqual(2014); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should return the month of the year', function() { |
| 52 | + var block = {'args' : ['month']}; |
| 53 | + expect(sensingPrims.prototype.primTimeDate(block)).toEqual(5); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should return the day of the week', function() { |
| 57 | + var block = {'args' : ['day of week']}; |
| 58 | + expect(sensingPrims.prototype.primTimeDate(block)).toEqual(5); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should return the hour of the day', function() { |
| 62 | + var block = {'args' : ['hour']}; |
| 63 | + expect(sensingPrims.prototype.primTimeDate(block)).toEqual(9); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should return the minute of the hour', function() { |
| 67 | + var block = {'args' : ['minute']}; |
| 68 | + expect(sensingPrims.prototype.primTimeDate(block)).toEqual(18); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should return the second of the minute', function() { |
| 72 | + var block = {'args' : ['second']}; |
| 73 | + expect(sensingPrims.prototype.primTimeDate(block)).toEqual(36); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should return the 0 on year', function() { |
| 77 | + var block = {'args' : ['anythingElse']}; |
| 78 | + expect(sensingPrims.prototype.primTimeDate(block)).toEqual(0); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments