-
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.
Fix(web-react): Warn when icon asset is missing from the map
- Loading branch information
Showing
2 changed files
with
45 additions
and
9 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 |
---|---|---|
@@ -1,20 +1,49 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useIcon } from '../useIcon'; | ||
import React, { ReactNode } from 'react'; | ||
import warning from '../../common/utilities/warning'; | ||
import { IconsProvider } from '../../context/IconsContext'; | ||
import { useIcon } from '../useIcon'; | ||
|
||
jest.mock('../../common/utilities/warning', () => jest.fn()); | ||
|
||
describe('useIcon', () => { | ||
const mockedWarning = warning as jest.MockedFunction<typeof warning>; | ||
const icons = { warning: '<path d="ERRW ADSFDSFDS"></path>' }; | ||
const wrapper = ({ children }: { children: ReactNode }) => <IconsProvider value={icons}>{children}</IconsProvider>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return empty string', () => { | ||
const { result } = renderHook(() => useIcon('')); | ||
|
||
expect(result.current).toBe(''); | ||
}); | ||
|
||
it('should raise warning when icon name is missing from the assets', () => { | ||
renderHook(() => useIcon('warning'), { | ||
wrapper: ({ children }: { children: ReactNode }) => <IconsProvider value={{}}>{children}</IconsProvider>, | ||
}); | ||
|
||
expect(mockedWarning).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should return icon path', () => { | ||
const icons = { warning: '<path d="ERRW ADSFDSFDS"></path>' }; | ||
const wrapper = ({ children }: { children: ReactNode }) => <IconsProvider value={icons}>{children}</IconsProvider>; | ||
const { result } = renderHook(() => useIcon('warning'), { wrapper }); | ||
|
||
expect(result.current).toBe('<path d="ERRW ADSFDSFDS"></path>'); | ||
}); | ||
|
||
it('should return icon path based on fallback icon', () => { | ||
const { result } = renderHook(() => useIcon('danger'), { wrapper }); | ||
|
||
expect(result.current).toBe('<path d="ERRW ADSFDSFDS"></path>'); | ||
}); | ||
|
||
it('should raise warning when fallback icon name is used', () => { | ||
renderHook(() => useIcon('danger'), { wrapper }); | ||
|
||
expect(mockedWarning).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