@@ -259,14 +259,51 @@ describe('numberingPlugin', () => {
259259 expect ( result ) . toBe ( tr ) ;
260260 } ) ;
261261
262- it ( 'clears list rendering when the definition details are missing ' , ( ) => {
262+ it ( 'does not write list rendering when a missing definition is already cleared ' , ( ) => {
263263 const editor = createEditor ( ) ;
264264 const plugin = createNumberingPlugin ( editor ) ;
265265 const { appendTransaction } = plugin . spec ;
266266
267267 const paragraph = {
268268 type : { name : 'paragraph' } ,
269269 attrs : {
270+ listRendering : null ,
271+ paragraphProperties : {
272+ numberingProperties : { numId : 2 , ilvl : 0 } ,
273+ } ,
274+ } ,
275+ } ;
276+
277+ const doc = makeDoc ( [ { node : paragraph , pos : 7 } ] ) ;
278+ const tr = createTransaction ( ) ;
279+ const transactions = [ { docChanged : true , getMeta : vi . fn ( ) . mockReturnValue ( false ) } ] ;
280+
281+ ListHelpers . getListDefinitionDetails . mockReturnValue ( null ) ;
282+
283+ const result = appendTransaction ( transactions , { } , { doc, tr } ) ;
284+
285+ expect ( tr . setNodeAttribute ) . not . toHaveBeenCalled ( ) ;
286+ expect ( generateOrderedListIndex ) . not . toHaveBeenCalled ( ) ;
287+ expect ( docxNumberingHelpers . normalizeLvlTextChar ) . not . toHaveBeenCalled ( ) ;
288+ expect ( numberingManager . calculateCounter ) . not . toHaveBeenCalled ( ) ;
289+ expect ( result ) . toBeNull ( ) ;
290+ } ) ;
291+
292+ it ( 'clears stale list rendering when the definition details are missing' , ( ) => {
293+ const editor = createEditor ( ) ;
294+ const plugin = createNumberingPlugin ( editor ) ;
295+ const { appendTransaction } = plugin . spec ;
296+
297+ const paragraph = {
298+ type : { name : 'paragraph' } ,
299+ attrs : {
300+ listRendering : {
301+ markerText : '1.' ,
302+ suffix : '.' ,
303+ justification : 'left' ,
304+ path : [ 1 ] ,
305+ numberingType : 'decimal' ,
306+ } ,
270307 paragraphProperties : {
271308 numberingProperties : { numId : 2 , ilvl : 0 } ,
272309 } ,
@@ -341,7 +378,7 @@ describe('numberingPlugin', () => {
341378 expect ( tr . setNodeAttribute ) . toHaveBeenCalledWith ( 3 , 'sdBlockRev' , 6 ) ;
342379 } ) ;
343380
344- it ( 'increments sdBlockRev when listRendering is cleared due to missing definition ' , ( ) => {
381+ it ( 'does not bump sdBlockRev when a missing definition is already cleared ' , ( ) => {
345382 const editor = createEditor ( ) ;
346383 const plugin = createNumberingPlugin ( editor ) ;
347384 const { appendTransaction } = plugin . spec ;
@@ -350,6 +387,40 @@ describe('numberingPlugin', () => {
350387 type : { name : 'paragraph' } ,
351388 attrs : {
352389 sdBlockRev : 10 ,
390+ listRendering : null ,
391+ paragraphProperties : {
392+ numberingProperties : { numId : 2 , ilvl : 0 } ,
393+ } ,
394+ } ,
395+ } ;
396+
397+ const doc = makeDoc ( [ { node : paragraph , pos : 5 } ] ) ;
398+ const tr = createTransaction ( ) ;
399+ const transactions = [ { docChanged : true , getMeta : vi . fn ( ) . mockReturnValue ( false ) } ] ;
400+
401+ ListHelpers . getListDefinitionDetails . mockReturnValue ( null ) ;
402+
403+ appendTransaction ( transactions , { } , { doc, tr } ) ;
404+
405+ expect ( tr . setNodeAttribute ) . not . toHaveBeenCalled ( ) ;
406+ } ) ;
407+
408+ it ( 'increments sdBlockRev when stale listRendering is cleared due to a missing definition' , ( ) => {
409+ const editor = createEditor ( ) ;
410+ const plugin = createNumberingPlugin ( editor ) ;
411+ const { appendTransaction } = plugin . spec ;
412+
413+ const paragraph = {
414+ type : { name : 'paragraph' } ,
415+ attrs : {
416+ sdBlockRev : 10 ,
417+ listRendering : {
418+ markerText : '1.' ,
419+ suffix : '.' ,
420+ justification : 'left' ,
421+ path : [ 1 ] ,
422+ numberingType : 'decimal' ,
423+ } ,
353424 paragraphProperties : {
354425 numberingProperties : { numId : 2 , ilvl : 0 } ,
355426 } ,
0 commit comments