Skip to content

Commit 03b256f

Browse files
committed
reducer tests finalized
1 parent 07e4952 commit 03b256f

21 files changed

+490
-282
lines changed

__tests__/businessReducer.js

Lines changed: 245 additions & 83 deletions
Large diffs are not rendered by default.

__tests__/composerTests.js

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
11
/* eslint-disable react/jsx-props-no-spreading */
22
import React from 'react';
3-
import { configure, shallow } from 'enzyme';
4-
import Adapter from 'enzyme-adapter-react-16';
53
import ProtocolSelect from '../src/client/components/composer/NewRequest/ProtocolSelect.jsx';
64

7-
configure({ adapter: new Adapter() });
5+
// Commented out this file since it is using Enzyme, which has been falling out of favor
6+
// TODO: for the next tester, recommended to migrate to React Testing Library
87

9-
describe('GraphQL Composer', () => {
10-
const state = {
11-
currentTab: 'First Tab',
12-
reqResArray: [],
13-
history: [],
14-
warningMessage: '',
15-
newRequestFields: {
16-
method: 'GET',
17-
protocol: '',
18-
url: '',
19-
graphQL: false,
20-
},
21-
newRequestHeaders: {
22-
headersArr: [],
23-
count: 0,
24-
},
25-
newRequestCookies: {
26-
cookiesArr: [],
27-
count: 0,
28-
},
29-
newRequestBody: {
30-
bodyContent: '',
31-
bodyType: 'raw',
32-
rawType: 'text/plain',
33-
JSONFormatted: true,
34-
bodyVariables: '',
35-
},
36-
};
37-
describe('Setting GQL fields, headers, and body', () => {
38-
describe('ProtocolSelect', () => {
39-
let wrapper;
40-
const props = {
41-
currentProtocol: '',
42-
onChangeHandler: jest.fn(),
43-
graphQL: false,
44-
};
8+
// import { configure, shallow } from 'enzyme';
9+
// import Adapter from 'enzyme-adapter-react-16';
4510

46-
beforeAll(() => {
47-
wrapper = shallow(<ProtocolSelect {...props} />);
48-
});
11+
// configure({ adapter: new Adapter() });
4912

50-
it('Renders a <div>', () => {
51-
expect(wrapper.type()).toEqual('div');
52-
});
53-
});
54-
});
55-
});
13+
// describe('GraphQL Composer', () => {
14+
// const state = {
15+
// currentTab: 'First Tab',
16+
// reqResArray: [],
17+
// history: [],
18+
// warningMessage: '',
19+
// newRequestFields: {
20+
// method: 'GET',
21+
// protocol: '',
22+
// url: '',
23+
// graphQL: false,
24+
// },
25+
// newRequestHeaders: {
26+
// headersArr: [],
27+
// count: 0,
28+
// },
29+
// newRequestCookies: {
30+
// cookiesArr: [],
31+
// count: 0,
32+
// },
33+
// newRequestBody: {
34+
// bodyContent: '',
35+
// bodyType: 'raw',
36+
// rawType: 'text/plain',
37+
// JSONFormatted: true,
38+
// bodyVariables: '',
39+
// },
40+
// };
41+
// describe('Setting GQL fields, headers, and body', () => {
42+
// describe('ProtocolSelect', () => {
43+
// let wrapper;
44+
// const props = {
45+
// currentProtocol: '',
46+
// onChangeHandler: jest.fn(),
47+
// graphQL: false,
48+
// };
49+
50+
// beforeAll(() => {
51+
// wrapper = shallow(<ProtocolSelect {...props} />);
52+
// });
53+
54+
// it('Renders a <div>', () => {
55+
// expect(wrapper.type()).toEqual('div');
56+
// });
57+
// });
58+
// });
59+
// });

__tests__/dbTests.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,3 @@ describe('db test', () => {
5252
});
5353
});
5454
});
55-
// describe("collection tests", () => {});
56-
// });

__tests__/httpTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ReqResCtrl from '../src/client/controllers/reqResController';
22

