@@ -149,6 +149,63 @@ describe('EditorDraftComponent', () => {
149
149
expect ( component . draftText . editor ! . getContents ( ) . ops ) . toEqual ( draftDelta . ops ) ;
150
150
} ) ) ;
151
151
152
+ it ( 'should support a timestamp earlier than the oldest draft' , fakeAsync ( ( ) => {
153
+ const testProjectDoc : SFProjectProfileDoc = {
154
+ data : createTestProjectProfile ( )
155
+ } as SFProjectProfileDoc ;
156
+ when ( mockDraftGenerationService . draftExists ( anything ( ) , anything ( ) , anything ( ) ) ) . thenReturn ( of ( true ) ) ;
157
+ when ( mockDraftGenerationService . getGeneratedDraftHistory ( anything ( ) , anything ( ) , anything ( ) ) ) . thenReturn (
158
+ of ( draftHistory )
159
+ ) ;
160
+ when ( mockActivatedProjectService . changes$ ) . thenReturn ( of ( testProjectDoc ) ) ;
161
+ spyOn < any > ( component , 'getTargetOps' ) . and . returnValue ( of ( targetDelta . ops ! ) ) ;
162
+ when ( mockDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . thenReturn ( of ( cloneDeep ( draftDelta . ops ! ) ) ) ;
163
+ when ( mockDraftHandlingService . draftDataToOps ( anything ( ) , anything ( ) ) ) . thenReturn ( draftDelta . ops ! ) ;
164
+ when ( mockDraftHandlingService . isDraftSegmentMap ( anything ( ) ) ) . thenReturn ( false ) ;
165
+
166
+ // Set the date to a time before the earliest draft
167
+ fixture . componentInstance . timestamp = new Date ( '2024-03-22T03:02:01Z' ) ;
168
+
169
+ // SUT
170
+ fixture . detectChanges ( ) ;
171
+ tick ( EDITOR_READY_TIMEOUT ) ;
172
+
173
+ verify ( mockDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
174
+ verify ( mockDraftHandlingService . draftDataToOps ( anything ( ) , anything ( ) ) ) . once ( ) ;
175
+ expect ( component . draftCheckState ) . toEqual ( 'draft-present' ) ;
176
+ expect ( component . draftText . editor ! . getContents ( ) . ops ) . toEqual ( draftDelta . ops ) ;
177
+ } ) ) ;
178
+
179
+ it ( 'should support a timestamp close to the oldest draft' , fakeAsync ( ( ) => {
180
+ const testProjectDoc : SFProjectProfileDoc = {
181
+ data : createTestProjectProfile ( )
182
+ } as SFProjectProfileDoc ;
183
+ when ( mockDraftGenerationService . draftExists ( anything ( ) , anything ( ) , anything ( ) ) ) . thenReturn ( of ( true ) ) ;
184
+ when ( mockDraftGenerationService . getGeneratedDraftHistory ( anything ( ) , anything ( ) , anything ( ) ) ) . thenReturn (
185
+ of ( draftHistory )
186
+ ) ;
187
+ when ( mockActivatedProjectService . changes$ ) . thenReturn ( of ( testProjectDoc ) ) ;
188
+ spyOn < any > ( component , 'getTargetOps' ) . and . returnValue ( of ( targetDelta . ops ! ) ) ;
189
+ when ( mockDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . thenReturn ( of ( cloneDeep ( draftDelta . ops ! ) ) ) ;
190
+ when ( mockDraftHandlingService . draftDataToOps ( anything ( ) , anything ( ) ) ) . thenReturn ( draftDelta . ops ! ) ;
191
+ when ( mockDraftHandlingService . isDraftSegmentMap ( anything ( ) ) ) . thenReturn ( false ) ;
192
+
193
+ // Set the date to a time just before the earliest draft
194
+ // This will account for the delay in storing the draft
195
+ const timestamp = new Date ( draftHistory [ 0 ] . timestamp ) ;
196
+ timestamp . setMinutes ( timestamp . getMinutes ( ) - 10 ) ;
197
+ fixture . componentInstance . timestamp = timestamp ;
198
+
199
+ // SUT
200
+ fixture . detectChanges ( ) ;
201
+ tick ( EDITOR_READY_TIMEOUT ) ;
202
+
203
+ verify ( mockDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
204
+ verify ( mockDraftHandlingService . draftDataToOps ( anything ( ) , anything ( ) ) ) . once ( ) ;
205
+ expect ( component . draftCheckState ) . toEqual ( 'draft-present' ) ;
206
+ expect ( component . draftText . editor ! . getContents ( ) . ops ) . toEqual ( draftDelta . ops ) ;
207
+ } ) ) ;
208
+
152
209
it ( 'should return ops and update the editor when no revision' , fakeAsync ( ( ) => {
153
210
const testProjectDoc : SFProjectProfileDoc = {
154
211
data : createTestProjectProfile ( )
0 commit comments