diff --git a/components/__snapshots__/user_list.test.jsx.snap b/components/__snapshots__/user_list.test.jsx.snap new file mode 100644 index 000000000000..388b86a04c65 --- /dev/null +++ b/components/__snapshots__/user_list.test.jsx.snap @@ -0,0 +1,49 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/UserList should match default snapshot 1`] = ` +
+
+

+ +

+
+
+`; + +exports[`components/UserList should match default snapshot when there are users 1`] = ` +
+ + +
+`; diff --git a/components/user_list.jsx b/components/user_list.jsx index c4024f6368ae..2192a9f484c8 100644 --- a/components/user_list.jsx +++ b/components/user_list.jsx @@ -1,6 +1,5 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -/* eslint-disable react/no-string-refs */ import PropTypes from 'prop-types'; import React from 'react'; @@ -21,7 +20,7 @@ export default class UserList extends React.PureComponent { isDisabled: PropTypes.bool, // the type of user list row to render - rowComponentType: PropTypes.node, + rowComponentType: PropTypes.object, } static defaultProps = { @@ -32,9 +31,14 @@ export default class UserList extends React.PureComponent { rowComponentType: UserListRow, } + constructor(props) { + super(props); + this.containerRef = React.createRef(); + } + scrollToTop = () => { - if (this.refs.container) { - this.refs.container.scrollTop = 0; + if (this.containerRef.current) { + this.containerRef.current.scrollTop = 0; } } @@ -80,10 +84,9 @@ export default class UserList extends React.PureComponent { } return ( -
+
{content}
); } } -/* eslint-enable react/no-string-refs */ diff --git a/components/user_list.test.jsx b/components/user_list.test.jsx new file mode 100644 index 000000000000..b01c212c06a6 --- /dev/null +++ b/components/user_list.test.jsx @@ -0,0 +1,30 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import React from 'react'; +import {shallow} from 'enzyme'; + +import UserList from './user_list.jsx'; + +describe('components/UserList', () => { + test('should match default snapshot', () => { + const wrapper = shallow( + , + ); + expect(wrapper).toMatchSnapshot(); + }); + + test('should match default snapshot when there are users', () => { + const props = { + users: [ + {id: 'id1'}, + {id: 'id2'}, + ], + actionUserProps: {}, + }; + const wrapper = shallow( + , + ); + expect(wrapper).toMatchSnapshot(); + }); +});