Skip to content

Commit 461e868

Browse files
committed
merge of rtl update
2 parents 98bbb96 + d421471 commit 461e868

File tree

14 files changed

+2604
-1006
lines changed

14 files changed

+2604
-1006
lines changed

__mocks__/styleMocks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
// module.exports = 'test-file-stub';
2+
13
module.exports = {};

__tests__/basicTest.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import React from "react";
2+
import { createStore } from "redux";
3+
import { Provider } from "react-redux";
4+
import format from "date-fns/format";
5+
import uuid from "uuid/v4";
6+
import { render, screen, fireEvent } from "@testing-library/react";
7+
import HistoryContainer from "../src/client/components/containers/HistoryContainer";
8+
import * as actions from "../src/client/actions/actions.js";
9+
import reducers from "../src/client/reducers/index.js";
10+
import "@testing-library/jest-dom/extend-expect";
11+
// import store from "../src/client/store";
12+
import { getAllByAltText, queryAllByRole } from "@testing-library/react";
13+
14+
//generate date for today
15+
let today = new Date();
16+
//generate date for yesterday
17+
let yesterday = new Date();
18+
yesterday.setDate(yesterday.getDate() - 1);
19+
//generate date for two days prior
20+
let twoDaysAgo = new Date();
21+
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
22+
23+
24+
describe("history container test", () => {
25+
const initialState = {
26+
business: {history: [
27+
{
28+
date: format(today, "MM/DD/YYYY"),
29+
history: [
30+
{
31+
id: 1,
32+
created_at: today,
33+
url: "http://google.com",
34+
request: {
35+
method: "GET",
36+
},
37+
},
38+
],
39+
},
40+
{
41+
date: format(yesterday, "MM/DD/YYYY"),
42+
history: [
43+
{
44+
id: 2,
45+
created_at: yesterday,
46+
url: "http://facebook.com",
47+
request: {
48+
method: "GET",
49+
},
50+
},
51+
],
52+
},
53+
{
54+
date: format(twoDaysAgo, "MM/DD/YYYY"),
55+
history: [
56+
{
57+
id: 3,
58+
created_at: twoDaysAgo,
59+
url: "http://instagram.com",
60+
request: {
61+
method: "GET",
62+
},
63+
},
64+
],
65+
},
66+
],
67+
}}
68+
const renderWithRedux = (
69+
component,
70+
{ store = createStore(reducers, initialState) } = {}
71+
) => {
72+
console.log('store is: ', store.getState())
73+
console.log('initial state is: ', initialState)
74+
return {
75+
...render(<Provider store={store}>{component}</Provider>),
76+
store,
77+
}
78+
}
79+
80+
beforeEach(() => {
81+
renderWithRedux(<HistoryContainer />);
82+
screen.debug();
83+
});
84+
test("renders history from store", () => {
85+
console.log(screen.queryAllByRole("queryDate"));
86+
expect(screen.queryAllByRole("queryDate").length).toBe(3);
87+
});
88+
// test('renders a history header', () => {
89+
// expect(screen.queryByRole('queryDate')).toBeInTheDocument();
90+
// })
91+
});
92+
//test if container renders
93+
// test("renders", () => {
94+
// render(<HistoryContainer />);
95+
96+
// screen.debug();
97+
// });
98+
99+
//
100+
101+
/* FOR EACH COMPONENT - UNIT TESTING */
102+
//renders
103+
//buttons work (clear history, etc.)
104+
//forms function (accepts input)
105+
//state updates appropriately
106+

__tests__/test-utils.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,81 @@ export * from "@testing-library/react";
120120

121121
// override render method
122122
export { render };
123+
import reducers from "../src/client/reducers/index.js";
124+
125+
// const initialState = {
126+
// currentTab: "First Tab",
127+
// reqResArray: [],
128+
// history: [],
129+
// collections: [],
130+
// warningMessage: "",
131+
// newRequestFields: {
132+
// protocol: "",
133+
// url: "http://",
134+
// method: "GET",
135+
// graphQL: false,
136+
// gRPC: false,
137+
// },
138+
// newRequestHeaders: {
139+
// headersArr: [],
140+
// count: 0,
141+
// },
142+
// newRequestStreams: {
143+
// streamsArr: [],
144+
// count: 0,
145+
// streamContent: [],
146+
// selectedPackage: null,
147+
// selectedRequest: null,
148+
// selectedService: null,
149+
// selectedStreamingType: null,
150+
// initialQuery: null,
151+
// queryArr: null,
152+
// protoPath: null,
153+
// services: null,
154+
// protoContent: "",
155+
// },
156+
// newRequestCookies: {
157+
// cookiesArr: [],
158+
// count: 0,
159+
// },
160+
// newRequestBody: {
161+
// bodyContent: "",
162+
// bodyVariables: "",
163+
// bodyType: "raw",
164+
// rawType: "Text (text/plain)",
165+
// JSONFormatted: true,
166+
// },
167+
// newRequestSSE: {
168+
// isSSE: false,
169+
// },
170+
// };
171+
172+
// function render(
173+
// ui,
174+
// {
175+
// initialState,
176+
// store = createStore(reducers, initialState),
177+
// ...renderOptions
178+
// }
179+
// ) {
180+
// function Wrapper({ children }) {
181+
// return <Provider store={store}>{children}</Provider>;
182+
// }
183+
// return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
184+
// }
185+
186+
// // re-export everything
187+
// export * from "@testing-library/react";
188+
189+
// // override render method
190+
// export { render };
191+
192+
const renderWithRedux = (
193+
component,
194+
{ initialState, store = createStore(reducer, initialState) } = {}
195+
) => {
196+
return {
197+
...render(<Provider store={store}>{component}</Provider>),
198+
store,
199+
};
200+
};

index-csp.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<!-- <link rel="stylesheet" href="./node_modules/chart.js/dist/Chart.min.css" /> -->
7-
<title>Document</title>
8-
</head>
9-
<body></body>
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<!-- <link rel="stylesheet" href="./node_modules/chart.js/dist/Chart.min.css" /> -->
8+
<title>Swell</title>
9+
</head>
10+
11+
<body></body>
12+
1013
</html>

jest.config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
const { defaults } = require("jest-config");
2-
31
module.exports = {
4-
moduleDirectories: ["node_modules"],
52
verbose: true,
63
runner: "@jest-runner/electron",
74
testEnvironment: "@jest-runner/electron/environment",
85
moduleNameMapper: {
9-
"\\.(css.|less|sass|scss)$": "<rootDir>/__mocks__/styleMocks.js",
6+
// "collectCoverage": true,
7+
electron: "<rootDir>/__mocks__/electronMock.js",
8+
"\\.(css|less|sass|scss)$": "<rootDir>/__mocks__/styleMocks.js",
109
"\\.(gif|ttf|eot|svg|png)$": "<rootDir>/__mocks__/fileMock.js",
1110
},
1211
resolver: null,

0 commit comments

Comments
 (0)