Skip to content

Commit 2cf8620

Browse files
authored
Merge pull request #32 from REST-API-Client/test/moreTestCode
[2022/07/18] - ์ปดํฌ๋„ŒํŠธ ์œ ๋‹› ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€ + ์ˆœ์ˆ˜ ํ•จ์ˆ˜ ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€
2 parents 6b4a9d5 + e53106f commit 2cf8620

File tree

61 files changed

+546
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+546
-52
lines changed

โ€Ž.babelrc

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
{
2-
"presets": ["@babel/preset-env", "@babel/preset-react"]
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "current"
8+
}
9+
}
10+
],
11+
"@babel/preset-react"
12+
]
313
}

โ€Žjest.config.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
module.exports = {
22
collectCoverage: true,
3-
collectCoverageFrom: ["webview/**/*.{js}"],
3+
collectCoverageFrom: ["webview/**/*.{js,jsx}"],
44
coverageDirectory: "coverage",
5+
moduleNameMapper: {
6+
"^.+.(svg|png|jpg)$": "jest-transform-stub",
7+
},
58
testEnvironment: "jsdom",
69
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
10+
transform: {
11+
"^.+\\.[jt]sx?$": "babel-jest",
12+
"^.+\\.svg$": "jest-transform-stub",
13+
},
714
};

โ€Žpackage-lock.json

+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

