diff --git a/app/components/__snapshots__/badge.test.js.snap b/app/components/__snapshots__/badge.test.js.snap new file mode 100644 index 000000000..7504a2d53 --- /dev/null +++ b/app/components/__snapshots__/badge.test.js.snap @@ -0,0 +1,56 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Badge should match snapshot 1`] = ` + + + + 1 + + + +`; diff --git a/app/components/badge.js b/app/components/badge.js index d74e33ea1..6366d3534 100644 --- a/app/components/badge.js +++ b/app/components/badge.js @@ -15,8 +15,8 @@ import { export default class Badge extends PureComponent { static defaultProps = { extraPaddingHorizontal: 10, - minHeight: 0, - minWidth: 0, + minHeight: 20, + minWidth: 20, }; static propTypes = { @@ -81,7 +81,7 @@ export default class Badge extends PureComponent { } else { width = e.nativeEvent.layout.width + this.props.extraPaddingHorizontal; } - width = Math.max(width + 10, this.props.minWidth); + width = Math.max(this.props.count < 10 ? width : width + 10, this.props.minWidth); const borderRadius = width / 2; this.setNativeProps({ style: { @@ -105,12 +105,19 @@ export default class Badge extends PureComponent { extra.marginBottom = 1; } return ( - - {text} - + + + {text} + + + ); }; @@ -124,14 +131,7 @@ export default class Badge extends PureComponent { {...this.panResponder.panHandlers} onPress={this.handlePress} > - - - {this.renderText()} - - + {this.renderText()} ); } diff --git a/app/components/badge.test.js b/app/components/badge.test.js new file mode 100644 index 000000000..7e2a05975 --- /dev/null +++ b/app/components/badge.test.js @@ -0,0 +1,27 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import React from 'react'; +import {Text, TouchableWithoutFeedback} from 'react-native'; +import {shallow} from 'enzyme'; + +import Badge from './badge'; + +describe('Badge', () => { + const baseProps = { + count: 1, + countStyle: {color: '#145dbf', fontSize: 10}, + style: {backgroundColor: '#ffffff'}, + onPress: jest.fn(), + }; + + test('should match snapshot', () => { + const wrapper = shallow( + + ); + + expect(wrapper.instance().renderText()).toMatchSnapshot(); + expect(wrapper.find(TouchableWithoutFeedback).exists()).toEqual(true); + expect(wrapper.find(Text).first().props().children).toContain('1'); + }); +}); diff --git a/app/components/sidebars/main/channels_list/channel_item/channel_item.js b/app/components/sidebars/main/channels_list/channel_item/channel_item.js index edc3f6b5d..ff7c9c71c 100644 --- a/app/components/sidebars/main/channels_list/channel_item/channel_item.js +++ b/app/components/sidebars/main/channels_list/channel_item/channel_item.js @@ -162,8 +162,6 @@ export default class ChannelItem extends PureComponent { style={style.badge} countStyle={style.mention} count={mentions} - minHeight={20} - minWidth={20} onPress={this.onPress} /> ); diff --git a/app/components/sidebars/main/channels_list/switch_teams_button/switch_teams_button.js b/app/components/sidebars/main/channels_list/switch_teams_button/switch_teams_button.js index c894b3560..772b6f1aa 100644 --- a/app/components/sidebars/main/channels_list/switch_teams_button/switch_teams_button.js +++ b/app/components/sidebars/main/channels_list/switch_teams_button/switch_teams_button.js @@ -53,8 +53,6 @@ export default class SwitchTeamsButton extends React.PureComponent { style={styles.badge} countStyle={styles.mention} count={mentionCount} - minHeight={20} - minWidth={20} /> ); diff --git a/app/components/sidebars/main/teams_list/teams_list_item/teams_list_item.js b/app/components/sidebars/main/teams_list/teams_list_item/teams_list_item.js index 18fd06d11..7978cfd76 100644 --- a/app/components/sidebars/main/teams_list/teams_list_item/teams_list_item.js +++ b/app/components/sidebars/main/teams_list/teams_list_item/teams_list_item.js @@ -61,8 +61,6 @@ export default class TeamsListItem extends React.PureComponent { style={styles.badge} countStyle={styles.mention} count={mentionCount} - minHeight={20} - minWidth={20} /> ); diff --git a/app/screens/channel/channel_nav_bar/channel_drawer_button.js b/app/screens/channel/channel_nav_bar/channel_drawer_button.js index df71b4043..6baf65cb2 100644 --- a/app/screens/channel/channel_nav_bar/channel_drawer_button.js +++ b/app/screens/channel/channel_nav_bar/channel_drawer_button.js @@ -113,8 +113,6 @@ class ChannelDrawerButton extends PureComponent { style={style.badge} countStyle={style.mention} count={badgeCount} - minHeight={20} - minWidth={20} onPress={this.handlePress} /> );