1
+ import { locale } from '$lib/stores/preferences.store' ;
1
2
import { parseUtcDate } from '$lib/utils/date-time' ;
2
3
import { formatGroupTitle } from '$lib/utils/timeline-util' ;
3
4
import { DateTime } from 'luxon' ;
@@ -16,48 +17,63 @@ describe('formatGroupTitle', () => {
16
17
17
18
it ( 'formats today' , ( ) => {
18
19
const date = parseUtcDate ( '2024-07-27T01:00:00Z' ) ;
19
- expect ( formatGroupTitle ( date . setLocale ( 'en' ) ) ) . toBe ( 'today' ) ;
20
- expect ( formatGroupTitle ( date . setLocale ( 'es' ) ) ) . toBe ( 'hoy' ) ;
20
+ locale . set ( 'en' ) ;
21
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'today' ) ;
22
+ locale . set ( 'es' ) ;
23
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'hoy' ) ;
21
24
} ) ;
22
25
23
26
it ( 'formats yesterday' , ( ) => {
24
27
const date = parseUtcDate ( '2024-07-26T23:59:59Z' ) ;
25
- expect ( formatGroupTitle ( date . setLocale ( 'en' ) ) ) . toBe ( 'yesterday' ) ;
26
- expect ( formatGroupTitle ( date . setLocale ( 'fr' ) ) ) . toBe ( 'hier' ) ;
28
+ locale . set ( 'en' ) ;
29
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'yesterday' ) ;
30
+ locale . set ( 'fr' ) ;
31
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'hier' ) ;
27
32
} ) ;
28
33
29
34
it ( 'formats last week' , ( ) => {
30
35
const date = parseUtcDate ( '2024-07-21T00:00:00Z' ) ;
31
- expect ( formatGroupTitle ( date . setLocale ( 'en' ) ) ) . toBe ( 'Sunday' ) ;
32
- expect ( formatGroupTitle ( date . setLocale ( 'ar-SA' ) ) ) . toBe ( 'الأحد' ) ;
36
+ locale . set ( 'en' ) ;
37
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'Sunday' ) ;
38
+ locale . set ( 'ar-SA' )
39
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'الأحد' ) ;
33
40
} ) ;
34
41
35
42
it ( 'formats date 7 days ago' , ( ) => {
36
43
const date = parseUtcDate ( '2024-07-20T00:00:00Z' ) ;
37
- expect ( formatGroupTitle ( date . setLocale ( 'en' ) ) ) . toBe ( 'Sat, Jul 20' ) ;
38
- expect ( formatGroupTitle ( date . setLocale ( 'de' ) ) ) . toBe ( 'Sa., 20. Juli' ) ;
44
+ locale . set ( 'en' ) ;
45
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'Sat, Jul 20' ) ;
46
+ locale . set ( 'de' )
47
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'Sa., 20. Juli' ) ;
39
48
} ) ;
40
49
41
50
it ( 'formats date this year' , ( ) => {
42
51
const date = parseUtcDate ( '2020-01-01T00:00:00Z' ) ;
43
- expect ( formatGroupTitle ( date . setLocale ( 'en' ) ) ) . toBe ( 'Wed, Jan 1, 2020' ) ;
44
- expect ( formatGroupTitle ( date . setLocale ( 'ja' ) ) ) . toBe ( '2020年1月1日(水)' ) ;
52
+ locale . set ( 'en' ) ;
53
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'Wed, Jan 1, 2020' ) ;
54
+ locale . set ( 'ja' )
55
+ expect ( formatGroupTitle ( date ) ) . toBe ( '2020年1月1日(水)' ) ;
45
56
} ) ;
46
57
47
58
it ( 'formats future date' , ( ) => {
48
59
const tomorrow = parseUtcDate ( '2024-07-28T00:00:00Z' ) ;
49
- expect ( formatGroupTitle ( tomorrow . setLocale ( 'en' ) ) ) . toBe ( 'Sun, Jul 28' ) ;
60
+ locale . set ( 'en' )
61
+ expect ( formatGroupTitle ( tomorrow ) ) . toBe ( 'Sun, Jul 28' ) ;
50
62
51
63
const nextMonth = parseUtcDate ( '2024-08-28T00:00:00Z' ) ;
52
- expect ( formatGroupTitle ( nextMonth . setLocale ( 'en' ) ) ) . toBe ( 'Wed, Aug 28' ) ;
64
+ locale . set ( 'en' ) ;
65
+ expect ( formatGroupTitle ( nextMonth ) ) . toBe ( 'Wed, Aug 28' ) ;
53
66
54
67
const nextYear = parseUtcDate ( '2025-01-10T12:00:00Z' ) ;
55
- expect ( formatGroupTitle ( nextYear . setLocale ( 'en' ) ) ) . toBe ( 'Fri, Jan 10, 2025' ) ;
68
+ locale . set ( 'en' ) ;
69
+ expect ( formatGroupTitle ( nextYear ) ) . toBe ( 'Fri, Jan 10, 2025' ) ;
56
70
} ) ;
57
71
58
72
it ( 'returns "Invalid DateTime" when date is invalid' , ( ) => {
59
73
const date = DateTime . invalid ( 'test' ) ;
60
- expect ( formatGroupTitle ( date . setLocale ( 'en' ) ) ) . toBe ( 'Invalid DateTime' ) ;
61
- expect ( formatGroupTitle ( date . setLocale ( 'es' ) ) ) . toBe ( 'Invalid DateTime' ) ;
74
+ locale . set ( 'en' ) ;
75
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'Invalid DateTime' ) ;
76
+ locale . set ( 'es' ) ;
77
+ expect ( formatGroupTitle ( date ) ) . toBe ( 'Invalid DateTime' ) ;
62
78
} ) ;
63
79
} ) ;
0 commit comments