update tests for new user sub-list tables

This commit is contained in:
Keith J. Grant
2021-04-29 16:04:42 -07:00
parent 7c86edd825
commit d1cb0781ce
6 changed files with 93 additions and 55 deletions

View File

@@ -18,7 +18,7 @@ const QS_CONFIG = getQSConfig('organizations', {
type: 'organization', type: 'organization',
}); });
function UserOrganizationsList() { function UserOrganizationList() {
const location = useLocation(); const location = useLocation();
const { id: userId } = useParams(); const { id: userId } = useParams();
@@ -77,4 +77,4 @@ function UserOrganizationsList() {
); );
} }
export default UserOrganizationsList; export default UserOrganizationList;

View File

@@ -7,7 +7,7 @@ import {
waitForElement, waitForElement,
} from '../../../../testUtils/enzymeHelpers'; } from '../../../../testUtils/enzymeHelpers';
import UserOrganizationsList from './UserOrganizationsList'; import UserOrganizationList from './UserOrganizationList';
import { UsersAPI } from '../../../api'; import { UsersAPI } from '../../../api';
jest.mock('../../../api/models/Users'); jest.mock('../../../api/models/Users');
@@ -15,6 +15,7 @@ jest.mock('../../../api/models/Users');
describe('<UserOrganizationlist />', () => { describe('<UserOrganizationlist />', () => {
let history; let history;
let wrapper; let wrapper;
beforeEach(async () => { beforeEach(async () => {
history = createMemoryHistory({ history = createMemoryHistory({
initialEntries: ['/users/1/organizations'], initialEntries: ['/users/1/organizations'],
@@ -36,7 +37,7 @@ describe('<UserOrganizationlist />', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<Route <Route
path="/users/:id/organizations" path="/users/:id/organizations"
component={() => <UserOrganizationsList />} component={() => <UserOrganizationList />}
/>, />,
{ {
context: { context: {
@@ -52,12 +53,15 @@ describe('<UserOrganizationlist />', () => {
); );
}); });
}); });
afterEach(() => { afterEach(() => {
jest.clearAllMocks(); jest.clearAllMocks();
}); });
test('successfully mounts', async () => { test('successfully mounts', async () => {
await waitForElement(wrapper, 'UserOrganizationListItem'); await waitForElement(wrapper, 'UserOrganizationListItem');
}); });
test('calls api to get organizations', () => { test('calls api to get organizations', () => {
expect(UsersAPI.readOrganizations).toBeCalledWith('1', { expect(UsersAPI.readOrganizations).toBeCalledWith('1', {
order_by: 'name', order_by: 'name',

View File

@@ -9,9 +9,13 @@ describe('<UserOrganizationListItem />', () => {
let wrapper; let wrapper;
act(() => { act(() => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<UserOrganizationListItem <table>
organization={{ name: 'foo', id: 1, description: 'Bar' }} <tbody>
/> <UserOrganizationListItem
organization={{ name: 'foo', id: 1, description: 'Bar' }}
/>
</tbody>
</table>
); );
}); });
expect(wrapper.find('UserOrganizationListItem').length).toBe(1); expect(wrapper.find('UserOrganizationListItem').length).toBe(1);
@@ -20,20 +24,24 @@ describe('<UserOrganizationListItem />', () => {
let wrapper; let wrapper;
act(() => { act(() => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<UserOrganizationListItem <table>
organization={{ name: 'foo', id: 1, description: 'Bar' }} <tbody>
/> <UserOrganizationListItem
organization={{ name: 'foo', id: 1, description: 'Bar' }}
/>
</tbody>
</table>
); );
}); });
expect( expect(
wrapper wrapper
.find('DataListCell') .find('Td')
.at(0) .at(0)
.text() .text()
).toBe('foo'); ).toBe('foo');
expect( expect(
wrapper wrapper
.find('DataListCell') .find('Td')
.at(1) .at(1)
.text() .text()
).toBe('Bar'); ).toBe('Bar');

View File

@@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import UserOrganizationsList from './UserOrganizationsList'; import UserOrganizationList from './UserOrganizationList';
function UserOrganizations() { function UserOrganizations() {
return <UserOrganizationsList />; return <UserOrganizationList />;
} }
export default UserOrganizations; export default UserOrganizations;

View File

@@ -19,63 +19,91 @@ describe('<UserRolesListItem/>', () => {
}; };
test('should mount properly', () => { test('should mount properly', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<UserRolesListItem <table>
role={role} <tbody>
detailUrl="/templates/job_template/15/details" <UserRolesListItem
/> role={role}
detailUrl="/templates/job_template/15/details"
/>
</tbody>
</table>
); );
expect(wrapper.length).toBe(1); expect(wrapper.length).toBe(1);
}); });
test('should render proper list item data', () => { test('should render proper list item data', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<UserRolesListItem <table>
role={role} <tbody>
detailUrl="/templates/job_template/15/details" <UserRolesListItem
/> role={role}
detailUrl="/templates/job_template/15/details"
/>
</tbody>
</table>
); );
const cells = wrapper.find('Td');
expect(cells.at(0).text()).toBe('template delete project');
expect( expect(
wrapper.find('PFDataListCell[aria-label="Resource name"]').text() cells.at(1).text()
).toBe('template delete project'); // wrapper.find('PFDataListCell[aria-label="Resource type"]').text()
expect(
wrapper.find('PFDataListCell[aria-label="Resource type"]').text()
).toContain('Job Template'); ).toContain('Job Template');
expect( expect(
wrapper.find('PFDataListCell[aria-label="Resource role"]').text() cells.at(2).text()
// wrapper.find('PFDataListCell[aria-label="Resource role"]').text()
).toContain('Admin'); ).toContain('Admin');
}); });
test('should render deletable chip', () => { test('should render deletable chip', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<UserRolesListItem <table>
role={role} <tbody>
detailUrl="/templates/job_template/15/details" <UserRolesListItem
/> role={role}
detailUrl="/templates/job_template/15/details"
/>
</tbody>
</table>
); );
expect(wrapper.find('Chip').prop('isReadOnly')).toBe(false); expect(wrapper.find('Chip').prop('isReadOnly')).toBe(false);
}); });
test('should render read only chip', () => { test('should render read only chip', () => {
role.summary_fields.user_capabilities.unattach = false; role.summary_fields.user_capabilities.unattach = false;
wrapper = mountWithContexts( wrapper = mountWithContexts(
<UserRolesListItem <table>
role={role} <tbody>
detailUrl="/templates/job_template/15/details" <UserRolesListItem
/> role={role}
detailUrl="/templates/job_template/15/details"
/>
</tbody>
</table>
); );
expect(wrapper.find('Chip').prop('isReadOnly')).toBe(true); expect(wrapper.find('Chip').prop('isReadOnly')).toBe(true);
}); });
test('should display System as name when no resource_name is present in summary_fields', () => { test('should display System as name when no resource_name is present in summary_fields', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<UserRolesListItem <table>
role={{ <tbody>
...role, <UserRolesListItem
summary_fields: { role={{
user_capabilities: { unattach: false }, ...role,
}, summary_fields: {
}} user_capabilities: { unattach: false },
/> },
}}
/>
</tbody>
</table>
); );
expect( expect(
wrapper.find('PFDataListCell[aria-label="Resource name"]').text() wrapper
.find('Td')
.at(0)
.text()
// wrapper.find('PFDataListCell[aria-label="Resource name"]').text()
).toBe('System'); ).toBe('System');
}); });
}); });

