-
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.
test: add FullScreen functional components test
- Loading branch information
1 parent
e90cb20
commit fedccce
Showing
1 changed file
with
67 additions
and
0 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,67 @@ | ||
import React from 'react'; | ||
|
||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
|
||
import '@testing-library/jest-dom'; | ||
import { useFullScreen } from './hook'; | ||
|
||
import { FullScreen } from '.'; | ||
|
||
jest.mock('./hook', () => ({ | ||
useFullScreen: jest.fn(), | ||
})); | ||
|
||
describe('functional/FullScreen', () => { | ||
const handle = { | ||
active: false, | ||
enter: jest.fn(), | ||
exit: jest.fn(), | ||
}; | ||
const handleClick = jest.fn(); | ||
|
||
beforeEach(() => { | ||
(useFullScreen as jest.Mock).mockImplementation(() => ({ | ||
handle, | ||
handleClick, | ||
})); | ||
}); | ||
|
||
test('renders children and a Maximize button when not active', () => { | ||
render( | ||
<FullScreen> | ||
<div>Test Content</div> | ||
</FullScreen> | ||
); | ||
|
||
expect(screen.getByText('Test Content')).toBeInTheDocument(); | ||
|
||
expect(screen.getByRole('button')).toHaveClass( | ||
'absolute right-0 bottom-0 z-50' | ||
); | ||
}); | ||
|
||
test('calls handleClick when the Maximize button is clicked', () => { | ||
render( | ||
<FullScreen> | ||
<div>Test Content</div> | ||
</FullScreen> | ||
); | ||
|
||
fireEvent.click(screen.getByRole('button')); | ||
|
||
expect(handleClick).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('renders a Minimize button when active', () => { | ||
handle.active = true; | ||
render( | ||
<FullScreen> | ||
<div>Test Content</div> | ||
</FullScreen> | ||
); | ||
|
||
expect(screen.getByRole('button')).toHaveClass( | ||
'absolute right-0 bottom-0 p-2' | ||
); | ||
}); | ||
}); |