-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MultiWords): Adding MultiWords support (#25)
* Adding multiwords * MultiWords and tests * refacto(examples): Using only one folder example (#26) * WIP * Upgrading create-react-app * Adding multiwords * MultiWords and tests * Fix conflicts * remove package-lock * Fix shine for MultiWords * Fix multiwords shine
- Loading branch information
Marvin Frachet
authored
Oct 18, 2017
1 parent
d24f404
commit 4dcbcfb
Showing
7 changed files
with
192 additions
and
38 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,5 @@ | ||
{ | ||
"expoServerPort": null, | ||
"packagerPort": null, | ||
"packagerPid": null | ||
} |
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,9 @@ | ||
{ | ||
"hostType": "tunnel", | ||
"lanType": "ip", | ||
"dev": true, | ||
"strict": false, | ||
"minify": false, | ||
"urlType": "exp", | ||
"urlRandomness": null | ||
} |
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,82 @@ | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
import { shallow } from 'enzyme'; | ||
import MultiWords from './../multiWords'; | ||
import Line from './../../line/line'; | ||
|
||
const TEXT_SIZE = 12; | ||
const words = [ | ||
{ | ||
width: '20%', | ||
color: 'red', | ||
}, | ||
{ | ||
width: '10%', | ||
color: 'blue', | ||
}, | ||
{ | ||
width: '30%', | ||
color: 'green', | ||
}, | ||
]; | ||
|
||
/** @test {MultiWords#render} */ | ||
describe('MultiWords#render', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<MultiWords words={words} textSize={TEXT_SIZE} />); | ||
}); | ||
|
||
it('shouldnt have any line', () => { | ||
wrapper = shallow(<MultiWords />); | ||
expect(wrapper.find(Line).length).toEqual(0); | ||
}); | ||
|
||
it('should have 3 lines', () => { | ||
expect(wrapper.find(Line).length).toEqual(3); | ||
}); | ||
|
||
words.forEach((word, index) => { | ||
it(`should have the ${index} word with props textSize equals to ${TEXT_SIZE}`, () => { | ||
expect( | ||
wrapper | ||
.find(Line) | ||
.at(index) | ||
.prop('textSize'), | ||
).toEqual(TEXT_SIZE); | ||
}); | ||
|
||
it(`should have the ${index} word with props colors equals to ${word.color}`, () => { | ||
expect( | ||
wrapper | ||
.find(Line) | ||
.at(index) | ||
.prop('color'), | ||
).toEqual(word.color); | ||
}); | ||
|
||
it(`should have the ${index + 1} View with props style.width equals to ${word.width}`, () => { | ||
expect( | ||
wrapper | ||
.find(View) | ||
.at(index + 1) | ||
.prop('style')[1].width, | ||
).toEqual(word.width); | ||
}); | ||
|
||
it(`should have the ${index + 1} View with props style to have a special border style`, () => { | ||
const realIndex = index + 1; | ||
const view = wrapper.find(View).at(realIndex); | ||
const lastIndex = words.length; | ||
const result = | ||
lastIndex === realIndex | ||
? false | ||
: { | ||
borderRightWidth: 12, | ||
borderRightColor: 'transparent', | ||
}; | ||
expect(view.prop('style')[0]).toEqual(result); | ||
}); | ||
}); | ||
}); |
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,49 @@ | ||
import React from "react"; | ||
import { View, StyleSheet } from "react-native"; | ||
import PropTypes from "prop-types"; | ||
import Line from "./../line/line"; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flexDirection: "row" | ||
} | ||
}); | ||
|
||
function MultiWords({ words, textSize }) { | ||
const borderStyle = { | ||
borderRightWidth: textSize, | ||
borderRightColor: "transparent" | ||
}; | ||
|
||
const lastIndex = words.length - 1; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
{words.map((word, index) => ( | ||
<View | ||
key={index} | ||
style={[lastIndex !== index && borderStyle, { width: word.width }]} | ||
> | ||
<Line textSize={textSize} color={word.color} /> | ||
</View> | ||
))} | ||
</View> | ||
); | ||
} | ||
|
||
MultiWords.propTypes = { | ||
words: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
color: PropTypes.string, | ||
width: PropTypes.string.isRequired | ||
}) | ||
), | ||
textSize: PropTypes.number | ||
}; | ||
|
||
MultiWords.defaultProps = { | ||
words: [], | ||
textSize: 12 | ||
}; | ||
|
||
export default MultiWords; |
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