View File

@@ -1,6 +1,4 @@
import React from 'react'; import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { I18nProvider } from '@lingui/react';
import { i18n } from '@lingui/core'; import { i18n } from '@lingui/core';
import { en } from 'make-plural/plurals'; import { en } from 'make-plural/plurals';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers'; import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
@@ -14,8 +12,8 @@ i18n.activate('en');
describe('<UserTeamListItem />', () => { describe('<UserTeamListItem />', () => {
test('should render item', () => { test('should render item', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<I18nProvider i18n={i18n}> <table>
<MemoryRouter initialEntries={['/teams']} initialIndex={0}> <tbody>
<UserTeamListItem <UserTeamListItem
team={{ team={{
id: 1, id: 1,
@@ -32,14 +30,14 @@ describe('<UserTeamListItem />', () => {
isSelected={false} isSelected={false}
onSelect={() => {}} onSelect={() => {}}
/> />
</MemoryRouter> </tbody>
</I18nProvider> </table>
); );
const cells = wrapper.find('DataListCell'); const cells = wrapper.find('Td');
expect(cells).toHaveLength(3); expect(cells).toHaveLength(4);
expect(cells.at(0).text()).toEqual('Team 1'); expect(cells.at(1).text()).toEqual('Team 1');
expect(cells.at(1).text()).toEqual('Organization The Org'); expect(cells.at(2).text()).toEqual('The Org');
expect(cells.at(2).text()).toEqual('something something team'); expect(cells.at(3).text()).toEqual('something something team');
}); });
}); });