Skip to content

Commit

Permalink
Update Dropdown_test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
cardosource authored Oct 19, 2024
1 parent 1fde26a commit e934787
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions tests/components/Dropdown_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*
* License: MIT
*/

import React from "react";
import { mount } from "enzyme";
import { render, screen, fireEvent } from "@testing-library/react";
import '@testing-library/jest-dom';

Check failure on line 8 in tests/components/Dropdown_test.js

View workflow job for this annotation

GitHub Actions / lint

Replace `'@testing-library/jest-dom';··` with `"@testing-library/jest-dom";`

import icons from "../../src/icons";
import Dropdown from "../../src/components/Dropdown";
Expand All @@ -24,7 +24,7 @@ describe("Dropdown Component", () => {
testContext = {};
testContext.selected = "metal";
testContext.onChange = jest.fn();
testContext.component = mount(
render(
<Dropdown
items={dropdownItems}
selected={testContext.selected}
Expand All @@ -34,48 +34,32 @@ describe("Dropdown Component", () => {
});

it("renders without problems", () => {
expect(testContext.component).toBeDefined();
expect(screen.getByText("Metal")).toBeInTheDocument();
});

it("renders dropdown items", () => {
const items = testContext.component.find(DropdownItem);
expect(items).toHaveLength(4);
const items = screen.getAllByRole('menuitem');

Check failure on line 41 in tests/components/Dropdown_test.js

View workflow job for this annotation

GitHub Actions / lint

Replace `'menuitem');··` with `"menuitem");`
expect(items).toHaveLength(3);

Check failure on line 42 in tests/components/Dropdown_test.js

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
});

it("renders default selected dropdown item", () => {
const selected = testContext.component.find(DropdownItem).first();

const text = selected.find("span");
expect(text.text()).toEqual("Metal");
const selected = screen.getByText("Metal");
expect(selected).toBeInTheDocument();
});

it("is possible to click on the dropdrown item", () => {
const item = testContext.component.find(DropdownItem).at(1);

expect(testContext.onChange).not.toHaveBeenCalled();

item.find("div").simulate("click");

it("is possible to click on the dropdown item", () => {
const item = screen.getByText("Metal");
fireEvent.click(item);
expect(testContext.onChange).toHaveBeenCalled();
});

it("toggles dropdown on click", () => {
const wrapper = testContext.component.find("div").first();

wrapper.simulate("click");
expect(
testContext.component
.find("div")
.first()
.hasClass("dropdown__wrapper--open")
).toEqual(true);
const wrapper = screen.getByText("Metal");

Check failure on line 57 in tests/components/Dropdown_test.js

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
fireEvent.click(wrapper);
expect(wrapper.closest("div")).toHaveClass("dropdown__wrapper--open");

wrapper.simulate("click");
expect(
testContext.component
.find("div")
.first()
.hasClass("dropdown__wrapper--open")
).toEqual(false);
fireEvent.click(wrapper);
expect(wrapper.closest("div")).not.toHaveClass("dropdown__wrapper--open");
});
});

Check failure on line 65 in tests/components/Dropdown_test.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`

0 comments on commit e934787

Please sign in to comment.