-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 @@ | ||
import faker from '@faker-js/faker'; | ||
import { render } from '@testing-library/react'; | ||
import { Badge } from './Badge'; | ||
|
||
describe('the badge', () => { | ||
it('should render a badge with the correct label', () => { | ||
const testLabel = faker.lorem.sentence(); | ||
|
||
const { getByText } = render( | ||
<Badge colour='gray' label={testLabel} /> | ||
); | ||
|
||
expect(getByText(testLabel)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render a badge with the correct colour when gray is selected', () => { | ||
const testLabel = 'Test Label'; | ||
|
||
const { getByText } = render( | ||
<Badge colour='gray' label={testLabel} /> | ||
); | ||
|
||
expect(getByText(testLabel)).toHaveClass('bg-gray-500'); | ||
}); | ||
|
||
it('should render a badge with the correct colour when blue is selected', () => { | ||
const testLabel = 'Test Label'; | ||
|
||
const { getByText } = render( | ||
<Badge colour='blue' label={testLabel} /> | ||
); | ||
|
||
expect(getByText(testLabel)).toHaveClass('bg-blue-500'); | ||
}); | ||
|
||
it('should render a badge with the correct colour when red is selected', () => { | ||
const testLabel = 'Test Label'; | ||
|
||
const { getByText } = render( | ||
<Badge colour='red' label={testLabel} /> | ||
); | ||
|
||
expect(getByText(testLabel)).toHaveClass('bg-red-500'); | ||
}); | ||
}); |
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,13 @@ | ||
import * as React from 'react'; | ||
import { determineBadgeColour } from './helpers/determineBadgeColour'; | ||
|
||
interface IBadgeProps { | ||
label: string; | ||
colour: 'red' | 'blue' | 'gray'; | ||
} | ||
|
||
export const Badge: React.FunctionComponent<IBadgeProps> = ({ colour, label }) => { | ||
return <span className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${determineBadgeColour(colour)} text-white`}> | ||
{label} | ||
</span>; | ||
}; |
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,13 @@ | ||
import { determineBadgeColour } from './determineBadgeColour'; | ||
|
||
describe('determineBadgeColour', () => { | ||
it('should return the correct string', () => { | ||
const redColourString = determineBadgeColour('red'); | ||
const blueColourString = determineBadgeColour('blue'); | ||
const grayColourString = determineBadgeColour('gray'); | ||
|
||
expect(blueColourString).toEqual('bg-blue-500'); | ||
expect(redColourString).toEqual('bg-red-500'); | ||
expect(grayColourString).toEqual('bg-gray-500'); | ||
}); | ||
}); |
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,9 @@ | ||
export const determineBadgeColour = (colour: 'red' | 'blue' | 'gray'): string => { | ||
switch (colour) { | ||
case 'red': return 'bg-red-500'; | ||
case 'blue': return 'bg-blue-500'; | ||
case 'gray': return 'bg-gray-500'; | ||
default: | ||
return 'bg-gray-500'; | ||
} | ||
}; |