import { Calendar } from "model/calendar" ; import moment from "moment" ; describe ( 'Calendar' , ( ) : void => { let calendar = new Calendar ( moment ( "2021-09-23" ) ) ; test ( 'constructor()' , ( ) : void => { expect ( calendar . current . monthStart . format ( "YYYY-MM-DD" ) ) . toBe ( "2021-09-01" ) ; expect ( calendar . current . weeks . length ) . toBe ( 5 ) ; expect ( calendar . current . weeks [ 0 ] ! . days [ 0 ] ! . date . format ( "YYYY-MM-DD" ) ) . toBe ( "2021-08-29" ) ; expect ( calendar . current . weeks [ 4 ] ! . days [ 6 ] ! . date . format ( "YYYY-MM-DD" ) ) . toBe ( "2021-10-02" ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 0 ] ! . days [ 2 ] ! . date ) ) . toBe ( false ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 0 ] ! . days [ 3 ] ! . date ) ) . toBe ( true ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 4 ] ! . days [ 4 ] ! . date ) ) . toBe ( true ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 4 ] ! . days [ 5 ] ! . date ) ) . toBe ( false ) ; } ) ; test ( 'nextMonth()' , ( ) : void => { calendar = calendar . nextMonth ( ) ; expect ( calendar . current . monthStart . format ( "YYYY-MM-DD" ) ) . toBe ( "2021-10-01" ) ; expect ( calendar . current . weeks . length ) . toBe ( 6 ) ; expect ( calendar . current . weeks [ 0 ] ! . days [ 0 ] ! . date . format ( "YYYY-MM-DD" ) ) . toBe ( "2021-09-26" ) ; expect ( calendar . current . weeks [ 5 ] ! . days [ 6 ] ! . date . format ( "YYYY-MM-DD" ) ) . toBe ( "2021-11-06" ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 0 ] ! . days [ 4 ] ! . date ) ) . toBe ( false ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 0 ] ! . days [ 5 ] ! . date ) ) . toBe ( true ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 5 ] ! . days [ 0 ] ! . date ) ) . toBe ( true ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 5 ] ! . days [ 1 ] ! . date ) ) . toBe ( false ) ; } ) ; test ( 'previousMonth()' , ( ) : void => { calendar = calendar . previousMonth ( ) ; expect ( calendar . current . monthStart . format ( "YYYY-MM-DD" ) ) . toBe ( "2021-09-01" ) ; expect ( calendar . current . weeks . length ) . toBe ( 5 ) ; expect ( calendar . current . weeks [ 0 ] ! . days [ 0 ] ! . date . format ( "YYYY-MM-DD" ) ) . toBe ( "2021-08-29" ) ; expect ( calendar . current . weeks [ 4 ] ! . days [ 6 ] ! . date . format ( "YYYY-MM-DD" ) ) . toBe ( "2021-10-02" ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 0 ] ! . days [ 2 ] ! . date ) ) . toBe ( false ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 0 ] ! . days [ 3 ] ! . date ) ) . toBe ( true ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 4 ] ! . days [ 4 ] ! . date ) ) . toBe ( true ) ; expect ( calendar . current . isThisMonth ( calendar . current . weeks [ 4 ] ! . days [ 5 ] ! . date ) ) . toBe ( false ) ; } ) ; } ) ;