Skip to content

Commit c85e82b

Browse files
committed
hooks validation complete
1 parent 7a10854 commit c85e82b

File tree

6 files changed

+52
-46
lines changed

6 files changed

+52
-46
lines changed

src/components/EditorView/EditorView.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
line-height: 1.5;
2929
position: relative;
3030
top: -18px;
31+
color: rgb(90, 90, 90);
3132
}

src/components/ReactHooksTestComponent/HookUpdates/HookUpdates.jsx

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ const HookUpdates = ({ hookUpdates, index }) => {
6161
<h3>Hooks</h3>
6262
</div>
6363
<div id={styles.hooksFlexBox}>
64-
{/* <div id={styles.hooks}>
65-
<label htmlFor='hookFile'>Import Hook From</label>
66-
<SearchInput
67-
options={Object.keys(filePathMap)}
68-
dispatch={dispatchToHooksTestCase}
69-
action={updateHooksFilePath}
70-
filePathMap={filePathMap}
71-
/>
72-
</div> */}
7364
<div id={styles.serverInput}>
7465
<label htmlFor='test-statement'>Test description</label>
7566
<div
@@ -111,44 +102,26 @@ const HookUpdates = ({ hookUpdates, index }) => {
111102
/>
112103
</div>
113104
</div>
114-
{/* <div id={styles.cb}>
115-
<label htmlFor='callbackFunc'>Callback Function</label>
116-
<input
117-
type='text'
118-
id='callbackFunc'
119-
onChange={(e) => handleChangeHookUpdatesFields(e, 'callbackFunc')}
120-
placeholder='e.g. incrementCount'
121-
/>
122-
</div> */}
123105
{hookUpdates.callbackFunc.map((callbackFunc, i) => {
124106
return (
125107
<div id={styles.cbFlexBox}>
126108
<HooksCallback callbackFunc={callbackFunc} index={index} id={i} />{' '}
127109
</div>
128110
);
129111
})}{' '}
130-
<div className={styles.buttonsContainer}>
131-
<button
132-
// id={id}
133-
onClick={addCallbackHandleClick}
134-
className={styles.assertionButton}
135-
>
136-
<i className='fas fa-plus'></i>
137-
Callback
138-
</button>
139-
</div>
112+
<div className={styles.buttonsContainer}></div>
140113
{hookUpdates.assertions.map((assertion, i) => {
141114
return <HooksAssertion assertion={assertion} index={index} id={i} />;
142115
})}{' '}
143116
<div className={styles.buttonsContainer} id={styles.stateFlexBox}>
144-
<button
145-
// id={id}
146-
onClick={addAssertionHandleClick}
147-
className={styles.assertionButton}
148-
>
117+
<button onClick={addAssertionHandleClick} className={styles.assertionButton}>
149118
<i className='fas fa-plus'></i>
150119
Assertion
151120
</button>
121+
<button onClick={addCallbackHandleClick} className={styles.assertionButton}>
122+
<i className='fas fa-plus'></i>
123+
Callback
124+
</button>
152125
</div>
153126
</div>
154127
)}

src/components/TestMenu/EndpointTestMenu.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
updateFile,
77
setFilePath,
88
setValidCode,
9+
toggleExportBool,
910
} from '../../context/actions/globalActions';
1011
import styles from './TestMenu.module.scss';
1112
import Modal from '../Modals/Modal';
@@ -26,7 +27,7 @@ const EndpointTestMenu = () => {
2627
const [{ projectFilePath, file, exportBool }, dispatchToGlobal] = useContext<any>(GlobalContext);
2728
const { title, isModalOpen, openModal, openScriptModal, closeModal } = useToggleModal('endpoint');
2829
const generateTest = useGenerateTest('endpoint', projectFilePath);
29-
30+
let valid;
3031
// Endpoint testing docs url
3132
const endpointUrl = 'https://www.npmjs.com/package/supertest';
3233

@@ -57,11 +58,11 @@ const EndpointTestMenu = () => {
5758
} else dispatchToEndpointTestCase(toggleDB('PostgreSQL'));
5859
};
5960

