Skip to content

Commit 710a64c

Browse files
authored
Merge pull request #25 from JIB3377/endpoint-guide
Linked Puppeteer testing command to terminal & Added Endpoint-config Guide to the modal
2 parents 1165ad3 + 02a2c8a commit 710a64c

File tree

3 files changed

+84
-39
lines changed

3 files changed

+84
-39
lines changed

src/components/Modals/ExportFileModal.module.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@
224224
flex: 1;
225225
flex-direction: column;
226226
}
227+
#endPointGuide {
228+
margin: 8px;
229+
}
230+
#configGuide {
231+
display: flex;
232+
flex: 1;
233+
flex-direction: column;
234+
line-height: normal;
235+
}
227236

228237
pre {
229238
display: flex;

src/components/Modals/Modal.jsx

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React, { useState, useContext } from 'react';
77
import ReactModal from 'react-modal';
88
import styles from './ExportFileModal.module.scss';
99
import { useCopy, useNewTest, useGenerateScript } from './modalHooks';
10-
import {setTabIndex,} from '../../context/actions/globalActions';
10+
import { setTabIndex, } from '../../context/actions/globalActions';
1111
// Accordion view
1212
import Accordion from '@material-ui/core/Accordion';
1313
import AccordionSummary from '@material-ui/core/AccordionSummary';
@@ -68,7 +68,7 @@ const Modal = ({
6868
}
6969

7070
const changeDirectory = () => {
71-
ipc.send('terminal.toTerm', `"${script.cd}"${execute}`);
71+
ipc.send('terminal.toTerm', `${script.cd}${execute}`);
7272
setBtnFeedback({ ...btnFeedback, changedDir: true });
7373
};
7474

@@ -100,36 +100,36 @@ const Modal = ({
100100
if (title === 'New Test') {
101101
return (
102102
<ReactModal
103-
className={styles.modal}
104-
isOpen={isModalOpen}
105-
onRequestClose={closeModal}
106-
contentLabel="Save?"
107-
shouldCloseOnOverlayClick={true}
108-
shouldCloseOnEsc={true}
109-
ariaHideApp={false}
110-
style={{
111-
content: {
112-
top: '20%',
113-
left: isFileDirectoryOpen ? '22%' : '11%',
114-
},
115-
overlay: {
116-
zIndex: 3,
117-
left: isFileDirectoryOpen ? '276px' : '46px',
118-
minWidth: isFileDirectoryOpen ? '600px' : '600px',
119-
width: isFileDirectoryOpen ? 'calc(59.9% - 276px)':'calc(49.9% - 46px)',
120-
},
121-
}}>
103+
className={styles.modal}
104+
isOpen={isModalOpen}
105+
onRequestClose={closeModal}
106+
contentLabel="Save?"
107+
shouldCloseOnOverlayClick={true}
108+
shouldCloseOnEsc={true}
109+
ariaHideApp={false}
110+
style={{
111+
content: {
112+
top: '20%',
113+
left: isFileDirectoryOpen ? '22%' : '11%',
114+
},
115+
overlay: {
116+
zIndex: 3,
117+
left: isFileDirectoryOpen ? '276px' : '46px',
118+
minWidth: isFileDirectoryOpen ? '600px' : '600px',
119+
width: isFileDirectoryOpen ? 'calc(59.9% - 276px)' : 'calc(49.9% - 46px)',
120+
},
121+
}}>
122122
<div id={styles.title}>
123123
<p>{title}</p>
124124
</div>
125125

126126
<div id={styles.body}>
127127
<p id={styles.text}>
128128
Do you want to start a new test? All unsaved changes
129-
<br/>
129+
<br />
130130
will be lost.
131131
</p>
132-
<span id={styles.newTestButtons} style={{justifyContent: 'center', alignItems: 'center'}}>
132+
<span id={styles.newTestButtons} style={{ justifyContent: 'center', alignItems: 'center' }}>
133133
<button id={styles.save} onClick={handleNewTest}>
134134
{title}
135135
</button>
@@ -139,9 +139,39 @@ const Modal = ({
139139
</span>
140140
</div>
141141
</ReactModal>
142-
);
142+
);
143143
}
144144

145+
146+
const EndPointGuide = () => {
147+
// endpoint guide only exists when user is in endpoint testing
148+
if (script.endPointGuide) {
149+
const array = [];
150+
for (let step in script.endPointGuide) {
151+
array.push(<div id={styles.endPointGuide}>{script.endPointGuide[step]}{'\n'}</div>)
152+
}
153+
// return accordion element
154+
return (
155+
<Accordion hidden={false}>
156+
<AccordionSummary
157+
expandIcon={<ExpandMoreIcon />}
158+
aria-controls="panel1a-content"
159+
id="panel1a-header"
160+
id={styles.accordionSummary}
161+
>
162+
Endpoint Testing Configuration Guide
163+
</AccordionSummary>
164+
<AccordionDetails id={styles.configGuide}>
165+
{array}
166+
</AccordionDetails>
167+
</Accordion>
168+
);
169+
}
170+
171+
// return anything to not render accordion
172+
return true;
173+
};
174+
145175
return (
146176
<ReactModal
147177
className={styles.modal2}
@@ -161,7 +191,7 @@ const Modal = ({
161191
overlay: {
162192
left: isFileDirectoryOpen ? '276px' : '46px',
163193
minWidth: isFileDirectoryOpen ? '600px' : '600px',
164-
width: isFileDirectoryOpen ? 'calc(59.9% - 276px)':'calc(49.9% - 46px)',
194+
width: isFileDirectoryOpen ? 'calc(59.9% - 276px)' : 'calc(49.9% - 46px)',
165195
},
166196
}}
167197
>
@@ -179,6 +209,7 @@ const Modal = ({
179209
{/* Accordian View */}
180210
<div>
181211
{/* Configuration Guide */}
212+
<EndPointGuide />
182213
<Accordion>
183214
<AccordionSummary
184215
expandIcon={<ExpandMoreIcon />}
@@ -282,7 +313,7 @@ const Modal = ({
282313
{/* To do: make button toggle on/off */}
283314
<pre>
284315
<div className="code-wrapper">
285-
<code>
316+
<code>
286317
{`jest ${fileName}\n`}
287318
{`jest --verbose ${fileName}\n`}
288319
{`jest --coverage ${fileName}\n`}

src/components/Modals/modalHooks.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ export function useGenerateScript(test, testType = null, puppeteerUrl = 'sample.
5757
}
5858
if (testType === 'puppeteer') {
5959
return (
60-
`cd ${projectFilePath}
61-
npm i -D axe-core puppeteer
62-
node <YOUR_DIR_PATH/TEST_FILE.JS> ${puppeteerUrl}
63-
`
60+
{
61+
cd: `cd ${projectFilePath}`,
62+
install: 'npm i -D axe-core puppeteer',
63+
}
6464
);
6565
}
6666
return 'error';
@@ -87,14 +87,14 @@ export function useGenerateScript(test, testType = null, puppeteerUrl = 'sample.
8787
);
8888
case 'endpoint':
8989
const endPointGuide = {
90-
Pre: "Please follow these steps to configure your files correctly. The tests will not run properly if you skip these steps",
91-
1: `Your server file MUST export your server object.`,
92-
2: `Comment out or remove the appropriate lines of code where the call to the server's listen method takes place`,
93-
3: `If you are testing a route that involves querying a database, you must import the file where your database instance is created.`,
94-
4: `In that file, you must export your database instance object`,
95-
'4a': `PostgreSQL: Pool, Client, or pg object`,
96-
'4b': `MongoDB: MongoClient instance`,
97-
'4c': `Mongoose: mongoose instance`,
90+
1: `1. Please follow these steps to configure your files correctly. The tests will not run properly if you skip these steps.`,
91+
2: `2. Your server file MUST export your server object.`,
92+
3: `3. Comment out or remove the appropriate lines of code where the call to the server's listen method takes place.`,
93+
4: `4. If you are testing a route that involves querying a database, you must import the file where your database instance is created.`,
94+
5: `5. In that file, you must export your database instance object.`,
95+
'5a': `5a. PostgreSQL: Pool, Client, or pg object.`,
96+
'5b': `5b. MongoDB: MongoClient instance.`,
97+
'5c': `5c. Mongoose: mongoose instance.`,
9898
}
9999
return (
100100
{
@@ -104,7 +104,12 @@ export function useGenerateScript(test, testType = null, puppeteerUrl = 'sample.
104104
}
105105
);
106106
case 'puppeteer':
107-
return `cd ${projectFilePath}\nnpm i -D jest puppeteer\nnpm run test`;
107+
return (
108+
{
109+
cd: `cd ${projectFilePath}`,
110+
install: 'npm i -D puppeteer',
111+
}
112+
);
108113
default:
109114
return '';
110115
// code block

0 commit comments

Comments
 (0)