Movie_Search/movie-search/__tests__/SearchBar.test.jsx

42 lines
1.4 KiB
React
Raw Permalink Normal View History

2024-05-25 01:03:21 -04:00
import "@testing-library/jest-dom";
import { fireEvent, render, screen } from "@testing-library/react";
import SearchBar from "@/app/Search/SearchBar.tsx";
import { queryOMDb } from "@/api/omdb";
2024-06-02 01:21:21 -04:00
describe("SearchBar Operations", () => {
test("SearchBar Allows user input", () => {
render(<SearchBar />);
const input = screen.getByPlaceholderText("Search by Title");
2024-05-25 01:03:21 -04:00
2024-06-02 01:21:21 -04:00
fireEvent.change(input, { target: { value: "some value" } });
2024-05-25 01:03:21 -04:00
2024-06-02 01:21:21 -04:00
expect(input.value).toBe("some value");
});
2024-05-25 01:03:21 -04:00
2024-06-02 01:21:21 -04:00
test("SearchBar Allows user input and Clear button clears", () => {
render(<SearchBar />);
const input = screen.getByTestId("SearchBar-input");
const clear = screen.getByText("Clear");
2024-05-25 01:03:21 -04:00
2024-06-02 01:21:21 -04:00
fireEvent.change(input, { target: { value: "some value" } });
expect(input.value).toBe("some value");
2024-05-25 01:03:21 -04:00
2024-06-02 01:21:21 -04:00
fireEvent.click(clear);
2024-05-25 01:03:21 -04:00
2024-06-02 01:21:21 -04:00
expect(input.value).toBe("");
});
2024-05-25 01:03:21 -04:00
2024-06-02 01:21:21 -04:00
// test("SearchBar Allows user submit", () => {
// render(<SearchBar />);
// const input = screen.getByPlaceholderText("Search by Title");
// const submit = screen.getByText("Search");
// const spy = jest.spyOn({ queryOMDb }, "queryOMDb");
// fireEvent.change(input, { target: { value: "back to the" } });
// fireEvent.click(submit);
// // Somehow test for form submission - currently facing this issue
// // https://github.com/vercel/next.js/issues/54757
// // expect(spy).toHaveBeenCalled();
// });
});