1
+ describe ( "Utils Spec" , function ( ) {
2
+ it ( "can format file sizes in a human readable form" , function ( ) {
3
+ expect ( formatBytes ( 10 ) ) . toBe ( "0.01 KB" ) ;
4
+ expect ( formatBytes ( 1000000000 ) ) . toBe ( "1.00 GB" ) ;
5
+ expect ( formatBytes ( 1000000 ) ) . toBe ( "1.00 MB" ) ;
6
+ } ) ;
7
+
8
+ it ( "can format a date to the financial year in which it falls" , function ( ) {
9
+
10
+ expect ( isoDateToFinancialYear ( "2017-12-31T13:00:00Z" ) ) . toBe ( "2017/2018" ) ;
11
+ expect ( isoDateToFinancialYear ( "2017-05-30T14:00:00Z" ) ) . toBe ( "2016/2017" ) ;
12
+ expect ( isoDateToFinancialYear ( "2017-07-01T14:00:00Z" ) ) . toBe ( "2017/2018" ) ;
13
+
14
+ } ) ;
15
+
16
+ it ( "will treat a date at midnight of July 1 as the previous financial year" , function ( ) {
17
+ expect ( isoDateToFinancialYear ( "2017-06-30T14:00:00Z" ) ) . toBe ( "2016/2017" ) ;
18
+ } ) ;
19
+
20
+ it ( "can parse a date from an iso string" , function ( ) {
21
+ var date = Date . fromISO ( "2019-02-01T03:23:55Z" ) ;
22
+ expect ( date . getUTCDate ( ) ) . toBe ( 1 ) ;
23
+ expect ( date . getUTCMonth ( ) ) . toBe ( 1 ) ;
24
+ expect ( date . getUTCFullYear ( ) ) . toBe ( 2019 ) ;
25
+ expect ( date . getUTCMinutes ( ) ) . toBe ( 23 ) ;
26
+ expect ( date . getUTCHours ( ) ) . toBe ( 3 ) ;
27
+ } ) ;
28
+
29
+ it ( "can tell if a date is valid" , function ( ) {
30
+ expect ( isValidDate ( "3" ) ) . toBeFalsy ( ) ;
31
+ expect ( isValidDate ( new Date ( ) ) ) . toBeTruthy ( ) ;
32
+ } ) ;
33
+
34
+ it ( "can format a UTC date into a simple date string" , function ( ) {
35
+ expect ( convertToSimpleDate ( "2019-01-31T13:00:00Z" ) ) . toBe ( "01-02-2019" ) ;
36
+ } ) ;
37
+
38
+ it ( "can format a date in ISO 8601 format" , function ( ) {
39
+ expect ( convertToIsoDate ( "2019-01-31T13:00:00Z" ) ) . toBe ( "2019-01-31T13:00:00Z" ) ;
40
+ expect ( convertToIsoDate ( "31-01-2019" ) ) . toBe ( "2019-01-30T13:00:00Z" ) ; // Potentially problematic due to time zones in travis...
41
+ } )
42
+ } ) ;
0 commit comments