Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dropdown_test.js #456

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
50 changes: 17 additions & 33 deletions tests/components/Dropdown_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*
* 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";
import DropdownItem from "../../src/components/DropdownItem";

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

View workflow job for this annotation

GitHub Actions / lint

'DropdownItem' is defined but never used

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

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 `⏎`
Loading