@@ -233,16 +233,6 @@ describe('XMLEditor', () => {
233233 expect ( called ) . to . equal ( 1 ) ;
234234 expect ( editor . past ) . to . have . lengthOf ( 1 ) ;
235235
236- editor . undo ( ) ;
237- expect ( called ) . to . equal ( 1 ) ;
238- expect ( editor . past ) . to . have . lengthOf ( 0 ) ;
239- expect ( editor . future ) . to . have . lengthOf ( 1 ) ;
240-
241- editor . redo ( ) ;
242- expect ( called ) . to . equal ( 1 ) ;
243- expect ( editor . past ) . to . have . lengthOf ( 1 ) ;
244- expect ( editor . future ) . to . have . lengthOf ( 0 ) ;
245-
246236 const unsubscribed = unsubscribe ( ) ;
247237 expect ( unsubscribed ) . to . equal ( callback ) ;
248238
@@ -252,6 +242,52 @@ describe('XMLEditor', () => {
252242 expect ( editor . past ) . to . have . lengthOf ( 2 ) ;
253243 } ) ;
254244
245+ it ( 'notifies subscribers on undo with the previous commit' , ( ) => {
246+ const node = sclDoc . querySelector ( 'Substation' ) ! ;
247+ const edit = { node } ;
248+
249+ const subscriber = sinon . spy ( ) ;
250+
251+ editor . subscribe ( subscriber ) ;
252+
253+ const firstCommit = editor . commit ( edit , { title : 'first' } ) ;
254+ sinon . assert . calledOnce ( subscriber ) ;
255+ sinon . assert . calledWithExactly ( subscriber , firstCommit ) ;
256+
257+ const secondCommit = editor . commit ( edit , { title : 'second' } ) ;
258+ sinon . assert . calledTwice ( subscriber ) ;
259+ sinon . assert . calledWithExactly ( subscriber , secondCommit ) ;
260+
261+ editor . undo ( ) ;
262+ sinon . assert . calledThrice ( subscriber ) ;
263+ sinon . assert . calledWithExactly ( subscriber , firstCommit ) ;
264+ } ) ;
265+
266+ it ( 'notifies subscribers on redo with the redone commit' , ( ) => {
267+ const node = sclDoc . querySelector ( 'Substation' ) ! ;
268+ const edit = { node } ;
269+
270+ const subscriber = sinon . spy ( ) ;
271+
272+ editor . subscribe ( subscriber ) ;
273+
274+ const firstCommit = editor . commit ( edit , { title : 'first' } ) ;
275+ sinon . assert . calledOnce ( subscriber ) ;
276+ sinon . assert . calledWithExactly ( subscriber , firstCommit ) ;
277+
278+ const secondCommit = editor . commit ( edit , { title : 'second' } ) ;
279+ sinon . assert . calledTwice ( subscriber ) ;
280+ sinon . assert . calledWithExactly ( subscriber , secondCommit ) ;
281+
282+ editor . undo ( ) ;
283+ sinon . assert . calledThrice ( subscriber ) ;
284+ sinon . assert . calledWithExactly ( subscriber , firstCommit ) ;
285+
286+ editor . redo ( ) ;
287+ sinon . assert . callCount ( subscriber , 4 ) ;
288+ sinon . assert . calledWithExactly ( subscriber , secondCommit ) ;
289+ } ) ;
290+
255291 it ( 'unsubscribes the correct subscriber among many' , ( ) => {
256292 const node = sclDoc . querySelector ( 'Substation' ) ! ;
257293 const edit = { node } ;
0 commit comments