1
1
import { computed , inject } from '@angular/core' ;
2
- import { fakeAsync , TestBed , tick } from '@angular/core/testing' ;
2
+ import { TestBed } from '@angular/core/testing' ;
3
3
import {
4
4
patchState ,
5
5
signalStore ,
@@ -73,7 +73,7 @@ describe('withUndoRedo', () => {
73
73
} ) ;
74
74
75
75
describe ( 'undo and redo' , ( ) => {
76
- it ( 'restores previous state for regular store key' , fakeAsync ( ( ) => {
76
+ it ( 'restores previous state for regular store key' , ( ) => {
77
77
TestBed . runInInjectionContext ( ( ) => {
78
78
const Store = signalStore (
79
79
withState ( testState ) ,
@@ -85,24 +85,22 @@ describe('withUndoRedo', () => {
85
85
) ;
86
86
87
87
const store = new Store ( ) ;
88
- tick ( 1 ) ;
89
88
90
89
store . updateTest ( newValue ) ;
91
- tick ( 1 ) ;
90
+
92
91
expect ( store . test ( ) ) . toEqual ( newValue ) ;
93
92
expect ( store . canUndo ( ) ) . toBe ( true ) ;
94
93
expect ( store . canRedo ( ) ) . toBe ( false ) ;
95
94
96
95
store . undo ( ) ;
97
- tick ( 1 ) ;
98
96
99
97
expect ( store . test ( ) ) . toEqual ( '' ) ;
100
98
expect ( store . canUndo ( ) ) . toBe ( false ) ;
101
99
expect ( store . canRedo ( ) ) . toBe ( true ) ;
102
100
} ) ;
103
- } ) ) ;
101
+ } ) ;
104
102
105
- it ( 'restores previous state for regular store key and respects skip' , fakeAsync ( ( ) => {
103
+ it ( 'restores previous state for regular store key and respects skip' , ( ) => {
106
104
TestBed . runInInjectionContext ( ( ) => {
107
105
const Store = signalStore (
108
106
withState ( testState ) ,
@@ -114,30 +112,26 @@ describe('withUndoRedo', () => {
114
112
) ;
115
113
116
114
const store = new Store ( ) ;
117
- tick ( 1 ) ;
118
115
119
116
store . updateTest ( newValue ) ;
120
- tick ( 1 ) ;
117
+
121
118
expect ( store . test ( ) ) . toEqual ( newValue ) ;
122
119
123
120
store . updateTest ( newerValue ) ;
124
- tick ( 1 ) ;
125
121
126
122
store . undo ( ) ;
127
- tick ( 1 ) ;
128
123
129
124
expect ( store . test ( ) ) . toEqual ( newValue ) ;
130
125
expect ( store . canUndo ( ) ) . toBe ( false ) ;
131
126
132
127
store . undo ( ) ;
133
- tick ( 1 ) ;
134
128
135
129
// should not change
136
130
expect ( store . test ( ) ) . toEqual ( newValue ) ;
137
131
} ) ;
138
- } ) ) ;
132
+ } ) ;
139
133
140
- it ( 'undoes and redoes previous state for entity' , fakeAsync ( ( ) => {
134
+ it ( 'undoes and redoes previous state for entity' , ( ) => {
141
135
const Store = signalStore (
142
136
withEntities ( { entity : type < { id : string } > ( ) } ) ,
143
137
withMethods ( ( store ) => ( {
@@ -149,19 +143,19 @@ describe('withUndoRedo', () => {
149
143
TestBed . configureTestingModule ( { providers : [ Store ] } ) ;
150
144
TestBed . runInInjectionContext ( ( ) => {
151
145
const store = inject ( Store ) ;
152
- tick ( 1 ) ;
146
+
153
147
expect ( store . entities ( ) ) . toEqual ( [ ] ) ;
154
148
expect ( store . canUndo ( ) ) . toBe ( false ) ;
155
149
expect ( store . canRedo ( ) ) . toBe ( false ) ;
156
150
157
151
store . addEntity ( newValue ) ;
158
- tick ( 1 ) ;
152
+
159
153
expect ( store . entities ( ) ) . toEqual ( [ { id : newValue } ] ) ;
160
154
expect ( store . canUndo ( ) ) . toBe ( true ) ;
161
155
expect ( store . canRedo ( ) ) . toBe ( false ) ;
162
156
163
157
store . addEntity ( newerValue ) ;
164
- tick ( 1 ) ;
158
+
165
159
expect ( store . entities ( ) ) . toEqual ( [
166
160
{ id : newValue } ,
167
161
{ id : newerValue } ,
@@ -182,21 +176,20 @@ describe('withUndoRedo', () => {
182
176
expect ( store . canRedo ( ) ) . toBe ( true ) ;
183
177
184
178
store . redo ( ) ;
185
- tick ( 1 ) ;
186
179
187
180
expect ( store . entities ( ) ) . toEqual ( [ { id : newValue } ] ) ;
188
181
expect ( store . canUndo ( ) ) . toBe ( true ) ;
189
182
expect ( store . canRedo ( ) ) . toBe ( true ) ;
190
183
191
184
// should return canRedo=false after a change
192
185
store . addEntity ( 'newest' ) ;
193
- tick ( 1 ) ;
186
+
194
187
expect ( store . canUndo ( ) ) . toBe ( true ) ;
195
188
expect ( store . canRedo ( ) ) . toBe ( false ) ;
196
189
} ) ;
197
- } ) ) ;
190
+ } ) ;
198
191
199
- it ( 'restores previous state for named entity' , fakeAsync ( ( ) => {
192
+ it ( 'restores previous state for named entity' , ( ) => {
200
193
TestBed . runInInjectionContext ( ( ) => {
201
194
const Store = signalStore (
202
195
withEntities ( {
@@ -215,22 +208,20 @@ describe('withUndoRedo', () => {
215
208
) ;
216
209
217
210
const store = new Store ( ) ;
218
- tick ( 1 ) ;
219
211
220
212
store . addEntity ( newValue ) ;
221
- tick ( 1 ) ;
213
+
222
214
expect ( store . flightEntities ( ) ) . toEqual ( [ { id : newValue } ] ) ;
223
215
expect ( store . canUndo ( ) ) . toBe ( true ) ;
224
216
expect ( store . canRedo ( ) ) . toBe ( false ) ;
225
217
226
218
store . undo ( ) ;
227
- tick ( 1 ) ;
228
219
229
220
expect ( store . flightEntities ( ) ) . toEqual ( [ ] ) ;
230
221
expect ( store . canUndo ( ) ) . toBe ( false ) ;
231
222
expect ( store . canRedo ( ) ) . toBe ( true ) ;
232
223
} ) ;
233
- } ) ) ;
224
+ } ) ;
234
225
235
226
it ( 'clears undo redo stack' , ( ) => {
236
227
const Store = signalStore (
@@ -253,7 +244,7 @@ describe('withUndoRedo', () => {
253
244
expect ( store . canRedo ( ) ) . toBe ( false ) ;
254
245
} ) ;
255
246
256
- it ( 'cannot undo after clearing and setting a new value' , fakeAsync ( ( ) => {
247
+ it ( 'cannot undo after clearing and setting a new value' , ( ) => {
257
248
const Store = signalStore (
258
249
{ providedIn : 'root' } ,
259
250
withState ( testState ) ,
@@ -266,22 +257,18 @@ describe('withUndoRedo', () => {
266
257
const store = TestBed . inject ( Store ) ;
267
258
268
259
store . update ( 'Alan' ) ;
269
- tick ( 1 ) ;
270
260
271
261
store . update ( 'Gordon' ) ;
272
- tick ( 1 ) ;
273
262
274
263
store . clearStack ( ) ;
275
- tick ( 1 ) ;
276
264
277
265
// After clearing the undo/redo stack, there is no previous item anymore.
278
266
// The following update becomes the first value.
279
267
// Since there is no other value before, it cannot be undone.
280
268
store . update ( 'Hugh' ) ;
281
- tick ( 1 ) ;
282
269
283
270
expect ( store . canUndo ( ) ) . toBe ( false ) ;
284
271
expect ( store . canRedo ( ) ) . toBe ( false ) ;
285
- } ) ) ;
272
+ } ) ;
286
273
} ) ;
287
274
} ) ;
0 commit comments