@@ -1581,6 +1581,94 @@ describe('comments-store', () => {
15811581 expect ( editorDispatch ) . toHaveBeenCalledWith ( tr ) ;
15821582 } ) ;
15831583
1584+ it ( 'bootstraps story tracked-change comments during initial DOCX load' , async ( ) => {
1585+ const editorDispatch = vi . fn ( ) ;
1586+ const tr = { setMeta : vi . fn ( ) } ;
1587+ const editor = {
1588+ converter : { commentThreadingProfile : 'range-based' } ,
1589+ state : { doc : { type : 'body-doc' } } ,
1590+ view : { state : { tr } , dispatch : editorDispatch } ,
1591+ options : { documentId : 'doc-1' } ,
1592+ } ;
1593+ const storyState = { doc : { type : 'header-doc' } } ;
1594+ const snapshot = {
1595+ type : 'insert' ,
1596+ excerpt : 'header test' ,
1597+ anchorKey : 'tc::hf:part:rId9::raw-hf-1' ,
1598+ author : 'Alice' ,
1599+ authorEmail : 'alice@example.com' ,
1600+ authorImage : null ,
1601+ date : 123 ,
1602+ story : { kind : 'story' , storyType : 'headerFooterPart' , refId : 'rId9' } ,
1603+ storyKind : 'headerFooter' ,
1604+ storyLabel : 'Header' ,
1605+ runtimeRef : { rawId : 'raw-hf-1' } ,
1606+ } ;
1607+
1608+ __mockSuperdoc . documents . value = [ { id : 'doc-1' , type : 'docx' } ] ;
1609+
1610+ trackChangesHelpersMock . getTrackChanges . mockImplementation ( ( state , id ) => {
1611+ if ( state === storyState && id === 'raw-hf-1' ) {
1612+ return [ { mark : { type : { name : 'trackInsert' } , attrs : { id : 'raw-hf-1' } } } ] ;
1613+ }
1614+ return [ ] ;
1615+ } ) ;
1616+ groupChangesMock . mockReturnValue ( [ ] ) ;
1617+ getTrackedChangeIndexMock . mockReturnValue ( {
1618+ getAll : vi . fn ( ( ) => [ snapshot ] ) ,
1619+ invalidate : vi . fn ( ) ,
1620+ invalidateAll : vi . fn ( ) ,
1621+ subscribe : vi . fn ( ( ) => ( ) => { } ) ,
1622+ dispose : vi . fn ( ) ,
1623+ } ) ;
1624+ resolveTrackedChangeInStoryMock . mockReturnValue ( {
1625+ editor : { state : storyState } ,
1626+ story : snapshot . story ,
1627+ runtimeRef : { storyKey : 'hf:part:rId9' , rawId : 'raw-hf-1' } ,
1628+ change : { rawId : 'raw-hf-1' } ,
1629+ } ) ;
1630+ createOrUpdateTrackedChangeCommentMock . mockReturnValue ( {
1631+ event : 'add' ,
1632+ changeId : 'raw-hf-1' ,
1633+ trackedChangeType : 'insert' ,
1634+ trackedChangeDisplayType : 'insert' ,
1635+ trackedChangeText : 'header test' ,
1636+ deletedText : null ,
1637+ author : 'Alice' ,
1638+ authorEmail : 'alice@example.com' ,
1639+ documentId : 'doc-1' ,
1640+ coords : { } ,
1641+ } ) ;
1642+
1643+ store . processLoadedDocxComments ( {
1644+ superdoc : __mockSuperdoc ,
1645+ editor,
1646+ comments : [ ] ,
1647+ documentId : 'doc-1' ,
1648+ } ) ;
1649+
1650+ vi . runAllTimers ( ) ;
1651+ await nextTick ( ) ;
1652+
1653+ expect ( resolveTrackedChangeInStoryMock ) . toHaveBeenCalledWith ( editor , {
1654+ kind : 'entity' ,
1655+ entityType : 'trackedChange' ,
1656+ entityId : 'raw-hf-1' ,
1657+ story : snapshot . story ,
1658+ } ) ;
1659+ expect ( store . commentsList ) . toEqual ( [
1660+ expect . objectContaining ( {
1661+ commentId : 'raw-hf-1' ,
1662+ trackedChange : true ,
1663+ trackedChangeText : 'header test' ,
1664+ trackedChangeStoryKind : 'headerFooter' ,
1665+ trackedChangeAnchorKey : 'tc::hf:part:rId9::raw-hf-1' ,
1666+ } ) ,
1667+ ] ) ;
1668+ expect ( tr . setMeta ) . toHaveBeenCalledWith ( 'CommentsPluginKey' , { type : 'force' } ) ;
1669+ expect ( editorDispatch ) . toHaveBeenCalledWith ( tr ) ;
1670+ } ) ;
1671+
15841672 it ( 'should load comments with correct created time' , ( ) => {
15851673 store . init ( {
15861674 readOnly : true ,
0 commit comments