-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathGraphQLAssertion.tsx
113 lines (105 loc) · 3.89 KB
/
GraphQLAssertion.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
import React, { useContext } from 'react';
import styles from './GraphQL.module.scss';
import stylez from '../ReactTestComponent/Assertion/Assertion.module.scss';
import { GraphQLTestCaseContext } from '../../context/reducers/graphQLTestCaseReducer';
import { deleteAssertion, updateAssertion } from '../../context/actions/graphQLTestCaseActions';
import { GlobalContext } from '../../context/reducers/globalReducer';
import { openBrowserDocs } from '../../context/actions/globalActions';
import jestMatchers from './JestMatchers';
import { Assertion, EventTarget } from '../../utils/graphQLTypes';
interface GraphQLProps {
assertion: Assertion;
index: number;
id: number;
}
const GraphQLAssertion = ({ assertion, index, id }: GraphQLProps) => {
const [, dispatchToGraphQLTestCase] = useContext(GraphQLTestCaseContext);
const [, dispatchToGlobal] = useContext<any>(GlobalContext);
const questionIcon = require('../../assets/images/help-circle.png');
const closeIcon = require('../../assets/images/close.png');
const jestURL: string = 'https://jestjs.io/docs/en/expect';
const handleClickDeleteAssertion = () => {
dispatchToGraphQLTestCase(deleteAssertion(index, id));
};
const handleChangeUpdateAssertion = ({ target }: EventTarget, field: string) => {
const updatedAssertion =
field === 'not'
? { ...assertion, [field]: !assertion[field] }
: { ...assertion, [field]: target.value };
dispatchToGraphQLTestCase(updateAssertion(index, id, updatedAssertion));
};
const handleClickTooltip = () => {
dispatchToGlobal(openBrowserDocs(jestURL));
};
return (
<div id={styles.groupFlexboxAssertion}>
<div id={styles.labelInput}>
<label htmlFor='requestBody'>Expect Response</label>
<div id={styles.inputFlexBox}>
<input
type='text'
list='responseProperties'
value={assertion.expectedResponse}
onChange={(e) => handleChangeUpdateAssertion(e, 'expectedResponse')}
/>
<datalist id='responseProperties'>
<option value='Headers'></option>
<option value='Status'></option>
<option value='Body'></option>
<option value='Text'></option>
<option value='Type'></option>
</datalist>
</div>
</div>
<div id={styles.dropdownWrapper}>
<div id={styles.endMatcherLabel}>
<div>
<label htmlFor='matcher'>Matcher</label>
</div>
<div id={styles.notDiv}>
Not?
<input
type='checkbox'
onChange={(e) => handleChangeUpdateAssertion(e, 'not')}
style={{ marginLeft: '5px' }}
/>
</div>
</div>
<div id={styles.dropdownFlex}>
<select
id='method'
value={assertion.matcher}
onChange={(e) => handleChangeUpdateAssertion(e, 'matcher')}
>
{jestMatchers.map((matcher) => (
<option value={matcher}>{matcher}</option>
))}
</select>{' '}
<span id={stylez.hastooltip} role='tooltip'>
<img src={questionIcon} alt='help' onClick={handleClickTooltip} />
<span id={stylez.tooltip}>Click me to find out more about Jest test matchers</span>
</span>
</div>
</div>
<div id={styles.labelInput}>
<label htmlFor='value'>Expected Value</label>
<div id={styles.inputFlexBox}>
<input
type='text'
name='value'
placeholder='eg. 200'
value={assertion.value}
onChange={(e) => handleChangeUpdateAssertion(e, 'value')}
/>
</div>
</div>
<img
src={closeIcon}
style={{ position: 'relative', top: '-15px' }}
alt='close'
onClick={handleClickDeleteAssertion}
/>
</div>
);
};
export default GraphQLAssertion;