mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
get users if the only user in state is the current user (#470)
This commit is contained in:
parent
ea6ca72f43
commit
2b24dcc731
2 changed files with 50 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import React, { Component, PropTypes } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { first, isEqual, size } from 'lodash';
|
||||
|
||||
import entityGetter from '../../../redux/utilities/entityGetter';
|
||||
import Button from '../../../components/buttons/Button';
|
||||
|
|
@ -29,9 +30,10 @@ class UserManagementPage extends Component {
|
|||
}
|
||||
|
||||
componentWillMount () {
|
||||
const { dispatch, invites, users } = this.props;
|
||||
const { currentUser, dispatch, invites, users } = this.props;
|
||||
|
||||
if (!users.length) {
|
||||
if (!size(users) ||
|
||||
(size(users) === 1 && isEqual(first(users), currentUser))) {
|
||||
dispatch(userActions.loadAll());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ const currentUser = {
|
|||
position: 'Head of Gnar',
|
||||
username: 'gnardog',
|
||||
};
|
||||
const loadUsersAction = { type: 'users_LOAD_REQUEST' };
|
||||
const store = {
|
||||
auth: {
|
||||
user: {
|
||||
|
|
@ -54,4 +55,49 @@ describe('UserManagementPage - component', () => {
|
|||
|
||||
expect(page.text()).toInclude('Listing 2 users');
|
||||
});
|
||||
|
||||
it('gets all users if there are no users in state', () => {
|
||||
const mockStore = reduxMockStore({
|
||||
...store,
|
||||
entities: {
|
||||
...store.entities,
|
||||
users: {
|
||||
...store.entities.users,
|
||||
data: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
mount(connectedComponent(UserManagementPage, { mockStore }));
|
||||
|
||||
expect(mockStore.getActions()).toInclude(loadUsersAction);
|
||||
});
|
||||
|
||||
it('gets all users if the only user in state is the current user', () => {
|
||||
const mockStore = reduxMockStore(store);
|
||||
|
||||
mount(connectedComponent(UserManagementPage, { mockStore }));
|
||||
|
||||
expect(mockStore.getActions()).toInclude(loadUsersAction);
|
||||
});
|
||||
|
||||
it('does not get users if users are already loaded', () => {
|
||||
const mockStore = reduxMockStore({
|
||||
...store,
|
||||
entities: {
|
||||
...store.entities,
|
||||
users: {
|
||||
...store.entities.users,
|
||||
data: {
|
||||
1: { ...currentUser },
|
||||
2: { id: 2, email: 'hi@gnar.dog', full_name: 'GnarDog' },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
mount(connectedComponent(UserManagementPage, { mockStore }));
|
||||
|
||||
expect(mockStore.getActions()).toNotInclude(loadUsersAction);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue