forked from TowhidKashem/snapchat-clone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d65ea78
commit b537703
Showing
23 changed files
with
248 additions
and
95 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
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import Avatar, { sizeType, sizeMap } from './index'; | ||
|
||
const defaultProps = { src: '' }; | ||
|
||
describe('<Avatar />', () => { | ||
it('renders without crashing', () => { | ||
const component = shallow(<Avatar {...defaultProps} />); | ||
expect(component.length).toBe(1); | ||
}); | ||
|
||
it('loads img tag with the url as src', () => { | ||
const src = '/path/to/img.png'; | ||
const component = shallow(<Avatar src={src} />); | ||
expect(component.find('img').prop('src')).toEqual(src); | ||
}); | ||
|
||
it('can pass different sizes', () => { | ||
Object.keys(sizeMap).forEach((size) => { | ||
const component = shallow(<Avatar {...defaultProps} size={size as sizeType} />); | ||
expect(component.find('img').prop('width')).toEqual(sizeMap[size]); | ||
}); | ||
}); | ||
}); |
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,47 @@ | ||
import React from 'react'; | ||
import { shallow, mount } from 'enzyme'; | ||
import Button from 'common/Button'; | ||
import Input from 'common/Input'; | ||
import Icon from 'common/Icon'; | ||
import Header from './index'; | ||
|
||
const defaultProps = { showDrawer: jest.fn() }; | ||
|
||
describe('<Header />', () => { | ||
it('renders without crashing', () => { | ||
const component = shallow(<Header {...defaultProps} />); | ||
expect(component.length).toBe(1); | ||
}); | ||
|
||
it('contains avatar/user icons and input field', () => { | ||
const component = shallow(<Header {...defaultProps} />); | ||
expect(component.find(Button).first().prop('buttonClass')).toEqual('btn-user'); | ||
expect(component.find(Button).last().prop('buttonClass')).toEqual('btn-flip-camera'); | ||
expect(component.find(Input)).toHaveLength(1); | ||
}); | ||
|
||
it('contains avatar image', () => { | ||
const image = '/path/to/img.png'; | ||
const component = mount(<Header {...defaultProps} avatar={image} />); | ||
expect(component.find('img').prop('src')).toEqual(image); | ||
}); | ||
|
||
it("contains user icon if avatar prop isn't passed", () => { | ||
const component = mount(<Header {...defaultProps} />); | ||
expect(component.find(Icon).first().prop('icon')).toEqual('faUserCircle'); | ||
}); | ||
|
||
it('clicking avatar opens account drawer', () => { | ||
const component = mount(<Header {...defaultProps} />); | ||
component.find(Button).first().simulate('click'); | ||
expect(defaultProps.showDrawer).toHaveBeenCalledWith({ component: 'account' }); | ||
}); | ||
|
||
it('clicking input field opens search drawer', () => { | ||
const component = mount(<Header {...defaultProps} />); | ||
component.find(Input).simulate('click'); | ||
expect(defaultProps.showDrawer).toHaveBeenCalledWith( | ||
expect.objectContaining({ component: 'search' }) | ||
); | ||
}); | ||
}); |
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,27 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import Icon, { iconMap } from './index'; | ||
|
||
const defaultProps = { icon: 'faSnapchatSquare' }; | ||
|
||
describe('<Icon />', () => { | ||
it('renders without crashing', () => { | ||
const component = shallow(<Icon {...defaultProps} />); | ||
expect(component.length).toBe(1); | ||
}); | ||
|
||
it('loads fontawesome icon', () => { | ||
const component = shallow(<Icon {...defaultProps} />); | ||
expect(component.find(FontAwesomeIcon).prop('icon')).toEqual( | ||
iconMap[defaultProps.icon] | ||
); | ||
}); | ||
|
||
it('supports click handler', () => { | ||
const callback = jest.fn(); | ||
const component = shallow(<Icon {...defaultProps} onClick={callback} />); | ||
component.simulate('click'); | ||
expect(callback).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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,47 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import Input from 'common/Input'; | ||
|
||
const defaultProps = { placeholder: '' }; | ||
|
||
describe('<Input />', () => { | ||
it('renders without crashing', () => { | ||
const component = shallow(<Input {...defaultProps} />); | ||
expect(component.length).toBe(1); | ||
}); | ||
|
||
describe('event handlers', () => { | ||
it('supports `onClick` handler', () => { | ||
const callback = jest.fn(); | ||
const component = shallow(<Input {...defaultProps} onClick={callback} />); | ||
component.simulate('click'); | ||
expect(callback).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('supports `onEnter` handler', () => { | ||
const callback = jest.fn(); | ||
const component = shallow(<Input {...defaultProps} onEnter={callback} />); | ||
component.find('input[type="text"]').simulate('keypress', { key: 'Enter' }); | ||
expect(callback).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('supports `onFocus`, `onBlur` and `onChange` handlers', () => { | ||
const handlers = { | ||
onFocus: jest.fn(), | ||
onBlur: jest.fn(), | ||
onChange: jest.fn() | ||
}; | ||
const events = { | ||
onFocus: 'focus', | ||
onBlur: 'blur', | ||
onChange: 'change' | ||
}; | ||
for (let i in handlers) { | ||
const prop = { [i]: handlers[i] }; | ||
const component = shallow(<Input {...defaultProps} {...prop} />); | ||
component.find('input[type="text"]').simulate(events[i]); | ||
expect(handlers[i]).toHaveBeenCalledTimes(1); | ||
} | ||
}); | ||
}); | ||
}); |
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.