66 setFilePath ,
77 toggleRightPanel ,
88 setValidCode ,
9+ toggleExportBool ,
910} from '../../context/actions/globalActions' ;
1011import styles from './TestMenu.module.scss' ;
1112import {
@@ -16,12 +17,12 @@ import {
1617import Modal from '../Modals/Modal' ;
1718import useGenerateTest from '../../context/useGenerateTest' ;
1819import { HooksTestCaseContext } from '../../context/reducers/hooksTestCaseReducer' ;
19- import { useToggleModal } from './testMenuHooks' ;
20+ import { useToggleModal , validateInputs } from './testMenuHooks' ;
2021
2122const 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 } >
0 commit comments