-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(modal-close): some modal close unexpectedly clicking on the overlay
- Loading branch information
1 parent
2a43b44
commit 3d97bad
Showing
9 changed files
with
79 additions
and
8 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
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,34 @@ | ||
/* eslint-disable padding-line-between-statements */ | ||
import '@testing-library/jest-dom' | ||
import { fireEvent, render } from '@testing-library/react' | ||
import * as modalStore from '../../../stores/useModalStore' | ||
import { SettingsModal } from '../index' | ||
|
||
jest.mock('../../../stores/useModalStore', () => ({ | ||
useModalStore: jest.fn(), | ||
useModal: jest.fn().mockImplementation((id) => ({ | ||
close: jest.fn(), | ||
open: jest.fn(), | ||
visible: id === 'settings', | ||
})), | ||
useSomeModalIsOpen: jest.fn(), | ||
})) | ||
|
||
describe('SettingsModal', () => { | ||
it('Settings Modal does not close on overlay click', () => { | ||
const { getByTestId } = render(<SettingsModal />) | ||
|
||
const overlay = getByTestId('modal-overlay') | ||
|
||
fireEvent.click(overlay) | ||
|
||
// Check Settings modal is still open | ||
const modalContent = getByTestId('settings-modal') | ||
expect(modalContent).toBeInTheDocument() | ||
|
||
// Check close function was not called | ||
const { close } = modalStore.useModal('settings') | ||
|
||
expect(close).not.toHaveBeenCalled() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable padding-line-between-statements */ | ||
import '@testing-library/jest-dom' | ||
import { fireEvent, render } from '@testing-library/react' | ||
import * as modalStore from '~/stores/useModalStore' | ||
import { SourcesTableModal } from '../index' | ||
|
||
jest.mock('~/stores/useModalStore', () => ({ | ||
useModalStore: jest.fn(), | ||
useModal: jest.fn().mockImplementation((id) => ({ | ||
close: jest.fn(), | ||
open: jest.fn(), | ||
visible: id === 'sourcesTable', | ||
})), | ||
useSomeModalIsOpen: jest.fn(), | ||
})) | ||
|
||
describe('SourcesTable Modal', () => { | ||
it('SourcesTable Modal does not close on overlay click', () => { | ||
const { getByTestId } = render(<SourcesTableModal />) | ||
|
||
const overlay = getByTestId('modal-overlay') | ||
|
||
fireEvent.click(overlay) | ||
|
||
// Check SourcesTable modal is still open | ||
const modalContent = getByTestId('sources-table') | ||
expect(modalContent).toBeInTheDocument() | ||
|
||
// Check close function was not called | ||
const { close } = modalStore.useModal('sourcesTable') | ||
|
||
expect(close).not.toHaveBeenCalled() | ||
}) | ||
}) |
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