Skip to content

Commit fa86dbb

Browse files
authored
Merge pull request #13 from mbcoker/react_tests
React tests
2 parents 76ac06c + ee5a0f3 commit fa86dbb

File tree

6 files changed

+94
-58
lines changed

6 files changed

+94
-58
lines changed

src/containers/LeftPanel/SearchInput/SearchInput.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react';
22
import './SearchInput.scss';
33

4-
export const Autocomplete = ({dispatch, action, filePathMap, options}) => {
4+
export const Autocomplete = ({dispatch, action, filePathMap, options, reactTestCase}) => {
55

66
const [activeOption, setActiveOption] = useState(0)
77
const [filteredOptions, setFilteredOptions] = useState([])
@@ -54,10 +54,14 @@ export const Autocomplete = ({dispatch, action, filePathMap, options}) => {
5454
}
5555
};
5656
let optionList;
57+
let optionStyles = 'options'
5758
if (showOptions && userInput) {
5859
if (filteredOptions.length) {
60+
if(reactTestCase) {
61+
optionStyles = 'react-test-options'
62+
}
5963
optionList = (
60-
<ul className="options">
64+
<ul className={optionStyles}>
6165
{filteredOptions.map((optionName, index) => {
6266
let className;
6367
if (index === activeOption) {

src/containers/LeftPanel/SearchInput/SearchInput.scss

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,23 @@ ul.options li.option-active {
1717
position: absolute;
1818
z-index: 1;
1919
width: -webkit-fill-available ;
20-
}
20+
}
21+
22+
.react-test-options {
23+
background-color: white;
24+
overflow: auto;
25+
position: absolute;
26+
z-index: 4;
27+
width: 137px;
28+
}
29+
ul.react-test-options li:hover {
30+
font-weight: bold;
31+
color: #00b4cc;
32+
cursor: pointer;
33+
transition: 0.3s all;
34+
}
35+
36+
ul.react-test-options li.option-active {
37+
background: whitesmoke;
38+
color: #00b4cc;
39+
}

src/containers/LeftPanel/TestCase/ReactTestCase.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const ReactTestCase = () => {
5353
Enter Component Name:
5454
</label>
5555
<SearchInput
56+
reactTestCase={true}
5657
dispatch={dispatchToReactTestCase}
5758
action={updateRenderComponent}
5859
filePathMap={filePathMap}

src/containers/LeftPanel/TestMenu/ReactTestMenu.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ReactTestMenu = ({ dispatchToTestCase, dispatchToMockData }) => {
3333
id={styles.right}
3434
style={{ display: 'flex', flexWrap: 'wrap', justifyContent: 'center' }}
3535
>
36-
<button onClick={handleAddDescribeBlock}>+Describe Block</button>
36+
<button data-testid='addDescribeButton' onClick={handleAddDescribeBlock}>+Describe Block</button>
3737
</div>
3838
</div>
3939
</div>
Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
2-
import TestCase from '../TestCase/TestCase';
2+
import ReactTestCase from '../TestCase/ReactTestCase';
33
import { GlobalContext } from '../../../context/globalReducer';
4-
import { TestCaseContext } from '../../../context/testCaseReducer';
4+
import { ReactTestCaseContext } from '../../../context/reactTestCaseReducer';
55
import { MockDataContext } from '../../../context/mockDataReducer';
66
import { TestFileModalContext } from '../../../context/testFileModalReducer'
77
import { mount, configure } from 'enzyme';
@@ -29,28 +29,47 @@ beforeEach(() => {
2929
dispatchToGlobal = jest.fn();
3030

3131
testCase = {
32-
testStatement: '',
33-
statements: [
34-
{
35-
id: 0,
36-
type: 'render',
37-
componentName: '',
38-
filePath: '',
39-
props: [],
40-
hasProp: false,
32+
hasReact: 0,
33+
describeId: 1,
34+
itId: 1,
35+
statementId: 1,
36+
propId: 1,
37+
describeBlocks: {
38+
byId: {
39+
describe0: {
40+
id: 'describe0',
41+
text: '',
42+
},
4143
},
42-
{
43-
id: 1,
44-
type: 'assertion',
45-
queryVariant: '',
46-
querySelector: '',
47-
queryValue: '',
48-
isNot: false,
49-
matcherType: '',
50-
matcherValue: '',
51-
suggestions: [],
44+
allIds: ['describe0'],
45+
},
46+
itStatements: {
47+
byId: {
48+
it0: {
49+
id: 'it0',
50+
describeId: 'describe0',
51+
text: '',
52+
},
5253
},
53-
],
54+
allIds: ['it0'],
55+
},
56+
statements: {
57+
byId: {
58+
statement0: {
59+
id: 'statement0',
60+
itId: 'it0',
61+
describeId: 'describe0',
62+
type: 'render',
63+
componentName: '',
64+
filePath: '',
65+
props: [],
66+
hasProp: false,
67+
},
68+
},
69+
allIds: ['statement0'],
70+
componentPath: '',
71+
componentName: '',
72+
},
5473
};
5574

5675
dispatchToTestCase = jest.fn();
@@ -66,48 +85,30 @@ beforeEach(() => {
6685

6786
wrapper = mount(
6887
<GlobalContext.Provider value={[globalM, dispatchToGlobal]}>
69-
<TestCaseContext.Provider value={[testCase, dispatchToTestCase]}>
88+
<ReactTestCaseContext.Provider value={[testCase, dispatchToTestCase]}>
7089
<MockDataContext.Provider value={[mockData, dispatchToMockData]}>
7190
<TestFileModalContext.Provider value={[testFileModal, dispatchToTestFileModal]}>
72-
<TestCase />
91+
<ReactTestCase />
7392
</TestFileModalContext.Provider>
7493
</MockDataContext.Provider>
75-
</TestCaseContext.Provider>
94+
</ReactTestCaseContext.Provider>
7695
</GlobalContext.Provider>
7796
);
7897

7998
jest.resetModules();
8099
});
81100

82101
describe('testing left panel react test menu', () => {
83-
it('renders the react menu with initial buttons and first render boxes', () => {
84-
expect(wrapper.text()).toContain('Do you need mock data?');
85-
expect(wrapper.text()).toContain('Do you need props?');
86-
expect(wrapper.text()).toContain('Action');
87-
expect(wrapper.text()).toContain('Assertion');
88-
expect(wrapper.text()).toContain('Rerender');
102+
it('renders the react menu with initial buttons, component input, first Describe Block', () => {
103+
expect(wrapper.text()).toContain('Enter Component Name:');
104+
expect(wrapper.text()).toContain('Mock Data');
105+
expect(wrapper.text()).toContain('+Describe Block');
89106
expect(wrapper.text()).toContain('New Test +');
90107
});
91108

92-
it('onclick function is invoked when assertion button is clicked', () => {
93-
const btn = wrapper.find('button[data-testid="assertionButton"]');
94-
btn.simulate('click');
95-
expect(dispatchToTestCase).toHaveBeenCalled();
96-
});
97-
98-
it('onclick function is invoked when action button is clicked', () => {
99-
const btn = wrapper.find('button[data-testid="actionButton"]');
109+
it('onclick function is invoked when add Describe Block button is clicked', () => {
110+
const btn = wrapper.find("button[data-testid='addDescribeButton']");
100111
btn.simulate('click');
101112
expect(dispatchToTestCase).toHaveBeenCalled();
102113
});
103-
104-
it('onclick function is invoked when rerender button is clicked', () => {
105-
const btn = wrapper.find('button[data-testid="rerenderButton"]');
106-
btn.simulate('click');
107-
expect(dispatchToTestCase).toHaveBeenCalled();
108-
});
109-
110-
it('there should be 4 buttons', () => {
111-
expect(wrapper.find('button').length).toEqual(4)
112-
});
113114
});

src/containers/LeftPanel/__tests__/testFileModal.test.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { GlobalContext } from '../../../context/globalReducer';
55
import { TestFileModalContext } from '../../../context/testFileModalReducer';
66
import { HooksTestCaseContext } from '../../../context/hooksTestCaseReducer';
77
import { ReduxTestCaseContext } from '../../../context/reduxTestCaseReducer';
8-
import { TestCaseContext } from '../../../context/testCaseReducer';
8+
import { ReactTestCaseContext } from '../../../context/reactTestCaseReducer';
99
import { EndpointTestCaseContext } from '../../../context/endpointTestCaseReducer';
10+
import { PuppeteerTestCaseContext } from '../../../context/puppeteerTestCaseReducer';
1011

1112
import { mount } from 'enzyme';
1213
import { configure } from 'enzyme';
@@ -26,7 +27,9 @@ let wrapper,
2627
testCase,
2728
dispatchToTestCase,
2829
endpointTestCaseState,
29-
dispatchToEndpointTestCase;
30+
dispatchToEndpointTestCase,
31+
pupeteerTestCaseState,
32+
dispatchToPuppeteerTestCase;
3033

3134
beforeEach(() => {
3235
globalM = {
@@ -96,18 +99,26 @@ beforeEach(() => {
9699
};
97100
dispatchToEndpointTestCase = jest.fn();
98101

102+
pupeteerTestCaseState = {
103+
puppeteerStatements: [],
104+
hasPuppeteer: 0,
105+
};
106+
dispatchToPuppeteerTestCase = jest.fn();
107+
99108
wrapper = mount(
100109
<GlobalContext.Provider value={[globalM, dispatchToGlobal]}>
101110
<TestFileModalContext.Provider value={[testFileModal, dispatchToTestFileModal]}>
102111
<HooksTestCaseContext.Provider value={[hooksTestCase, dispatchToHooksTestCase]}>
103112
<ReduxTestCaseContext.Provider value={[reduxTestCaseState, dispatchToReduxTestCase]}>
104-
<TestCaseContext.Provider value={[testCase, dispatchToTestCase]}>
113+
<ReactTestCaseContext.Provider value={[testCase, dispatchToTestCase]}>
105114
<EndpointTestCaseContext.Provider
106115
value={[endpointTestCaseState, dispatchToEndpointTestCase]}
107116
>
108-
<TestFile />
117+
<PuppeteerTestCaseContext.Provider value={[pupeteerTestCaseState, dispatchToPuppeteerTestCase]}>
118+
<TestFile />
119+
</PuppeteerTestCaseContext.Provider>
109120
</EndpointTestCaseContext.Provider>
110-
</TestCaseContext.Provider>
121+
</ReactTestCaseContext.Provider>
111122
</ReduxTestCaseContext.Provider>
112123
</HooksTestCaseContext.Provider>
113124
</TestFileModalContext.Provider>

0 commit comments

Comments
 (0)