-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add unit tests for Rank component
- Loading branch information
1 parent
61284da
commit 1392b84
Showing
2 changed files
with
64 additions
and
3 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,60 @@ | ||
import { render } from '@testing-library/react'; | ||
import Rank from './Rank'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
|
||
describe('Rank Component', () => { | ||
it('renders with the correct class and text', () => { | ||
const rank = { | ||
class: 'gold', | ||
text: 'Gold Rank', | ||
}; | ||
|
||
const { getByTestId, getByText } = render(<Rank rank={rank} />); | ||
|
||
const rankElement = getByTestId('rank'); | ||
|
||
// Check if the main div has the correct classes | ||
expect(rankElement.classList.contains('aha__rank')).toBe(true); | ||
expect(rankElement.classList.contains('gold')).toBe(true); | ||
expect(rankElement.classList.contains('offsetCup')).toBe(true); | ||
|
||
// Check if the h4 element contains the correct text | ||
expect(document.body.contains(getByText('Gold Rank'))).toBe(true); | ||
}); | ||
|
||
it('does not have offsetCup class when text is empty', () => { | ||
const rank = { | ||
class: 'silver', | ||
text: '', | ||
}; | ||
|
||
const { getByTestId } = render(<Rank rank={rank} />); | ||
|
||
const rankElement = getByTestId('rank'); | ||
|
||
// Check if the main div has the correct classes | ||
expect(rankElement.classList.contains('aha__rank')).toBe(true); | ||
expect(rankElement.classList.contains('silver')).toBe(true); | ||
expect(rankElement.classList.contains('offsetCup')).toBe(false); | ||
|
||
// Check if the h4 element contains the correct text | ||
const rankText = getByTestId('rank-text'); | ||
expect(document.body.contains(rankText)).toBe(true); | ||
expect(rankText.textContent).toBe(''); | ||
}); | ||
|
||
it('renders the cup div', () => { | ||
const rank = { | ||
class: 'bronze', | ||
text: 'Bronze Rank', | ||
}; | ||
|
||
const { getByTestId } = render(<Rank rank={rank} />); | ||
|
||
const cupElement = getByTestId('cup-animation'); | ||
|
||
// Check if the cup div is present | ||
expect(document.body.contains(cupElement)).toBe(true); | ||
}); | ||
}); |
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