@@ -271,6 +271,46 @@ describe('HeaderFooterEditorManager', () => {
271271 expect ( sectionPages . textContent ) . toBe ( '3' ) ;
272272 } ) ;
273273
274+ it ( 'refreshes section page count DOM text when section context is available' , ( ) => {
275+ const editor = createMockEditor ( ) ;
276+ const manager = new HeaderFooterEditorManager ( editor ) ;
277+ const descriptor = { id : 'rId-header-default' , kind : 'header' } as const ;
278+ const host = document . createElement ( 'div' ) ;
279+
280+ const sectionEditor = manager . ensureEditorSync ( descriptor , { editorHost : host } ) ;
281+ expect ( sectionEditor ) . toBeDefined ( ) ;
282+ const sectionPages = document . createElement ( 'span' ) ;
283+ sectionPages . dataset . id = 'auto-section-pages' ;
284+ sectionPages . textContent = '3' ;
285+ sectionEditor ! . view . dom . appendChild ( sectionPages ) ;
286+
287+ manager . ensureEditorSync ( descriptor , { editorHost : host , sectionPageCount : 5 } ) ;
288+
289+ expect ( sectionPages . textContent ) . toBe ( '5' ) ;
290+ } ) ;
291+
292+ it ( 'refreshes section page count DOM text with node pageNumberFormat' , ( ) => {
293+ const editor = createMockEditor ( ) ;
294+ const manager = new HeaderFooterEditorManager ( editor ) ;
295+ const descriptor = { id : 'rId-header-default' , kind : 'header' } as const ;
296+ const host = document . createElement ( 'div' ) ;
297+
298+ const sectionEditor = manager . ensureEditorSync ( descriptor , { editorHost : host } ) ;
299+ expect ( sectionEditor ) . toBeDefined ( ) ;
300+ const sectionPages = document . createElement ( 'span' ) ;
301+ sectionPages . dataset . id = 'auto-section-pages' ;
302+ sectionPages . textContent = '3' ;
303+ sectionEditor ! . view . dom . appendChild ( sectionPages ) ;
304+ ( sectionEditor ! . view as unknown as { posAtDOM : ReturnType < typeof vi . fn > } ) . posAtDOM = vi . fn ( ( ) => 0 ) ;
305+ ( sectionEditor as unknown as { state : { doc : { nodeAt : ReturnType < typeof vi . fn > } } } ) . state = {
306+ doc : { nodeAt : vi . fn ( ( ) => ( { attrs : { pageNumberFormat : 'upperRoman' } } ) ) } ,
307+ } ;
308+
309+ manager . ensureEditorSync ( descriptor , { editorHost : host , sectionPageCount : 4 } ) ;
310+
311+ expect ( sectionPages . textContent ) . toBe ( 'IV' ) ;
312+ } ) ;
313+
274314 it ( 'emits contentChanged and syncs converter/Yjs data when section editor updates' , async ( ) => {
275315 const editor = createMockEditor ( ) ;
276316 const manager = new HeaderFooterEditorManager ( editor ) ;
0 commit comments