Skip to content

Commit ad53648

Browse files
authored
Merge pull request #60 from bkwak/feature
Feature
2 parents 11500f5 + b074cdb commit ad53648

26 files changed

+247
-144
lines changed

src/App.jsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@ const App = () => {
2323
</GlobalContext.Provider>
2424
</div>
2525
);
26-
} else if (global.isProjectLoaded === 'about') {
27-
return (
28-
<>
29-
<About dispatch={dispatchToGlobal} />
30-
</>
31-
);
3226
} else {
3327
return (
3428
/**
35-
* Wrap the components that we want to share the unique states with (ex: share testCase state with navbar & left panel (the two containers that hold the components that need testCaseRducer)) in the unique providers (ex: TestCaseContext.Provider).
29+
* Wrap the components that we want to share the unique states with.
3630
* You can only provide one value to a Provider.
3731
* - In order to avoid creating separate Contexts, wrap multiples in an array (ex: testCase and dispatchToTestCase).
3832
*
@@ -45,7 +39,9 @@ const App = () => {
4539
*/
4640
<div
4741
id={
48-
global.isFileDirectoryOpen
42+
global.isProjectLoaded === 'about'
43+
? ''
44+
: global.isFileDirectoryOpen
4945
? global.isRightPanelOpen
5046
? styles.fileDirectoryOpenRightPanelOpen
5147
: styles.fileDirectoryOpenRightPanelClosed
@@ -55,8 +51,17 @@ const App = () => {
5551
}
5652
>
5753
<GlobalContext.Provider value={[global, dispatchToGlobal]}>
58-
<NavBar />
59-
<LeftPanel />
54+
{global.isProjectLoaded === 'about' ? (
55+
<>
56+
<NavBar inAboutPage={true} />
57+
<About dispatch={dispatchToGlobal} />{' '}
58+
</>
59+
) : (
60+
<>
61+
<NavBar inAboutPage={false} />
62+
<LeftPanel />
63+
</>
64+
)}
6065
{global.isRightPanelOpen ? <RightPanel /> : ''}
6166
</GlobalContext.Provider>
6267
</div>

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/EndpointTestComponent/Endpoint.jsx renamed to src/components/EndpointTestComponent/Endpoint.tsx

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styles from './Endpoint.module.scss';
44
import style from '../ReactTestComponent/Render/Render.module.scss';
55
import styled from '../ReactTestComponent/Render/Prop.module.scss';
66
import EndpointAssertion from './EndpointAssertion';
7+
import { Assertion, EndpointObj, Header, Action, EventTarget } from '../../utils/endpointTypes';
78

89
import {
910
deleteEndpoint,
@@ -18,17 +19,31 @@ const closeIcon = require('../../assets/images/close.png');
1819
const dragIcon = require('../../assets/images/drag-vertical.png');
1920
const minusIcon = require('../../assets/images/minus-box-outline.png');
2021

21-
const Endpoint = ({ endpoint, index, dispatchToEndpointTestCase }) => {
22-
const handleChangeEndpointFields = (e, field) => {
22+
interface EndpointProps {
23+
endpoint: EndpointObj;
24+
index: number;
25+
dispatchToEndpointTestCase: (action: Action) => void;
26+
}
27+
28+
// declare global {
29+
// namespace JSX {
30+
// interface IntrinsicElements {
31+
// input: { id: number | string };
32+
// }
33+
// }
34+
// }
35+
36+
const Endpoint = ({ endpoint, index, dispatchToEndpointTestCase }: EndpointProps) => {
37+
const handleChangeEndpointFields = ({ target }: EventTarget, field: string) => {
2338
let updatedEndpoint = { ...endpoint };
2439

2540
field === 'headerName' || field === 'headerValue'
26-
? (updatedEndpoint.headers[e.target.id][field] = e.target.value)
27-
: (updatedEndpoint[field] = e.target.value);
41+
? (updatedEndpoint.headers[Number(target.id)][field] = target.value)
42+
: (updatedEndpoint[field] = target.value);
2843
dispatchToEndpointTestCase(updateEndpoint(updatedEndpoint));
2944

30-
if (e.target.value === 'post') dispatchToEndpointTestCase(togglePost(index));
31-
else if (e.target.type === 'select-one' && endpoint.post)
45+
if (target.value === 'post') dispatchToEndpointTestCase(togglePost(index));
46+
else if (target.type === 'select-one' && endpoint.post)
3247
dispatchToEndpointTestCase(togglePost(index));
3348
};
3449

@@ -41,21 +56,21 @@ const Endpoint = ({ endpoint, index, dispatchToEndpointTestCase }) => {
4156
dispatchToEndpointTestCase(addHeader(index));
4257
};
4358

44-
const handleClickDeleteHeader = (i) => {
59+
const handleClickDeleteHeader = (i: number) => {
4560
dispatchToEndpointTestCase(deleteHeader(index, i));
4661
};
4762

48-
const updatePostData = (e) => {
49-
dispatchToEndpointTestCase(updatePost(e.target.value, index));
50-
e.target.style.height = 'inherit';
51-
e.target.style.height = `${Math.max(Math.min(e.target.scrollHeight, 200), 102)}px`;
63+
const updatePostData = ({ target }: EventTarget) => {
64+
dispatchToEndpointTestCase(updatePost(target.value, index));
65+
target.style.height = 'inherit';
66+
target.style.height = `${Math.max(Math.min(target.scrollHeight, 200), 102)}px`;
5267
};
5368

5469
const addAssertionHandleClick = () => {
5570
dispatchToEndpointTestCase(addAssertion(index));
5671
};
5772

58-
const testDescription = useRef(null);
73+
const testDescription = useRef<HTMLInputElement>(null);
5974

6075
useEffect(() => {
6176
if (testDescription && testDescription.current) {
@@ -141,7 +156,7 @@ const Endpoint = ({ endpoint, index, dispatchToEndpointTestCase }) => {
141156
</div>
142157
</div>
143158
</div>{' '}
144-
{endpoint.assertions.map((assertion, i) => {
159+
{endpoint.assertions.map((assertion: Assertion, i: number) => {
145160
return <EndpointAssertion assertion={assertion} index={index} id={i} />;
146161
})}{' '}
147162
{endpoint.post && (
@@ -180,7 +195,7 @@ const Endpoint = ({ endpoint, index, dispatchToEndpointTestCase }) => {
180195
</label>
181196
</div>
182197
<hr />
183-
{endpoint.headers.map((header, i) => {
198+
{endpoint.headers.map((header: Header, i) => {
184199
return (
185200
<div id={styled.renderPropsFlexBox}>
186201
<input

src/components/EndpointTestComponent/EndpointAssertion.jsx renamed to src/components/EndpointTestComponent/EndpointAssertion.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,32 @@ import { EndpointTestCaseContext } from '../../context/reducers/endpointTestCase
55
import { deleteAssertion, updateAssertion } from '../../context/actions/endpointTestCaseActions';
66
import { GlobalContext } from '../../context/reducers/globalReducer';
77
import { openBrowserDocs } from '../../context/actions/globalActions';
8-
import jestMatchers from './JestMatchers.js';
8+
import jestMatchers from './JestMatchers';
9+
import { Assertion, EventTarget } from '../../utils/endpointTypes';
910

10-
const EndpointAssertion = ({ assertion, index, id }) => {
11+
interface EndpointProps {
12+
assertion: Assertion;
13+
index: number;
14+
id: number;
15+
}
16+
17+
const EndpointAssertion = ({ assertion, index, id }: EndpointProps) => {
1118
const [, dispatchToEndpointTestCase] = useContext(EndpointTestCaseContext);
12-
const [, dispatchToGlobal] = useContext(GlobalContext);
19+
const [, dispatchToGlobal] = useContext<any>(GlobalContext);
1320

1421
const questionIcon = require('../../assets/images/help-circle.png');
1522
const closeIcon = require('../../assets/images/close.png');
16-
const jestURL = 'https://jestjs.io/docs/en/expect';
23+
const jestURL: string = 'https://jestjs.io/docs/en/expect';
1724

1825
const handleClickDeleteAssertion = () => {
1926
dispatchToEndpointTestCase(deleteAssertion(index, id));
2027
};
2128

22-
const handleChangeUpdateAssertion = (e, field) => {
29+
const handleChangeUpdateAssertion = ({ target }: EventTarget, field: string) => {
2330
const updatedAssertion =
2431
field === 'not'
2532
? { ...assertion, [field]: !assertion[field] }
26-
: { ...assertion, [field]: e.target.value };
33+
: { ...assertion, [field]: target.value };
2734
dispatchToEndpointTestCase(updateAssertion(index, id, updatedAssertion));
2835
};
2936

src/components/EndpointTestComponent/JestMatchers.js renamed to src/components/EndpointTestComponent/JestMatchers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const jestMatchers = [
1+
const jestMatchers: string[] = [
22
'',
33
'to Be',
44
'to Equal (object)',

src/components/FileDirectory/FileDirectory.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
background-color: white;
1515
overflow: auto;
1616
border-right: 1px dotted $mint;
17+
z-index: 1;
1718

1819
ul {
1920
list-style-type: none;

src/components/Modals/ExportFileModal.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const ExportFileModal = ({ isExportModalOpen, setIsExportModalOpen }) => {
5656
await fs.writeFile(projectFilePath + `/__tests__/${fileName}.test.js`, file, (err) => {
5757
if (err) throw err;
5858
});
59-
6059
dispatchToGlobal(createFileTree(generateFileTreeObject(projectFilePath)));
6160
displayTestFile(projectFilePath + '/__tests__');
6261
};
@@ -67,7 +66,7 @@ const ExportFileModal = ({ isExportModalOpen, setIsExportModalOpen }) => {
6766
dispatchToGlobal(toggleFolderView(testFolderFilePath));
6867
dispatchToGlobal(highlightFile(`${fileName}.test.js`));
6968
};
70-
69+
// co
7170
const filePathMap = {};
7271
const generateFileTreeObject = (projectFilePath) => {
7372
const fileArray = fs.readdirSync(projectFilePath).map((fileName) => {
@@ -96,7 +95,6 @@ const ExportFileModal = ({ isExportModalOpen, setIsExportModalOpen }) => {
9695
}
9796
return file;
9897
});
99-
10098
dispatchToGlobal(setFilePathMap(filePathMap));
10199
return fileArray;
102100
};

src/components/NavBar/NavBar.jsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const browserIcon = require('../../assets/images/google-chrome.png');
2424
const codeIcon = require('../../assets/images/visual-studio-code.png');
2525
const homeIcon = require('../../assets/images/home.png');
2626

27-
const NavBar = () => {
27+
const NavBar = ({ inAboutPage }) => {
2828
const [
2929
{ fileTree, isFileDirectoryOpen, projectUrl, rightPanelDisplay },
3030
dispatchToGlobal,
@@ -38,11 +38,12 @@ const NavBar = () => {
3838

3939
/* switches between code and browser view */
4040
const handleEditorToggle = () => {
41-
dispatchToGlobal(toggleRightPanel('codeEditorView'));
41+
if (!inAboutPage) dispatchToGlobal(toggleRightPanel('codeEditorView'));
4242
};
4343

4444
/* switches between code and browser view */
4545
const handleBrowserToggle = () => {
46+
if (inAboutPage) return;
4647
if (rightPanelDisplay === 'browserView' && projectUrl) {
4748
dispatchToGlobal(resetToProjectUrl());
4849
}
@@ -67,7 +68,7 @@ const NavBar = () => {
6768
* renders: buttons + icons for navbar, exportFileModal, boxes to open new folder and enter url, file directory
6869
*/
6970
return (
70-
<div id={styles.navBar}>
71+
<div id={inAboutPage ? styles.inAboutPage : styles.navBar}>
7172
<button className={styles.navBtn} onClick={handleToggleFileDirectory}>
7273
<img src={menuIcon} className={styles.icons} alt='fileExplorer' />
7374
<span className={styles.tooltip}>Expand File Explorer</span>
@@ -76,10 +77,12 @@ const NavBar = () => {
7677
<img src={exportIcon} className={styles.icons} alt='export' title='Export a test file' />
7778
<span className={styles.tooltip}>Export</span>
7879
</button>
79-
<ExportFileModal
80-
isExportModalOpen={isExportModalOpen}
81-
setIsExportModalOpen={setIsExportModalOpen}
82-
/>
80+
{!inAboutPage && (
81+
<ExportFileModal
82+
isExportModalOpen={isExportModalOpen}
83+
setIsExportModalOpen={setIsExportModalOpen}
84+
/>
85+
)}
8386
<OpenFolder />
8487
<button className={styles.navBtn} onClick={handleEditorToggle}>
8588
<img src={codeIcon} className={styles.icons} alt='codeview' title='Code View' />

src/components/NavBar/NavBar.module.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
flex-direction: column;
1010
align-items: center;
1111
justify-content: flex-start;
12+
// position: absolute;
13+
// top: 0;
14+
// left: 0;
1215
}
1316

1417
.navBtn {
@@ -36,10 +39,18 @@
3639
text-align: center;
3740
border-radius: 8px;
3841
margin: 0 auto;
39-
z-index: 2;
42+
z-index: 3;
4043
}
4144

4245
.navBtn:hover .tooltip {
4346
visibility: visible;
4447
margin-left: 5px;
4548
}
49+
50+
#inAboutPage {
51+
@extend #navBar;
52+
float: left;
53+
position: fixed;
54+
top: 0;
55+
left: 0;
56+
}

src/components/OpenFolder/OpenFolderButton.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import {
99
createFileTree,
1010
setFilePathMap,
1111
setProjectFilePath,
12-
// updateFile,
13-
// setFilePath,
12+
toggleFileDirectory,
13+
setTestCase,
14+
toggleModal,
1415
} from '../../context/actions/globalActions';
1516
import { GlobalContext } from '../../context/reducers/globalReducer';
1617

@@ -21,7 +22,9 @@ const electronFs = remote.require('fs');
2122
const { dialog } = remote;
2223

2324
const OpenFolder = () => {
24-
const [{ isProjectLoaded }, dispatchToGlobal] = useContext(GlobalContext);
25+
const [{ isProjectLoaded, isFileDirectoryOpen, isTestModalOpen }, dispatchToGlobal] = useContext(
26+
GlobalContext
27+
);
2528
const filePathMap = {};
2629

2730
const handleOpenFolder = () => {
@@ -42,6 +45,9 @@ const OpenFolder = () => {
4245
dispatchToGlobal(setProjectFilePath(directoryPath));
4346
dispatchToGlobal(createFileTree(generateFileTreeObject(directoryPath)));
4447
dispatchToGlobal(loadProject('load'));
48+
dispatchToGlobal(setTestCase(''));
49+
if (!isTestModalOpen) dispatchToGlobal(toggleModal());
50+
if (!isFileDirectoryOpen) dispatchToGlobal(toggleFileDirectory());
4551
}
4652
};
4753

0 commit comments

Comments
 (0)