-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Handle FlagshipUI for cozy-drive cases
- Loading branch information
Showing
8 changed files
with
240 additions
and
31 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
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,14 @@ | ||
import { useEffect } from 'react' | ||
import { useWebviewIntent } from 'cozy-intent' | ||
|
||
export const useSetFlagshipUI = (onMount, onUnmount) => { | ||
const webviewIntent = useWebviewIntent() | ||
|
||
useEffect(() => { | ||
webviewIntent && webviewIntent.call('setFlagshipUI', onMount) | ||
|
||
return () => { | ||
webviewIntent && webviewIntent.call('setFlagshipUI', onUnmount) | ||
} | ||
}, [webviewIntent]) | ||
} |
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,95 @@ | ||
import { renderHook } from '@testing-library/react-hooks' | ||
import { useSetFlagshipUI } from './useSetFlagshipUI' | ||
import { useWebviewIntent } from 'cozy-intent' | ||
|
||
jest.mock('cozy-intent') | ||
|
||
const mockCall = jest.fn() | ||
const mockCSSValue = '#fff' | ||
|
||
beforeEach(() => { | ||
useWebviewIntent.mockImplementation(() => ({ call: mockCall })) | ||
}) | ||
|
||
afterEach(() => { | ||
mockCall.mockClear() | ||
}) | ||
|
||
it('should call webviewIntent with the correct params, once at mount and once at unmount', () => { | ||
const { unmount } = renderHook(() => | ||
useSetFlagshipUI( | ||
{ | ||
bottomBackground: mockCSSValue, | ||
bottomOverlay: 'transparent', | ||
bottomTheme: 'dark', | ||
topBackground: mockCSSValue, | ||
topOverlay: 'transparent', | ||
topTheme: 'dark' | ||
}, | ||
{ | ||
bottomBackground: mockCSSValue, | ||
bottomOverlay: 'transparent', | ||
bottomTheme: 'light', | ||
topBackground: mockCSSValue, | ||
topOverlay: 'transparent', | ||
topTheme: 'light' | ||
} | ||
) | ||
) | ||
|
||
expect(mockCall).toHaveBeenNthCalledWith(1, 'setFlagshipUI', { | ||
bottomBackground: mockCSSValue, | ||
bottomOverlay: 'transparent', | ||
bottomTheme: 'dark', | ||
topBackground: mockCSSValue, | ||
topOverlay: 'transparent', | ||
topTheme: 'dark' | ||
}) | ||
|
||
unmount() | ||
|
||
expect(mockCall).toHaveBeenNthCalledWith(2, 'setFlagshipUI', { | ||
bottomBackground: mockCSSValue, | ||
bottomOverlay: 'transparent', | ||
bottomTheme: 'light', | ||
topBackground: mockCSSValue, | ||
topOverlay: 'transparent', | ||
topTheme: 'light' | ||
}) | ||
}) | ||
|
||
it('should call webviewIntent with the correct params with few args, once at mount and once at unmount', () => { | ||
const { unmount } = renderHook(() => | ||
useSetFlagshipUI( | ||
{ bottomBackground: mockCSSValue }, | ||
{ bottomBackground: mockCSSValue } | ||
) | ||
) | ||
|
||
expect(mockCall).toHaveBeenNthCalledWith(1, 'setFlagshipUI', { | ||
bottomBackground: mockCSSValue | ||
}) | ||
|
||
unmount() | ||
|
||
expect(mockCall).toHaveBeenNthCalledWith(2, 'setFlagshipUI', { | ||
bottomBackground: mockCSSValue | ||
}) | ||
}) | ||
|
||
it('should call nothing with no webviewIntent and not throw', () => { | ||
useWebviewIntent.mockImplementation(() => undefined) | ||
|
||
const { unmount } = renderHook(() => | ||
useSetFlagshipUI( | ||
{ bottomBackground: mockCSSValue }, | ||
{ bottomBackground: mockCSSValue } | ||
) | ||
) | ||
|
||
expect(mockCall).not.toHaveBeenCalled() | ||
|
||
unmount() | ||
|
||
expect(mockCall).not.toHaveBeenCalled() | ||
}) |