Skip to content

Commit 17f43b5

Browse files
committed
Add more scenarios to test for createReducerBuilder
1 parent ecbf3f2 commit 17f43b5

File tree

4 files changed

+108
-12
lines changed

4 files changed

+108
-12
lines changed

packages/rtk-codemods/transforms/createReducerBuilder/__testfixtures__/basic-ts.input.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,31 @@ createReducer(todoInitialState, {
1616
[todoAdded1a]: (state: TodoSliceState, action: PayloadAction<string>) => {
1717
// stuff
1818
},
19-
[todoRemoved]: todoAdapter.removeOne,
20-
todoAdded: todoAdapter.addOne
19+
[todoAdded1b]: (state: TodoSliceState, action: PayloadAction<string>) => action.payload,
20+
[todoAdded1c + 'test']: (state:TodoSliceState, action: PayloadAction<string>) => {
21+
// stuff
22+
},
23+
[todoAdded1d](state: TodoSliceState, action: PayloadAction<string>) {
24+
// stuff
25+
},
26+
[todoAdded1e]: function(state: TodoSliceState, action: PayloadAction<string>) {
27+
// stuff
28+
},
29+
todoAdded1f: (state: TodoSliceState, action: PayloadAction<string>) => {
30+
//stuff
31+
},
32+
[todoAdded1g]: someFunc,
33+
todoAdded1h: todoAdapter.removeOne,
2134
})
2235

2336
createReducer(todoInitialState, {
24-
[todoAdded](state: TodoSliceState, action: PayloadAction<string>) {
37+
[todoAdded2a]: (state: TodoSliceState, action: PayloadAction<string>) => {
38+
// stuff
39+
},
40+
[todoAdded2b](state: TodoSliceState, action: PayloadAction<string>) {
41+
// stuff
42+
},
43+
[todoAdded2c]: function(state: TodoSliceState, action: PayloadAction<string>) {
2544
// stuff
2645
}
2746
})

packages/rtk-codemods/transforms/createReducerBuilder/__testfixtures__/basic-ts.output.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,44 @@ createReducer(todoInitialState, (builder) => {
1717
// stuff
1818
});
1919

20-
builder.addCase(todoRemoved, todoAdapter.removeOne);
21-
builder.addCase(todoAdded, todoAdapter.addOne);
20+
builder.addCase(
21+
todoAdded1b,
22+
(state: TodoSliceState, action: PayloadAction<string>) => action.payload
23+
);
24+
25+
builder.addCase(
26+
todoAdded1c + 'test',
27+
(state:TodoSliceState, action: PayloadAction<string>) => {
28+
// stuff
29+
}
30+
);
31+
32+
builder.addCase(todoAdded1d, (state: TodoSliceState, action: PayloadAction<string>) => {
33+
// stuff
34+
});
35+
36+
builder.addCase(todoAdded1e, (state: TodoSliceState, action: PayloadAction<string>) => {
37+
// stuff
38+
});
39+
40+
builder.addCase(todoAdded1f, (state: TodoSliceState, action: PayloadAction<string>) => {
41+
//stuff
42+
});
43+
44+
builder.addCase(todoAdded1g, someFunc);
45+
builder.addCase(todoAdded1h, todoAdapter.removeOne);
2246
})
2347

2448
createReducer(todoInitialState, (builder) => {
25-
builder.addCase(todoAdded, (state: TodoSliceState, action: PayloadAction<string>) => {
49+
builder.addCase(todoAdded2a, (state: TodoSliceState, action: PayloadAction<string>) => {
50+
// stuff
51+
});
52+
53+
builder.addCase(todoAdded2b, (state: TodoSliceState, action: PayloadAction<string>) => {
54+
// stuff
55+
});
56+
57+
builder.addCase(todoAdded2c, (state: TodoSliceState, action: PayloadAction<string>) => {
2658
// stuff
2759
});
2860
})

packages/rtk-codemods/transforms/createReducerBuilder/__testfixtures__/basic.input.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,31 @@ createReducer(todoInitialState, {
88
[todoAdded1a]: (state, action) => {
99
// stuff
1010
},
11-
[todoRemoved]: todoAdapter.removeOne,
12-
todoAdded: todoAdapter.addOne
11+
[todoAdded1b]: (state, action) => action.payload,
12+
[todoAdded1c + 'test']: (state, action) => {
13+
// stuff
14+
},
15+
[todoAdded1d](state, action) {
16+
// stuff
17+
},
18+
[todoAdded1e]: function (state, action) {
19+
// stuff
20+
},
21+
todoAdded1f: (state, action) => {
22+
//stuff
23+
},
24+
[todoAdded1g]: someFunc,
25+
todoAdded1h: todoAdapter.removeOne,
1326
});
1427

1528
createReducer(todoInitialState, {
16-
[todoAdded](state, action) {
29+
[todoAdded2a]: (state, action) => {
30+
// stuff
31+
},
32+
[todoAdded2b](state, action) {
33+
// stuff
34+
},
35+
[todoAdded2c]: function (state, action) {
1736
// stuff
1837
}
1938
});

packages/rtk-codemods/transforms/createReducerBuilder/__testfixtures__/basic.output.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,38 @@ createReducer(todoInitialState, (builder) => {
99
// stuff
1010
});
1111

12-
builder.addCase(todoRemoved, todoAdapter.removeOne);
13-
builder.addCase(todoAdded, todoAdapter.addOne);
12+
builder.addCase(todoAdded1b, (state, action) => action.payload);
13+
14+
builder.addCase(todoAdded1c + 'test', (state, action) => {
15+
// stuff
16+
});
17+
18+
builder.addCase(todoAdded1d, (state, action) => {
19+
// stuff
20+
});
21+
22+
builder.addCase(todoAdded1e, (state, action) => {
23+
// stuff
24+
});
25+
26+
builder.addCase(todoAdded1f, (state, action) => {
27+
//stuff
28+
});
29+
30+
builder.addCase(todoAdded1g, someFunc);
31+
builder.addCase(todoAdded1h, todoAdapter.removeOne);
1432
});
1533

1634
createReducer(todoInitialState, (builder) => {
17-
builder.addCase(todoAdded, (state, action) => {
35+
builder.addCase(todoAdded2a, (state, action) => {
36+
// stuff
37+
});
38+
39+
builder.addCase(todoAdded2b, (state, action) => {
40+
// stuff
41+
});
42+
43+
builder.addCase(todoAdded2c, (state, action) => {
1844
// stuff
1945
});
2046
});

0 commit comments

Comments
 (0)