This repository has been archived by the owner on Mar 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from bigbellies/rating-tests
Added tests for Rating and RatingStar
- Loading branch information
Showing
6 changed files
with
1,352 additions
and
1,921 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import render from '../../_utils/tests/render'; | ||
import { fireEvent, cleanup } from 'react-testing-library'; | ||
import Rating from '../Rating'; | ||
import 'jest-styled-components'; | ||
|
||
afterEach(cleanup); | ||
|
||
it('renders correctly for a basic rating', () => { | ||
const { container } = render(<Rating />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders correctly with a default rating', () => { | ||
const { container } = render(<Rating defaultRating={3} />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders correctly with a different max rating', () => { | ||
const { container } = render(<Rating maxRating={10} />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
describe('sizes', () => { | ||
['small', 'medium', 'large'].forEach(size => { | ||
it(`renders correctly for a select with size ${size}`, () => { | ||
const { container } = render(<Rating size={size} />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('behavior', () => { | ||
it('should call onRate with correct values when a rating is selected', () => { | ||
const handleRate = jest.fn(); | ||
const { getByLabelText } = render(<Rating onRate={handleRate} />); | ||
const fifthStar = getByLabelText('5'); | ||
fireEvent.click(fifthStar); | ||
expect(handleRate).toHaveBeenCalledWith({ rating: 5, maxRating: 5 }); | ||
}); | ||
|
||
it('should call not call onRate when disabled', () => { | ||
const handleRate = jest.fn(); | ||
const { getByLabelText } = render(<Rating onRate={handleRate} disabled />); | ||
const fifthStar = getByLabelText('5'); | ||
fireEvent.click(fifthStar); | ||
expect(handleRate).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import render from '../../_utils/tests/render'; | ||
import RatingStar from '../RatingStar'; | ||
import 'jest-styled-components'; | ||
|
||
it('renders correctly in basic form', () => { | ||
const { container } = render(<RatingStar />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders correctly when active', () => { | ||
const { container } = render(<RatingStar active />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
describe('sizes', () => { | ||
['small', 'medium', 'large'].forEach(size => { | ||
it(`renders correctly for a select with size ${size}`, () => { | ||
const { container } = render(<RatingStar size={size} />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.