Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
29 changes: 29 additions & 0 deletions __tests__/components/popups/submission/_partials/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import SubmissionPopup from "@/components/popups/submission/_partials/Header";
import "@testing-library/jest-dom";
import { render, screen, fireEvent } from "@testing-library/react";

describe("SubmissionPopup", () => {
const mockOnClose = jest.fn();


it("renders the component with correct text", () => {
render(<SubmissionPopup onClose={mockOnClose} />);
expect(screen.getByText("communities.submission")).toBeInTheDocument();
});

it("calls onClose when clicking the arrow icon", () => {
render(<SubmissionPopup onClose={mockOnClose} />);

const arrowButton = screen.getByText("communities.submission").parentElement;
fireEvent.click(arrowButton!);
expect(mockOnClose).toHaveBeenCalled();
});

it("calls onClose when clicking the close button", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it("calls onClose when clicking the close button", () => {
it("Invokes the onClose function when the close button is clicked", () => {

render(<SubmissionPopup onClose={mockOnClose} />);
const closeButton = screen.getByRole("button");
fireEvent.click(closeButton);
expect(mockOnClose).toHaveBeenCalled();
});

});
27 changes: 27 additions & 0 deletions __tests__/components/popups/submission/indext.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import SubmissionPopup from "@/components/popups/submission";
import { renderWithRedux } from "@__mocks__/renderWithRedux";
import "@testing-library/jest-dom";
import { fireEvent, screen } from "@testing-library/react";
describe("SubmissionPopup", () => {

const mockOnClose = jest.fn();

it("renders the popup when show is true", () => {
renderWithRedux(<SubmissionPopup show={true} onClose={mockOnClose} submissionId="123" />);
expect(screen.getByTestId("overlay")).toBeInTheDocument();
expect(screen.getByText("communities.submission")).toBeInTheDocument();
expect(screen.getByTestId("viewId")).toBeInTheDocument();
});

it("does not render the popup when show is false", () => {
renderWithRedux(<SubmissionPopup show={false} onClose={mockOnClose} submissionId="123" />);
expect(screen.queryByTestId("overlay")).not.toBeInTheDocument();
});

it("calls onClose when the close button is clicked", () => {
renderWithRedux(<SubmissionPopup show={true} onClose={mockOnClose} submissionId="123" />);
const buttonElement = screen.getByText("communities.submission").parentElement;
fireEvent.click(buttonElement!);
expect(mockOnClose).toHaveBeenCalled();
});
});