Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: revert code coverage on home page #614

Merged
merged 4 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion __tests__/pages/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { getStaticProps } from "~/pages";
import React from "react";

import { render } from "@testing-library/react";
import { latestNewsItemBuilder } from "~/lib/content/__mocks__/builders/informasi-terbaru";
import HomePage, { getStaticProps } from "~/pages";

jest.mock("~/lib/content/home-page");
jest.mock("~/lib/content/welcome-message");

describe("HomePage", () => {
it("home page content rendered properly", () => {
const { container } = render(
<HomePage latestNews={[latestNewsItemBuilder()]} />,
);

expect(container.firstChild?.hasChildNodes()).toBeTruthy();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antoooks We should use more robust assertions instead of just asserting the existence of a child node to avoid false positive test results.

FYI Mas @rubiagatra.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok @zainfathoni, will lookout for it on the weekend

});
});

describe("getStaticProps", () => {
// TODO: (ZF) Find a way to load the markdown files in Jest so that we can test the successful case.
it("returns an empty array when failing to load the markdown files", async () => {
Expand Down
2 changes: 1 addition & 1 deletion components/home/__tests__/homepage-content.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ describe("homepage content render correctly", () => {
const { container } = render(<HomePageContent />);

it("renders correctly", () => {
expect(container.firstChild).toHaveClass("flex-1");
expect(container.hasChildNodes()).toBeTruthy();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antoooks We should use more robust assertions instead of just asserting the existence of a child node to avoid false positive test results.

FYI Mas @rubiagatra.

});
});
13 changes: 8 additions & 5 deletions components/ui/__tests__/alert.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ describe("Alert", () => {
"border-red-400",
);
expect(container.firstChild?.firstChild).toHaveClass("p-4", "babayaga");

expect(
container.firstChild?.firstChild?.firstChild?.firstChild?.firstChild,
).toHaveClass("flex-shrink-0 mr-3");
expect(
container.firstChild?.firstChild?.firstChild?.childNodes[1],
).toHaveClass(`close-button text-red-400 hover:text-red-500`);
container.getElementsByClassName("flex-shrink-0 mr-3")[0].hasChildNodes(),
).toBeTruthy();

expect(screen.getByRole("button")).toHaveClass(
`close-button text-red-400 hover:text-red-500`,
);

fireEvent.click(screen.getByRole("button"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antoooks We should assert what should happen after the button is clicked.

FYI Mas @rubiagatra.

});
});