-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: group configurations - resolve discussions
fix: [AXIMST-714] icon is aligned with text (#210)
- Loading branch information
1 parent
48b0aeb
commit 5afea18
Showing
14 changed files
with
218 additions
and
53 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,24 @@ | ||
import { useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const PromptIfDirty = ({ dirty }) => { | ||
useEffect(() => { | ||
// eslint-disable-next-line consistent-return | ||
const handleBeforeUnload = (event) => { | ||
if (dirty) { | ||
event.preventDefault(); | ||
} | ||
}; | ||
window.addEventListener('beforeunload', handleBeforeUnload); | ||
|
||
return () => { | ||
window.removeEventListener('beforeunload', handleBeforeUnload); | ||
}; | ||
}, [dirty]); | ||
|
||
return null; | ||
}; | ||
PromptIfDirty.propTypes = { | ||
dirty: PropTypes.bool.isRequired, | ||
}; | ||
export default PromptIfDirty; |
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,72 @@ | ||
import React from 'react'; | ||
import { render, unmountComponentAtNode } from 'react-dom'; | ||
import { act } from 'react-dom/test-utils'; | ||
import PromptIfDirty from './PromptIfDirty'; | ||
|
||
describe('PromptIfDirty', () => { | ||
let container = null; | ||
let mockEvent = null; | ||
|
||
beforeEach(() => { | ||
container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
mockEvent = new Event('beforeunload'); | ||
jest.spyOn(window, 'addEventListener'); | ||
jest.spyOn(window, 'removeEventListener'); | ||
jest.spyOn(mockEvent, 'preventDefault'); | ||
Object.defineProperty(mockEvent, 'returnValue', { writable: true }); | ||
mockEvent.returnValue = ''; | ||
}); | ||
|
||
afterEach(() => { | ||
window.addEventListener.mockRestore(); | ||
window.removeEventListener.mockRestore(); | ||
mockEvent.preventDefault.mockRestore(); | ||
mockEvent = null; | ||
unmountComponentAtNode(container); | ||
container.remove(); | ||
container = null; | ||
}); | ||
|
||
it('should add event listener on mount', () => { | ||
act(() => { | ||
render(<PromptIfDirty dirty />, container); | ||
}); | ||
|
||
expect(window.addEventListener).toHaveBeenCalledWith('beforeunload', expect.any(Function)); | ||
}); | ||
|
||
it('should remove event listener on unmount', () => { | ||
act(() => { | ||
render(<PromptIfDirty dirty />, container); | ||
}); | ||
act(() => { | ||
unmountComponentAtNode(container); | ||
}); | ||
|
||
expect(window.removeEventListener).toHaveBeenCalledWith('beforeunload', expect.any(Function)); | ||
}); | ||
|
||
it('should call preventDefault and set returnValue when dirty is true', () => { | ||
act(() => { | ||
render(<PromptIfDirty dirty />, container); | ||
}); | ||
act(() => { | ||
window.dispatchEvent(mockEvent); | ||
}); | ||
|
||
expect(mockEvent.preventDefault).toHaveBeenCalled(); | ||
expect(mockEvent.returnValue).toBe(''); | ||
}); | ||
|
||
it('should not call preventDefault when dirty is false', () => { | ||
act(() => { | ||
render(<PromptIfDirty dirty={false} />, container); | ||
}); | ||
act(() => { | ||
window.dispatchEvent(mockEvent); | ||
}); | ||
|
||
expect(mockEvent.preventDefault).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
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
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
Oops, something went wrong.