-
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.
Merge pull request #56 from route-master/test
Test
- Loading branch information
Showing
3 changed files
with
73 additions
and
26 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
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,48 @@ | ||
import { useState } from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import Modal from './Modal'; | ||
|
||
describe('Modal', () => { | ||
const Content = <div>test</div>; | ||
|
||
function MockModal() { | ||
const [modalOpen, setModalOpen] = useState(false); | ||
|
||
return ( | ||
<div> | ||
<button type="button" onClick={() => setModalOpen(true)}> | ||
Open Modal Btn | ||
</button> | ||
{modalOpen && ( | ||
<Modal | ||
setModalOpen={setModalOpen} | ||
Content={Content} | ||
mywidth="100px" | ||
myheight="100px" | ||
/> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
it('renders Modal with content', () => { | ||
render(<MockModal />); | ||
fireEvent.click(screen.getByText('Open Modal Btn')); | ||
expect(screen.getByText('test')).toBeInTheDocument(); | ||
}); | ||
|
||
it('closes Modal on close button click', () => { | ||
render(<MockModal />); | ||
fireEvent.click(screen.getByText('Open Modal Btn')); | ||
fireEvent.click(screen.getByText('x')); | ||
expect(screen.queryByText('test')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('closes when clicking on the background', () => { | ||
render(<MockModal />); | ||
fireEvent.click(screen.getByText('Open Modal Btn')); | ||
const background = screen.getByTestId('modal-background'); // Add this data-testid to your background div | ||
fireEvent.click(background); | ||
expect(screen.queryByText('test')).not.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