@@ -94,18 +94,33 @@ describe('getDateRepresentationWithoutSameDate', () => {
94
94
} )
95
95
96
96
describe ( 'getDisplayDate' , ( ) => {
97
- const dateISO = '2001-04-04T05:20:34'
98
-
99
- it ( 'should get time string when not modified' , ( ) => {
100
- expect ( getDisplayDate ( dateISO , dateISO ) ) . toBe ( '05:20' )
97
+ beforeEach ( ( ) => {
98
+ vi . useFakeTimers ( )
101
99
} )
102
- it ( 'should get time string when same date' , ( ) => {
103
- const dateISO2 = '2001-04-04T08:25:34'
104
- expect ( getDisplayDate ( dateISO , dateISO2 ) ) . toBe ( '08:25' )
100
+ afterEach ( ( ) => {
101
+ vi . useRealTimers ( )
105
102
} )
106
- it ( 'should get date string when not same date' , ( ) => {
107
- const dateISO2 = '2001-06-04T08:25:34'
108
- expect ( getDisplayDate ( dateISO , dateISO2 ) ) . toBe ( '06/04 08:25' )
103
+
104
+ const createdDateISO = '2010-04-01T12:34:56'
105
+ const updatedDateISO = '2010-05-02T14:28:57'
106
+
107
+ it ( 'should say 今日 when updated today' , ( ) => {
108
+ vi . setSystemTime ( '2010-05-02T15:00:00' )
109
+ expect ( getDisplayDate ( createdDateISO , updatedDateISO ) ) . toBe ( '今日 14:28' )
110
+ } )
111
+ it ( 'should say 昨日 when updated yesterday' , ( ) => {
112
+ vi . setSystemTime ( '2010-05-03T15:00:00' )
113
+ expect ( getDisplayDate ( createdDateISO , updatedDateISO ) ) . toBe ( '昨日 14:28' )
114
+ } )
115
+ it ( 'should get MM/DD when updated in the same year' , ( ) => {
116
+ vi . setSystemTime ( '2010-07-07T15:00:00' )
117
+ expect ( getDisplayDate ( createdDateISO , updatedDateISO ) ) . toBe ( '05/02 14:28' )
118
+ } )
119
+ it ( 'should get YYYY/MM/DD when updated before last year' , ( ) => {
120
+ vi . setSystemTime ( '2015-10-10T15:00:00' )
121
+ expect ( getDisplayDate ( createdDateISO , updatedDateISO ) ) . toBe (
122
+ '2010/05/02 14:28'
123
+ )
109
124
} )
110
125
} )
111
126
0 commit comments