-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
113 additions
and
2 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,69 @@ | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import React, { useState } from 'react'; | ||
import Accordion from './accordion.component'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { QueryClient, QueryClientProvider } from 'react-query'; | ||
|
||
// export function mockOffsetSize(width: number, height: number) { | ||
// const originalFunction = window.getComputedStyle; | ||
// const spyGetComputedStyle = jest.spyOn(window, 'getComputedStyle'); | ||
// spyGetComputedStyle.mockImplementation((elt, _) => { | ||
// const originalStyle = originalFunction(elt); | ||
// originalStyle.fontSize = '14px'; | ||
// originalStyle.paddingLeft = '0px'; | ||
// originalStyle.paddingRight = '0px'; | ||
// originalStyle.paddingTop = '0px'; | ||
// originalStyle.paddingBottom = '0px'; | ||
// return originalStyle; | ||
// }); | ||
// } | ||
|
||
describe('Accordion', () => { | ||
// beforeAll(() => { | ||
// mockOffsetSize(1000, 1000); | ||
// }); | ||
const selectors = { | ||
accordionToggle: () => screen.getByRole('button'), | ||
accordionContainer: () => screen.getByRole('region'), | ||
accordionContent: () => screen.queryByText(/Test content/i), | ||
}; | ||
const renderAccordion = () => { | ||
const queryClient = new QueryClient(); | ||
render( | ||
<QueryClientProvider client={queryClient}> | ||
<Accordion title="Advanced Testings" id="test-accordion"> | ||
<div>Test content</div> | ||
</Accordion> | ||
</QueryClientProvider>, | ||
); | ||
}; | ||
it('should render the Accordion component with title and content', () => { | ||
renderAccordion(); | ||
|
||
const accordionToggle = selectors.accordionToggle(); | ||
expect(accordionToggle).toBeInTheDocument(); | ||
const accordionContent = selectors.accordionContent(); | ||
expect(accordionContent).toBeInTheDocument(); | ||
}); | ||
|
||
it('should toggle the content when clicking on the accordion header', () => { | ||
renderAccordion(); | ||
const accordionToggle = selectors.accordionToggle(); | ||
const accordionContent = selectors.accordionContent(); | ||
expect(accordionContent).not.toBeVisible(); | ||
userEvent.click(accordionToggle); | ||
expect(accordionContent).toBeVisible(); | ||
}); | ||
|
||
it('should toggle the content when pressing the enter key or space key on the accordion header', () => { | ||
renderAccordion(); | ||
const accordionToggle = selectors.accordionToggle(); | ||
const accordionContent = selectors.accordionContent(); | ||
expect(accordionContent).not.toBeVisible(); | ||
accordionToggle.focus(); | ||
userEvent.keyboard('{enter}'); | ||
expect(accordionContent).toBeVisible(); | ||
userEvent.keyboard('{space}'); | ||
expect(accordionContent).not.toBeVisible(); | ||
}); | ||
}); |
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