Skip to content

Commit d421471

Browse files
committed
get RTC to render html
1 parent 1a570d9 commit d421471

File tree

8 files changed

+2298
-427
lines changed

8 files changed

+2298
-427
lines changed

__mocks__/fileMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'test-file-stub';

__mocks__/styleMocks.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = 'test-file-stub';
1+
// module.exports = 'test-file-stub';
2+
3+
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: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// test-utils.js
2+
import React from "react";
3+
import { render as rtlRender } from "@testing-library/react";
4+
import { createStore } from "redux";
5+
import { Provider } from "react-redux";
6+
import reducers from "../src/client/reducers/index.js";
7+
8+
// const initialState = {
9+
// currentTab: "First Tab",
10+
// reqResArray: [],
11+
// history: [],
12+
// collections: [],
13+
// warningMessage: "",
14+
// newRequestFields: {
15+
// protocol: "",
16+
// url: "http://",
17+
// method: "GET",
18+
// graphQL: false,
19+
// gRPC: false,
20+
// },
21+
// newRequestHeaders: {
22+
// headersArr: [],
23+
// count: 0,
24+
// },
25+
// newRequestStreams: {
26+
// streamsArr: [],
27+
// count: 0,
28+
// streamContent: [],
29+
// selectedPackage: null,
30+
// selectedRequest: null,
31+
// selectedService: null,
32+
// selectedStreamingType: null,
33+
// initialQuery: null,
34+
// queryArr: null,
35+
// protoPath: null,
36+
// services: null,
37+
// protoContent: "",
38+
// },
39+
// newRequestCookies: {
40+
// cookiesArr: [],
41+
// count: 0,
42+
// },
43+
// newRequestBody: {
44+
// bodyContent: "",
45+
// bodyVariables: "",
46+
// bodyType: "raw",
47+
// rawType: "Text (text/plain)",
48+
// JSONFormatted: true,
49+
// },
50+
// newRequestSSE: {
51+
// isSSE: false,
52+
// },
53+
// };
54+
55+
// function render(
56+
// ui,
57+
// {
58+
// initialState,
59+
// store = createStore(reducers, initialState),
60+
// ...renderOptions
61+
// }
62+
// ) {
63+
// function Wrapper({ children }) {
64+
// return <Provider store={store}>{children}</Provider>;
65+
// }
66+
// return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
67+
// }
68+
69+
// // re-export everything
70+
// export * from "@testing-library/react";
71+
72+
// // override render method
73+
// export { render };
74+
75+
const renderWithRedux = (
76+
component,
77+
{ initialState, store = createStore(reducer, initialState) } = {}
78+
) => {
79+
return {
80+
...render(<Provider store={store}>{component}</Provider>),
81+
store,
82+
}
83+
}

jest.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
verbose: true,
3+
runner: "@jest-runner/electron",
4+
testEnvironment: "@jest-runner/electron/environment",
5+
moduleNameMapper: {
6+
// "collectCoverage": true,
7+
"electron": "<rootDir>/__mocks__/electronMock.js",
8+
"\\.(css|less|sass|scss)$": "<rootDir>/__mocks__/styleMocks.js",
9+
"\\.(gif|ttf|eot|svg|png)$": "<rootDir>/__mocks__/fileMock.js",
10+
},
11+
resolver: null,
12+
};

0 commit comments

Comments
 (0)