|
| 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 | +}); |
0 commit comments