Skip to content

Commit

Permalink
Adding appropriate spacing front-end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khushiagl committed Jul 18, 2023
1 parent f0a1d42 commit 700d01a
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ describe("SingleSelectDropdown", () => {
let props;
let onChange = jest.fn();
let options = ["a", "b", "c"];

beforeEach(() => {
props = {
options: options,
selected: "",
select: onChange,
defaultValue: "",
};

render(<SingleSelectDropDown {...props} />);
});

Expand All @@ -22,11 +24,13 @@ describe("SingleSelectDropdown", () => {
expect(screen.getByTestId("selection")).toHaveTextContent("");
});
});

it("should not load the dropdown options", () => {
expect(screen.queryByText("a")).toBeNull();
expect(screen.queryByText("b")).toBeNull();
expect(screen.queryByText("c")).toBeNull();
});

it("should render a down arrow within the dropdown", () => {
expect(screen.getByTestId("arrow-down")).toBeInTheDocument();
});
Expand All @@ -42,10 +46,12 @@ describe("SingleSelectDropdown", () => {
expect(screen.getAllByRole("listitem").length).toBe(3);
});
});

describe("No options available", () => {
beforeAll(() => {
options = [];
});

it("should show no options available when there aren't any options to choose from", () => {
fireEvent.click(screen.getByTestId("dropdown"));
expect(screen.getByText("No options available")).toBeInTheDocument();
Expand All @@ -54,10 +60,12 @@ describe("SingleSelectDropdown", () => {
expect(screen.queryByText("c")).toBeNull();
});
});

it("should render a upward arrow within the dropdown", () => {
fireEvent.click(screen.getByTestId("dropdown"));
expect(screen.getByTestId("arrow-up")).toBeInTheDocument();
});

it("should close the dropdown when clicked again", () => {
fireEvent.click(screen.getByTestId("dropdown"));
fireEvent.click(screen.getByTestId("dropdown"));
Expand Down

0 comments on commit 700d01a

Please sign in to comment.