Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(StarRating): move to 1 based instead of 0 (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored Feb 6, 2018
1 parent 301ce04 commit eb0152d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/react-instantsearch/src/components/StarRating.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class StarRating extends Component {

// min & max are always set when there is a results, otherwise it means
// that we don't want to render anything since we don't have any values.
const limitMin = min !== undefined && min >= 0 ? min : 0;
const limitMax = max !== undefined && max >= 0 ? max : -1;
const limitMin = min !== undefined && min >= 0 ? min : 1;
const limitMax = max !== undefined && max >= 0 ? max : 0;
const inclusiveLength = limitMax - limitMin + 1;
const safeInclusiveLength = Math.max(inclusiveLength, 0);

Expand Down
13 changes: 7 additions & 6 deletions packages/react-instantsearch/src/components/StarRating.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ describe('StarRating', () => {
}).not.toThrow();
});

it('expect to not throw when only max is defined', () => {
expect(() => {
renderer.create(
it('expect to render when only max is defined', () => {
const tree = renderer
.create(
<StarRating
createURL={() => '#'}
refine={() => null}
Expand All @@ -124,11 +124,12 @@ describe('StarRating', () => {
]}
canRefine={true}
/>
);
}).not.toThrow();
)
.toJSON();
expect(tree).toMatchSnapshot();
});

it('expect to render from from 0 when min is negative', () => {
it('expect to render from from 1 when min is negative', () => {
const tree = renderer
.create(
<StarRating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ exports[`StarRating applies translations 1`] = `
</div>
`;

exports[`StarRating expect to render from from 0 when min is negative 1`] = `
exports[`StarRating expect to render from from 1 when min is negative 1`] = `
<div
className="ais-StarRating__root"
>
Expand Down Expand Up @@ -324,11 +324,9 @@ exports[`StarRating expect to render from from 0 when min is negative 1`] = `
14
</span>
</a>
<a
<div
className="ais-StarRating__ratingLink ais-StarRating__ratingLinkSelected"
disabled={false}
href="#"
onClick={[Function]}
>
<span
className="ais-StarRating__ratingIcon ais-StarRating__ratingIconSelected"
Expand Down Expand Up @@ -358,6 +356,48 @@ exports[`StarRating expect to render from from 0 when min is negative 1`] = `
>
15
</span>
</div>
</div>
`;

exports[`StarRating expect to render nothing when min is higher than max 1`] = `
<div
className="ais-StarRating__root"
/>
`;

exports[`StarRating expect to render when only max is defined 1`] = `
<div
className="ais-StarRating__root"
>
<a
className="ais-StarRating__ratingLink"
disabled={false}
href="#"
onClick={[Function]}
>
<span
className="ais-StarRating__ratingIcon"
/>
<span
className="ais-StarRating__ratingIcon"
/>
<span
className="ais-StarRating__ratingIcon"
/>
<span
className="ais-StarRating__ratingLabel"
>
& Up
</span>
<span>
</span>
<span
className="ais-StarRating__ratingCount"
>
3
</span>
</a>
<a
className="ais-StarRating__ratingLink"
Expand All @@ -366,14 +406,37 @@ exports[`StarRating expect to render from from 0 when min is negative 1`] = `
onClick={[Function]}
>
<span
className="ais-StarRating__ratingIconEmpty"
className="ais-StarRating__ratingIcon"
/>
<span
className="ais-StarRating__ratingIconEmpty"
className="ais-StarRating__ratingIcon"
/>
<span
className="ais-StarRating__ratingIconEmpty"
/>
<span
className="ais-StarRating__ratingLabel"
>
& Up
</span>
<span>
</span>
<span
className="ais-StarRating__ratingCount"
>
5
</span>
</a>
<a
className="ais-StarRating__ratingLink"
disabled={false}
href="#"
onClick={[Function]}
>
<span
className="ais-StarRating__ratingIcon"
/>
<span
className="ais-StarRating__ratingIconEmpty"
/>
Expand All @@ -391,18 +454,12 @@ exports[`StarRating expect to render from from 0 when min is negative 1`] = `
<span
className="ais-StarRating__ratingCount"
>
15
6
</span>
</a>
</div>
`;

exports[`StarRating expect to render nothing when min is higher than max 1`] = `
<div
className="ais-StarRating__root"
/>
`;

exports[`StarRating supports passing max/min values 1`] = `
<div
className="ais-StarRating__root"
Expand Down

0 comments on commit eb0152d

Please sign in to comment.