Fix tests

This commit is contained in:
Rodrigo Nascimento 2017-11-08 18:52:35 -02:00
parent 60c7a9b31e
commit 556cf0d813
No known key found for this signature in database
GPG Key ID: CFCE33B7B01AC335
6 changed files with 37 additions and 25 deletions

View File

@ -6,29 +6,30 @@ import RoomItem from '../app/presentation/RoomItem';
import renderer from 'react-test-renderer';
const date = new Date(2017, 10, 10, 10);
const dateFormat = 'MM-DD-YYYY HH:mm:ss';
jest.mock('react-native-img-cache', () => { return { CachedImage: 'View' } });
it('renders correctly', () => {
expect(renderer.create(<RoomItem type="d" _updatedAt={date} name="name" />).toJSON()).toMatchSnapshot();
expect(renderer.create(<RoomItem type="d" dateFormat={dateFormat} _updatedAt={date} name="name" />).toJSON()).toMatchSnapshot();
});
it('render unread', () => {
expect(renderer.create(<RoomItem type="d" _updatedAt={date} name="name" unread={1} />).toJSON()).toMatchSnapshot();
expect(renderer.create(<RoomItem type="d" dateFormat={dateFormat} _updatedAt={date} name="name" unread={1} />).toJSON()).toMatchSnapshot();
});
it('render unread +999', () => {
expect(renderer.create(<RoomItem type="d" _updatedAt={date} name="name" unread={1000} />).toJSON()).toMatchSnapshot();
expect(renderer.create(<RoomItem type="d" dateFormat={dateFormat} _updatedAt={date} name="name" unread={1000} />).toJSON()).toMatchSnapshot();
});
it('render no icon', () => {
expect(renderer.create(<RoomItem type="X" _updatedAt={date} name="name" />).toJSON()).toMatchSnapshot();
expect(renderer.create(<RoomItem type="X" dateFormat={dateFormat} _updatedAt={date} name="name" />).toJSON()).toMatchSnapshot();
});
it('render private group', () => {
expect(renderer.create(<RoomItem type="g" _updatedAt={date} name="private-group" /> ).toJSON()).toMatchSnapshot();
expect(renderer.create(<RoomItem type="g" dateFormat={dateFormat} _updatedAt={date} name="private-group" /> ).toJSON()).toMatchSnapshot();
});
it('render channel', () => {
expect(renderer.create(<RoomItem type="c" _updatedAt={date} name="general" />).toJSON()).toMatchSnapshot();
expect(renderer.create(<RoomItem type="c" dateFormat={dateFormat} _updatedAt={date} name="general" />).toJSON()).toMatchSnapshot();
});

View File

@ -115,7 +115,7 @@ exports[`render channel 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
</View>
@ -193,7 +193,7 @@ exports[`render no icon 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
</View>
@ -271,7 +271,7 @@ exports[`render private group 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
</View>
@ -386,7 +386,7 @@ exports[`render unread +999 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
<Text
@ -522,7 +522,7 @@ exports[`render unread 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
<Text
@ -658,7 +658,7 @@ exports[`renders correctly 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
</View>

View File

@ -285,7 +285,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
</View>
@ -416,7 +416,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
</View>
@ -547,7 +547,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
<Text
@ -699,7 +699,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
<Text
@ -851,7 +851,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
<Text
@ -1003,7 +1003,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
<Text
@ -1155,7 +1155,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
<Text
@ -1288,7 +1288,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
</View>
@ -1400,7 +1400,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
</View>
@ -1512,7 +1512,7 @@ exports[`Storyshots Channel Cell Direct Messages 1`] = `
}
}
>
2017-11-10T10:00:00-02:00
11-10-2017 10:00:00
</Text>
</View>
</View>

View File

@ -76,7 +76,7 @@ export default class RoomItem extends React.PureComponent {
unread: PropTypes.number,
baseUrl: PropTypes.string,
onPress: PropTypes.func,
Message_DateFormat: PropTypes.string.isRequired
dateFormat: PropTypes.string.isRequired
}
get icon() {
@ -131,7 +131,7 @@ export default class RoomItem extends React.PureComponent {
{this.icon}
<View style={styles.roomNameView}>
<Text style={styles.roomName} ellipsizeMode='tail' numberOfLines={1}>{ name }</Text>
<Text style={styles.update} ellipsizeMode='tail' numberOfLines={1}>{ moment(_updatedAt).format(this.props.Message_DateFormat) }</Text>
<Text style={styles.update} ellipsizeMode='tail' numberOfLines={1}>{ moment(_updatedAt).format(this.props.dateFormat) }</Text>
</View>
{this.renderNumber(unread)}
</TouchableOpacity>

View File

@ -243,7 +243,7 @@ export default class RoomsListView extends React.Component {
key={item._id}
type={item.t}
baseUrl={this.props.Site_Url}
Message_DateFormat={'MM-DD-YYYY HH:mm:ss'}
dateFormat={'MM-DD-YYYY HH:mm:ss'}
onPress={() => this._onPressItem(item._id, item)}
/>
)

View File

@ -4,6 +4,7 @@ import { ScrollView } from 'react-native';
import RoomItem from '../../../app/presentation/RoomItem';
const date = new Date(2017, 10, 10, 10);
const dateFormat = 'MM-DD-YYYY HH:mm:ss';
export default (
<ScrollView>
@ -11,12 +12,14 @@ export default (
type='d'
name='rocket.cat'
_updatedAt={date}
dateFormat={dateFormat}
baseUrl='https://demo.rocket.chat'
/>
<RoomItem
type='d'
unread={0}
_updatedAt={date}
dateFormat={dateFormat}
name='rocket.cat'
baseUrl='https://demo.rocket.chat'
/>
@ -24,6 +27,7 @@ export default (
type='d'
unread={1}
_updatedAt={date}
dateFormat={dateFormat}
name='rocket.cat'
baseUrl='https://demo.rocket.chat'
/>
@ -31,6 +35,7 @@ export default (
type='d'
unread={9}
_updatedAt={date}
dateFormat={dateFormat}
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'
/>
@ -38,6 +43,7 @@ export default (
type='d'
unread={99}
_updatedAt={date}
dateFormat={dateFormat}
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'
/>
@ -45,6 +51,7 @@ export default (
type='d'
unread={100}
_updatedAt={date}
dateFormat={dateFormat}
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'
/>
@ -52,6 +59,7 @@ export default (
type='d'
unread={100000}
_updatedAt={date}
dateFormat={dateFormat}
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'
/>
@ -59,18 +67,21 @@ export default (
type='d'
name='W'
_updatedAt={date}
dateFormat={dateFormat}
unread={-100}
/>
<RoomItem
type='d'
name='WW'
_updatedAt={date}
dateFormat={dateFormat}
unread={-100}
/>
<RoomItem
type='d'
name=''
_updatedAt={date}
dateFormat={dateFormat}
unread={-100}
/>
</ScrollView>