Skip to content

Commit 307f5a1

Browse files
committed
history container unit test with RTL
1 parent 2545ded commit 307f5a1

File tree

3 files changed

+8
-227
lines changed

3 files changed

+8
-227
lines changed

__tests__/historyContainerTest.js

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,9 @@ describe("history container test", () => {
8181
screen.debug();
8282
});
8383
test("renders all items in history array from store", () => {
84-
//console.log(screen.queryAllByLabelText("queryDate"));
8584
expect(screen.queryAllByLabelText("queryDate").length).toBe(3);
8685
});
8786
test("correctly renders headers in history container", () => {
88-
//let oldDay = format(twoDaysAgo, "MM/DD/YYYY");
8987
expect(screen.queryByText("Today")).toBeTruthy();
9088
expect(screen.queryByText("Yesterday")).toBeTruthy();
9189
expect(
@@ -100,18 +98,15 @@ describe("history container test", () => {
10098
test("correctly renders request method for each header in history", () => {
10199
expect(screen.queryAllByText("GET").length).toBe(3);
102100
});
103-
test("clear history button clears history", () => {
104-
105-
})
101+
test("clear history button renders", () => {
102+
expect(screen.queryByText("Clear History")).toBeTruthy();
103+
});
104+
/* Doesn't work in RTL at present */
105+
// test("clear history pop-up clears history", () => {
106+
// store.dispatch(actions.clearHistory());
107+
// expect(screen.queryAllByLabelText("queryDate").length).toBe(0);
108+
// });
106109
});
107-
//test if container renders
108-
// test("renders", () => {
109-
// render(<HistoryContainer />);
110-
111-
// screen.debug();
112-
// });
113-
114-
//
115110

116111
/* FOR EACH COMPONENT - UNIT TESTING */
117112
//renders

__tests__/test-utils.js

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -3,125 +3,7 @@ import React from "react";
33
import { render as rtlRender } from "@testing-library/react";
44
import { createStore } from "redux";
55
import { Provider } from "react-redux";
6-
import format from "date-fns/format";
76
import reducers from "../src/client/reducers/index.js";
8-
9-
let today = new Date();
10-
//generate date for yesterday
11-
let yesterday = new Date();
12-
yesterday.setDate(yesterday.getDate() - 1);
13-
//generate date for two days prior
14-
let twoDaysAgo = new Date();
15-
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
16-
17-
const initialState = {
18-
currentTab: "First Tab",
19-
reqResArray: [],
20-
history: [
21-
{
22-
date: format(today, "MM/DD/YYYY"),
23-
history: [
24-
{
25-
id: 1,
26-
created_at: today,
27-
url: "http://google.com",
28-
request: {
29-
method: "GET",
30-
},
31-
},
32-
],
33-
},
34-
{
35-
date: format(yesterday, "MM/DD/YYYY"),
36-
history: [
37-
{
38-
id: 2,
39-
created_at: yesterday,
40-
url: "http://facebook.com",
41-
request: {
42-
method: "GET",
43-
},
44-
},
45-
],
46-
},
47-
{
48-
date: format(twoDaysAgo, "MM/DD/YYYY"),
49-
history: [
50-
{
51-
id: 3,
52-
created_at: twoDaysAgo,
53-
url: "http://instagram.com",
54-
request: {
55-
method: "GET",
56-
},
57-
},
58-
],
59-
},
60-
],
61-
collections: [],
62-
warningMessage: "",
63-
newRequestFields: {
64-
protocol: "",
65-
url: "http://",
66-
method: "GET",
67-
graphQL: false,
68-
gRPC: false,
69-
},
70-
newRequestHeaders: {
71-
headersArr: [],
72-
count: 0,
73-
},
74-
newRequestStreams: {
75-
streamsArr: [],
76-
count: 0,
77-
streamContent: [],
78-
selectedPackage: null,
79-
selectedRequest: null,
80-
selectedService: null,
81-
selectedStreamingType: null,
82-
initialQuery: null,
83-
queryArr: null,
84-
protoPath: null,
85-
services: null,
86-
protoContent: "",
87-
},
88-
newRequestCookies: {
89-
cookiesArr: [],
90-
count: 0,
91-
},
92-
newRequestBody: {
93-
bodyContent: "",
94-
bodyVariables: "",
95-
bodyType: "raw",
96-
rawType: "Text (text/plain)",
97-
JSONFormatted: true,
98-
},
99-
newRequestSSE: {
100-
isSSE: false,
101-
},
102-
};
103-
104-
function render(
105-
ui,
106-
{
107-
initialState = initialState,
108-
store = createStore(reducers, initialState),
109-
...renderOptions
110-
} = {}
111-
) {
112-
function Wrapper({ children }) {
113-
return <Provider store={store}>{children}</Provider>;
114-
}
115-
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
116-
}
117-
118-
// re-export everything
119-
export * from "@testing-library/react";
120-
121-
// override render method
122-
export { render };
123-
import reducers from "../src/client/reducers/index.js";
124-
1257
// const initialState = {
1268
// currentTab: "First Tab",
1279
// reqResArray: [],
@@ -168,7 +50,6 @@ import reducers from "../src/client/reducers/index.js";
16850
// isSSE: false,
16951
// },
17052
// };
171-
17253
// function render(
17354
// ui,
17455
// {
@@ -182,13 +63,10 @@ import reducers from "../src/client/reducers/index.js";
18263
// }
18364
// return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
18465
// }
185-
18666
// // re-export everything
18767
// export * from "@testing-library/react";
188-
18968
// // override render method
19069
// export { render };
191-
19270
const renderWithRedux = (
19371
component,
19472
{ initialState, store = createStore(reducer, initialState) } = {}

0 commit comments

Comments
 (0)