Skip to content

Commit

Permalink
Adds more tests to RatingBar
Browse files Browse the repository at this point in the history
  • Loading branch information
rabidkitten committed May 17, 2023
1 parent 37b7217 commit 95c21b2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ditus/react-web-retail",
"version": "1.0.29",
"version": "1.0.30",
"description": "A set of reusable React web components based on Material UI for retail applications.",
"private": false,
"main": "dist/index.js",
Expand Down
34 changes: 34 additions & 0 deletions src/components/rating-bar/rating-bar.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import RatingBar from './rating-bar';
import RatingSummary from '../rating-summary/rating-summary';

// eslint-disable-next-line react/jsx-props-no-spreading
jest.mock('../rating-summary/rating-summary', () => jest.fn(() => (<div />)));

describe('RatingBar', () => {
it('does not display when no ratings are specified.', async () => {
Expand Down Expand Up @@ -125,4 +129,34 @@ describe('RatingBar', () => {

expect(screen.queryByRole('presentation')).not.toBeInTheDocument();
});

it('displays a summary popover when the mouse hovers over the star rating.', async () => {
const user = userEvent.setup();
const fn = jest.fn();

render(
<RatingBar
ratings={[1, 2, 3, 4, 5]}
averageRating={5}
totalRatings={10}
onTotalRatingClick={fn}
/>,
);

const rating = screen.queryByLabelText('Rating');
await user.hover(rating);

expect(RatingSummary).toHaveBeenCalledWith({
averageRating: 5,
totalRatings: 10,
ratings: [
1,
2,
3,
4,
5,
],
onTotalRatingClick: fn,
}, {});
});
});

0 comments on commit 95c21b2

Please sign in to comment.