2014-03-07 10:47:50 -07:00
/* jasmine specs for primitives/SensingPrims.js go here */
2014-03-10 21:04:56 -06:00
describe ( 'SensingPrims' , function ( ) {
2014-04-09 01:18:14 -07:00
var sensingPrims ;
2014-03-07 10:47:50 -07:00
beforeEach ( function ( ) {
2014-04-09 01:18:14 -07:00
sensingPrims = SensingPrims ;
realDate = Date ;
2014-03-07 10:47:50 -07:00
} ) ;
2014-04-09 01:18:14 -07:00
afterEach ( function ( ) {
Date = realDate ;
2014-03-07 10:47:50 -07:00
} ) ;
2014-04-09 01:18:14 -07:00
describe ( 'primTimestamp' , function ( ) {
beforeEach ( function ( ) {
/* MonkeyPatching the built-in Javascript Date */
var epochDate = new Date ( 2000 , 0 , 1 ) ;
var nowDate = new Date ( 2014 , 5 , 16 ) ;
Date = function ( ) {
return ( arguments . length ? epochDate : nowDate ) ;
} ;
} ) ;
it ( 'should return the days since 2000' , function ( ) {
2014-04-10 12:25:43 -07:00
expect ( sensingPrims . prototype . primTimestamp ( ) ) . toBeCloseTo ( 5280 ) ;
2014-04-09 01:18:14 -07:00
} ) ;
2014-03-07 10:47:50 -07:00
} ) ;
2014-04-09 01:18:14 -07:00
describe ( 'primTimeDate' , function ( ) {
beforeEach ( function ( ) {
/* MonkeyPatching the built-in Javascript Date */
Date = function ( ) {
return {
'getFullYear' : function ( ) { return 2014 ; } ,
'getMonth' : function ( ) { return 4 ; } ,
'getDate' : function ( ) { return 16 ; } ,
'getDay' : function ( ) { return 4 ; } ,
'getHours' : function ( ) { return 9 ; } ,
'getMinutes' : function ( ) { return 18 ; } ,
'getSeconds' : function ( ) { return 36 ; } ,
'getTime' : function ( ) { }
} ;
} ;
} ) ;
it ( 'should return the year' , function ( ) {
var block = { 'args' : [ 'year' ] } ;
expect ( sensingPrims . prototype . primTimeDate ( block ) ) . toEqual ( 2014 ) ;
} ) ;
it ( 'should return the month of the year' , function ( ) {
var block = { 'args' : [ 'month' ] } ;
expect ( sensingPrims . prototype . primTimeDate ( block ) ) . toEqual ( 5 ) ;
} ) ;
it ( 'should return the day of the week' , function ( ) {
var block = { 'args' : [ 'day of week' ] } ;
expect ( sensingPrims . prototype . primTimeDate ( block ) ) . toEqual ( 5 ) ;
} ) ;
it ( 'should return the hour of the day' , function ( ) {
var block = { 'args' : [ 'hour' ] } ;
expect ( sensingPrims . prototype . primTimeDate ( block ) ) . toEqual ( 9 ) ;
} ) ;
it ( 'should return the minute of the hour' , function ( ) {
var block = { 'args' : [ 'minute' ] } ;
expect ( sensingPrims . prototype . primTimeDate ( block ) ) . toEqual ( 18 ) ;
} ) ;
it ( 'should return the second of the minute' , function ( ) {
var block = { 'args' : [ 'second' ] } ;
expect ( sensingPrims . prototype . primTimeDate ( block ) ) . toEqual ( 36 ) ;
} ) ;
it ( 'should return the 0 on year' , function ( ) {
var block = { 'args' : [ 'anythingElse' ] } ;
expect ( sensingPrims . prototype . primTimeDate ( block ) ) . toEqual ( 0 ) ;
} ) ;
2014-03-07 10:47:50 -07:00
} ) ;
2014-04-09 01:18:14 -07:00
describe ( 'primAnswer' , function ( ) {
beforeEach ( function ( ) {
interp = interpreterMock ( { 'targetSprite' : new targetMock ( ) } ) ;
} ) ;
2014-03-09 11:59:38 -06:00
2014-04-09 01:18:14 -07:00
it ( 'should return the answer variable from the targetedSprite' , function ( ) {
expect ( sensingPrims . prototype . primAnswer ( ) ) . toBe ( 12 ) ;
} ) ;
2014-03-09 11:59:38 -06:00
} ) ;
2014-04-09 01:18:14 -07:00
describe ( 'primDoAsk' , function ( ) {
var askBlock , targetSpriteMock ;
beforeEach ( function ( ) {
targetSpriteMock = targetMock ( ) ;
askBlock = { 'args' : 'what to ask' } ;
interp = interpreterMock ( { 'targetSprite' : targetSpriteMock } , { 'arg' : askBlock } ) ;
} ) ;
it ( 'should call the showBubble method on the targetedSprite' , function ( ) {
spyOn ( window , "showBubble" ) ;
spyOn ( targetSpriteMock , "showAsk" ) ;
sensingPrims . prototype . primDoAsk ( askBlock ) ;
expect ( window . showBubble ) . toHaveBeenCalledWith ( { args : 'what to ask' } , 'doAsk' ) ;
expect ( targetSpriteMock . showAsk ) . toHaveBeenCalled ;
expect ( interp . activeThread . paused ) . toBe ( true ) ;
} ) ;
2014-03-09 11:59:38 -06:00
} ) ;
2014-03-07 10:47:50 -07:00
} ) ;