This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test coverage for accordion, tooltip and tabs
- Loading branch information
1 parent
741faee
commit c8153f5
Showing
4 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/components/CustomAccordion/__tests__/custom-accordion.test.tsx
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,31 @@ | ||
import React from 'react'; | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import CustomAccordion from '..'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const mock_accordion_items = [ | ||
{ header: 'header_1', content: 'content 1' }, | ||
{ header: 'header_2', content: 'content 2' }, | ||
]; | ||
|
||
describe('CustomAccordion', () => { | ||
beforeEach(() => { | ||
render(<CustomAccordion items={mock_accordion_items} />); | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
it('should render the custom accordion', () => { | ||
const header = screen.getByText('header_1'); | ||
expect(header).toBeInTheDocument(); | ||
}); | ||
|
||
it('should open accordion content on click', async () => { | ||
const header = screen.getByText('header_2'); | ||
await userEvent.click(header); | ||
const content = screen.getByText('content 2'); | ||
expect(content).toBeInTheDocument(); | ||
}); | ||
}); |
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,31 @@ | ||
import React from 'react'; | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import CustomTabs from '..'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const mock_tabs = [ | ||
{ label: 'tab_1', content: 'content 1' }, | ||
{ label: 'tab_2', content: 'content 2' }, | ||
]; | ||
|
||
describe('CustomTabs', () => { | ||
beforeEach(() => { | ||
render(<CustomTabs tabs={mock_tabs}></CustomTabs>); | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
it('should render the custom tabs', () => { | ||
const tab = screen.getByText('tab_1'); | ||
expect(tab).toBeInTheDocument(); | ||
}); | ||
|
||
it('should change tab content on different tab click', async () => { | ||
const tab = screen.getByText('tab_2'); | ||
await userEvent.click(tab); | ||
const content = screen.getByText('content 2'); | ||
expect(content).toBeInTheDocument(); | ||
}); | ||
}); |
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
30 changes: 30 additions & 0 deletions
30
src/components/CustomTooltip/__tests__/custom-tooltip.test.tsx
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,30 @@ | ||
import React from 'react'; | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import CustomTooltip from '..'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
describe('CustomTooltip', () => { | ||
beforeEach(() => { | ||
render( | ||
<CustomTooltip text='tooltip text'> | ||
<div>outer text</div> | ||
</CustomTooltip>, | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
it('should render the custom tooltip with children', () => { | ||
const text = screen.getByText('outer text'); | ||
expect(text).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the tooltip text on hover', async () => { | ||
const text = screen.getByText('outer text'); | ||
await userEvent.hover(text); | ||
const tooltip_text = screen.getAllByText('tooltip text'); | ||
expect(tooltip_text[0]).toBeInTheDocument(); | ||
}); | ||
}); |