60-
if (!file && exportBool) {
61-
validateInputs('endpoint', endpointTestCase)
62-
? dispatchToGlobal(setValidCode(true))
63-
: dispatchToGlobal(setValidCode(false));
64-
dispatchToGlobal(updateFile(generateTest(endpointTestCase)));
61+
if (exportBool) {
62+
valid = validateInputs('endpoint', endpointTestCase);
63+
valid ? dispatchToGlobal(setValidCode(true)) : dispatchToGlobal(setValidCode(false));
64+
dispatchToGlobal(toggleExportBool());
65+
if (valid && !file) dispatchToGlobal(updateFile(generateTest(endpointTestCase)));
6566
}
6667

6768
return (

src/components/TestMenu/HooksTestMenu.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
setFilePath,
77
toggleRightPanel,
88
setValidCode,
9+
toggleExportBool,
910
} from '../../context/actions/globalActions';
1011
import styles from './TestMenu.module.scss';
1112
import {
@@ -16,12 +17,12 @@ import {
1617
import Modal from '../Modals/Modal';
1718
import useGenerateTest from '../../context/useGenerateTest';
1819
import { HooksTestCaseContext } from '../../context/reducers/hooksTestCaseReducer';
19-
import { useToggleModal } from './testMenuHooks';
20+
import { useToggleModal, validateInputs } from './testMenuHooks';
2021

2122
const HooksTestMenu = () => {
2223
// Hooks testing docs url
2324
const hooksUrl = 'https://react-hooks-testing-library.com/usage/basic-hooks';
24-
25+
let valid;
2526
const [{ hooksTestStatement, hooksStatements }, dispatchToHooksTestCase] = useContext(
2627
HooksTestCaseContext
2728
);
@@ -30,7 +31,7 @@ const HooksTestMenu = () => {
3031
const generateTest = useGenerateTest('hooks', projectFilePath);
3132

3233
useEffect(() => {
33-
dispatchToGlobal(setValidCode(true));
34+
dispatchToGlobal(setValidCode(false));
3435
}, []);
3536

3637
const handleAddContexts = () => {
@@ -51,9 +52,19 @@ const HooksTestMenu = () => {
5152
dispatchToGlobal(setFilePath(''));
5253
};
5354

54-
if (!file && exportBool)
55-
dispatchToGlobal(updateFile(generateTest({ hooksTestStatement, hooksStatements })));
55+
if (exportBool) {
56+
valid = validateInputs('hooks', hooksStatements);
57+
valid ? dispatchToGlobal(setValidCode(true)) : dispatchToGlobal(setValidCode(false));
58+
dispatchToGlobal(toggleExportBool());
59+
if (valid && !file) dispatchToGlobal(updateFile(generateTest(hooksStatements)));
60+
}
5661

62+
if (!file && exportBool) {
63+
validateInputs('hooks', hooksStatements)
64+
? dispatchToGlobal(setValidCode(true))
65+
: dispatchToGlobal(setValidCode(false));
66+
dispatchToGlobal(updateFile(generateTest({ hooksTestStatement, hooksStatements })));
67+
}
5768
return (
5869
<div id='test'>
5970
<div id={styles.testMenu}>

src/components/TestMenu/ReduxTestMenu.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
setFilePath,
66
toggleRightPanel,
77
setValidCode,
8+
toggleExportBool,
89
} from '../../context/actions/globalActions';
910
import {
1011
addAsync,
@@ -18,7 +19,7 @@ import useGenerateTest from '../../context/useGenerateTest.jsx';
1819
import { GlobalContext } from '../../context/reducers/globalReducer';
1920
import { openBrowserDocs } from '../../context/actions/globalActions';
2021
import { ReduxTestCaseContext } from '../../context/reducers/reduxTestCaseReducer';
21-
import { useToggleModal } from './testMenuHooks';
22+
import { useToggleModal, validateInputs } from './testMenuHooks';
2223

2324
const ReduxTestMenu = () => {
2425
const [{ reduxTestStatement, reduxStatements }, dispatchToReduxTestCase] = useContext(
@@ -61,7 +62,7 @@ const ReduxTestMenu = () => {
6162
};
6263

6364
if (!file && exportBool)
64-
dispatchToGlobal(updateFile(generateTest({ reduxStatements, reduxTestStatement })));
65+
dispatchToGlobal(updateFile(generateTest({ reduxTestStatement, reduxStatements })));
6566

6667
return (
6768
<div id='test'>

src/components/TestMenu/testMenuHooks.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ export const validateInputs = (testSuite, testCaseState) => {
3535
}
3636
}
3737
return true;
38+
case 'hooks':
39+
let hookTest, callback;
40+
for (hookTest of testCaseState) {
41+
console.log(hookTest);
42+
if (!hookTest.hookFilePath || !hookTest.hook) return false;
43+
for (callback of hookTest.callbackFunc) {
44+
if (!callback.callbackFunc) {
45+
console.log('hi');
46+
return false;
47+
}
48+
}
49+
for (assertion of hookTest.assertions) {
50+
if (!assertion.expectedState || !assertion.expectedValue || !assertion.matcher)
51+
return false;
52+
}
53+
}
54+
return true;
55+
// case 'react':
56+
3857
default:
3958
}
4059
};

0 commit comments

Comments
 (0)