@@ -27,7 +27,9 @@ export const reactTestCaseState = {
2727 text : '' ,
2828 } ,
2929 } ,
30- allIds : [ 'it0' ] ,
30+ allIds : {
31+ describe0 : [ 'it0' ] ,
32+ } ,
3133 } ,
3234 statements : {
3335 byId : {
@@ -102,14 +104,26 @@ const createProp = (propId, statementId) => ({
102104 propValue : '' ,
103105} ) ;
104106
105- const deleteChildren = ( object , deletionId , lookup ) => {
106- const allIdCopy = object . allIds . filter ( ( id ) => object . byId [ id ] [ lookup ] !== deletionId ) ;
107-
108- object . allIds . forEach ( ( id ) => {
109- if ( object . byId [ id ] [ lookup ] === deletionId ) {
107+ const deleteChildren = ( object , deletionId , lookup , it ) => {
108+ let allIdCopy ;
109+ if ( it ) {
110+ // delete everything appropriate in itStatements.byId object
111+ object . allIds [ deletionId ] . forEach ( ( id ) => {
110112 delete object . byId [ id ] ;
111- }
112- } ) ;
113+ } ) ;
114+ // delete everything appropriate in itStatements.allIds object
115+ delete object . allIds [ deletionId ] ;
116+ allIdCopy = object . allIds ;
117+ } else {
118+ // use .filter to delete from statements.allIds array
119+ allIdCopy = object . allIds . filter ( ( id ) => object . byId [ id ] [ lookup ] !== deletionId ) ;
120+ // delete from statements.byId object
121+ object . allIds . forEach ( ( id ) => {
122+ if ( object . byId [ id ] [ lookup ] === deletionId ) {
123+ delete object . byId [ id ] ;
124+ }
125+ } ) ;
126+ }
113127
114128 return allIdCopy ;
115129} ;
@@ -145,6 +159,13 @@ export const reactTestCaseReducer = (state, action) => {
145159 } ,
146160 allIds : [ ...( describeBlocks . allIds || [ ] ) , describeId ] ,
147161 } ,
162+ itStatements : {
163+ ...itStatements ,
164+ allIds : {
165+ ...itStatements . allIds ,
166+ [ describeId ] : [ ] ,
167+ } ,
168+ } ,
148169 } ;
149170 }
150171 case actionTypes . DELETE_DESCRIBE_BLOCK : {
@@ -153,7 +174,7 @@ export const reactTestCaseReducer = (state, action) => {
153174 delete byId [ describeId ] ;
154175 const allIds = describeBlocks . allIds . filter ( ( id ) => id !== describeId ) ;
155176
156- const itStatementAllIds = deleteChildren ( itStatements , describeId , 'describeId' ) ;
177+ const itStatementAllIds = deleteChildren ( itStatements , describeId , 'describeId' , 'it' ) ;
157178 const statementAllIds = deleteChildren ( statements , describeId , 'describeId' ) ;
158179
159180 return {
@@ -170,7 +191,7 @@ export const reactTestCaseReducer = (state, action) => {
170191 byId : {
171192 ...itStatements . byId ,
172193 } ,
173- allIds : [ ... itStatementAllIds ] ,
194+ allIds : itStatementAllIds ,
174195 } ,
175196 statements : {
176197 ...statements ,
@@ -224,7 +245,10 @@ export const reactTestCaseReducer = (state, action) => {
224245 ...itStatements . byId ,
225246 [ itId ] : createItStatement ( describeId , itId ) ,
226247 } ,
227- allIds : [ ...( itStatements . allIds || [ ] ) , itId ] ,
248+ allIds : {
249+ ...itStatements . allIds ,
250+ [ describeId ] : [ ...itStatements . allIds [ describeId ] , itId ] ,
251+ } ,
228252 } ,
229253 } ;
230254 }
@@ -248,9 +272,10 @@ export const reactTestCaseReducer = (state, action) => {
248272 }
249273 case actionTypes . DELETE_ITSTATEMENT : {
250274 const { itId } = action ;
275+ const { describeId } = itStatements . byId [ itId ] ;
251276 const byId = { ...itStatements . byId } ;
252277 delete byId [ itId ] ;
253- const allIds = itStatements . allIds . filter ( ( id ) => id !== itId ) ;
278+ const allIds = itStatements . allIds [ describeId ] . filter ( ( id ) => id !== itId ) ;
254279 const statementAllIds = deleteChildren ( statements , itId , 'itId' ) ;
255280
256281 return {
@@ -260,7 +285,10 @@ export const reactTestCaseReducer = (state, action) => {
260285 byId : {
261286 ...byId ,
262287 } ,
263- allIds : [ ...allIds ] ,
288+ allIds : {
289+ ...itStatements . allIds ,
290+ [ describeId ] : [ ...allIds ] ,
291+ } ,
264292 } ,
265293 statements : {
266294 ...statements ,
@@ -272,12 +300,15 @@ export const reactTestCaseReducer = (state, action) => {
272300 } ;
273301 }
274302 case actionTypes . UPDATE_ITSTATEMENT_ORDER : {
275- const { reorderedIt } = action ;
303+ const { reorderedIt, describeId } = action ;
276304 return {
277305 ...state ,
278306 itStatements : {
279307 ...itStatements ,
280- allIds : reorderedIt ,
308+ allIds : {
309+ ...itStatements . allIds ,
310+ [ describeId ] : reorderedIt ,
311+ } ,
281312 } ,
282313 } ;
283314 }
@@ -545,7 +576,7 @@ export const reactTestCaseReducer = (state, action) => {
545576 } ,
546577 itStatements : {
547578 byId : { } ,
548- allIds : [ ] ,
579+ allIds : { } ,
549580 } ,
550581 statements : {
551582 byId : { } ,
0 commit comments