-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathUploadTestModal.tsx
120 lines (110 loc) · 3.87 KB
/
UploadTestModal.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import React, { useState, useContext } from 'react';
import ReactModal from '/react-modal';
import { AccTestCaseContext } from '../../context/reducers/accTestCaseReducer';
import { EndpointTestCaseContext } from '../../context/reducers/endpointTestCaseReducer';
import { HooksTestCaseContext } from '../../context/reducers/hooksTestCaseReducer';
import { PuppeteerTestCaseContext } from '../../context/reducers/puppeteerTestCaseReducer';
import { ReactTestCaseContext } from '../../context/reducers/reactTestCaseReducer';
import { ReduxTestCaseContext } from '../../context/reducers/reduxTestCaseReducer';
import styles from './Modal.module.scss';
/**
* This react component UploadTestModal renders a modal that allows the user to save a test case to the database
* @returns A modal that allows the user to save a test case.
*/
interface UploadTestModalProps {
uploadTestModalIsOpen: React.Dispatch<Element>;
setUploadTestModalIsOpen: React.Dispatch<boolean>;
testType: string;
}
const UploadTestModal = ({ uploadTestModalIsOpen, setUploadTestModalIsOpen, testType }: UploadTestModalProps) => {
const [testName, setTestName] = useState('');
const [accTestCase] = useContext(AccTestCaseContext);
const [endpointTestCase] = useContext(EndpointTestCaseContext);
const [hooksTestCase] = useContext(HooksTestCaseContext);
const [puppeteerTestCase] = useContext(PuppeteerTestCaseContext);
const [reactTestCase] = useContext(ReactTestCaseContext);
const [reduxTestCase] = useContext(ReduxTestCaseContext);
/**
* Closes the upload modal
*/
const closeUploadModal = () => {
setUploadTestModalIsOpen(false);
};
const handleChangeTestName = (e: React.BaseSyntheticEvent<KeyboardEvent>) => {
setTestName(e.target.value);
};
const handleClickSave = () => {
let testState;
switch (testType) {
case 'acc':
testState = accTestCase;
break;
case 'endpoint test':
testState = endpointTestCase;
break;
case 'hooks':
testState = hooksTestCase;
break;
case 'puppeteer':
testState = puppeteerTestCase;
break;
case 'react':
testState = reactTestCase;
break;
case 'redux':
testState = reduxTestCase;
break;
default:
testState = [];
break;
}
fetch('http://spearmint.us-west-1.elasticbeanstalk.com/upload', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ testName, testType, testState }),
})
.then((res) => res.json())
.then((data) => console.log(data))
.catch((err) => console.log(err));
closeUploadModal();
};
const modalStyles = {
overlay: {
zIndex: 3,
},
};
return (
<ReactModal
className={styles.modal}
isOpen={uploadTestModalIsOpen}
onRequestClose={closeUploadModal}
contentLabel='Save testing file'
shouldCloseOnOverlayClick={true}
shouldCloseOnEsc={true}
ariaHideApp={false}
style={modalStyles}
>
<div id={styles.container}>
<div id={styles.title}>
<p>Save Test Case</p>
<svg id={styles.close} onClick={closeUploadModal}>
<path d='M19,3H16.3H7.7H5A2,2 0 0,0 3,5V7.7V16.4V19A2,2 0 0,0 5,21H7.7H16.4H19A2,2 0 0,0 21,19V16.3V7.7V5A2,2 0 0,0 19,3M15.6,17L12,13.4L8.4,17L7,15.6L10.6,12L7,8.4L8.4,7L12,10.6L15.6,7L17,8.4L13.4,12L17,15.6L15.6,17Z' />
</svg>
</div>
<div id={styles.body}>
<p>File Name</p>
<input type='text' value={testName} onChange={handleChangeTestName} />
<button id={styles.save} onClick={closeUploadModal}>
Cancel
</button>
<button id={styles.save} onClick={handleClickSave}>
Save
</button>
</div>
</div>
</ReactModal>
);
};
export default UploadTestModal;