forked from react-native-elements/react-native-elements
-
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.
- Added snapshot test for Text Component - Updated tests for Text to use loop to search for style
- Loading branch information
Showing
6 changed files
with
631 additions
and
6 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,8 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 |
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,117 @@ | ||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
import Button from '../Button'; | ||
import colors from '../../config/colors'; | ||
|
||
describe('Button Component', () => { | ||
it('should render without issues', () => { | ||
const component = shallow(<Button />); | ||
|
||
expect(component.length).toBe(1); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it('should show loading indicator', () => { | ||
const component = shallow(<Button loading />); | ||
|
||
expect(component.find('ActivityIndicator').length).toBe(1); | ||
}); | ||
|
||
it('should have onPress event', () => { | ||
const onPress = jest.fn(); | ||
const component = shallow(<Button onPress={onPress} />); | ||
|
||
component.simulate('press'); | ||
expect(onPress).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should render primary color', () => { | ||
const component = shallow(<Button primary />); | ||
|
||
expect(component.find('View').props().style[0].backgroundColor).toBe(colors.primary) | ||
}); | ||
|
||
it('should render primary1 color', () => { | ||
const component = shallow(<Button primary1 />); | ||
const styles = component.find('View').props().style | ||
let backgroundColorStyles = [] | ||
for(let i = 0; i < styles.length; i++) { | ||
if(styles[i] && styles[i].hasOwnProperty('backgroundColor')) { | ||
backgroundColorStyles.push(styles[i].backgroundColor); | ||
} | ||
} | ||
|
||
expect(backgroundColorStyles[1]).toBe(colors.primary1) | ||
}); | ||
|
||
it('should render primary2 color', () => { | ||
const component = shallow(<Button primary2 />); | ||
const styles = component.find('View').props().style | ||
let backgroundColorStyles = [] | ||
for(let i = 0; i < styles.length; i++) { | ||
if(styles[i] && styles[i].hasOwnProperty('backgroundColor')) { | ||
backgroundColorStyles.push(styles[i].backgroundColor); | ||
} | ||
} | ||
|
||
expect(backgroundColorStyles[1]).toBe(colors.primary2) | ||
}); | ||
|
||
it('should render secondary color', () => { | ||
const component = shallow(<Button secondary />); | ||
const styles = component.find('View').props().style | ||
let backgroundColorStyles = [] | ||
for(let i = 0; i < styles.length; i++) { | ||
if(styles[i] && styles[i].hasOwnProperty('backgroundColor')) { | ||
backgroundColorStyles.push(styles[i].backgroundColor); | ||
} | ||
} | ||
|
||
expect(backgroundColorStyles[1]).toBe(colors.secondary) | ||
}); | ||
|
||
it('should render secondary2 color', () => { | ||
const component = shallow(<Button secondary2 />); | ||
const styles = component.find('View').props().style | ||
let backgroundColorStyles = [] | ||
for(let i = 0; i < styles.length; i++) { | ||
if(styles[i] && styles[i].hasOwnProperty('backgroundColor')) { | ||
backgroundColorStyles.push(styles[i].backgroundColor); | ||
} | ||
} | ||
|
||
expect(backgroundColorStyles[1]).toBe(colors.secondary2) | ||
}); | ||
|
||
it('should render secondary3 color', () => { | ||
const component = shallow(<Button secondary3 />); | ||
const styles = component.find('View').props().style | ||
let backgroundColorStyles = [] | ||
for(let i = 0; i < styles.length; i++) { | ||
if(styles[i] && styles[i].hasOwnProperty('backgroundColor')) { | ||
backgroundColorStyles.push(styles[i].backgroundColor); | ||
} | ||
} | ||
|
||
expect(backgroundColorStyles[1]).toBe(colors.secondary3) | ||
}); | ||
|
||
it('should render custom background color', () => { | ||
const component = shallow(<Button backgroundColor='#777' />); | ||
const styles = component.find('View').props().style | ||
let backgroundColorStyles = [] | ||
for(let i = 0; i < styles.length; i++) { | ||
if(styles[i] && styles[i].hasOwnProperty('backgroundColor')) { | ||
backgroundColorStyles.push(styles[i].backgroundColor); | ||
} | ||
} | ||
|
||
expect(backgroundColorStyles[1]).toBe('#777') | ||
}); | ||
|
||
it('should render title as text inside the button', () => { | ||
const component = shallow(<Button title="My Button" />); | ||
|
||
expect(component.find("View").props().children[2].props.children).toBe("My Button"); | ||
}); | ||
}); |
Oops, something went wrong.