2022-01-19 23:41:47 +00:00
//Clock renders date, time and pre,current,next week calender view
class TimeCalClock {
DATE _FONT _SIZE ( ) { return 20 ; }
TIME _FONT _SIZE ( ) { return 40 ; }
/ * *
* @ param { Date } date optional the date ( e . g . for testing )
* @ param { Settings } settings optional settings to use e . g . for testing
* /
constructor ( date , settings ) {
if ( date )
this . date = date ;
if ( settings )
this . _settings = settings ;
else
this . _settings = require ( "Storage" ) . readJSON ( "timecal.settings.json" , 1 ) || { } ;
const defaults = {
2022-01-28 10:23:43 +00:00
shwDate : 1 , //0:none, 1:locale, 2:month, 3:monthshort.year #week
2022-02-01 22:44:59 +00:00
wdStrt : 0 , //identical to getDay() 0->Su, 1->Mo, ... //Issue #1154: weekstart So/Mo, -1 for use today
2022-01-19 23:41:47 +00:00
2022-02-01 22:44:59 +00:00
tdyNumClr : 3 , //0:fg, 1:red=#E00, 2:green=#0E0, 3:blue=#00E
2022-01-28 10:23:43 +00:00
tdyMrkr : 0 , //0:none, 1:circle, 2:rectangle, 3:filled
tdyMrkClr : 2 , //1:red=#E00, 2:green=#0E0, 3:blue=#00E
tdyMrkPxl : 3 , //px
2022-01-19 23:41:47 +00:00
2022-02-01 22:44:59 +00:00
suClr : 1 , //0:fg, 1:red=#E00, 2:green=#0E0, 3:blue=#00E
2022-01-28 10:23:43 +00:00
//phColor:"#E00", //public holiday
2022-01-19 23:41:47 +00:00
2022-01-28 10:23:43 +00:00
calBrdr : false
2022-01-19 23:41:47 +00:00
} ;
for ( const k in this . _settings ) if ( ! defaults . hasOwnProperty ( k ) ) delete this . _settings [ k ] ; //remove invalid settings
for ( const k in defaults ) if ( ! this . _settings . hasOwnProperty ( k ) ) this . _settings [ k ] = defaults [ k ] ; //assign missing defaults
g . clear ( ) ;
Bangle . setUI ( "clock" ) ;
Bangle . loadWidgets ( ) ;
Bangle . drawWidgets ( ) ;
2022-01-28 10:23:43 +00:00
this . centerX = Bangle . appRect . w / 2 ;
this . nrgb = [ g . theme . fg , "#E00" , "#0E0" , "#00E" ] ; //fg, r ,g , b
2022-02-01 22:44:59 +00:00
this . ABR _DAY = [ ] ;
if ( require ( "locale" ) && require ( "locale" ) . dow )
for ( let d = 0 ; d <= 6 ; d ++ ) {
var refDay = new Date ( ) ;
refDay . setFullYear ( 1972 ) ;
refDay . setMonth ( 0 ) ;
refDay . setDate ( 2 + d ) ;
this . ABR _DAY . push ( require ( "locale" ) . dow ( refDay ) ) ;
}
else
this . ABR _DAY = [ "Sun" , "Mon" , "Tue" , "Wed" , "Thu" , "Fri" , "Sat" ] ;
2022-01-19 23:41:47 +00:00
}
/ * *
* @ returns { Object } current settings object
* /
settings ( ) {
return this . _settings ;
}
/ *
* Run forest run
* * /
draw ( ) {
this . drawTime ( ) ;
2022-02-01 22:44:59 +00:00
if ( this . TZOffset === undefined || this . TZOffset !== d . getTimezoneOffset ( ) )
this . drawDateAndCal ( ) ;
}
2022-01-19 23:41:47 +00:00
/ * *
* draw given or current time from date
* overwatch timezone changes
* schedules itself to update
* /
drawTime ( ) {
d = this . date ? this . date : new Date ( ) ;
const Y = Bangle . appRect . y + this . DATE _FONT _SIZE ( ) + 10 ;
d = d ? d : new Date ( ) ;
g . setFontAlign ( 0 , - 1 ) ;
g . setFont ( "Vector" , this . TIME _FONT _SIZE ( ) ) ;
g . setColor ( g . theme . fg ) ;
g . clearRect ( Bangle . appRect . x , Y , Bangle . appRect . x2 , Y + this . TIME _FONT _SIZE ( ) - 7 ) ;
2022-01-28 10:23:43 +00:00
g . drawString ( ( "0" + require ( "locale" ) . time ( d , 1 ) ) . slice ( - 5 ) , this . centerX , Y ) ;
2022-01-19 23:41:47 +00:00
//.drawRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7); //DEV-Option
2022-02-01 22:44:59 +00:00
setTimeout ( this . draw . bind ( this ) , 60000 - ( d . getSeconds ( ) * 1000 ) - d . getMilliseconds ( ) ) ;
2022-01-19 23:41:47 +00:00
}
/ * *
* draws given date and cal
* @ param { Date } d provide date or uses today
* /
drawDateAndCal ( ) {
d = this . date ? this . date : new Date ( ) ;
2022-02-01 22:44:59 +00:00
this . TZOffset = d . getTimezoneOffset ( ) ;
2022-01-19 23:41:47 +00:00
this . drawDate ( ) ;
this . drawCal ( ) ;
2022-02-01 22:44:59 +00:00
if ( this . tOutD ) //abort exisiting
clearTimeout ( this . tOutD ) ;
2022-01-19 23:41:47 +00:00
this . tOutD = setTimeout ( this . drawDateAndCal . bind ( this ) , 86400000 - ( d . getHours ( ) * 24 * 60 * 1000 ) - ( d . getMinutes ( ) * 60 * 1000 ) - d . getSeconds ( ) - d . getMilliseconds ( ) ) ;
}
/ * *
* draws given date as defiend in settings
* /
drawDate ( ) {
d = this . date ? this . date : new Date ( ) ;
const FONT _SIZE = 20 ;
const Y = Bangle . appRect . y ;
var render = false ;
var dateStr = "" ;
2022-01-28 10:23:43 +00:00
if ( this . settings ( ) . shwDate > 0 ) { //skip if exactly -none
const dateSttngs = [ "" , "l" , "M" , "m.Y #W" ] ;
for ( let c of dateSttngs [ this . settings ( ) . shwDate ] ) { //add part as configured
2022-01-19 23:41:47 +00:00
switch ( c ) {
case "l" : { //locale
render = true ;
dateStr += require ( "locale" ) . date ( d , 1 ) ;
break ;
}
case "m" : { //month e.g. Jan.
render = true ;
dateStr += require ( "locale" ) . month ( d , 1 ) ;
break ;
}
2022-01-28 10:23:43 +00:00
case "M" : { //month e.g. January
render = true ;
dateStr += require ( "locale" ) . month ( d , 0 ) ;
break ;
}
case "y" : { //year e.g. 22
render = true ;
dateStr += d . getFullYear ( ) . slice ( - 2 ) ;
break ;
}
case "Y" : { //year e.g. 2022
2022-01-19 23:41:47 +00:00
render = true ;
dateStr += d . getFullYear ( ) ;
break ;
}
2022-01-28 10:23:43 +00:00
case "w" : { //week e.g. #2
dateStr += ( this . ISO8601calWeek ( d ) ) ;
break ;
}
case "W" : { //week e.g. #02
2022-01-19 23:41:47 +00:00
dateStr += ( "0" + this . ISO8601calWeek ( d ) ) . slice ( - 2 ) ;
break ;
}
default : //append c
dateStr += c ;
render = dateStr . length > 0 ;
break ; //noop
}
}
2022-01-28 10:23:43 +00:00
}
2022-01-19 23:41:47 +00:00
if ( render ) {
g . clearRect ( Bangle . appRect . x , Y , Bangle . appRect . x2 , Y + FONT _SIZE - 3 ) ;
g . setFont ( "Vector" , FONT _SIZE ) ;
g . setColor ( g . theme . fg ) ;
g . setFontAlign ( 0 , - 1 ) ;
2022-01-28 10:23:43 +00:00
g . drawString ( dateStr , this . centerX , Y ) ;
2022-01-19 23:41:47 +00:00
}
//g.drawRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+FONT_SIZE-3); //DEV-Option
}
/ * *
* draws calender week view ( - 1 , 0 , 1 ) for given date
* /
drawCal ( ) {
d = this . date ? this . date : new Date ( ) ;
const DAY _NAME _FONT _SIZE = 10 ;
const CAL _Y = Bangle . appRect . y + this . DATE _FONT _SIZE ( ) + 10 + this . TIME _FONT _SIZE ( ) + 3 ;
const CAL _AREA _H = Bangle . appRect . h - CAL _Y - 24 ; //0,24,48 no,1,2 widget lines
const CELL _W = Bangle . appRect . w / 7 ; //cell width
const CELL _H = ( CAL _AREA _H - DAY _NAME _FONT _SIZE ) / 3 ; //cell heigth
const DAY _NUM _FONT _SIZE = Math . min ( CELL _H - 1 , 15 ) ; //size down, max 15
g . clearRect ( Bangle . appRect . x , CAL _Y , Bangle . appRect . x2 , CAL _Y + CAL _AREA _H ) ;
g . setFont ( "Vector" , DAY _NAME _FONT _SIZE ) ;
g . setColor ( g . theme . fg ) ;
g . setFontAlign ( - 1 , - 1 ) ;
2022-01-28 10:23:43 +00:00
2022-01-19 23:41:47 +00:00
//draw grid & Headline
2022-01-28 10:23:43 +00:00
const dNames = this . ABR _DAY . map ( ( a ) => a . length <= 2 ? a : a . substr ( 0 , 2 ) ) ; //force shrt 2
2022-01-19 23:41:47 +00:00
for ( var dNo = 0 ; dNo < dNames . length ; dNo ++ ) {
2022-02-01 22:44:59 +00:00
const dIdx = this . settings ( ) . wdStrt >= 0 ? ( dNo + this . settings ( ) . wdStrt ) % 7 : ( dNo + d . getDay ( ) + 4 ) % 7 ;
const dName = dNames [ dIdx ] ;
if ( dIdx == 0 ) //sunday colorize txt
g . setColor ( this . nrgb [ this . settings ( ) . suClr ] ) ;
else
g . setColor ( g . theme . fg ) ;
2022-01-19 23:41:47 +00:00
g . drawString ( dName , dNo * CELL _W + ( CELL _W - g . stringWidth ( dName ) ) / 2 + 2 , CAL _Y + 1 ) ; //center Names
if ( dNo > 0 )
g . drawLine ( dNo * CELL _W , CAL _Y , dNo * CELL _W , CAL _Y + CAL _AREA _H - 1 ) ;
}
var nextY = CAL _Y + DAY _NAME _FONT _SIZE ;
for ( i = 0 ; i < 3 ; i ++ ) {
const y = nextY + i * CELL _H ;
g . drawLine ( Bangle . appRect . x , y , Bangle . appRect . x2 , y ) ;
}
g . setFont ( "Vector" , DAY _NUM _FONT _SIZE ) ;
//write days
2022-02-01 22:44:59 +00:00
const tdyDate = d . getDate ( ) ;
const days = this . settings ( ) . wdStrt >= 0 ? 7 + ( ( 7 + d . getDay ( ) - this . settings ( ) . wdStrt ) % 7 ) : 10 ; //start day (week before=7 days + days in this week realtive to week start) or fixed 7+3 days
var rD = new Date ( d . getTime ( ) ) ;
2022-01-19 23:41:47 +00:00
rD . setDate ( rD . getDate ( ) - days ) ;
var rDate = rD . getDate ( ) ;
for ( var y = 0 ; y < 3 ; y ++ ) {
for ( var x = 0 ; x < dNames . length ; x ++ ) {
2022-01-28 10:23:43 +00:00
if ( rDate === tdyDate ) { //today
g . setColor ( this . nrgb [ this . settings ( ) . tdyMrkClr ] ) ; //today marker color or fg color
switch ( this . settings ( ) . tdyMrkr ) { //0:none, 1:circle, 2:rectangle, 3:filled
case 1 :
for ( m = 1 ; m <= this . settings ( ) . tdyMrkPxl && m < CELL _H - 1 && m < CELL _W - 1 ; m ++ )
2022-02-01 22:44:59 +00:00
g . drawCircle ( x * CELL _W + ( CELL _W / 2 ) + 1 , nextY + ( CELL _H * y ) + ( CELL _H / 2 ) + 1 , Math . min ( ( CELL _W - m ) / 2 , ( CELL _H - m ) / 2 ) - 2 ) ;
2022-01-19 23:41:47 +00:00
break ;
2022-01-28 10:23:43 +00:00
case 2 :
for ( m = 1 ; m <= this . settings ( ) . tdyMrkPxl && m < CELL _H - 1 && m < CELL _W - 1 ; m ++ )
2022-01-19 23:41:47 +00:00
g . drawRect ( x * CELL _W + m , nextY + CELL _H + m , x * CELL _W + CELL _W - m , nextY + CELL _H + CELL _H - m ) ;
break ;
2022-01-28 10:23:43 +00:00
case 3 :
2022-01-19 23:41:47 +00:00
g . fillRect ( x * CELL _W + 1 , nextY + CELL _H + 1 , x * CELL _W + CELL _W - 1 , nextY + CELL _H + CELL _H - 1 ) ;
break ;
default :
break ;
}
2022-01-28 10:23:43 +00:00
g . setColor ( this . nrgb [ this . settings ( ) . tdyNumClr ] ) ; //today color or fg color
2022-02-01 22:44:59 +00:00
} else if ( this . settings ( ) . suClr && rD . getDay ( ) == 0 ) { //sundays
g . setColor ( this . nrgb [ this . settings ( ) . suClr ] ) ;
2022-01-19 23:41:47 +00:00
} else { //default
g . setColor ( g . theme . fg ) ;
}
g . drawString ( rDate , x * CELL _W + ( ( CELL _W - g . stringWidth ( rDate ) ) / 2 ) + 2 , nextY + ( ( CELL _H - DAY _NUM _FONT _SIZE + 2 ) / 2 ) + ( CELL _H * y ) ) ;
rD . setDate ( rDate + 1 ) ;
rDate = rD . getDate ( ) ;
}
}
if ( this . settings ( ) . calBorder ) {
g . setColor ( g . theme . fg ) ;
g . drawRect ( Bangle . appRect . x , CAL _Y , Bangle . appRect . x2 , CAL _Y + CAL _AREA _H - 1 ) ;
}
}
/ * *
* calculates current ISO8601 week number e . g . 2
* @ param { Date } date for the date
* @ returns { Number } } e . g . 2
* /
ISO8601calWeek ( date ) { //copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480
var tdt = new Date ( date . valueOf ( ) ) ;
var dayn = ( date . getDay ( ) + 6 ) % 7 ;
tdt . setDate ( tdt . getDate ( ) - dayn + 3 ) ;
var firstThursday = tdt . valueOf ( ) ;
tdt . setMonth ( 0 , 1 ) ;
if ( tdt . getDay ( ) !== 4 ) {
tdt . setMonth ( 0 , 1 + ( ( 4 - tdt . getDay ( ) ) + 7 ) % 7 ) ;
}
return Number ( 1 + Math . ceil ( ( firstThursday - tdt ) / 604800000 ) ) ;
}
2022-02-01 22:44:59 +00:00
}
2022-01-19 23:41:47 +00:00
2022-01-28 10:23:43 +00:00
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//Copy ABOVE the src code of clock-app and load via espruino WEB IDE
//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
2022-01-19 23:41:47 +00:00
/ * *
* Severity for logging
* /
const LogSeverity = {
DEBUG : 5 ,
INFO : 4 ,
WARNING : 3 ,
ERROR : 2 ,
EXCEPTION : 1
2022-02-01 22:44:59 +00:00
} ;
2022-01-19 23:41:47 +00:00
/ * *
* Exception : Mandatory Field not provided
* /
class EmptyMandatoryError extends Error {
/ * *
* Create Exception
* @ param { String } name of the field
* @ param { * } given data e . g . an object
* @ param { * } expected * optional * an working example
* /
constructor ( name , given , expected ) {
this . field = name ;
this . got = given ;
this . message = "Missing mandatory '" + name + "'. given '" + JSON . stringify ( given ) + "'" ;
if ( expected ) {
this . message += " != expected: '" + JSON . stringify ( expected ) + "'" ;
this . sample = expected ;
}
Error ( this . message ) ;
}
toString ( ) {
return this . message ;
}
}
/ * *
* Exception : Invalid Function
* /
class InvalidMethodName extends Error {
/ * *
* Create Exception
* @ param { String } name of the field
* @ param { * } given data e . g . an object
* @ param { * } expected * optional * an working example
* /
constructor ( className , methodName ) {
this . class = className ;
this . method = methodName ;
this . message = "Function '" + methodName + "' not found in '" + className + "'" ;
Error ( this . message ) ;
}
toString ( ) {
return this . message ;
}
}
/*************************************************************************/
/ * *
* All Test Masterclass
* /
class Test {
}
/*************************************************************************/
/ * *
* Test Settings - use this if you want e . g . test draw / render function ( s )
* /
class TestSetting extends Test {
TEST _SETTING _SAMPLE ( ) {
return {
setting : "<settingName>" ,
cases : [
{
value : "required,<settingValue>" ,
beforeTxt : "optional,<textToDisplayBeforeTest>" ,
beforeExpression : "optional,<expressionExpectedTrue>" ,
afterText : "optional,<textToDisplayAfterTest>" ,
afterExpression : "optional,<expressionExpectedTrue>"
}
2022-01-28 10:23:43 +00:00
] ,
constructorParams : [ "optional: <cpar1>" , "|TEST_SETTINGS|" , "..." ] , //TEST_SETTINGS will be replcaed with each current {setting: case}
functionNames : [ "required, <function under test>" , "..." ] ,
functionParams : [ "optional: <fpar1>" , "|TEST_SETTINGS|" , "..." ]
2022-02-01 22:44:59 +00:00
} ;
2022-01-19 23:41:47 +00:00
}
constructor ( data ) {
this . _validate ( data ) ;
this . setting = data . setting ;
this . cases = data . cases . map ( ( entry ) => {
return {
value : entry . value ,
beforeTxt : entry . beforeTxt || "" ,
beforeExpression : entry . beforeExpression || true ,
afterTxt : entry . afterTxt || "" ,
afterExpression : entry . afterExpression || true
} ;
} ) ;
2022-02-01 22:44:59 +00:00
this . constructorParams = data . constructorParams ;
2022-01-28 10:23:43 +00:00
this . functionNames = data . functionNames ;
this . functionParams = data . functionParams ;
2022-01-19 23:41:47 +00:00
}
/ * *
* validates the given data config
* /
_validate ( data ) {
//validate given config
if ( ! data . setting ) throw new EmptyMandatoryError ( "setting" , data , this . TEST _SETTING _SAMPLE ( ) ) ;
2022-01-28 10:23:43 +00:00
if ( ! ( data . cases instanceof Array ) || data . cases . length == 0 ) throw new EmptyMandatoryError ( "cases" , data , this . TEST _SETTING _SAMPLE ( ) ) ;
if ( ! ( data . functionNames instanceof Array ) || data . functionNames == 0 ) throw new EmptyMandatoryError ( "functionNames" , data , this . TEST _SETTING _SAMPLE ( ) ) ;
2022-01-19 23:41:47 +00:00
data . cases . forEach ( ( entry , idx ) => {
2022-01-28 10:23:43 +00:00
if ( entry . value === undefined ) throw new EmptyMandatoryError ( "cases[" + idx + "].value" , entry , this . TEST _SETTING _SAMPLE ( ) ) ;
2022-01-19 23:41:47 +00:00
} ) ;
}
}
/*************************************************************************/
/ * *
* Testing a Bangle object
* /
class BangleTestRunner {
/ * *
* create for ObjClass
* @ param { Class } objClass
* @ param { LogSeverity } minSeverity to Log
* /
constructor ( objClass , minSeverity ) {
this . TESTCASE _MSG _BEFORE _TIMEOUT = 1000 ; //5s
this . TESTCASE _RUN _TIMEOUT = 1000 ; //5s
this . TESTCASE _MSG _AFTER _TIMEOUT = 1000 ; //5s
this . oClass = objClass ;
this . minSvrty = minSeverity ;
this . tests = [ ] ;
this . currentCaseNum = this . currentTestNum = this . currentTest = this . currentCase = undefined ;
}
/ * *
* add a Setting Test , return instance for chaining
* @ param { TestSetting }
* /
2022-01-28 10:23:43 +00:00
addTestSettings ( sttngs ) {
this . tests . push ( new TestSetting ( sttngs ) ) ;
2022-01-19 23:41:47 +00:00
return this ;
}
/ * *
* Test execution of all tests
* /
execute ( ) {
this . _init ( ) ;
while ( this . _nextTest ( ) ) {
this . _beforeTest ( ) ;
while ( this . _nextCase ( ) ) {
this . _beforeCase ( ) ;
this . _runCase ( ) ;
this . _afterCase ( ) ;
}
this . _afterTest ( ) ;
2022-02-01 22:44:59 +00:00
this . _firstCase ( ) ;
2022-01-28 10:23:43 +00:00
}
2022-02-01 22:44:59 +00:00
this . _exit ( ) ;
2022-01-19 23:41:47 +00:00
}
/ * *
2022-01-28 10:23:43 +00:00
* global prepare - before all test
2022-01-19 23:41:47 +00:00
* /
_init ( ) {
2022-02-01 22:44:59 +00:00
console . log ( this . _nowTime ( ) , ">>init" ) ;
2022-01-19 23:41:47 +00:00
this . currentTestNum = - 1 ;
this . currentCaseNum = - 1 ;
}
/ * *
* before each test
* /
_beforeTest ( ) {
2022-02-01 22:44:59 +00:00
console . log ( this . _nowTime ( ) , ">>test #" + this . currentTestNum ) ;
2022-01-19 23:41:47 +00:00
}
/ * *
* befor each testcase
* /
_beforeCase ( ) {
2022-02-01 22:44:59 +00:00
console . log ( this . _nowTime ( ) , ">>case #" + this . currentTestNum + "." + this . currentCaseNum + "/" + ( this . currentTest . cases . length - 1 ) ) ;
if ( this . currentTest instanceof TestSetting )
console . log ( this . currentTest . setting + "=" + this . currentCase . value + "\n"
+ this . currentCase . beforeTxt ? "testcase:" + this . currentCase . beforeTxt : ""
2022-01-19 23:41:47 +00:00
) ;
}
2022-01-28 10:23:43 +00:00
/ * *
* testcase runner
* /
2022-01-19 23:41:47 +00:00
_runCase ( ) {
2022-02-01 22:44:59 +00:00
console . log ( this . _nowTime ( ) , ">>running..." ) ;
2022-01-19 23:41:47 +00:00
var returns = [ ] ;
2022-01-28 10:23:43 +00:00
this . currentTest . functionNames . forEach ( ( fName ) => {
var settings = { } ; settings [ this . currentTest . setting ] = this . currentCase . value ;
var cParams = this . currentTest . constructorParams || [ ] ;
2022-02-01 22:44:59 +00:00
cParams = cParams . map ( ( v ) => ( v && v instanceof String && v === "|TEST_SETTINGS|" ) ? settings : v ) ; //replace settings in call params
2022-01-28 10:23:43 +00:00
var fParams = this . currentTest . functionParams || [ ] ;
2022-02-01 22:44:59 +00:00
fParams = fParams . map ( ( v ) => ( v && v instanceof String && v === "|TEST_SETTINGS|" ) ? settings : v ) ; //replace settings in call params
2022-01-28 10:23:43 +00:00
2022-02-01 22:44:59 +00:00
var creatorFunc = new Function ( "console.log('Constructor params:', arguments); return new " + this . oClass + "(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8],arguments[9])" ) ; //prepare spwan arguments[0],arguments[1]
2022-01-28 10:23:43 +00:00
let instance = creatorFunc . call ( this . oClass , cParams [ 0 ] , cParams [ 1 ] , cParams [ 2 ] , cParams [ 3 ] , cParams [ 4 ] , cParams [ 5 ] , cParams [ 6 ] , cParams [ 7 ] , cParams [ 8 ] , cParams [ 9 ] ) ; //spwan
console . log ( ">>" + this . oClass + "[" + fName + "]()" ) ;
2022-02-01 22:44:59 +00:00
console . log ( 'Instance:' , instance ) ;
console . log ( 'Function params:' , fParams ) ;
2022-01-28 10:23:43 +00:00
returns . push ( instance [ fName ] ( fParams [ 0 ] , fParams [ 1 ] , fParams [ 2 ] , fParams [ 3 ] , fParams [ 4 ] , fParams [ 5 ] , fParams [ 6 ] , fParams [ 7 ] , fParams [ 8 ] , fParams [ 9 ] ) ) ; //run method and store result
g . dump ( ) ;
2022-02-01 22:44:59 +00:00
console . log ( "<<" + this . oClass + "[" + fName + "]()" ) ;
2022-01-19 23:41:47 +00:00
} ) ;
2022-02-01 22:44:59 +00:00
console . log ( this . _nowTime ( ) , "<<...running" ) ;
2022-01-19 23:41:47 +00:00
}
2022-01-28 10:23:43 +00:00
/ * *
* after each testcase
* /
2022-01-19 23:41:47 +00:00
_afterCase ( ) {
2022-02-01 22:44:59 +00:00
if ( this . currentTest instanceof TestSetting )
if ( this . currentCase . afterTxt . length > 0 )
console . log ( "++EXPECTED:" + this . currentCase . afterTxt + "EXPECTED++" ) ;
console . log ( this . _nowTime ( ) , "<<case #" + this . currentTestNum + "." + this . currentCaseNum + "/" + ( this . currentTest . cases . length - 1 ) ) ;
2022-01-19 23:41:47 +00:00
}
2022-01-28 10:23:43 +00:00
/ * *
* after each test
* /
2022-01-19 23:41:47 +00:00
_afterTest ( ) {
2022-02-01 22:44:59 +00:00
console . log ( this . _nowTime ( ) , "<<test #" + this . currentTestNum ) ;
2022-01-19 23:41:47 +00:00
}
2022-01-28 10:23:43 +00:00
/ * *
* after all tests
* /
2022-01-19 23:41:47 +00:00
_exit ( ) {
2022-02-01 22:44:59 +00:00
console . log ( this . _nowTime ( ) , "<<exit" ) ;
2022-01-19 23:41:47 +00:00
}
/ * *
* delays for x seconds
* @ param { Number } sec to delay
* /
_delay ( sec ) {
return new Promise ( resolve => setTimeout ( resolve , sec ) ) ;
}
_waits ( sec ) {
this . _delay ( 1 ) . then ( ) ;
}
_log ( ) {
}
_nextTest ( ) {
if ( this . currentTestNum >= - 1 && ( this . currentTestNum + 1 ) < this . tests . length ) {
2022-02-01 22:44:59 +00:00
this . currentTestNum ++ ; this . currentTest = this . tests [ this . currentTestNum ] ;
2022-01-19 23:41:47 +00:00
return true ;
}
return false ;
}
2022-02-01 22:44:59 +00:00
_firstCase ( ) {
this . currentCaseNum = - 1 ;
}
2022-01-19 23:41:47 +00:00
_nextCase ( ) {
if ( this . currentCaseNum >= - 1 && ( this . currentCaseNum + 1 ) < this . currentTest . cases . length ) {
2022-02-01 22:44:59 +00:00
this . currentCaseNum ++ ; this . currentCase = this . currentTest . cases [ this . currentCaseNum ] ;
2022-01-19 23:41:47 +00:00
return true ;
}
return false ;
}
2022-02-01 22:44:59 +00:00
_nowTime ( ) {
d = new Date ( ) ;
return ( ( "0" + d . getHours ( ) ) . slice ( - 2 ) + ":" + ( "0" + d . getMinutes ( ) ) . slice ( - 2 ) + ":" + ( "0" + d . getSeconds ( ) ) . slice ( - 2 ) + "." + ( "00" + d . getMilliseconds ( ) ) . slice ( - 3 ) )
}
2022-01-19 23:41:47 +00:00
}
/ * *
2022-01-28 10:23:43 +00:00
* TEST all Settings
2022-01-19 23:41:47 +00:00
* /
2022-02-01 22:44:59 +00:00
const SUNDAY =
2022-01-28 10:23:43 +00:00
new BangleTestRunner ( "TimeCalClock" , LogSeverity . INFO )
2022-02-01 22:44:59 +00:00
/ *
. addTestSettings ( {
setting : "shwDate" ,
cases : [
{ value : 0 , beforeTxt : "No date display?" , afterTxt : "top area should be 'emtpy'" } ,
{ value : 1 , beforeTxt : "Locale date display?" , afterTxt : "date should be 06/05/1234" } ,
{ value : 2 , beforeTxt : "Month longname?" , afterTxt : "date should be June" } ,
{ value : 3 , beforeTxt : "Monthshort yearshort #week" , afterTxt : "date should be Jun.34 #23" }
] ,
constructorParams : [ new Date ( 1234 , 5 , 6 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawDate" ] ,
functionParams : [ ] ,
} )
* /
/ *
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : 0 , beforeTxt : "Week start Sunday?" , afterTxt : "Calendar first day is Sunday" } ,
{ value : 1 , beforeTxt : "Week start Monday?" , afterTxt : "Calendar first day is Monday" } ,
{ value : 2 , beforeTxt : "Week start Tuesday?" , afterTxt : "Calendar first day is Tuesday" } ,
{ value : 3 , beforeTxt : "Week start Wednesday?" , afterTxt : "Calendar first day is Wednesday" } ,
{ value : 4 , beforeTxt : "Week start Thursday?" , afterTxt : "Calendar first day is Thursday" } ,
{ value : 5 , beforeTxt : "Week start Friday?" , afterTxt : "Calendar first day is Friday" } ,
{ value : 6 , beforeTxt : "Week start Saturday?" , afterTxt : "Calendar first day is Saturday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 3 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
2022-01-28 10:23:43 +00:00
. addTestSettings ( {
2022-02-01 22:44:59 +00:00
setting : "wdStrt" ,
cases : [
{ value : 0 , beforeTxt : "Week start Sunday?" , afterTxt : "Calendar first day is Sunday" } ,
{ value : 1 , beforeTxt : "Week start Monday?" , afterTxt : "Calendar first day is Monday" } ,
{ value : 2 , beforeTxt : "Week start Tuesday?" , afterTxt : "Calendar first day is Tuesday" } ,
{ value : 3 , beforeTxt : "Week start Wednesday?" , afterTxt : "Calendar first day is Wednesday" } ,
{ value : 4 , beforeTxt : "Week start Thursday?" , afterTxt : "Calendar first day is Thursday" } ,
{ value : 5 , beforeTxt : "Week start Friday?" , afterTxt : "Calendar first day is Friday" } ,
{ value : 6 , beforeTxt : "Week start Saturday?" , afterTxt : "Calendar first day is Saturday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 4 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : 0 , beforeTxt : "Week start Sunday?" , afterTxt : "Calendar first day is Sunday" } ,
{ value : 1 , beforeTxt : "Week start Monday?" , afterTxt : "Calendar first day is Monday" } ,
{ value : 2 , beforeTxt : "Week start Tuesday?" , afterTxt : "Calendar first day is Tuesday" } ,
{ value : 3 , beforeTxt : "Week start Wednesday?" , afterTxt : "Calendar first day is Wednesday" } ,
{ value : 4 , beforeTxt : "Week start Thursday?" , afterTxt : "Calendar first day is Thursday" } ,
{ value : 5 , beforeTxt : "Week start Friday?" , afterTxt : "Calendar first day is Friday" } ,
{ value : 6 , beforeTxt : "Week start Saturday?" , afterTxt : "Calendar first day is Saturday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 5 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : 0 , beforeTxt : "Week start Sunday?" , afterTxt : "Calendar first day is Sunday" } ,
{ value : 1 , beforeTxt : "Week start Monday?" , afterTxt : "Calendar first day is Monday" } ,
{ value : 2 , beforeTxt : "Week start Tuesday?" , afterTxt : "Calendar first day is Tuesday" } ,
{ value : 3 , beforeTxt : "Week start Wednesday?" , afterTxt : "Calendar first day is Wednesday" } ,
{ value : 4 , beforeTxt : "Week start Thursday?" , afterTxt : "Calendar first day is Thursday" } ,
{ value : 5 , beforeTxt : "Week start Friday?" , afterTxt : "Calendar first day is Friday" } ,
{ value : 6 , beforeTxt : "Week start Saturday?" , afterTxt : "Calendar first day is Saturday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 6 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : 0 , beforeTxt : "Week start Sunday?" , afterTxt : "Calendar first day is Sunday" } ,
{ value : 1 , beforeTxt : "Week start Monday?" , afterTxt : "Calendar first day is Monday" } ,
{ value : 2 , beforeTxt : "Week start Tuesday?" , afterTxt : "Calendar first day is Tuesday" } ,
{ value : 3 , beforeTxt : "Week start Wednesday?" , afterTxt : "Calendar first day is Wednesday" } ,
{ value : 4 , beforeTxt : "Week start Thursday?" , afterTxt : "Calendar first day is Thursday" } ,
{ value : 5 , beforeTxt : "Week start Friday?" , afterTxt : "Calendar first day is Friday" } ,
{ value : 6 , beforeTxt : "Week start Saturday?" , afterTxt : "Calendar first day is Saturday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 7 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : 0 , beforeTxt : "Week start Sunday?" , afterTxt : "Calendar first day is Sunday" } ,
{ value : 1 , beforeTxt : "Week start Monday?" , afterTxt : "Calendar first day is Monday" } ,
{ value : 2 , beforeTxt : "Week start Tuesday?" , afterTxt : "Calendar first day is Tuesday" } ,
{ value : 3 , beforeTxt : "Week start Wednesday?" , afterTxt : "Calendar first day is Wednesday" } ,
{ value : 4 , beforeTxt : "Week start Thursday?" , afterTxt : "Calendar first day is Thursday" } ,
{ value : 5 , beforeTxt : "Week start Friday?" , afterTxt : "Calendar first day is Friday" } ,
{ value : 6 , beforeTxt : "Week start Saturday?" , afterTxt : "Calendar first day is Saturday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 8 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
* /
/ *
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : - 1 , beforeTxt : "Sunday in mid?" , afterTxt : "Calendar focus today: Sunday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 3 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : - 1 , beforeTxt : "Monday in mid?" , afterTxt : "Calendar focus today: Monday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 4 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : - 1 , beforeTxt : "Tuesday in mid?" , afterTxt : "Calendar focus today: Tuesday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 5 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
. addTestSettings ( {
setting : "wdStrt" ,
2022-01-28 10:23:43 +00:00
cases : [
2022-02-01 22:44:59 +00:00
{ value : - 1 , beforeTxt : "Wednesday in mid?" , afterTxt : "Calendar focus today: Wednesday" } ,
2022-01-28 10:23:43 +00:00
] ,
constructorParams : [ new Date ( 1234 , 5 , 6 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
2022-02-01 22:44:59 +00:00
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : - 1 , beforeTxt : "Thursday in mid?" , afterTxt : "Calendar focus today: Thursday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 7 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : - 1 , beforeTxt : "Friday in mid?" , afterTxt : "Calendar focus today: Friday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 8 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
. addTestSettings ( {
setting : "wdStrt" ,
cases : [
{ value : - 1 , beforeTxt : "Saturday in mid?" , afterTxt : "Calendar focus today: Saturday" } ,
] ,
constructorParams : [ new Date ( 1234 , 5 , 9 , 7 , 8 , 9 ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
* /
/ *
. addTestSettings ( {
setting : "tdyNumClr" ,
cases : [
{ value : 1 , beforeTxt : "Today color: red?" , afterTxt : "Today is marked red" } ,
{ value : 2 , beforeTxt : "Today color: green?" , afterTxt : "Today is marked green" } ,
{ value : 3 , beforeTxt : "Today color: blue?" , afterTxt : "Today is marked blue" } ,
] ,
constructorParams : [ new Date ( ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
* /
/ *
. addTestSettings ( {
setting : "tdyMrkr" ,
cases : [
{ value : 1 , beforeTxt : "Today highlight cricle?" , afterTxt : "Today circled." } ,
{ value : 2 , beforeTxt : "Today highlight rectangle?" , afterTxt : "Today rectangled." } ,
{ value : 3 , beforeTxt : "Today highlight filled?" , afterTxt : "Today filled." } ,
] ,
constructorParams : [ new Date ( ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
functionParams : [ ] ,
} )
* /
/ *
. addTestSettings ( {
setting : "suClr" ,
cases : [
{ value : 1 , beforeTxt : "Sundays color: red?" , afterTxt : "Sundays are red" } ,
{ value : 2 , beforeTxt : "Sundays color: green?" , afterTxt : "Sundays are green" } ,
{ value : 3 , beforeTxt : "Sundays color: blue?" , afterTxt : "Sundays are blue" } ,
] ,
constructorParams : [ new Date ( ) , "|TEST_SETTINGS|" ] ,
functionNames : [ "drawCal" ] ,
2022-01-28 10:23:43 +00:00
functionParams : [ ] ,
2022-02-01 22:44:59 +00:00
} )
* /
2022-01-28 10:23:43 +00:00
. execute ( ) ;