Skip to content

Commit f93dd1e

Browse files
authored
Merge pull request #3 from annieshinn/cleanUp
Initial clean up
2 parents 0975034 + 0fd8e8c commit f93dd1e

File tree

6 files changed

+70
-57
lines changed

6 files changed

+70
-57
lines changed

src/__tests__/globalReducer.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,14 @@ describe('Global Reducer works properly', () => {
179179
});
180180
});
181181

182-
it('should handle UPDATE_FILE_SHOW', () => {
183-
let action = { type: 'UPDATE_FILE_SHOW', testString: '' };
182+
it('should handle UPDATE_FILE', () => {
183+
let action = { type: 'UPDATE_FILE', testString: '' };
184184
expect(globalReducer(initialState, action)).toEqual({
185185
...initialState,
186186
file: '',
187187
});
188188
action = {
189-
type: 'UPDATE_FILE_SHOW',
189+
type: 'UPDATE_FILE',
190190
testString: `import React from "react";
191191
import { render, fireEvent } from '@testing-library/react';
192192
import '@testing-library/jest-dom/extend-expect`,

src/components/Modals/Modal.jsx

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Handles modals that pop up from pressing buttons "New Test +" or "Run Test",
3+
* which render on the top Test Menu component.
4+
*/
5+
16
import React from 'react';
27
import ReactModal from 'react-modal';
38
import styles from './ExportFileModal.module.scss';
@@ -16,7 +21,7 @@ const Modal = ({
1621
dispatchToMockData,
1722
dispatchTestCase,
1823
createTest,
19-
closeModal
24+
closeModal,
2025
);
2126

2227
const script = useGenerateScript(title);
@@ -32,7 +37,7 @@ const Modal = ({
3237
className={styles.modal}
3338
isOpen={isModalOpen}
3439
onRequestClose={closeModal}
35-
contentLabel='Save?'
40+
contentLabel="Save?"
3641
shouldCloseOnOverlayClick={true}
3742
shouldCloseOnEsc={true}
3843
ariaHideApp={false}
@@ -42,28 +47,38 @@ const Modal = ({
4247
<p>{title === 'New Test' ? title : 'Copy to Terminal'}</p>
4348
</div>
4449
<div id={styles.body}>
45-
{title === 'New Test' ? (
46-
<p id={styles.text}>
47-
Do you want to start a new test? All unsaved changes <br /> will be lost.{' '}
48-
</p>
49-
) : (
50-
<pre>
51-
<div className='code-wrapper'>
52-
<code ref={codeRef}>{script}</code>
53-
<p id={styles.endpoint}>Note if you are using Create React App do not install jest</p>
54-
</div>
55-
</pre>
56-
)}
57-
<span id={styles.newTestButtons}>
58-
{title === 'New Test' ? (
59-
<button id={styles.save} onClick={handleNewTest}>
60-
{title}
61-
</button>
62-
) : (
63-
<button id={styles.save} onClick={handleCopy}>
64-
{copySuccess ? 'Copied!' : 'Copy'}
65-
</button>
50+
{title === 'New Test'
51+
? (
52+
<p id={styles.text}>
53+
Do you want to start a new test? All unsaved changes
54+
<br />
55+
will be lost.
56+
</p>
57+
)
58+
: (
59+
<pre>
60+
<div className="code-wrapper">
61+
<code ref={codeRef}>
62+
{script}
63+
</code>
64+
<p id={styles.endpoint}>
65+
Note if you are using Create React App do not install jest
66+
</p>
67+
</div>
68+
</pre>
6669
)}
70+
<span id={styles.newTestButtons}>
71+
{title === 'New Test'
72+
? (
73+
<button id={styles.save} onClick={handleNewTest}>
74+
{title}
75+
</button>
76+
)
77+
: (
78+
<button id={styles.save} onClick={handleCopy}>
79+
{copySuccess ? 'Copied!' : 'Copy'}
80+
</button>
81+
)}
6782
<button id={styles.save} onClick={closeModal}>
6883
Cancel
6984
</button>

src/components/TestMenu/EndpointTestMenu.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const EndpointTestMenu = () => {
2727
const [{ projectFilePath, file, exportBool }, dispatchToGlobal] = useContext<any>(GlobalContext);
2828
const { title, isModalOpen, openModal, openScriptModal, closeModal } = useToggleModal('endpoint');
2929
const generateTest = useGenerateTest('endpoint', projectFilePath);
30-
let valid;
3130
// Endpoint testing docs url
3231
const endpointUrl = 'https://www.npmjs.com/package/supertest';
3332

@@ -59,8 +58,8 @@ const EndpointTestMenu = () => {
5958
};
6059

6160
if (exportBool) {
62-
valid = validateInputs('endpoint', endpointTestCase);
63-
valid ? dispatchToGlobal(setValidCode(true)) : dispatchToGlobal(setValidCode(false));
61+
const valid = validateInputs('endpoint', endpointTestCase);
62+
dispatchToGlobal(setValidCode(valid));
6463
dispatchToGlobal(toggleExportBool());
6564
if (valid && !file) dispatchToGlobal(updateFile(generateTest(endpointTestCase)));
6665
}

src/components/TestMenu/HooksTestMenu.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { useToggleModal, validateInputs } from './testMenuHooks';
1818
const HooksTestMenu = () => {
1919
// Hooks testing docs url
2020
const hooksUrl = 'https://react-hooks-testing-library.com/usage/basic-hooks';
21-
let valid;
2221
const [{ hooksTestStatement, hooksStatements }, dispatchToHooksTestCase] = useContext(
2322
HooksTestCaseContext
2423
);
@@ -45,16 +44,15 @@ const HooksTestMenu = () => {
4544
};
4645

4746
if (exportBool) {
48-
valid = validateInputs('hooks', hooksStatements);
49-
valid ? dispatchToGlobal(setValidCode(true)) : dispatchToGlobal(setValidCode(false));
47+
const valid = validateInputs('hooks', hooksStatements);
48+
dispatchToGlobal(setValidCode(valid));
5049
dispatchToGlobal(toggleExportBool());
5150
if (valid && !file) dispatchToGlobal(updateFile(generateTest(hooksStatements)));
5251
}
5352

5453
if (!file && exportBool) {
55-
validateInputs('hooks', hooksStatements)
56-
? dispatchToGlobal(setValidCode(true))
57-
: dispatchToGlobal(setValidCode(false));
54+
const valid = validateInputs('hooks', hooksStatements);
55+
dispatchToGlobal(setValidCode(valid));
5856
dispatchToGlobal(updateFile(generateTest({ hooksTestStatement, hooksStatements })));
5957
}
6058
return (

src/context/actions/globalActions.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export const actionTypes = {
1313
//added
1414
SET_TEST_CASE: 'SET_TEST_CASE',
1515
TOGGLE_MODAL: 'TOGGLE_MODAL',
16-
UPDATE_FILE_SHOW: 'UPDATE_FILE_SHOW',
16+
UPDATE_FILE: 'UPDATE_FILE',
1717
OPEN_BROWSER_DOCS: 'OPEN_BROWSER_DOCS',
18-
NEW_TEST_CLOSE_BROWSER_DOCS: 'NEW_TEST_CLOSE_BROWSER_DOCS',
19-
EXPORT: 'EXPORT',
18+
RESET_TO_PROJECT_URL: 'RESET_TO_PROJECT_URL', // formerly NEW_TEST_CLOSE_BROWSER_DOCS
19+
TOGGLE_EXPORT_BOOL: 'TOGGLE_EXPORT_BOOL',
2020
SET_FILE_PATH: 'SET_FILE_PATH',
2121
SET_VALID_CODE: 'SET_VALID_CODE',
2222
};
@@ -80,7 +80,7 @@ export const toggleModal = () => ({
8080
});
8181

8282
export const updateFile = (testString) => ({
83-
type: actionTypes.UPDATE_FILE_SHOW,
83+
type: actionTypes.UPDATE_FILE,
8484
testString,
8585
});
8686

@@ -89,20 +89,20 @@ export const openBrowserDocs = (docsUrl) => ({
8989
docsUrl,
9090
});
9191

92+
export const resetToProjectUrl = () => ({
93+
type: actionTypes.RESET_TO_PROJECT_URL,
94+
});
95+
9296
export const toggleExportBool = () => ({
93-
type: actionTypes.EXPORT,
97+
type: actionTypes.TOGGLE_EXPORT_BOOL,
9498
});
9599

96100
export const setFilePath = (filePath) => ({
97101
type: actionTypes.SET_FILE_PATH,
98102
filePath,
99103
});
100104

101-
export const resetToProjectUrl = () => ({
102-
type: actionTypes.NEW_TEST_CLOSE_BROWSER_DOCS,
103-
});
104-
105-
export const setValidCode = (verdict) => ({
105+
export const setValidCode = (validCode) => ({
106106
type: actionTypes.SET_VALID_CODE,
107-
validCode: verdict,
107+
validCode,
108108
});

src/context/reducers/globalReducer.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ export const globalReducer = (state, action) => {
3737
projectUrl: url,
3838
};
3939
case actionTypes.LOAD_PROJECT:
40+
const isProjectLoaded = action.load;
4041
return {
4142
...state,
42-
isProjectLoaded: action.load,
43+
isProjectLoaded,
4344
};
4445
case actionTypes.CREATE_FILE_TREE:
4546
const fileTree = action.fileTree;
@@ -49,10 +50,9 @@ export const globalReducer = (state, action) => {
4950
};
5051

5152
case actionTypes.TOGGLE_FILE_DIRECTORY:
52-
const isFileDirectoryOpen = !state.isFileDirectoryOpen;
5353
return {
5454
...state,
55-
isFileDirectoryOpen,
55+
isFileDirectoryOpen: !state.isFileDirectoryOpen,
5656
};
5757
case actionTypes.CLOSE_RIGHT_PANEL:
5858
const projUrl = state.projectUrl;
@@ -111,11 +111,11 @@ export const globalReducer = (state, action) => {
111111
isTestModalOpen: !state.isTestModalOpen,
112112
};
113113
//
114-
case actionTypes.UPDATE_FILE_SHOW:
115-
const updatedFile = action.testString;
114+
case actionTypes.UPDATE_FILE:
115+
const file = action.testString;
116116
return {
117117
...state,
118-
file: updatedFile,
118+
file,
119119
};
120120
case actionTypes.OPEN_BROWSER_DOCS:
121121
const docsUrl = action.docsUrl;
@@ -125,18 +125,18 @@ export const globalReducer = (state, action) => {
125125
isRightPanelOpen: true,
126126
rightPanelDisplay: 'browserView',
127127
};
128-
case actionTypes.NEW_TEST_CLOSE_BROWSER_DOCS:
128+
case actionTypes.RESET_TO_PROJECT_URL:
129+
// formerly NEW_TEST_CLOSE_BROWSER_DOCS
129130
const urlReset = state.projectUrl;
130131
return {
131132
...state,
132133
url: urlReset,
133134
projectUrl: urlReset,
134135
};
135-
case actionTypes.EXPORT:
136-
let exportBool = !state.exportBool;
136+
case actionTypes.TOGGLE_EXPORT_BOOL:
137137
return {
138138
...state,
139-
exportBool,
139+
exportBool: !state.exportBool,
140140
};
141141
case actionTypes.SET_FILE_PATH:
142142
const filePath = action.filePath;
@@ -145,9 +145,10 @@ export const globalReducer = (state, action) => {
145145
filePath,
146146
};
147147
case actionTypes.SET_VALID_CODE:
148+
const validCode = action.validCode;
148149
return {
149150
...state,
150-
validCode: action.validCode,
151+
validCode,
151152
};
152153
default:
153154
return state;

0 commit comments

Comments
 (0)