-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom limit to CountBadge (#935)
- Loading branch information
1 parent
3634149
commit 37cfd15
Showing
5 changed files
with
83 additions
and
23 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
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 |
---|---|---|
@@ -1,32 +1,48 @@ | ||
import React from 'react'; | ||
import {render} from '@testing-library/react'; | ||
import {CountBadge, CountBadgeProps} from '../index'; | ||
const context = describe; | ||
|
||
describe('CountBadge', () => { | ||
const renderCountBadge = (props = {} as Partial<CountBadgeProps>) => { | ||
return render(<CountBadge {...props} />); | ||
}; | ||
|
||
it('should default to 0 if no count is provided', () => { | ||
const expected = '0'; | ||
const {container} = renderCountBadge(); | ||
context('when the default count is set', () => { | ||
it('should default to 0 if no count is provided', () => { | ||
const expected = '0'; | ||
const {container} = renderCountBadge(); | ||
|
||
expect(container.textContent).toEqual(expected); | ||
expect(container.textContent).toEqual(expected); | ||
}); | ||
}); | ||
|
||
it('should render the count for numbers under 1000', () => { | ||
const count = 999; | ||
const expected = count.toString(); | ||
const {container} = renderCountBadge({count}); | ||
context('when the default limit is set', () => { | ||
it('should render the count for numbers under 1000', () => { | ||
const count = 999; | ||
const expected = count.toString(); | ||
const {container} = renderCountBadge({count}); | ||
|
||
expect(container.textContent).toEqual(expected); | ||
expect(container.textContent).toEqual(expected); | ||
}); | ||
|
||
it('should render 999+ for numbers 1000 and above', () => { | ||
const count = 1000; | ||
const expected = '999+'; | ||
const {container} = renderCountBadge({count}); | ||
|
||
expect(container.textContent).toEqual(expected); | ||
}); | ||
}); | ||
|
||
it('should render 999+ for numbers 1000 and above', () => { | ||
const count = 1000; | ||
const expected = '999+'; | ||
const {container} = renderCountBadge({count}); | ||
context('when a custom limit is set', () => { | ||
it('should render a formatted number if the count exceeds the limit', () => { | ||
const count = 100; | ||
const limit = 100; | ||
const expected = '99+'; | ||
const {container} = renderCountBadge({count, limit}); | ||
|
||
expect(container.textContent).toEqual(expected); | ||
expect(container.textContent).toEqual(expected); | ||
}); | ||
}); | ||
}); |
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