2017-07-31 22:09:08 +02:00
global . moment = require ( "moment" ) ;
2017-03-26 00:49:00 -03:00
2022-10-04 10:15:24 +02:00
describe ( "Functions into modules/default/calendar/calendar.js" , ( ) => {
2017-03-26 00:49:00 -03:00
// Fake for use by calendar.js
2019-06-04 10:19:25 +02:00
Module = { } ;
2017-03-26 00:49:00 -03:00
Module . definitions = { } ;
2022-10-04 10:15:24 +02:00
Module . register = ( name , moduleDefinition ) => {
2017-03-26 00:49:00 -03:00
Module . definitions [ name ] = moduleDefinition ;
} ;
2022-10-04 10:15:24 +02:00
beforeAll ( ( ) => {
2017-07-25 09:32:32 -04:00
// load calendar.js
require ( "../../../modules/default/calendar/calendar.js" ) ;
} ) ;
2017-03-26 00:49:00 -03:00
2022-10-04 10:15:24 +02:00
describe ( "capFirst" , ( ) => {
2020-05-05 14:54:49 +02:00
const words = {
2020-05-11 22:22:32 +02:00
rodrigo : "Rodrigo" ,
2017-04-19 00:45:55 -03:00
"123m" : "123m" ,
"magic mirror" : "Magic mirror" ,
",a" : ",a" ,
2020-05-11 22:22:32 +02:00
ñandú : "Ñandú"
2017-03-26 00:49:00 -03:00
} ;
2020-05-11 22:22:32 +02:00
Object . keys ( words ) . forEach ( ( word ) => {
2022-10-04 10:15:24 +02:00
it ( ` for ' ${ word } ' should return ' ${ words [ word ] } ' ` , ( ) => {
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . capFirst ( word ) ) . toBe ( words [ word ] ) ;
2017-03-26 00:49:00 -03:00
} ) ;
} ) ;
} ) ;
2017-07-29 16:02:53 +02:00
2022-10-04 10:15:24 +02:00
describe ( "getLocaleSpecification" , ( ) => {
it ( "should return a valid moment.LocaleSpecification for a 12-hour format" , ( ) => {
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . getLocaleSpecification ( 12 ) ) . toEqual ( { longDateFormat : { LT : "h:mm A" } } ) ;
2017-07-31 22:09:08 +02:00
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should return a valid moment.LocaleSpecification for a 24-hour format" , ( ) => {
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . getLocaleSpecification ( 24 ) ) . toEqual ( { longDateFormat : { LT : "HH:mm" } } ) ;
2017-07-31 22:09:08 +02:00
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should return the current system locale when called without timeFormat number" , ( ) => {
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . getLocaleSpecification ( ) ) . toEqual ( { longDateFormat : { LT : moment . localeData ( ) . longDateFormat ( "LT" ) } } ) ;
2017-07-31 22:09:08 +02:00
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should return a 12-hour longDateFormat when using the 'en' locale" , ( ) => {
2021-01-04 21:59:41 +01:00
const localeBackup = moment . locale ( ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( "en" ) ;
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . getLocaleSpecification ( ) ) . toEqual ( { longDateFormat : { LT : "h:mm A" } } ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( localeBackup ) ;
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should return a 12-hour longDateFormat when using the 'au' locale" , ( ) => {
2021-01-04 21:59:41 +01:00
const localeBackup = moment . locale ( ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( "au" ) ;
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . getLocaleSpecification ( ) ) . toEqual ( { longDateFormat : { LT : "h:mm A" } } ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( localeBackup ) ;
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should return a 12-hour longDateFormat when using the 'eg' locale" , ( ) => {
2021-01-04 21:59:41 +01:00
const localeBackup = moment . locale ( ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( "eg" ) ;
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . getLocaleSpecification ( ) ) . toEqual ( { longDateFormat : { LT : "h:mm A" } } ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( localeBackup ) ;
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should return a 24-hour longDateFormat when using the 'nl' locale" , ( ) => {
2021-01-04 21:59:41 +01:00
const localeBackup = moment . locale ( ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( "nl" ) ;
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . getLocaleSpecification ( ) ) . toEqual ( { longDateFormat : { LT : "HH:mm" } } ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( localeBackup ) ;
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should return a 24-hour longDateFormat when using the 'fr' locale" , ( ) => {
2021-01-04 21:59:41 +01:00
const localeBackup = moment . locale ( ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( "fr" ) ;
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . getLocaleSpecification ( ) ) . toEqual ( { longDateFormat : { LT : "HH:mm" } } ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( localeBackup ) ;
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should return a 24-hour longDateFormat when using the 'uk' locale" , ( ) => {
2021-01-04 21:59:41 +01:00
const localeBackup = moment . locale ( ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( "uk" ) ;
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . getLocaleSpecification ( ) ) . toEqual ( { longDateFormat : { LT : "HH:mm" } } ) ;
2017-07-31 22:09:08 +02:00
moment . locale ( localeBackup ) ;
} ) ;
} ) ;
2022-10-04 10:15:24 +02:00
describe ( "shorten" , ( ) => {
2020-05-05 14:54:49 +02:00
const strings = {
2022-12-10 21:50:56 +01:00
" String with whitespace at the beginning that needs trimming" : { length : 16 , return : "String with whit…" } ,
"long string that needs shortening" : { length : 16 , return : "long string that…" } ,
2017-07-29 16:02:53 +02:00
"short string" : { length : 16 , return : "short string" } ,
2020-05-11 22:22:32 +02:00
"long string with no maxLength defined" : { return : "long string with no maxLength defined" }
2017-07-29 16:02:53 +02:00
} ;
2020-05-11 22:22:32 +02:00
Object . keys ( strings ) . forEach ( ( string ) => {
2022-10-04 10:15:24 +02:00
it ( ` for ' ${ string } ' should return ' ${ strings [ string ] . return } ' ` , ( ) => {
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . shorten ( string , strings [ string ] . length ) ) . toBe ( strings [ string ] . return ) ;
2017-07-29 16:02:53 +02:00
} ) ;
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should return an empty string if shorten is called with a non-string" , ( ) => {
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . shorten ( 100 ) ) . toBe ( "" ) ;
2017-07-29 16:02:53 +02:00
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should not shorten the string if shorten is called with a non-number maxLength" , ( ) => {
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . shorten ( "This is a test string" , "This is not a number" ) ) . toBe ( "This is a test string" ) ;
2017-07-29 16:02:53 +02:00
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should wrap the string instead of shorten it if shorten is called with wrapEvents = true (with maxLength defined as 20)" , ( ) => {
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . shorten ( "This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true" , 20 , true ) ) . toBe (
2020-05-11 22:22:32 +02:00
"This is a <br>wrapEvent test. Should wrap <br>the string instead of <br>shorten it if called with <br>wrapEvent = true"
) ;
2017-07-29 16:02:53 +02:00
} ) ;
2022-10-04 10:15:24 +02:00
it ( "should wrap the string instead of shorten it if shorten is called with wrapEvents = true (without maxLength defined, default 25)" , ( ) => {
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . shorten ( "This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true" , undefined , true ) ) . toBe (
2020-05-11 22:22:32 +02:00
"This is a wrapEvent <br>test. Should wrap the string <br>instead of shorten it if called <br>with wrapEvent = true"
) ;
2017-07-29 16:02:53 +02:00
} ) ;
2020-07-15 13:15:03 +02:00
2022-10-04 10:15:24 +02:00
it ( "should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2" , ( ) => {
2021-06-08 00:47:15 +02:00
expect ( Module . definitions . calendar . shorten ( "This is a wrapEvent and maxTitleLines test. Should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2" , undefined , true , 2 ) ) . toBe (
2022-12-10 21:50:56 +01:00
"This is a wrapEvent and <br>maxTitleLines test. Should wrap and …"
2020-07-15 13:15:03 +02:00
) ;
} ) ;
2017-07-29 16:02:53 +02:00
} ) ;
2017-03-26 00:49:00 -03:00
} ) ;