3-
xdescribe('REST API Requests', () => {
3+
describe('REST API Requests', () => {
44
let state;
55
beforeEach(() => {
66
state = {

__tests__/uiReducer.js

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import uiReducer from '../src/client/reducers/ui';
1+
import reducer,{
2+
setSidebarActiveTab,
3+
setWorkspaceActiveTab,
4+
setResponsePaneActiveTab,
5+
toggleDarkMode,
6+
} from '../src/client/features/ui/uiSlice.ts';
27

38
describe('UI Reducer', () => {
49
let state;
510

611
beforeEach(() => {
712
state = {
8-
composerDisplay: 'Request',
13+
isDark: false,
914
sidebarActiveTab: 'composer',
1015
workspaceActiveTab: 'workspace',
1116
responsePaneActiveTab: 'events',
@@ -14,22 +19,57 @@ describe('UI Reducer', () => {
1419

1520
describe('default state', () => {
1621
it('should return a default state when given an undefined input', () => {
17-
expect(uiReducer(undefined, { type: undefined })).toEqual(state);
22+
expect(reducer(undefined, { type: undefined })).toEqual(state);
1823
});
1924
it('should return default state with unrecognized action types', () => {
20-
expect(uiReducer(undefined, { type: 'BAD_TYPE' })).toEqual(state);
25+
expect(reducer(undefined, { type: 'BAD_TYPE' })).toEqual(state);
26+
});
27+
});
28+
29+
describe('Set sidebar active tab', () => {
30+
const action = {
31+
payload: 'the active sidebar tab is this one!',
32+
};
33+
34+
it('sets the sidebar active tab', () => {
35+
const { sidebarActiveTab } = reducer(state, setSidebarActiveTab(action.payload));
36+
expect(sidebarActiveTab).toEqual(action.payload);
37+
});
38+
});
39+
40+
describe('Set workspace active tab', () => {
41+
const action = {
42+
payload: 'the active workspace tab is this one!',
43+
};
44+
45+
it('sets the workspace active tab', () => {
46+
const { workspaceActiveTab } = reducer(state, setWorkspaceActiveTab(action.payload));
47+
expect(workspaceActiveTab).toEqual(action.payload);
2148
});
2249
});
2350

24-
describe('should handle SET_COMPOSER_DISPLAY', () => {
51+
describe('Set response pane active tab', () => {
2552
const action = {
26-
type: 'SET_COMPOSER_DISPLAY',
27-
payload: 'warning',
53+
payload: 'the active response pane tab is this one!',
2854
};
2955

30-
it('should update the composerDisplay', () => {
31-
const { composerDisplay } = uiReducer(state, action);
32-
expect(composerDisplay).toEqual(action.payload);
56+
it('sets the response pane active tab', () => {
57+
const { responsePaneActiveTab } = reducer(state, setResponsePaneActiveTab(action.payload));
58+
expect(responsePaneActiveTab).toEqual(action.payload);
3359
});
3460
});
61+
62+
describe('Toggle dark mode', () => {
63+
const action = {
64+
payload: true,
65+
};
66+
67+
it('Toggles dark mode', () => {
68+
const newState = reducer(state, toggleDarkMode(false));
69+
expect(newState.isDark).toEqual(false);
70+
const { isDark } = reducer(newState, toggleDarkMode(action.payload));
71+
expect(isDark).toEqual(true);
72+
});
73+
});
74+
3575
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"@mui/material": "^5.6.4",
128128
"@redux-devtools/extension": "^3.2.2",
129129
"@reduxjs/toolkit": "^1.8.1",
130+
"@testing-library/react": "^13.2.0",
130131
"@uiw/react-codemirror": "^4.7.0",
131132
"apollo-server-express": "^3.6.7",
132133
"axios": "^0.27.1",

src/client/components/composer/NewRequest/GRPCTypeAndEndpointEntryForm.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const GRPCTypeAndEndpointEntryForm = ({
4343
<input
4444
className={`${isDark ? 'is-dark-300' : '' } ml-1 input input-is-medium is-info`}
4545
type="text"
46+
id = "url-input"
4647
placeholder="Enter endpoint"
4748
value={newRequestFields.grpcUrl}
4849
onChange={(e) => {

src/client/components/composer/NewRequest/GraphQLMethodAndEndpointEntryForm.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const GraphQLMethodAndEndpointEntryForm = ({
169169
<input
170170
className={`${isDark ? 'is-dark-300' : ''} ml-1 input input-is-medium is-info`}
171171
type="text"
172+
id = "url-input"
172173
placeholder="Enter endpoint"
173174
value={newRequestFields.gqlUrl}
174175
onChange={(e) => {

src/client/components/composer/NewRequest/WSEndpointEntryForm.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const WSEndpointEntryForm = ({
3636
<input
3737
className={`${isDark ? 'is-dark-300' : ''} ml-1 input input-is-medium is-info`}
3838
type="text"
39+
id = "url-input"
3940
placeholder="Enter endpoint"
4041
value={newRequestFields.wsUrl}
4142
onChange={(e) => {

src/client/controllers/graphQLController.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
import { ApolloClient, OperationVariables, InMemoryCache } from '@apollo/client';
24
import gql from 'graphql-tag';
35
import { WebSocketLink } from "@apollo/client/link/ws";
@@ -18,14 +20,15 @@ const { api }: { api: WindowAPI } = window as unknown as WindowExt;
1820
const graphQLController = {
1921
openGraphQLConnection(reqResObj: ReqRes): void {
2022
// initialize response data
21-
reqResObj.response.headers = {};
22-
reqResObj.response.events = [];
23-
reqResObj.response.cookies = [];
24-
reqResObj.connection = 'open';
25-
reqResObj.timeSent = Date.now();
23+
const newReqRes = {...reqResObj}
24+
newReqRes.response.headers = {};
25+
newReqRes.response.events = [];
26+
newReqRes.response.cookies = [];
27+
newReqRes.connection = 'open';
28+
newReqRes.timeSent = Date.now();
2629
// store.default.dispatch(actions.reqResUpdate(reqResObj));
2730
// send reqRes object to main process through context bridge
28-
this.sendGqlToMain({ reqResObj })
31+
this.sendGqlToMain({ newReqRes })
2932
.then((response) => {
3033
if (response.error)
3134
this.handleError(response.reqResObj.error, response.reqResObj);

0 commit comments

Comments
 (0)