-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Insert gif from giphy * Fix UT issue * Fix send giphy media * Add UT for send giphy message
- Loading branch information
1 parent
48967a8
commit 38ebc1b
Showing
16 changed files
with
1,354 additions
and
67 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,51 @@ | ||
import { SearchContextManager } from '@giphy/react-components'; | ||
import { shallow } from 'enzyme'; | ||
import React from 'react'; | ||
import { Giphy, GiphyComponents, Properties } from './giphy'; | ||
|
||
describe('Giphy', () => { | ||
const subject = (props: Partial<Properties>) => { | ||
const allProps: Properties = { | ||
onClose: jest.fn(), | ||
onClickGif: jest.fn(), | ||
...props, | ||
}; | ||
|
||
return shallow(<Giphy {...allProps} />); | ||
}; | ||
|
||
const initialDocument = global.document; | ||
|
||
beforeEach(() => { | ||
// @ts-ignore | ||
global.document = { | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
global.document = initialDocument; | ||
}); | ||
|
||
it('renders GiphyComponents', () => { | ||
const wrapper = subject({}); | ||
const searchContextManager = wrapper.find(SearchContextManager).shallow(); | ||
|
||
expect(searchContextManager.find(GiphyComponents).exists()).toBe(true); | ||
}); | ||
|
||
it('attach mousedown listener to document', () => { | ||
subject({}); | ||
|
||
expect(global.document.addEventListener).toHaveBeenCalledWith('mousedown', expect.any(Function)); | ||
}); | ||
|
||
it('removeEventListener mousedown listener to document', () => { | ||
const wrapper = subject({}); | ||
|
||
(wrapper.instance() as any).componentWillUnmount(); | ||
|
||
expect(global.document.removeEventListener).toHaveBeenCalledWith('mousedown', expect.any(Function)); | ||
}); | ||
}); |
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,62 @@ | ||
import React, { useContext } from 'react'; | ||
import { Grid, SearchBar, SearchContext, SearchContextManager } from '@giphy/react-components'; | ||
import { config } from '../../config'; | ||
|
||
export interface ComponentProperties { | ||
onClickGif: Grid['props']['onGifClick']; | ||
} | ||
|
||
export const GiphyComponents = ({ onClickGif }: Properties) => { | ||
const { fetchGifs, searchKey } = useContext(SearchContext); | ||
return ( | ||
<div className='giphy__container'> | ||
<SearchBar | ||
className='giphy__container-search' | ||
autoFocus | ||
/> | ||
<div className='giphy__container-grid'> | ||
<Grid | ||
key={searchKey} | ||
initialGifs={[]} | ||
columns={2} | ||
width={500} | ||
fetchGifs={fetchGifs} | ||
noLink | ||
onGifClick={onClickGif} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export interface Properties extends ComponentProperties { | ||
onClose: () => void; | ||
} | ||
|
||
export class Giphy extends React.Component<Properties> { | ||
componentDidMount = () => { | ||
document.addEventListener('mousedown', this.clickOutsideGiphyCheck); | ||
}; | ||
|
||
componentWillUnmount = () => { | ||
document.removeEventListener('mousedown', this.clickOutsideGiphyCheck); | ||
}; | ||
|
||
clickOutsideGiphyCheck = (event: MouseEvent) => { | ||
const [giphy] = document.getElementsByClassName('giphy__container'); | ||
|
||
if (giphy && event && event.target) { | ||
if (!giphy.contains(event.target as Node)) { | ||
this.props.onClose(); | ||
} | ||
} | ||
}; | ||
|
||
render = () => { | ||
return ( | ||
<SearchContextManager apiKey={config.giphySdkKey}> | ||
<GiphyComponents {...this.props} /> | ||
</SearchContextManager> | ||
); | ||
}; | ||
} |
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.