1+ import test from 'ava'
2+ import { EditType , clearHistory , history , redo , addToHistory , undoLastEvent , redoLastEvent } from './history' ;
3+
4+ import { setupPptrTab , teardownPptrTab }
5+ from '../../tests/helpers'
6+
7+ test . beforeEach ( setupPptrTab )
8+ test . afterEach ( teardownPptrTab )
9+
10+ // Note: I had to comment out applyEvent to run. Should mock document.
11+
12+ let mockEvent , mockEvent1 ;
13+ test . beforeEach ( ( ) => {
14+ mockEvent = {
15+ createdAt : new Date ( ) . toISOString ( ) ,
16+ selector : '.test' ,
17+ editType : EditType . STYLE ,
18+ newVal : { 'color' : 'red' } ,
19+ oldVal : { 'color' : 'blue' } ,
20+ } ;
21+
22+ mockEvent1 = {
23+ createdAt : new Date ( ) . toISOString ( ) ,
24+ selector : '.test1' ,
25+ editType : EditType . STYLE ,
26+ newVal : { 'color' : 'red1' } ,
27+ oldVal : { 'color' : 'blue1' } ,
28+ } ;
29+ } ) ;
30+
31+ test ( 'addToHistory adds an event to the history' , t => {
32+ clearHistory ( )
33+ addToHistory ( mockEvent ) ;
34+ t . is ( history . length , 1 ) ;
35+ t . deepEqual ( history [ 0 ] , mockEvent ) ;
36+ } ) ;
37+
38+ test ( 'addToHistory deduplicates events in history' , t => {
39+ clearHistory ( )
40+ addToHistory ( mockEvent ) ;
41+ addToHistory ( mockEvent ) ;
42+ addToHistory ( mockEvent1 ) ;
43+ addToHistory ( mockEvent1 ) ;
44+ t . is ( history . length , 2 ) ;
45+ t . deepEqual ( history [ 0 ] , mockEvent ) ;
46+ t . deepEqual ( history [ 1 ] , mockEvent1 ) ;
47+ } ) ;
48+
49+ test ( 'addToHistory deduplicates events in history if multiple' , t => {
50+ clearHistory ( )
51+ addToHistory ( mockEvent ) ;
52+ addToHistory ( mockEvent1 ) ;
53+ addToHistory ( mockEvent1 ) ;
54+ addToHistory ( mockEvent ) ;
55+ addToHistory ( mockEvent ) ;
56+ t . is ( history . length , 3 ) ;
57+ t . deepEqual ( history [ 0 ] , mockEvent ) ;
58+ t . deepEqual ( history [ 1 ] , mockEvent1 ) ;
59+ t . deepEqual ( history [ 2 ] , mockEvent ) ;
60+ } ) ;
61+
62+ test ( 'undoLastEvent moves the last event from history to redo' , t => {
63+ clearHistory ( )
64+ // Add to history and then undo
65+ addToHistory ( mockEvent ) ;
66+ undoLastEvent ( ) ;
67+ t . is ( history . length , 0 ) ;
68+ t . is ( redo . length , 1 ) ;
69+ } ) ;
70+
71+ test ( 'redoLastEvent moves the last event from redo to history' , t => {
72+ clearHistory ( )
73+ // Manually simulate an undo action
74+ addToHistory ( mockEvent ) ;
75+ undoLastEvent ( ) ;
76+ redoLastEvent ( ) ;
77+ t . is ( history . length , 1 ) ;
78+ t . is ( redo . length , 0 ) ;
79+ } ) ;
0 commit comments