-
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.
- Loading branch information
Showing
7 changed files
with
73 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import KeywordsPipeList from './KeywordsPipeList'; | ||
|
||
describe('KeywordsPipeList', () => { | ||
it('renders null if there keywords is undefined', () => { | ||
const { container } = render(<KeywordsPipeList keywords={undefined} />); | ||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
it('renders null if there keywords is empty', () => { | ||
// We don't want an empty <ul> | ||
const { container } = render(<KeywordsPipeList keywords={[]} />); | ||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
it('renders a list of all of the keywords sorted alphabetically', () => { | ||
render(<KeywordsPipeList keywords={['one', 'two', 'three']} />); | ||
expect(screen.getByRole('list')).toHaveTextContent('onethreetwo'); | ||
}); | ||
it('appends className props to predefined classes', () => { | ||
render(<KeywordsPipeList className="mb-2" keywords={['anything']} />); | ||
expect(screen.getByRole('list')).toHaveClass('mb-2'); | ||
expect(screen.getByRole('list')).toHaveClass('text-gray-500'); | ||
}); | ||
// If tests knew about tailwind we could probably test the pipes | ||
// but that is overkill at this point | ||
}); |
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,32 @@ | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
type KeywordsPipeListProps = { | ||
keywords?: string[]; | ||
} & React.HTMLAttributes<HTMLUListElement>; | ||
|
||
const KeywordsPipeList: React.FC<KeywordsPipeListProps> = ({ | ||
keywords, | ||
className, | ||
...rest | ||
}) => { | ||
if (!keywords || !keywords.length) { | ||
return null; | ||
} | ||
return ( | ||
<ul | ||
className={twMerge('text-gray-500 dark:text-gray-400', className)} | ||
{...rest} | ||
> | ||
{keywords.sort().map((k) => ( | ||
<li | ||
className="inline after:content-['_|_'] last:after:content-none" | ||
key={k} | ||
> | ||
{k} | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
}; | ||
|
||
export default KeywordsPipeList; |
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
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