-
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.
- Loading branch information
1 parent
0f04626
commit 19fbdfd
Showing
14 changed files
with
1,064 additions
and
747 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 |
---|---|---|
|
@@ -23,4 +23,6 @@ bundle-analysis** | |
storybook-static | ||
build-storybook.log | ||
|
||
debug.log | ||
debug.log | ||
|
||
coverage |
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
97 changes: 97 additions & 0 deletions
97
packages/lib/components/accordion-group/__tests__/accordion-group.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,97 @@ | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
import { AccordionGroup } from '../accordion-group'; | ||
import { describe, expect, it } from 'vitest'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
describe('AccordionGroup', () => { | ||
it('renders children', async () => { | ||
const { getByText } = render( | ||
<AccordionGroup expanded titles={['title 1', 'title 2']}> | ||
<div>Content 1</div> | ||
<div>Content 2</div> | ||
</AccordionGroup> | ||
); | ||
|
||
await expect(getByText('Content 1')).toBeInTheDocument(); | ||
await expect(getByText('Content 2')).toBeInTheDocument(); | ||
}); | ||
|
||
it('expands accordion when clicked', async () => { | ||
render( | ||
<AccordionGroup titles={['Title 1', 'Title 2']}> | ||
<div>Content 1</div> | ||
<div>Content 2</div> | ||
</AccordionGroup> | ||
); | ||
|
||
const title1 = screen.getByText('Title 1'); | ||
userEvent.click(title1); | ||
|
||
expect(await screen.findByText('Content 1')).toBeVisible(); | ||
}); | ||
|
||
it('only one accordion expanded at a time if autoClose', async () => { | ||
const { getByText } = render( | ||
<AccordionGroup autoClose titles={['Title 1', 'Title 2']}> | ||
<div>Content 1</div> | ||
<div>Content 2</div> | ||
</AccordionGroup> | ||
); | ||
|
||
const title1 = getByText('Title 1'); | ||
const title2 = getByText('Title 2'); | ||
|
||
fireEvent.click(title1); | ||
await waitFor( | ||
() => { | ||
expect(getByText('Content 1')).toBeInTheDocument(); | ||
}, | ||
{ timeout: 2000 } | ||
); | ||
|
||
fireEvent.click(title2); | ||
await waitFor( | ||
() => { | ||
expect(getByText('Content 2')).toBeInTheDocument(); | ||
}, | ||
{ | ||
timeout: 2000, | ||
} | ||
); | ||
}); | ||
|
||
it('multiple accordions stay open if no autoClose', async () => { | ||
const { getByText } = render( | ||
<AccordionGroup titles={['Title 1', 'Title 2']}> | ||
<div>Content 1</div> | ||
<div>Content 2</div> | ||
</AccordionGroup> | ||
); | ||
|
||
const title1 = getByText('Title 1'); | ||
const title2 = getByText('Title 2'); | ||
|
||
fireEvent.click(title1); | ||
|
||
await waitFor( | ||
() => { | ||
expect(getByText('Content 1')).toBeInTheDocument(); | ||
}, | ||
{ | ||
timeout: 1000, | ||
} | ||
); | ||
|
||
fireEvent.click(title2); | ||
|
||
await waitFor( | ||
() => { | ||
expect(getByText('Content 2')).toBeInTheDocument(); | ||
expect(getByText('Content 1')).toBeInTheDocument(); | ||
}, | ||
{ | ||
timeout: 2000, | ||
} | ||
); | ||
}); | ||
}); |
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
42 changes: 42 additions & 0 deletions
42
packages/lib/components/accordion/__tests__/accordion-header.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,42 @@ | ||
// test.jsamp | ||
|
||
import { expect, describe, it, vi } from 'vitest'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { AccordionHeader } from '../accordion-header'; | ||
|
||
describe('AccordionHeader', () => { | ||
it('renders title', () => { | ||
render(<AccordionHeader title="Test" />); | ||
|
||
expect(screen.getByText('Test')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders custom icon when provided', () => { | ||
const Icon = () => <div data-testid="custom-icon" />; | ||
|
||
render(<AccordionHeader customIcon={<Icon />} />); | ||
|
||
expect(screen.getByTestId('custom-icon')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls onToggle when clicked', async () => { | ||
const onToggle = vi.fn(); | ||
|
||
render(<AccordionHeader onToggle={onToggle} />); | ||
|
||
await userEvent.click(screen.getByRole('heading')); | ||
|
||
expect(onToggle).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('has aria-expanded=true when open', () => { | ||
render(<AccordionHeader open />); | ||
|
||
expect(screen.getByRole('heading')).toHaveAttribute( | ||
'aria-expanded', | ||
'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
Oops, something went wrong.
19fbdfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
react-creme – ./
react-creme-git-master-prabhuignoto.vercel.app
react-creme.vercel.app
react-creme.prabhumurthy.com
react-creme-prabhuignoto.vercel.app