Skip to content

Commit

Permalink
test: follow mike request - replace data-testid for querySelector by …
Browse files Browse the repository at this point in the history
…classes on files SideBarButtonInfo.jsx and SideBarButton.jsx
  • Loading branch information
William Spada authored and William Spada committed Sep 30, 2024
1 parent a80f6e3 commit 33b3164
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const SideBarButton = ({ children, description, onClick, isVisible }) => {
className={classes}
onClick={onClick}
data-id="side-bar-button"
data-testid="sidebar-button-container"
>
{showInfo && (
<SideBarButtonInfo data-id="button-info" description={description} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';

const SideBarButtonInfo = ({ description }) => (
<span
data-id="project-option-info"
data-testid="sidebar-button-description"
className="SideBar__info"
>
<span data-id="project-option-info" className="SideBar__info">
{description}
</span>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ describe('<SideBarButtonInfo />', () => {

it('contain the description', () => {
const description = 'description';
const { getByTestId } = render(
const { container } = render(
<SideBarButtonInfo description={description} />
);
const span = getByTestId('sidebar-button-description');
const span = container.querySelector('.SideBar__info');

expect(span.innerHTML).toEqual(description);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ describe('<SideBarButton />', () => {

it('render children', () => {
const children = 'I am children!';
const { getByTestId } = renderComponent({ children });
const { container } = renderComponent({ children });

expect(getByTestId('sidebar-button-container').innerHTML).toEqual(children);
expect(container.querySelector('.SideBar__link').innerHTML).toEqual(
children
);
});

it('does not render <SideBarButtonInfo />', () => {
Expand All @@ -36,38 +38,38 @@ describe('<SideBarButton />', () => {
describe('when click in <SideBarButton />', () => {
it('call onClick', () => {
const onClick = vi.fn();
const { getByTestId } = renderComponent({ onClick });
const { container } = renderComponent({ onClick });

const button = getByTestId('sidebar-button-container');
const button = container.querySelector('.SideBar__link');
fireEvent.click(button);
expect(onClick).toHaveBeenCalled();
});
});

describe('when mouse over', () => {
it('renders <SideBarButtonInfo />', async () => {
const { getByTestId, rerender } = renderComponent();
const { container } = renderComponent();

const button = getByTestId('sidebar-button-container');
const button = container.querySelector('.SideBar__link');
fireEvent.mouseOver(button);

expect(getByTestId('sidebar-button-description')).toBeInTheDocument();
expect(container.querySelector('.SideBar__info')).toBeInTheDocument();
});
});

describe('when isVisible is true', () => {
it('renders <SideBar /> with SideBar__link--is-visible class', () => {
const { getByTestId } = renderComponent({ isVisible: true });
const button = getByTestId('sidebar-button-container');
const { container } = renderComponent({ isVisible: true });
const button = container.querySelector('.SideBar__link');

expect(button).toHaveClass('SideBar__link--is-visible');
});
});

describe('when isVisible is false', () => {
it('render <SideBar /> without SideBar__link--is-visible class', () => {
const { getByTestId } = renderComponent();
const button = getByTestId('sidebar-button-container');
const { container } = renderComponent();
const button = container.querySelector('.SideBar__link');

expect(button).not.toHaveClass('SideBar__link--is-visible');
});
Expand Down

0 comments on commit 33b3164

Please sign in to comment.