From 60c7a9b31e432ae3b453b73575e3bd88be96aee9 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento <rodrigoknascimento@gmail.com> Date: Wed, 8 Nov 2017 18:46:59 -0200 Subject: [PATCH] Fix tests --- __tests__/RoomItem.js | 14 +- __tests__/__snapshots__/RoomItem.js.snap | 282 ++++++++--- .../__snapshots__/Storyshots.test.js.snap | 470 ++++++++++++++---- storybook/stories/Channels/DirectMessage.js | 12 + 4 files changed, 612 insertions(+), 166 deletions(-) diff --git a/__tests__/RoomItem.js b/__tests__/RoomItem.js index fbc92f2d8..627682345 100644 --- a/__tests__/RoomItem.js +++ b/__tests__/RoomItem.js @@ -5,28 +5,30 @@ import RoomItem from '../app/presentation/RoomItem'; // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer'; +const date = new Date(2017, 10, 10, 10); + jest.mock('react-native-img-cache', () => { return { CachedImage: 'View' } }); it('renders correctly', () => { - expect(renderer.create(<RoomItem type="d" name="name" />).toJSON()).toMatchSnapshot(); + expect(renderer.create(<RoomItem type="d" _updatedAt={date} name="name" />).toJSON()).toMatchSnapshot(); }); it('render unread', () => { - expect(renderer.create(<RoomItem type="d" name="name" unread={1} />).toJSON()).toMatchSnapshot(); + expect(renderer.create(<RoomItem type="d" _updatedAt={date} name="name" unread={1} />).toJSON()).toMatchSnapshot(); }); it('render unread +999', () => { - expect(renderer.create(<RoomItem type="d" name="name" unread={1000} />).toJSON()).toMatchSnapshot(); + expect(renderer.create(<RoomItem type="d" _updatedAt={date} name="name" unread={1000} />).toJSON()).toMatchSnapshot(); }); it('render no icon', () => { - expect(renderer.create(<RoomItem type="X" name="name" />).toJSON()).toMatchSnapshot(); + expect(renderer.create(<RoomItem type="X" _updatedAt={date} name="name" />).toJSON()).toMatchSnapshot(); }); it('render private group', () => { - expect(renderer.create(<RoomItem type="g" name="private-group" /> ).toJSON()).toMatchSnapshot(); + expect(renderer.create(<RoomItem type="g" _updatedAt={date} name="private-group" /> ).toJSON()).toMatchSnapshot(); }); it('render channel', () => { - expect(renderer.create(<RoomItem type="c" name="general" />).toJSON()).toMatchSnapshot(); + expect(renderer.create(<RoomItem type="c" _updatedAt={date} name="general" />).toJSON()).toMatchSnapshot(); }); diff --git a/__tests__/__snapshots__/RoomItem.js.snap b/__tests__/__snapshots__/RoomItem.js.snap index 11d20cb8f..94d4559c8 100644 --- a/__tests__/__snapshots__/RoomItem.js.snap +++ b/__tests__/__snapshots__/RoomItem.js.snap @@ -73,24 +73,51 @@ exports[`render channel 1`] = ` ï£ </Text> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - general - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + general + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> </View> `; @@ -124,24 +151,51 @@ exports[`render no icon 1`] = ` testID={undefined} tvParallaxProperties={undefined} > - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - name - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + name + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> </View> `; @@ -175,24 +229,51 @@ exports[`render private group 1`] = ` testID={undefined} tvParallaxProperties={undefined} > - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - private-group - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + private-group + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> </View> `; @@ -263,24 +344,51 @@ exports[`render unread +999 1`] = ` NA </Text> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - name - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + name + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> <Text accessible={true} allowFontScaling={true} @@ -372,24 +480,51 @@ exports[`render unread 1`] = ` NA </Text> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - name - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + name + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> <Text accessible={true} allowFontScaling={true} @@ -481,23 +616,50 @@ exports[`renders correctly 1`] = ` NA </Text> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - name - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + name + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> </View> `; diff --git a/__tests__/__snapshots__/Storyshots.test.js.snap b/__tests__/__snapshots__/Storyshots.test.js.snap index fb385ea80..8f2f46bb9 100644 --- a/__tests__/__snapshots__/Storyshots.test.js.snap +++ b/__tests__/__snapshots__/Storyshots.test.js.snap @@ -243,24 +243,51 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = ` } /> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - rocket.cat - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + rocket.cat + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> </View> <View accessibilityComponentType={undefined} @@ -347,24 +374,51 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = ` } /> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - rocket.cat - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + rocket.cat + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> </View> <View accessibilityComponentType={undefined} @@ -451,24 +505,51 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = ` } /> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - rocket.cat - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + rocket.cat + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> <Text accessible={true} allowFontScaling={true} @@ -576,24 +657,51 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = ` } /> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> <Text accessible={true} allowFontScaling={true} @@ -701,24 +809,51 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = ` } /> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> <Text accessible={true} allowFontScaling={true} @@ -826,24 +961,51 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = ` } /> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> <Text accessible={true} allowFontScaling={true} @@ -951,24 +1113,51 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = ` } /> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> <Text accessible={true} allowFontScaling={true} @@ -1057,24 +1246,51 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = ` W </Text> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - W - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + W + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> </View> <View accessibilityComponentType={undefined} @@ -1142,24 +1358,51 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = ` WW </Text> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - WW - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + WW + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> </View> <View accessibilityComponentType={undefined} @@ -1227,24 +1470,51 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = ` </Text> </View> - <Text - accessible={true} - allowFontScaling={true} - disabled={false} - ellipsizeMode="tail" - numberOfLines={1} + <View style={ Object { - "color": "#444", "flex": 1, - "fontSize": 16, "marginLeft": 16, "marginRight": 4, } } > - - </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#444", + "flex": 1, + "fontSize": 16, + "height": 16, + "paddingTop": 10, + } + } + > + + </Text> + <Text + accessible={true} + allowFontScaling={true} + disabled={false} + ellipsizeMode="tail" + numberOfLines={1} + style={ + Object { + "color": "#888", + "flex": 1, + "fontSize": 10, + "height": 10, + } + } + > + 2017-11-10T10:00:00-02:00 + </Text> + </View> </View> </View> </RCTScrollView> diff --git a/storybook/stories/Channels/DirectMessage.js b/storybook/stories/Channels/DirectMessage.js index 8ca1c0d01..0f11d6fd1 100644 --- a/storybook/stories/Channels/DirectMessage.js +++ b/storybook/stories/Channels/DirectMessage.js @@ -3,62 +3,74 @@ import { ScrollView } from 'react-native'; import RoomItem from '../../../app/presentation/RoomItem'; +const date = new Date(2017, 10, 10, 10); + export default ( <ScrollView> <RoomItem type='d' name='rocket.cat' + _updatedAt={date} baseUrl='https://demo.rocket.chat' /> <RoomItem type='d' unread={0} + _updatedAt={date} name='rocket.cat' baseUrl='https://demo.rocket.chat' /> <RoomItem type='d' unread={1} + _updatedAt={date} name='rocket.cat' baseUrl='https://demo.rocket.chat' /> <RoomItem type='d' unread={9} + _updatedAt={date} name="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries" baseUrl='https://demo.rocket.chat' /> <RoomItem type='d' unread={99} + _updatedAt={date} name="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries" baseUrl='https://demo.rocket.chat' /> <RoomItem type='d' unread={100} + _updatedAt={date} name="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries" baseUrl='https://demo.rocket.chat' /> <RoomItem type='d' unread={100000} + _updatedAt={date} name="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries" baseUrl='https://demo.rocket.chat' /> <RoomItem type='d' name='W' + _updatedAt={date} unread={-100} /> <RoomItem type='d' name='WW' + _updatedAt={date} unread={-100} /> <RoomItem type='d' name='' + _updatedAt={date} unread={-100} /> </ScrollView> -- GitLab