Skip to content

Commit b63df4a

Browse files
authored
Merge pull request #42 from lcwish/testCode
cleaned up renderHooks and reducer, fixed reducer import file path
2 parents 17aa39e + ccaa674 commit b63df4a

File tree

8 files changed

+51
-85
lines changed

8 files changed

+51
-85
lines changed

src/containers/LeftPanel/Action/Action.jsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,6 @@ const Action = ({ action, index, dispatchToTestCase }) => {
3737
return eventsWithValues.includes(eventType);
3838
};
3939

40-
// const dropDownMockOptions = [];
41-
// mockData.forEach(mockDatum => {
42-
// mockDatum.fieldKeys.forEach(key => {
43-
// dropDownMockOptions.push(`mock${mockDatum.name}.${key.fieldKey}`);
44-
// });
45-
// dropDownMockOptions.push(`[mock${mockDatum.name}]`);
46-
// dropDownMockOptions.push(`{mock${mockDatum.name}}`);
47-
// });
48-
49-
// let options = dropDownMockOptions.map(option => {
50-
// return (
51-
// <option id='eventValue' value={option}>
52-
// {option}
53-
// </option>
54-
// );
55-
// });
5640
return (
5741
<Draggable draggableId={action.id.toString()} index={index}>
5842
{provided => (

src/containers/LeftPanel/HookRender/HookRender.jsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,42 @@ const HookRender = ({ hookRender, index, dispatchToHooksTestCase }) => {
3737
{...provided.dragHandleProps}
3838
id={styles.hookRender}
3939
>
40-
{/* close icon, handle delete */}
40+
4141
<img
4242
src={closeIcon}
4343
id={styles.close}
4444
alt='close'
4545
onClick={handleClickDeleteHookRender}
4646
/>
4747

48-
{/* header / h3 name / drag icon */}
4948
<div id={styles.hookRenderHeader}>
5049
<img src={dragIcon} alt='drag' />
5150
<h3>Hook : Rendering</h3>
5251
</div>
5352

5453
<div id={styles.hookRenderFlexBox}>
55-
{/* file path input boxes */}
56-
5754
<div id={styles.hookRenderType}>
5855
<label htmlFor='hookFuncFolder'>Import Hook From</label>
59-
<input type='text' id='hookFuncFolder' onChange={handleChangeHookFileName} />
56+
<input type='text' id='hookFuncFolder' placeholder='File Name' onChange={handleChangeHookFileName} />
6057
</div>
6158
</div>
6259
<div id={styles.hookRenderFlexBox}>
6360
<div id={styles.hookRenderType}>
64-
<label htmlFor='hookFunction'>Hook</label>
61+
<label htmlFor='hook'>Hook</label>
6562
<input
6663
type='text'
67-
id='hookFunction'
68-
onChange={e => handleChangeHookRenderFields(e, 'hookFunction')}
64+
id='hook'
65+
placeholder='Hook Name'
66+
onChange={e => handleChangeHookRenderFields(e, 'hook')}
6967
/>
7068
</div>
7169

7270
<div id={styles.hookRenderType}>
73-
<label htmlFor='parameterOne'>1st Parameter</label>
71+
<label htmlFor='parameterOne'>Parameter (optional)</label>
7472
<input
7573
type='text'
7674
id='parameterOne'
75+
placeholder='Hook Function Parameter'
7776
onChange={e => handleChangeHookRenderFields(e, 'parameterOne')}
7877
/>
7978
</div>
@@ -84,6 +83,7 @@ const HookRender = ({ hookRender, index, dispatchToHooksTestCase }) => {
8483
<input
8584
type='text'
8685
id='returnValue'
86+
placeholder='Return Value'
8787
onChange={e => handleChangeHookRenderFields(e, 'returnValue')}
8888
/>
8989
</div>
@@ -92,6 +92,7 @@ const HookRender = ({ hookRender, index, dispatchToHooksTestCase }) => {
9292
<input
9393
type='text'
9494
id='expectedReturnValue'
95+
placeholder='Expected Return Value'
9596
onChange={e => handleChangeHookRenderFields(e, 'expectedReturnValue')}
9697
/>
9798
</div>

src/containers/LeftPanel/HookRender/HookRender.module.scss

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,4 @@
4242
margin-top: 6px;
4343
width: 100%;
4444
}
45-
}
46-
// #renderBody {
47-
// display: flex;
48-
// justify-content: space-between;
49-
// align-items: center;
50-
// margin-bottom: 10px;
51-
// }
52-
// #renderInputBox {
53-
// width: 150px;
54-
// }
55-
// #renderProp {
56-
// font-size: 13px;
57-
// margin-bottom: 0;
58-
// padding: 6px 0;
59-
// display: flex;
60-
// width: 60%;
61-
// justify-content: space-between;
62-
// }
63-
// #renderCheckbox {
64-
// float: right;
65-
// }
66-
67-
// #props {
68-
// margin: 5px 0;
69-
// }
45+
}

src/containers/LeftPanel/Reducer/Reducer.jsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,21 @@ const Reducer = ({ reducer, index, dispatchToReduxTestCase }) => {
5353

5454
<div id={styles.reducerNameFlexBox}>
5555
<div id={styles.reducerName}>
56-
<label htmlFor='typesFile'>Action Types File Name</label>
56+
<label htmlFor='typesFile'>Import Action Types From</label>
5757
<input
5858
type='text'
59+
placeholder='File Name'
5960
id={styles.renderInputBox}
6061
value={reducer.typesFile}
6162
onChange={handleChangeTypesFileName}
6263
/>
6364
</div>
6465

6566
<div id={styles.reducerName}>
66-
<label htmlFor='typesFile'>Reducer File Name</label>
67+
<label htmlFor='typesFile'>Import Reducer From</label>
6768
<input
6869
type='text'
70+
placeholder='File Name'
6971
id={styles.renderInputBox}
7072
value={reducer.reducerFile}
7173
onChange={handleChangeReducersFileName}
@@ -74,40 +76,44 @@ const Reducer = ({ reducer, index, dispatchToReduxTestCase }) => {
7476
</div>
7577
<div id={styles.reducerNameFlexBox}>
7678
<div id={styles.reducerName}>
77-
<label htmlFor='queryValue'>Reducer Name</label>
79+
<label htmlFor='reducerName'>Reducer Name</label>
7880
<input
7981
type='text'
80-
id='queryValue'
81-
onChange={e => handleChangeReducerFields(e, 'queryValue')}
82+
id='reducerName'
83+
placeholder='Reducer Name'
84+
onChange={e => handleChangeReducerFields(e, 'reducerName')}
8285
/>
8386
</div>
8487

8588
<div id={styles.reducerName}>
86-
<label htmlFor='querySelector'>Initial State</label>
89+
<label htmlFor='initialState'>Initial State</label>
8790
<input
8891
type='text'
89-
id='querySelector'
90-
onChange={e => handleChangeReducerFields(e, 'querySelector')}
92+
id='initialState'
93+
placeholder='Initial State'
94+
onChange={e => handleChangeReducerFields(e, 'initialState')}
9195
/>
9296
</div>
9397
</div>
9498

9599
<div id={styles.reducerNameFlexBox}>
96100
<div id={styles.reducerName}>
97-
<label htmlFor='queryVariant'>Action</label>
101+
<label htmlFor='reducerAction'>Action</label>
98102
<input
99103
type='text'
100-
id='queryVariant'
101-
onChange={e => handleChangeReducerFields(e, 'queryVariant')}
104+
id='reducerAction'
105+
placeholder='Action'
106+
onChange={e => handleChangeReducerFields(e, 'reducerAction')}
102107
/>
103108
</div>
104109

105110
<div id={styles.reducerName}>
106-
<label htmlFor='matcherValue'>Updated State</label>
111+
<label htmlFor='expectedState'>Updated State</label>
107112
<input
108113
type='text'
109-
id='matcherValue'
110-
onChange={e => handleChangeReducerFields(e, 'matcherValue')}
114+
placeholder='Expected State'
115+
id='expectedState'
116+
onChange={e => handleChangeReducerFields(e, 'expectedState')}
111117
/>
112118
</div>
113119
</div>

src/containers/LeftPanel/TestCase/ReduxTestCase.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const ReduxTestCase = () => {
1111
ReduxTestCaseContext
1212
);
1313

14-
/* here we are sending actions to the reducer */
1514
const handleUpdateReduxTestStatement = e => {
1615
dispatchToReduxTestCase(updateReduxTestStatement(e.target.value));
1716
};

src/containers/NavBar/Modals/ExportFileModal.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ const ExportFileModal = ({ isExportModalOpen, closeExportModal }) => {
275275
const createPathToReducers = statement => {
276276
let filePath = path.relative(projectFilePath, statement.reducersFilePath);
277277
filePath = filePath.replace(/\\/g, '/');
278-
testFileCode += `import * as reducers from '../${filePath}';`;
278+
testFileCode += `import ${statement.reducerName} from '../${filePath}';`;
279279
};
280280

281281
// Types Filepath
@@ -406,9 +406,9 @@ const ExportFileModal = ({ isExportModalOpen, closeExportModal }) => {
406406
}
407407
};
408408

409-
// Reducer Jest Test Code - Linda to refactor 2/1
409+
// Reducer Jest Test Code
410410
const addReducer = reducer => {
411-
testFileCode += `expect(${reducer.queryValue}(${reducer.querySelector},${reducer.queryVariant})).toEqual(${reducer.matcherValue})`;
411+
testFileCode += `expect(${reducer.reducerName}(${reducer.initialState},{${reducer.reducerAction}})).toEqual(${reducer.expectedState})`;
412412
};
413413

414414
// Async AC Jest Test Code
@@ -449,7 +449,7 @@ const ExportFileModal = ({ isExportModalOpen, closeExportModal }) => {
449449

450450
// Hook: Renders Jest Test Code
451451
const addHookRender = hookRender => {
452-
testFileCode += `const {result} = renderHook((${hookRender.parameterOne}) => ${hookRender.hook}())
452+
testFileCode += `const {result} = renderHook(() => ${hookRender.hook}(${hookRender.parameterOne}))
453453
expect(result.current.${hookRender.returnValue}).toBe(${hookRender.expectedReturnValue})`;
454454
};
455455

src/context/reduxTestCaseActions.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,25 @@ export const deleteReducer = id => ({
149149

150150
export const updateReducer = ({
151151
id,
152-
queryVariant,
153-
querySelector,
154-
queryValue,
152+
reducerAction,
153+
initialState,
154+
reducerName,
155155
typesFileName,
156156
typesFilePath,
157157
reducersFileName,
158158
reducersFilePath,
159-
matcherValue,
159+
expectedState,
160160
}) => ({
161161
type: actionTypes.UPDATE_REDUCER,
162162
id,
163-
queryVariant,
164-
querySelector,
165-
queryValue,
163+
reducerAction,
164+
initialState,
165+
reducerName,
166166
typesFileName,
167167
typesFilePath,
168168
reducersFileName,
169169
reducersFilePath,
170-
matcherValue,
170+
expectedState,
171171
});
172172

173173
export const updateActionsFilePath = (actionsFileName, filePath) => ({

src/context/reduxTestCaseReducer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ const createReducer = () => ({
6464
typesFilePath: '',
6565
reducersFileName: '',
6666
reducersFilePath: '',
67-
queryVariant: '',
68-
querySelector: '',
69-
queryValue: '',
70-
matcherValue: '',
67+
reducerAction: '',
68+
initialState: '',
69+
reducerName: '',
70+
expectedState: '',
7171
});
7272

7373
export const reduxTestCaseReducer = (state, action) => {
@@ -205,10 +205,10 @@ export const reduxTestCaseReducer = (state, action) => {
205205
statement.reducersFilePath = action.reducersFilePath;
206206
statement.typesFileName = action.typesFileName;
207207
statement.typesFilePath = action.typesFilePath;
208-
statement.queryVariant = action.queryVariant;
209-
statement.querySelector = action.querySelector;
210-
statement.queryValue = action.queryValue;
211-
statement.matcherValue = action.matcherValue;
208+
statement.reducerAction = action.reducerAction;
209+
statement.initialState = action.initialState;
210+
statement.reducerName = action.reducerName;
211+
statement.expectedState = action.expectedState;
212212
}
213213
return statement;
214214
});

0 commit comments

Comments
 (0)