Skip to content

Commit 7772f9d

Browse files
authored
Merge pull request #47 from davefranz/tests
Created tests for redux, react, and endpoints. Updated placeholder text render hooks and reducer
2 parents bd1d04c + 8da45e5 commit 7772f9d

File tree

6 files changed

+224
-37
lines changed

6 files changed

+224
-37
lines changed

src/containers/LeftPanel/HookRender/HookRender.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ const HookRender = ({ hookRender, index, dispatchToHooksTestCase }) => {
6262
<input
6363
type='text'
6464
id='hook'
65-
placeholder='Hook Name'
65+
placeholder='eg. useCounter'
6666
onChange={e => handleChangeHookRenderFields(e, 'hook')}
6767
/>
6868
</div>
6969

7070
<div id={styles.hookRenderType}>
71-
<label htmlFor='parameterOne'>Parameter (optional)</label>
71+
<label htmlFor='parameterOne'>Hook Parameter (optional)</label>
7272
<input
7373
type='text'
7474
id='parameterOne'
75-
placeholder='Hook Function Parameter'
75+
placeholder='eg. 9000'
7676
onChange={e => handleChangeHookRenderFields(e, 'parameterOne')}
7777
/>
7878
</div>
@@ -83,7 +83,7 @@ const HookRender = ({ hookRender, index, dispatchToHooksTestCase }) => {
8383
<input
8484
type='text'
8585
id='returnValue'
86-
placeholder='Return Value'
86+
placeholder='eg. count'
8787
onChange={e => handleChangeHookRenderFields(e, 'returnValue')}
8888
/>
8989
</div>
@@ -92,7 +92,7 @@ const HookRender = ({ hookRender, index, dispatchToHooksTestCase }) => {
9292
<input
9393
type='text'
9494
id='expectedReturnValue'
95-
placeholder='Expected Return Value'
95+
placeholder='eg. 0'
9696
onChange={e => handleChangeHookRenderFields(e, 'expectedReturnValue')}
9797
/>
9898
</div>

src/containers/LeftPanel/Reducer/Reducer.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const Reducer = ({ reducer, index, dispatchToReduxTestCase }) => {
8080
<input
8181
type='text'
8282
id='reducerName'
83-
placeholder='Reducer Name'
83+
placeholder='eg. todoReducer'
8484
onChange={e => handleChangeReducerFields(e, 'reducerName')}
8585
/>
8686
</div>
@@ -90,7 +90,7 @@ const Reducer = ({ reducer, index, dispatchToReduxTestCase }) => {
9090
<input
9191
type='text'
9292
id='initialState'
93-
placeholder='Initial State'
93+
placeholder="eg. { key: value }"
9494
onChange={e => handleChangeReducerFields(e, 'initialState')}
9595
/>
9696
</div>
@@ -102,7 +102,7 @@ const Reducer = ({ reducer, index, dispatchToReduxTestCase }) => {
102102
<input
103103
type='text'
104104
id='reducerAction'
105-
placeholder='Action'
105+
placeholder="eg. type: types.ADD_TASK"
106106
onChange={e => handleChangeReducerFields(e, 'reducerAction')}
107107
/>
108108
</div>
@@ -111,7 +111,7 @@ const Reducer = ({ reducer, index, dispatchToReduxTestCase }) => {
111111
<label htmlFor='expectedState'>Updated State</label>
112112
<input
113113
type='text'
114-
placeholder='Expected State'
114+
placeholder="eg. { key: updated-value }"
115115
id='expectedState'
116116
onChange={e => handleChangeReducerFields(e, 'expectedState')}
117117
/>

src/containers/LeftPanel/TestMenu/TestMenu.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const TestMenu = ({ dispatchToTestCase, dispatchToMockData }) => {
3838
id={styles.right}
3939
style={{ display: 'flex', flexWrap: 'wrap', justifyContent: 'center' }}
4040
>
41-
<button onClick={handleAddAction}>Action</button>
42-
<button data-testid='assertionButton' onClick={handleAddAssertion}>
41+
<button data-testid="actionButton" onClick={handleAddAction}>Action</button>
42+
<button data-testid='assertionButton' className='assertionButton' onClick={handleAddAssertion}>
4343
Assertion
4444
</button>
4545
<button data-testid='rerenderButton' onClick={handleAddRender}>
Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
import React from 'react';
2-
import LeftPanel from '../LeftPanel';
32
import TestCase from '../TestCase/TestCase';
4-
import TestFile from '../TestFile/TestFile';
5-
import TestMenu from '../../LeftPanel/TestMenu/TestMenu';
63
import { GlobalContext } from '../../../context/globalReducer';
74
import { TestCaseContext } from '../../../context/testCaseReducer';
85
import { MockDataContext } from '../../../context/mockDataReducer';
9-
10-
import { render, fireEvent } from '@testing-library/react';
11-
import { build, fake } from 'test-data-bot';
12-
import '@testing-library/react/cleanup-after-each';
13-
import 'jest-dom/extend-expect';
14-
15-
import { shallow, mount } from 'enzyme';
16-
import ReactDOM from 'react-dom';
17-
import { act } from 'react-dom/test-utils';
18-
19-
import { configure } from 'enzyme';
6+
import { TestFileModalContext } from '../../../context/testFileModalReducer'
7+
import { mount, configure } from 'enzyme';
208
import Adapter from 'enzyme-adapter-react-16';
21-
import { exportAllDeclaration } from '@babel/types';
22-
import Rerender from '../Render/Rerender';
23-
import Assertion from '../Assertion/Assertion';
9+
2410
configure({ adapter: new Adapter() });
2511

26-
let wrapper, globalM, dispatchToGlobal, testCase, dispatchToTestCase, mockData, dispatchToMockData;
12+
let wrapper, globalM, dispatchToGlobal, testCase, dispatchToTestCase, mockData, dispatchToMockData, testFileModal, dispatchToTestFileModal;
2713

2814
beforeEach(() => {
2915
globalM = {
@@ -39,7 +25,9 @@ beforeEach(() => {
3925
projectFilePath: '',
4026
filePathMap: {},
4127
};
28+
4229
dispatchToGlobal = jest.fn();
30+
4331
testCase = {
4432
testStatement: '',
4533
statements: [
@@ -64,18 +52,25 @@ beforeEach(() => {
6452
},
6553
],
6654
};
55+
6756
dispatchToTestCase = jest.fn();
57+
6858
mockData = {
6959
mockData: [],
7060
hasMockData: false,
7161
};
62+
7263
dispatchToMockData = jest.fn();
64+
testFileModal = {}
65+
dispatchToTestFileModal = jest.fn();
7366

7467
wrapper = mount(
7568
<GlobalContext.Provider value={[globalM, dispatchToGlobal]}>
7669
<TestCaseContext.Provider value={[testCase, dispatchToTestCase]}>
7770
<MockDataContext.Provider value={[mockData, dispatchToMockData]}>
78-
<TestCase />
71+
<TestFileModalContext.Provider value={[testFileModal, dispatchToTestFileModal]}>
72+
<TestCase />
73+
</TestFileModalContext.Provider>
7974
</MockDataContext.Provider>
8075
</TestCaseContext.Provider>
8176
</GlobalContext.Provider>
@@ -84,22 +79,43 @@ beforeEach(() => {
8479
jest.resetModules();
8580
});
8681

87-
describe('testing left panel', () => {
88-
it('renders the left panel with initial buttons and first render boxes', () => {
82+
describe('testing left panel react test menu', () => {
83+
it('renders the react menu with initial buttons and first render boxes', () => {
8984
expect(wrapper.text()).toContain('Do you need mock data?');
9085
expect(wrapper.text()).toContain('Do you need props?');
9186
expect(wrapper.text()).toContain('Action');
9287
expect(wrapper.text()).toContain('Assertion');
9388
expect(wrapper.text()).toContain('Rerender');
89+
expect(wrapper.text()).toContain('New Test +');
9490
});
9591

96-
it('new assertion card is produced when assertion button is clicked', () => {});
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"]');
100+
btn.simulate('click');
101+
expect(dispatchToTestCase).toHaveBeenCalled();
102+
});
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+
});
97113

98-
it('action card is removed when delete button is clicked', () => {});
114+
xit('action card is removed when delete button is clicked', () => { });
99115

100-
it('clicking the mock data checkbox renders mock data input fields', () => {});
116+
xit('clicking the mock data checkbox renders mock data input fields', () => { });
101117

102-
it('props table displays when prop checkbox on Render card is clicked', () => {});
118+
xit('props table displays when prop checkbox on Render card is clicked', () => { });
103119

104-
it('wipes existing test statements when new test button is clicked ', () => {});
120+
xit('wipes existing test statements when new test button is clicked ', () => { });
105121
});
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import React from 'react';
2+
import EndpointTestCase from '../TestCase/EndpointTestCase';
3+
import { GlobalContext } from '../../../context/globalReducer';
4+
import { EndpointTestCaseContext } from '../../../context/endpointTestCaseReducer';
5+
import { TestFileModalContext } from '../../../context/testFileModalReducer';
6+
import { mount, configure } from 'enzyme';
7+
import Adapter from 'enzyme-adapter-react-16';
8+
import Endpoint from '../Endpoint/Endpoint';
9+
10+
configure({ adapter: new Adapter() });
11+
12+
let wrapper, globalM, dispatchToGlobal, endpointTestCase, dispatchToEndpointTestCase, testFileModal, dispatchToTestFileModal;
13+
14+
beforeEach(() => {
15+
globalM = {
16+
url: null,
17+
isProjectLoaded: false,
18+
fileTree: null,
19+
componentName: '',
20+
isFileDirectoryOpen: true,
21+
rightPanelDisplay: 'browserView',
22+
displayedFileCode: '',
23+
isFolderOpen: {},
24+
isFileHighlighted: '',
25+
projectFilePath: '',
26+
filePathMap: {},
27+
};
28+
dispatchToGlobal = jest.fn();
29+
endpointTestCase = {
30+
endpointTestStatement: '',
31+
endpointStatements: [],
32+
hasEndpoint: 1,
33+
};
34+
35+
testFileModal = {}
36+
dispatchToTestFileModal = jest.fn();
37+
38+
dispatchToEndpointTestCase = jest.fn();
39+
40+
wrapper = mount(
41+
<GlobalContext.Provider value={[global, dispatchToGlobal]}>
42+
<TestFileModalContext.Provider value={[testFileModal, dispatchToTestFileModal]}>
43+
<EndpointTestCaseContext.Provider value={[endpointTestCase, dispatchToEndpointTestCase]}>
44+
<EndpointTestCase />
45+
</EndpointTestCaseContext.Provider>
46+
</TestFileModalContext.Provider>
47+
</GlobalContext.Provider>
48+
);
49+
50+
jest.resetModules();
51+
});
52+
53+
describe('testing left panel endpoint test menu', () => {
54+
it('renders the endpoint menu with initial buttons', () => {
55+
expect(wrapper.text()).toContain('Endpoint');
56+
});
57+
58+
it('onclick function is invoked when endpoint button is clicked', () => {
59+
const button = wrapper.find('[data-testid="endPointButton"]')
60+
button.simulate('click');
61+
expect(dispatchToEndpointTestCase).toHaveBeenCalled();
62+
});
63+
64+
it('there should be 2 buttons', () => {
65+
expect(wrapper.find('button').length).toEqual(2)
66+
});
67+
68+
xit('action card is removed when delete button is clicked', () => { });
69+
70+
xit('clicking the mock data checkbox renders mock data input fields', () => { });
71+
72+
xit('props table displays when prop checkbox on Render card is clicked', () => { });
73+
74+
xit('wipes existing test statements when new test button is clicked ', () => { });
75+
});
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import React from 'react';
2+
import ReduxTestCase from '../TestCase/ReduxTestCase';
3+
import { GlobalContext } from '../../../context/globalReducer';
4+
import { ReduxTestCaseContext } from '../../../context/reduxTestCaseReducer';
5+
import { TestFileModalContext } from '../../../context/testFileModalReducer';
6+
import { mount, configure } from 'enzyme';
7+
import Adapter from 'enzyme-adapter-react-16';
8+
import Reducer from '../Reducer/Reducer';
9+
10+
configure({ adapter: new Adapter() });
11+
12+
let wrapper, globalM, dispatchToGlobal, reduxTestCase, dispatchToReduxTestCase, testFileModal, dispatchToTestFileModal;
13+
14+
beforeEach(() => {
15+
globalM = {
16+
url: null,
17+
isProjectLoaded: false,
18+
fileTree: null,
19+
componentName: '',
20+
isFileDirectoryOpen: true,
21+
rightPanelDisplay: 'browserView',
22+
displayedFileCode: '',
23+
isFolderOpen: {},
24+
isFileHighlighted: '',
25+
projectFilePath: '',
26+
filePathMap: {},
27+
};
28+
dispatchToGlobal = jest.fn();
29+
reduxTestCase = {
30+
reduxTestStatement: '',
31+
reduxStatements: [],
32+
hasRedux: 1,
33+
};
34+
35+
testFileModal = {}
36+
dispatchToTestFileModal = jest.fn();
37+
38+
dispatchToReduxTestCase = jest.fn();
39+
40+
wrapper = mount(
41+
<GlobalContext.Provider value={[global, dispatchToGlobal]}>
42+
<TestFileModalContext.Provider value={[testFileModal, dispatchToTestFileModal]}>
43+
<ReduxTestCaseContext.Provider value={[reduxTestCase, dispatchToReduxTestCase]}>
44+
<ReduxTestCase />
45+
</ReduxTestCaseContext.Provider>
46+
</TestFileModalContext.Provider>
47+
</GlobalContext.Provider>
48+
);
49+
50+
jest.resetModules();
51+
});
52+
53+
describe('testing left panel redux test menu', () => {
54+
it('renders the redux menu with initial buttons and first render boxes', () => {
55+
expect(wrapper.text()).toContain('Reducer');
56+
expect(wrapper.text()).toContain('Action Creator');
57+
expect(wrapper.text()).toContain('Async Action Creator');
58+
expect(wrapper.text()).toContain('Middleware');
59+
});
60+
61+
it('onclick function is invoked when reducer button is clicked', () => {
62+
const button = wrapper.find('[data-testid="reducerButton"]')
63+
button.simulate('click');
64+
expect(dispatchToReduxTestCase).toHaveBeenCalled();
65+
});
66+
67+
it('onclick function is invoked when action creator button is clicked', () => {
68+
const button = wrapper.find('[data-testid="actionCreatorButton"]')
69+
button.simulate('click');
70+
expect(dispatchToReduxTestCase).toHaveBeenCalled();
71+
});
72+
73+
it('onclick function is invoked when async action creator button is clicked', () => {
74+
const button = wrapper.find('[data-testid="asyncButton"]')
75+
button.simulate('click');
76+
expect(dispatchToReduxTestCase).toHaveBeenCalled();
77+
});
78+
79+
it('onclick function is invoked when middleware button is clicked', () => {
80+
const button = wrapper.find('[data-testid="middlewareButton"]')
81+
button.simulate('click');
82+
expect(dispatchToReduxTestCase).toHaveBeenCalled();
83+
});
84+
85+
it('there should be 5 buttons', () => {
86+
expect(wrapper.find('button').length).toEqual(5)
87+
});
88+
89+
xit('action card is removed when delete button is clicked', () => { });
90+
91+
xit('clicking the mock data checkbox renders mock data input fields', () => { });
92+
93+
xit('props table displays when prop checkbox on Render card is clicked', () => { });
94+
95+
xit('wipes existing test statements when new test button is clicked ', () => { });
96+
});

0 commit comments

Comments
 (0)