File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,10 @@ struct Todos: ReducerProtocol {
50
50
return . none
51
51
52
52
case let . delete( indexSet) :
53
- state. todos. remove ( atOffsets: indexSet)
53
+ let filteredTodos = state. filteredTodos
54
+ for index in indexSet {
55
+ state. todos. remove ( id: filteredTodos [ index] . id)
56
+ }
54
57
return . none
55
58
56
59
case let . editModeChanged( editMode) :
Original file line number Diff line number Diff line change @@ -196,6 +196,41 @@ final class TodosTests: XCTestCase {
196
196
}
197
197
}
198
198
199
+ func testDeleteWhileFiltered( ) async {
200
+ let state = Todos . State (
201
+ filter: . completed,
202
+ todos: [
203
+ Todo . State (
204
+ description: " " ,
205
+ id: UUID ( uuidString: " 00000000-0000-0000-0000-000000000000 " ) !,
206
+ isComplete: false
207
+ ) ,
208
+ Todo . State (
209
+ description: " " ,
210
+ id: UUID ( uuidString: " 00000000-0000-0000-0000-000000000001 " ) !,
211
+ isComplete: false
212
+ ) ,
213
+ Todo . State (
214
+ description: " " ,
215
+ id: UUID ( uuidString: " 00000000-0000-0000-0000-000000000002 " ) !,
216
+ isComplete: true
217
+ ) ,
218
+ ]
219
+ )
220
+
221
+ let store = TestStore (
222
+ initialState: state,
223
+ reducer: Todos ( )
224
+ )
225
+
226
+ await store. send ( . delete( [ 0 ] ) ) {
227
+ $0. todos = [
228
+ $0. todos [ 0 ] ,
229
+ $0. todos [ 1 ] ,
230
+ ]
231
+ }
232
+ }
233
+
199
234
func testEditModeMoving( ) async {
200
235
let state = Todos . State (
201
236
todos: [
You can’t perform that action at this time.
0 commit comments