@@ -16,6 +16,14 @@ const UndoComponent = ({ disabled }: { disabled: boolean }) => {
16
16
} ,
17
17
] = useUndo ( 0 ) ;
18
18
const { present : presentCount } = countState ;
19
+ const doubleRedoCount = ( ) => {
20
+ redoCount ( ) ;
21
+ redoCount ( ) ;
22
+ } ;
23
+ const doubleUndoCount = ( ) => {
24
+ undoCount ( ) ;
25
+ undoCount ( ) ;
26
+ } ;
19
27
20
28
return (
21
29
< div >
@@ -57,6 +65,22 @@ const UndoComponent = ({ disabled }: { disabled: boolean }) => {
57
65
>
58
66
redo
59
67
</ button >
68
+ < button
69
+ key = "double undo"
70
+ data-testid = "double undo"
71
+ onClick = { doubleUndoCount }
72
+ disabled = { disabled && ! canUndo }
73
+ >
74
+ double undo
75
+ </ button >
76
+ < button
77
+ key = "double redo"
78
+ data-testid = "double redo"
79
+ onClick = { doubleRedoCount }
80
+ disabled = { disabled && ! canRedo }
81
+ >
82
+ double redo
83
+ </ button >
60
84
< button key = "reset" data-testid = "reset" onClick = { ( ) => resetCount ( 0 ) } >
61
85
reset to 0
62
86
</ button >
@@ -73,6 +97,8 @@ const setup = (defaultDisabled = true) => {
73
97
const decrementButton = getByTestId ( 'decrement' ) as HTMLButtonElement ;
74
98
const undoButton = getByTestId ( 'undo' ) as HTMLButtonElement ;
75
99
const redoButton = getByTestId ( 'redo' ) as HTMLButtonElement ;
100
+ const doubleUndoButton = getByTestId ( 'double undo' ) as HTMLButtonElement ;
101
+ const doubleRedoButton = getByTestId ( 'double redo' ) as HTMLButtonElement ;
76
102
const resetButton = getByTestId ( 'reset' ) as HTMLButtonElement ;
77
103
78
104
return {
@@ -82,6 +108,8 @@ const setup = (defaultDisabled = true) => {
82
108
decrementButton,
83
109
undoButton,
84
110
redoButton,
111
+ doubleUndoButton,
112
+ doubleRedoButton,
85
113
resetButton,
86
114
} ;
87
115
} ;
@@ -181,4 +209,34 @@ describe('use-undo', () => {
181
209
182
210
expect ( count . textContent ) . toBe ( 'count: 0' ) ;
183
211
} ) ;
212
+
213
+ describe ( 'when it can undo once' , ( ) => {
214
+ describe ( 'when calling undo multiple times in succession' , ( ) => {
215
+ it ( 'should return to the initial state' , ( ) => {
216
+ const { count, doubleUndoButton, incrementButton } = setup ( ) ;
217
+
218
+ fireEvent . click ( incrementButton ) ;
219
+
220
+ fireEvent . click ( doubleUndoButton ) ;
221
+
222
+ expect ( count . textContent ) . toBe ( 'count: 0' ) ;
223
+ } ) ;
224
+ } ) ;
225
+ } ) ;
226
+
227
+ describe ( 'when it can redo once' , ( ) => {
228
+ describe ( 'when calling redo multiple times in succession' , ( ) => {
229
+ it ( 'should return to the last state' , ( ) => {
230
+ const { count, undoButton, doubleRedoButton, incrementButton } =
231
+ setup ( ) ;
232
+
233
+ fireEvent . click ( incrementButton ) ;
234
+ fireEvent . click ( undoButton ) ;
235
+
236
+ fireEvent . click ( doubleRedoButton ) ;
237
+
238
+ expect ( count . textContent ) . toBe ( 'count: 1' ) ;
239
+ } ) ;
240
+ } ) ;
241
+ } ) ;
184
242
} ) ;
0 commit comments