-
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.
Merge pull request #38 from BuidlerDAO/comp/event
Updated test cases and css error for NModal
- Loading branch information
Showing
6 changed files
with
112 additions
and
38 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
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 |
---|---|---|
@@ -1,38 +1,44 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { render, screen, fireEvent, act } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { NModal } from '../NModal'; | ||
|
||
describe('NModal Component', () => { | ||
test('renders the modal when open and calls onClose when overlay is clicked', () => { | ||
const onCloseMock = jest.fn(); | ||
jest.mock('react-spring-bottom-sheet', () => ({ | ||
BottomSheet: function MockBottomSheet() { | ||
return <div data-testid="modal-bottom-sheet"></div>; | ||
}, | ||
})); | ||
|
||
describe('NModal', () => { | ||
test('renders modal when open', async () => { | ||
const handleClose = jest.fn(); | ||
|
||
render( | ||
<NModal open={true} onClose={onCloseMock} footer={<div>Footer Content</div>}> | ||
Modal Content | ||
<NModal zIndex={999} open={true} onClose={handleClose} unmountOnClose={true} stableHeight={0}> | ||
Test Content | ||
</NModal>, | ||
); | ||
|
||
// Check if the modal content is displayed | ||
expect(screen.getByText('Modal Content')).toBeInTheDocument(); | ||
expect(screen.getByText('Footer Content')).toBeInTheDocument(); | ||
await act(async () => { | ||
await new Promise((r) => setTimeout(r, 150)); | ||
}); | ||
|
||
// Simulate clicking the overlay | ||
const overlay = screen.getByRole('button', { hidden: true }); | ||
fireEvent.click(overlay); | ||
expect(screen.getByTestId('modal-container')).toBeInTheDocument(); | ||
expect(screen.getByTestId('modal-overlay')).toBeInTheDocument(); | ||
expect(screen.getByTestId('modal-bottom-sheet')).toBeInTheDocument(); | ||
|
||
// Ensure onClose is called | ||
expect(onCloseMock).toHaveBeenCalled(); | ||
const overlay = screen.getByTestId('modal-overlay'); | ||
fireEvent.click(overlay); | ||
expect(handleClose).toHaveBeenCalled(); | ||
}); | ||
|
||
test('does not render the modal when `open` is false and `unmountOnClose` is true', () => { | ||
test('does not render when closed', () => { | ||
render( | ||
<NModal open={false} unmountOnClose={true}> | ||
Modal Content | ||
Test Content | ||
</NModal>, | ||
); | ||
|
||
// Modal should not be in the DOM | ||
expect(screen.queryByText('Modal Content')).not.toBeInTheDocument(); | ||
expect(screen.queryByTestId('modal-container')).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
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