Skip to content

Commit

Permalink
Update: add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmakwe-onyeka committed Apr 10, 2024
1 parent 71678b8 commit 3abd58f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/components/molecules/f-restaurant-card/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
_April 10, 2024_

### Changed
- Create prop for max rating value
- Create new prop for f-restaurant-card
- Use prop as the max review threshold to limit the actual number of reviews shown on restaurant card

## v1.6.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,62 @@ describe('RestaurantRating component', () => {
});
});

describe('reviews count threshold', () => {
const countThreshold = 200;
it('shows proper value when count is less than threshold', () => {
// arrange
const propsData = {
mean: 5,
count: 150,
isOwnRating: false,
countThreshold
};
// act
const wrapper = mount(RestaurantRating, { propsData });
const countMessage = wrapper.find('[data-test-id="rating"]');
// assert
expect(countMessage.exists()).toBe(true);
expect(countMessage.text()).toStrictEqual('150');
});
it('shows proper value when count is higher than threshold', () => {
// arrange
const propsData = {
mean: 5,
count: 250,
isOwnRating: false,
countThreshold
};
// act
const wrapper = mount(RestaurantRating, { propsData });
const countMessage = wrapper.find('[data-test-id="rating"]');
// assert
expect(countMessage.exists()).toBe(true);
expect(countMessage.text()).toStrictEqual('200+');
});
it('shows proper value when count is higher than threshold but no threshold is supplies. it uses default threshold value', () => {
// arrange
const propsData = {
mean: 5,
count: 250,
isOwnRating: false
};
// act
const wrapper = mount(RestaurantRating, { propsData });
const countMessage = wrapper.find('[data-test-id="rating"]');
// assert
expect(countMessage.exists()).toBe(true);
expect(countMessage.text()).toStrictEqual('200+');
});
});

describe('isOwnRatingMessage is false', () => {
const isOwnRating = false;

it('shows a filled star, rating mean and count', () => {
// arrange
const propsData = {
mean: 5,
count: 200,
count: 250,
isOwnRating
};

Expand All @@ -189,7 +237,7 @@ describe('RestaurantRating component', () => {
expect(countMessage.exists()).toBe(true);

expect(ratingsMeanElement.text()).toStrictEqual('5.0');
expect(countMessage.text()).toStrictEqual('200');
expect(countMessage.text()).toStrictEqual('200+');
});

it('shows an empty star and a no ratings message if `mean` is missing', () => {
Expand Down

0 comments on commit 3abd58f

Please sign in to comment.