Skip to content

Commit 7849e11

Browse files
committed
2 parents 3a770c0 + dfcb285 commit 7849e11

29 files changed

+1041
-344
lines changed

src/__tests__/Hooks.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { renderHook, act, cleanup } from '@testing-library/react-hooks';
2+
import useToggleModal from '../components/TestMenu/testMenuHooks';
3+
4+
afterEach(cleanup);
5+
test('hooks should render', () => {
6+
const { result } = renderHook(() => useToggleModal('redux'));
7+
expect(result.current.title).toBe('redux');
8+
expect(result.current.isModalOpen).toBe(false);
9+
expect(typeof result.current.openModal).toBe('function');
10+
});
11+
12+
test('openModal should work', () => {
13+
const { result } = renderHook(() => useToggleModal('redux'));
14+
15+
act(() => {
16+
result.current.openModal();
17+
});
18+
expect(result.current.title).toBe('New Test');
19+
expect(result.current.isModalOpen).toBe(true);
20+
});
21+
22+
test('openScriptModal should work', () => {
23+
const { result } = renderHook(() => useToggleModal('redux'));
24+
25+
act(() => {
26+
result.current.openScriptModal();
27+
});
28+
expect(result.current.title).toBe('redux');
29+
expect(result.current.isModalOpen).toBe(true);
30+
});
31+
32+
test('closeModal should work', () => {
33+
const { result } = renderHook(() => useToggleModal('redux'));
34+
35+
act(() => {
36+
result.current.closeModal();
37+
});
38+
expect(result.current.title).toBe('redux');
39+
expect(result.current.isModalOpen).toBe(false);
40+
});

src/__tests__/jest.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/components/EditorView/EditorView.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { useContext, useState, useEffect } from 'react';
1+
import React, { useContext, useState } from 'react';
22
import MonacoEditor from 'react-monaco-editor';
3-
import { GlobalContext } from '../../context/reducers/globalReducer';
43
import { editor } from 'monaco-editor';
4+
import { GlobalContext } from '../../context/reducers/globalReducer';
55
import { updateFile } from '../../context/actions/globalActions';
66
import styles from './EditorView.module.scss';
77

