Skip to content

Commit

Permalink
refactor(component): skip one view level on multiwords
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrachet committed Jun 9, 2018
1 parent 9ce0907 commit 8120b8a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
19 changes: 10 additions & 9 deletions src/multiWords/__tests__/multiWords.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { View } from 'react-native';
import { shallow } from 'enzyme';
import MultiWords from './../multiWords';
import Placeholder from './../../placeholder';
Expand Down Expand Up @@ -56,21 +55,23 @@ describe('MultiWords#render', () => {
).toEqual(word.color);
});

it(`should have the ${index + 1} View with props style.width equals to ${word.width}`, () => {
it(`should have the ${index + 1} Placeholder.Line with props style.width equals to ${
word.width
}`, () => {
expect(
wrapper
.find(View)
.at(index + 1)
.find(Placeholder.Line)
.at(index)
.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;
it(`should have the ${index +
1} Placeholder.Line with props style to have a special border style`, () => {
const view = wrapper.find(Placeholder.Line).at(index);
const lastIndex = words.length - 1;
const result =
lastIndex === realIndex
lastIndex === index
? false
: {
borderRightWidth: 12,
Expand Down
9 changes: 6 additions & 3 deletions src/multiWords/multiWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ function MultiWords({ words, textSize }) {
return (
<View style={styles.container}>
{words.map((word, index) => (
<View key={index} style={[lastIndex !== index && borderStyle, { width: word.width }]}>
<Placeholder.Line textSize={textSize} color={word.color} />
</View>
<Placeholder.Line
textSize={textSize}
color={word.color}
key={index}
style={[lastIndex !== index && borderStyle, { width: word.width }]}
/>
))}
</View>
);
Expand Down
15 changes: 12 additions & 3 deletions src/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ const compose = (f, g) => x => f(g(x));
export default {
ImageContent: connect(ImageContent),
Paragraph: connect(Paragraph),
Media: compose(connect, stylify(computeStyleMedia))(View),
Line: compose(connect, stylify(computeStyleLine))(View),
Media: compose(
connect,
stylify(computeStyleMedia),
)(View),
Line: compose(
connect,
stylify(computeStyleLine),
)(View),
MultiWords: connect(MultiWords),
Box: compose(connect, stylify(computeStyleBox))(View),
Box: compose(
connect,
stylify(computeStyleBox),
)(View),
connect,
};

0 comments on commit 8120b8a

Please sign in to comment.