import React from 'react';
import { shallow } from 'enzyme';

import '../../testHelper';
import AdminUserList from '../../../app/assets/javascripts/components/settings/admin_users_list.jsx';

describe('AdminUserList', () => {
  it('renders a List component with correct elements', () => {
    const expectedAdminUsers = [{ id: 1, username: 'testUser', real_name: 'real name', permissions: 3 }];
    const wrapper = shallow(<AdminUserList adminUsers={expectedAdminUsers} />);

    const renderedUsers = wrapper
      .find('List')
      .first()
      .props()
      .elements.map((elem) => {
      return elem.props.user;
    });

    expect(renderedUsers).to.eql(expectedAdminUsers);
  });

  it('renders the correct empty message', () => {
    const expectedAdminUsers = [];
    const wrapper = shallow(<AdminUserList adminUsers={expectedAdminUsers} />);
    const list = wrapper.find('List').first();
    const renderedUsers = list
      .props()
      .elements.map((elem) => {
        return elem.props.user;
      });

    expect(renderedUsers).to.eql([]);
    expect(list.props().none_message).to.equal('no admin users');
  });
});

import React from 'react';
import { Provider } from 'react-redux';
import { render } from 'enzyme';

import '../../testHelper';
import AdminUserList from '../../../app/assets/javascripts/components/settings/admin_users_list.jsx';

describe('AdminUserList', () => {
  it('renders a List component with correct elements', () => {
    const expectedAdminUsers = [{ id: 1, username: 'testUser', real_name: 'real name', permissions: 3 }];
    const renderedList = render(
      <Provider store={reduxStore}>
        <AdminUserList adminUsers={expectedAdminUsers} />
      </Provider>
    );

    expect(renderedList.find('td.user__username').text()).to.eq('testUser');
  });
});

Fix jest tests to work with new List component
Fix jest tests to work with new List component

This rewrites the first test of the admins list to work with the new List. It removes the second, because it was testing the situation of zero admins... which should never be rendered anyway since the settings view requires (super) admin permissions to view.