@@ -16,7 +16,7 @@ const Editor = () => {
1616
const options = {
1717
selectOnLineNumbers: true,
1818
wordWrap: 'wordWrapColumn',
19-
wordWrapColumn: 70,
19+
wordWrapColumn: 90,
2020
autoIndent: true,
2121
colorDecorators: true,
2222
wrappingIndent: 'indent',
@@ -25,6 +25,7 @@ const Editor = () => {
2525

2626
const editorDidMount = () => {
2727
editor.setTheme('light-dark');
28+
// editor.focus();
2829
};
2930

3031
const updatafile = (newValue, e) => {
@@ -55,11 +56,11 @@ const Editor = () => {
5556
<div>
5657
<button id={styles.save} onClick={saveFile}>
5758
Save Changes
58-
</button>{' '}
59+
</button>
5960
<span id={styles.span}>{wasSaved}</span>
6061
<div onClick={() => setWasSaved('')}>
6162
<MonacoEditor
62-
height='95vh'
63+
height='100vh'
6364
language='javascript'
6465
theme='light-dark'
6566
value={

src/components/ReactHooksTestComponent/Context/Context.jsx

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext } from 'react';
1+
import React, { useContext, useRef, useEffect } from 'react';
22
import { Draggable } from 'react-beautiful-dnd';
33
import styles from './Context.module.scss';
44
import { GlobalContext } from '../../../context/reducers/globalReducer';
@@ -28,6 +28,14 @@ const Context = ({ context, index }) => {
2828
dispatchToHooksTestCase(deleteContexts(context.id));
2929
};
3030

31+
const testDescription = useRef(null);
32+
33+
useEffect(() => {
34+
if (testDescription && testDescription.current) {
35+
testDescription.current.focus();
36+
}
37+
}, []);
38+
3139
return (
3240
<Draggable draggableId={context.id.toString()} index={index}>
3341
{(provided) => (
@@ -46,18 +54,38 @@ const Context = ({ context, index }) => {
4654

4755
<div>
4856
<div id={styles.querySelector}>
49-
<div id={styles.contextBox}>
50-
<label htmlFor='contextFile' className={styles.queryLabel}>
51-
Import Context From
52-
</label>
53-
<SearchInput
54-
options={Object.keys(filePathMap)}
55-
dispatch={dispatchToHooksTestCase}
56-
action={updateContextFilePath}
57-
filePathMap={filePathMap}
58-
/>
57+
<div id={styles.contextFlexBox}>
58+
<div id={styles.contextBox}>
59+
<label htmlFor='contextFile' className={styles.queryLabel}>
60+
Import Context From
61+
</label>
62+
<SearchInput
63+
options={Object.keys(filePathMap)}
64+
dispatch={dispatchToHooksTestCase}
65+
action={updateContextFilePath}
66+
filePathMap={filePathMap}
67+
/>
68+
</div>
69+
<div id={styles.serverInput}>
70+
<label htmlFor='test-statement'>Test description</label>
71+
<div
72+
style={{
73+
display: 'flex',
74+
justifyContent: 'spaceBetween',
75+
}}
76+
>
77+
<div id={styles.labelInputTest}>
78+
<br />
79+
<input
80+
ref={testDescription}
81+
type='text'
82+
id={styles.testStatement}
83+
onChange={(e) => handleChangeContextFields(e, 'testName')}
84+
/>
85+
</div>
86+
</div>
87+
</div>
5988
</div>
60-
6189
<div id={styles.dropdownFlex}>
6290
{/* drop downs */}
6391
<div id={styles.contextDrop}>

src/components/ReactHooksTestComponent/Context/Context.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
}
8383
}
8484

85+
#contextFlexBox {
86+
display: flex;
87+
align-items: center;
88+
margin-bottom: 15px;
89+
}
90+
8591
#dropdownFlex {
8692
display: flex;
8793
align-items: center;

src/components/ReactHooksTestComponent/HookRender/HookRender.jsx

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext } from 'react';
1+
import React, { useContext, useState } from 'react';
22
import { Draggable } from 'react-beautiful-dnd';
33
import styles from './HookRender.module.scss';
44
import { GlobalContext } from '../../../context/reducers/globalReducer';
@@ -16,17 +16,53 @@ const dragIcon = require('../../../assets/images/drag-vertical.png');
1616
const HookRender = ({ hookRender, index }) => {
1717
const [{ filePathMap }] = useContext(GlobalContext);
1818
const [, dispatchToHooksTestCase] = useContext(HooksTestCaseContext);
19+
const [count, setCount] = useState(1);
20+
const [expectedCounts, setExpectedCount] = useState([{ id: `test${count}` }]);
1921

2022
const handleChangeHookRenderFields = (e, field) => {
2123
let updatedHookRender = { ...hookRender };
24+
2225
updatedHookRender[field] = e.target.value;
2326
dispatchToHooksTestCase(updateHookRender(updatedHookRender));
27+
console.log(updatedHookRender);
2428
};
2529

2630
const handleClickDeleteHookRender = (e) => {
2731
dispatchToHooksTestCase(deleteHookRender(hookRender.id));
2832
};
2933

34+
const handleAddInput = (e) => {
35+
setCount(count);
36+
setExpectedCount([...expectedCounts, { id: `test${count}` }]);
37+
};
38+
39+
let input = expectedCounts.map((obj) => {
40+
return (
41+
<div id={`${styles.hookRenderFlexBox}`}>
42+
<div id={styles.hookRenderType}>
43+
<label htmlFor='expectedState'>Expected State</label>
44+
<input
45+
type='text'
46+
id='expectedState'
47+
placeholder='eg. count'
48+
onChange={(e) => handleChangeHookRenderFields(e, 'expectedState')}
49+
/>
50+
</div>
51+
<div id={styles.hookRenderType}>
52+
<label htmlFor='expectedValue'>Current Value</label>
53+
<input
54+
type='text'
55+
id='expectedValue'
56+
placeholder='eg. 0'
57+
onChange={(e) => handleChangeHookRenderFields(e, 'expectedValue')}
58+
/>
59+
<div id={styles.hookRenderType}>
60+
<button onClick={handleAddInput}>+</button>
61+
</div>
62+
</div>
63+
</div>
64+
);
65+
});
3066
return (
3167
<Draggable draggableId={hookRender.id.toString()} index={index}>
3268
{(provided) => (
@@ -65,41 +101,22 @@ const HookRender = ({ hookRender, index }) => {
65101
<input
66102
type='text'
67103
id='hook'
68-
placeholder='eg. useCounter'
104+
placeholder='eg. useStringCounter'
69105
onChange={(e) => handleChangeHookRenderFields(e, 'hook')}
70106
/>
71107
</div>
72108

73109
<div id={styles.hookRenderType}>
74-
<label htmlFor='parameterOne'>Hook Parameter (optional)</label>
75-
<input
76-
type='text'
77-
id='parameterOne'
78-
placeholder='eg. 9000'
79-
onChange={(e) => handleChangeHookRenderFields(e, 'parameterOne')}
80-
/>
81-
</div>
82-
</div>
83-
<div id={styles.hookRenderFlexBox}>
84-
<div id={styles.hookRenderType}>
85-
<label htmlFor='returnValue'>Managed State</label>
86-
<input
87-
type='text'
88-
id='returnValue'
89-
placeholder='eg. count'
90-
onChange={(e) => handleChangeHookRenderFields(e, 'returnValue')}
91-
/>
92-
</div>
93-
<div id={styles.hookRenderType}>
94-
<label htmlFor='expectedReturnValue'>Current Value</label>
110+
<label htmlFor='parameters'>Hook Parameters (optional)</label>
95111
<input
96112
type='text'
97-
id='expectedReturnValue'
98-
placeholder='eg. 0'
99-
onChange={(e) => handleChangeHookRenderFields(e, 'expectedReturnValue')}
113+
id='parameters'
114+
placeholder='eg. 9000, "string"'
115+
onChange={(e) => handleChangeHookRenderFields(e, 'parameters')}
100116
/>
101117
</div>
102118
</div>
119+
{input}
103120
</div>
104121
)}
105122
</Draggable>

src/components/ReactHooksTestComponent/HookRender/HookRender.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@
4242
margin-top: 6px;
4343
width: 100%;
4444
}
45+
button {
46+
margin-top: 6px;
47+
width: 100%;
48+
}
4549
position: relative;
4650
}

0 commit comments

Comments
 (0)