โ€Žpackage.json

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
"glob": "^8.0.3",
103103
"jest": "^28.1.3",
104104
"jest-environment-jsdom": "^28.1.3",
105+
"jest-svg-transformer": "^1.0.0",
106+
"jest-transform-stub": "^2.0.0",
105107
"mocha": "^10.0.0",
106108
"path-browserify": "^1.0.1",
107109
"style-loader": "^3.3.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { render } from "@testing-library/react";
2+
import React from "react";
3+
4+
import EmptyFavoritesCollectionMessage from "../features/Sidebar/Message/EmptyFavoritesCollectionMessage";
5+
6+
describe("EmptyFavoritesCollectionMessage component test", () => {
7+
it("should display message from children component", () => {
8+
const { getByText } = render(<EmptyFavoritesCollectionMessage />);
9+
10+
expect(
11+
getByText(/Your favorites collection seems to be empty./i),
12+
).toBeInTheDocument();
13+
expect(
14+
getByText(
15+
/Press the heart icon from your history collection to add it to your favorites collection./i,
16+
),
17+
).toBeInTheDocument();
18+
});
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { render } from "@testing-library/react";
2+
import React from "react";
3+
4+
import EmptyHistoryCollectionMessage from "../features/Sidebar/Message/EmptyHistoryCollectionMessage";
5+
6+
describe("EmptyHistoryCollectionMessage component test", () => {
7+
it("should display correct message when history collection is empty", () => {
8+
const { getByText } = render(<EmptyHistoryCollectionMessage />);
9+
10+
expect(
11+
getByText(/Your history collection seems to be empty./i),
12+
).toBeInTheDocument();
13+
expect(
14+
getByText(/Start making requests to view your history collection./i),
15+
).toBeInTheDocument();
16+
});
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { render } from "@testing-library/react";
2+
import React from "react";
3+
4+
import EmptySearchResultMessage from "../features/Sidebar/Message/EmptySearchResultMessage";
5+
6+
describe("EmptyHistoryCollectionMessage component test", () => {
7+
it("should render search input value to empty search result message", () => {
8+
const { getByText } = render(<EmptySearchResultMessage value="google" />);
9+
10+
expect(getByText(/google/i)).toBeInTheDocument();
11+
});
12+
});

โ€Žwebview/__test__/RequestAuthSelectMenu.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe("RequestAuthSelectMenu component test", () => {
1010

1111
expect(getByRole("option", { name: "No Auth" }).selected).toBe(true);
1212
});
13+
1314
it("should display the correct number of options", () => {
1415
const { getAllByRole } = render(<RequestAuthSelectMenu />);
1516

โ€Žwebview/__test__/RequestBodyRawOptions.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe("RequestBodyRawOptions component test", () => {
1010

1111
expect(getByRole("option", { name: "Text" }).selected).toBe(true);
1212
});
13+
1314
it("should display the correct number of options", () => {
1415
const { getAllByRole } = render(<RequestBodyRawOptions />);
1516

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { render } from "@testing-library/react";
2+
import React from "react";
3+
4+
import RequestButton from "../features/Request/Button/RequestButton";
5+
6+
describe("RequestNoAuth component test", () => {
7+
it("should display correct message when auth option is not selected", () => {
8+
const { getByText } = render(<RequestButton />);
9+
10+
expect(getByText(/Send/i)).toBeInTheDocument();
11+
});
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { render } from "@testing-library/react";
2+
import React from "react";
3+
4+
import ResponseBodyMenu from "../features/Response/Body/ResponseBodyMenu";
5+
6+
describe("ResponseBodyMenu component test", () => {
7+
it("should render correct default response body option", () => {
8+
const { getByText } = render(<ResponseBodyMenu />);
9+
10+
expect(getByText(/pretty/i)).toBeInTheDocument();
11+
expect(getByText(/raw/i)).toBeInTheDocument();
12+
expect(getByText(/preview/i)).toBeInTheDocument();
13+
});
14+
15+
it("should render correct default response body pretty option", () => {
16+
const { getByRole } = render(<ResponseBodyMenu />);
17+
18+
expect(getByRole("option", { name: "JSON" }).selected).toBe(true);
19+
});
20+
21+
it("should display the correct number of options", () => {
22+
const { getAllByRole } = render(<ResponseBodyMenu />);
23+
24+
expect(getAllByRole("option").length).toBe(3);
25+
});
26+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { render } from "@testing-library/react";
2+
import userEvent from "@testing-library/user-event";
3+
import React from "react";
4+
5+
import ResponseBodyMenuOption from "../features/Response/Body/ResponseBodyMenuOption";
6+
7+
describe("ResponseBodyMenu component test", () => {
8+
it("should render correct default response body option", () => {
9+
const { getByText } = render(<ResponseBodyMenuOption />);
10+
11+
expect(getByText(/json/i)).toBeInTheDocument();
12+
expect(getByText(/html/i)).toBeInTheDocument();
13+
expect(getByText(/text/i)).toBeInTheDocument();
14+
});
15+
16+
it("should render correct default response body pretty option", () => {
17+
const { getByRole } = render(<ResponseBodyMenuOption />);
18+
19+
expect(getByRole("option", { name: "JSON" }).selected).toBe(true);
20+
});
21+
22+
it("should display the correct number of options", () => {
23+
const { getAllByRole } = render(<ResponseBodyMenuOption />);
24+
25+
expect(getAllByRole("option").length).toBe(3);
26+
});
27+
28+
it("should allow user to select body menu option", async () => {
29+
const { getByRole } = render(<ResponseBodyMenuOption />);
30+
31+
await userEvent.selectOptions(
32+
getByRole("combobox"),
33+
34+
getByRole("option", { name: "HTML" }),
35+
);
36+
37+
expect(getByRole("option", { name: "HTML" }).selected).toBe(true);
38+
expect(getByRole("option", { name: "JSON" }).selected).toBe(false);
39+
40+
await userEvent.selectOptions(
41+
getByRole("combobox"),
42+
43+
getByRole("option", { name: "Text" }),
44+
);
45+
46+
expect(getByRole("option", { name: "Text" }).selected).toBe(true);
47+
});
48+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { render } from "@testing-library/react";
2+
import React from "react";
3+
4+
import ResponsePreview from "../features/Response/Preview/ResponsePreview";
5+
6+
describe("ResponseEResponsePreviewmptyMenu component test", () => {
7+
it("should display iframe with correct title", () => {
8+
const { getByTitle } = render(<ResponsePreview />);
9+
10+
expect(getByTitle("Response Data Preview")).toBeInTheDocument();
11+
});
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { render } from "@testing-library/react";
2+
import React from "react";
3+
4+
import ResponseEmptyMenu from "../features/Response/Empty/ResponseEmptyMenu";
5+
6+
describe("ResponseEmptyMenu component test", () => {
7+
it("should display correct message when response empty menu", () => {
8+
const { getByText } = render(<ResponseEmptyMenu />);
9+
10+
expect(
11+
getByText(/Enter request URL and click send to get a response/i),
12+
).toBeInTheDocument();
13+
});
14+
15+
it("should display svg when response is not sent yet", () => {
16+
const { getByAltText } = render(<ResponseEmptyMenu />);
17+
18+
expect(getByAltText(/Connection SVG/i)).toBeTruthy();
19+
});
20+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { render } from "@testing-library/react";
2+
import React from "react";
3+
4+
import ResponseErrorMenu from "../features/Response/Error/ResponseErrorMenu";
5+
6+
describe("ResponseErrorMenu component test", () => {
7+
it("should display correct message when error response is received", () => {
8+
const { getByText } = render(
9+
<ResponseErrorMenu type="error" message="unable to find restapiclient" />,
10+
);
11+
12+
expect(getByText(/unable to find restapiclient/i)).toBeInTheDocument();
13+
});
14+
15+
it("should display correct message when image with correct alt", () => {
16+
const { getByAltText } = render(<ResponseErrorMenu />);
17+
18+
expect(getByAltText("error")).toBeTruthy();
19+
});
20+
});
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { render } from "@testing-library/react";
2+
import React from "react";
3+
4+
import ResponseMenu from "../features/Response/Menu/ResponseMenu";
5+
6+
describe("ResponseMenu component test", () => {
7+
it("should render response menu with three options", () => {
8+
const { getAllByRole } = render(<ResponseMenu />);
9+
10+
expect(getAllByRole("option").length).toEqual(3);
11+
});
12+
13+
it("should render response menu option correctly", () => {
14+
const { getByText } = render(<ResponseMenu />);
15+
16+
expect(getByText(/Body/i)).toBeInTheDocument();
17+
expect(getByText(/Headers/i)).toBeInTheDocument();
18+
});
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { render } from "@testing-library/react";
2+
import React from "react";
3+
4+
import ResponseMetaData from "../features/Response/MetaData/ResponseMetaData";
5+
6+
const mockData = {
7+
responseSize: 2600,
8+
requestTime: 398,
9+
statusCode: 200,
10+
statusText: "OK",
11+
};
12+
13+
const errorMockData = {
14+
responseSize: 12410,
15+
requestTime: 398,
16+
statusCode: 404,
17+
statusText: "Not Found",
18+
};
19+
20+
describe("ResponseMetaData component test", () => {
21+
it("should render meta data menu properly", () => {
22+
const { getByText } = render(<ResponseMetaData {...mockData} />);
23+
24+
expect(getByText(/size:/i)).toBeInTheDocument();
25+
expect(getByText(/time:/i)).toBeInTheDocument();
26+
expect(getByText(/status:/i)).toBeInTheDocument();
27+
});
28+
29+
it("should render meta data menu with correct data", () => {
30+
const { getByText } = render(<ResponseMetaData {...mockData} />);
31+
32+
expect(getByText(/200 OK/i)).toBeInTheDocument();
33+
expect(getByText(/398ms/i)).toBeInTheDocument();
34+
expect(getByText(/0.26 KB/i)).toBeInTheDocument();
35+
expect(getByText(/200 OK/i)).toHaveStyle("color:rgb(66 245 66)");
36+
});
37+
38+
it("should render meta data menu with 404 response properly", () => {
39+
const { getByText } = render(<ResponseMetaData {...errorMockData} />);
40+
41+
expect(getByText(/404 Not Found/i)).toBeInTheDocument();
42+
expect(getByText(/398/i)).toBeInTheDocument();
43+
expect(getByText(/1.24 KB/i)).toBeInTheDocument();
44+
expect(getByText(/404 Not Found/i)).toHaveStyle("color:rgb(255 100 100)");
45+
});
46+
});

0 commit comments

Comments
ย (0)