mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 18:40:01 -03:30
update tests for new user sub-list tables
This commit is contained in:
parent
7c86edd825
commit
d1cb0781ce
@ -18,7 +18,7 @@ const QS_CONFIG = getQSConfig('organizations', {
|
||||
type: 'organization',
|
||||
});
|
||||
|
||||
function UserOrganizationsList() {
|
||||
function UserOrganizationList() {
|
||||
const location = useLocation();
|
||||
const { id: userId } = useParams();
|
||||
|
||||
@ -77,4 +77,4 @@ function UserOrganizationsList() {
|
||||
);
|
||||
}
|
||||
|
||||
export default UserOrganizationsList;
|
||||
export default UserOrganizationList;
|
||||
@ -7,7 +7,7 @@ import {
|
||||
waitForElement,
|
||||
} from '../../../../testUtils/enzymeHelpers';
|
||||
|
||||
import UserOrganizationsList from './UserOrganizationsList';
|
||||
import UserOrganizationList from './UserOrganizationList';
|
||||
import { UsersAPI } from '../../../api';
|
||||
|
||||
jest.mock('../../../api/models/Users');
|
||||
@ -15,6 +15,7 @@ jest.mock('../../../api/models/Users');
|
||||
describe('<UserOrganizationlist />', () => {
|
||||
let history;
|
||||
let wrapper;
|
||||
|
||||
beforeEach(async () => {
|
||||
history = createMemoryHistory({
|
||||
initialEntries: ['/users/1/organizations'],
|
||||
@ -36,7 +37,7 @@ describe('<UserOrganizationlist />', () => {
|
||||
wrapper = mountWithContexts(
|
||||
<Route
|
||||
path="/users/:id/organizations"
|
||||
component={() => <UserOrganizationsList />}
|
||||
component={() => <UserOrganizationList />}
|
||||
/>,
|
||||
{
|
||||
context: {
|
||||
@ -52,12 +53,15 @@ describe('<UserOrganizationlist />', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test('successfully mounts', async () => {
|
||||
await waitForElement(wrapper, 'UserOrganizationListItem');
|
||||
});
|
||||
|
||||
test('calls api to get organizations', () => {
|
||||
expect(UsersAPI.readOrganizations).toBeCalledWith('1', {
|
||||
order_by: 'name',
|
||||
@ -9,9 +9,13 @@ describe('<UserOrganizationListItem />', () => {
|
||||
let wrapper;
|
||||
act(() => {
|
||||
wrapper = mountWithContexts(
|
||||
<UserOrganizationListItem
|
||||
organization={{ name: 'foo', id: 1, description: 'Bar' }}
|
||||
/>
|
||||
<table>
|
||||
<tbody>
|
||||
<UserOrganizationListItem
|
||||
organization={{ name: 'foo', id: 1, description: 'Bar' }}
|
||||
/>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
});
|
||||
expect(wrapper.find('UserOrganizationListItem').length).toBe(1);
|
||||
@ -20,20 +24,24 @@ describe('<UserOrganizationListItem />', () => {
|
||||
let wrapper;
|
||||
act(() => {
|
||||
wrapper = mountWithContexts(
|
||||
<UserOrganizationListItem
|
||||
organization={{ name: 'foo', id: 1, description: 'Bar' }}
|
||||
/>
|
||||
<table>
|
||||
<tbody>
|
||||
<UserOrganizationListItem
|
||||
organization={{ name: 'foo', id: 1, description: 'Bar' }}
|
||||
/>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
});
|
||||
expect(
|
||||
wrapper
|
||||
.find('DataListCell')
|
||||
.find('Td')
|
||||
.at(0)
|
||||
.text()
|
||||
).toBe('foo');
|
||||
expect(
|
||||
wrapper
|
||||
.find('DataListCell')
|
||||
.find('Td')
|
||||
.at(1)
|
||||
.text()
|
||||
).toBe('Bar');
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import UserOrganizationsList from './UserOrganizationsList';
|
||||
import UserOrganizationList from './UserOrganizationList';
|
||||
|
||||
function UserOrganizations() {
|
||||
return <UserOrganizationsList />;
|
||||
return <UserOrganizationList />;
|
||||
}
|
||||
export default UserOrganizations;
|
||||
|
||||
@ -19,63 +19,91 @@ describe('<UserRolesListItem/>', () => {
|
||||
};
|
||||
test('should mount properly', () => {
|
||||
wrapper = mountWithContexts(
|
||||
<UserRolesListItem
|
||||
role={role}
|
||||
detailUrl="/templates/job_template/15/details"
|
||||
/>
|
||||
<table>
|
||||
<tbody>
|
||||
<UserRolesListItem
|
||||
role={role}
|
||||
detailUrl="/templates/job_template/15/details"
|
||||
/>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
expect(wrapper.length).toBe(1);
|
||||
});
|
||||
|
||||
test('should render proper list item data', () => {
|
||||
wrapper = mountWithContexts(
|
||||
<UserRolesListItem
|
||||
role={role}
|
||||
detailUrl="/templates/job_template/15/details"
|
||||
/>
|
||||
<table>
|
||||
<tbody>
|
||||
<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(
|
||||
wrapper.find('PFDataListCell[aria-label="Resource name"]').text()
|
||||
).toBe('template delete project');
|
||||
expect(
|
||||
wrapper.find('PFDataListCell[aria-label="Resource type"]').text()
|
||||
cells.at(1).text()
|
||||
// wrapper.find('PFDataListCell[aria-label="Resource type"]').text()
|
||||
).toContain('Job Template');
|
||||
expect(
|
||||
wrapper.find('PFDataListCell[aria-label="Resource role"]').text()
|
||||
cells.at(2).text()
|
||||
// wrapper.find('PFDataListCell[aria-label="Resource role"]').text()
|
||||
).toContain('Admin');
|
||||
});
|
||||
|
||||
test('should render deletable chip', () => {
|
||||
wrapper = mountWithContexts(
|
||||
<UserRolesListItem
|
||||
role={role}
|
||||
detailUrl="/templates/job_template/15/details"
|
||||
/>
|
||||
<table>
|
||||
<tbody>
|
||||
<UserRolesListItem
|
||||
role={role}
|
||||
detailUrl="/templates/job_template/15/details"
|
||||
/>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
expect(wrapper.find('Chip').prop('isReadOnly')).toBe(false);
|
||||
});
|
||||
|
||||
test('should render read only chip', () => {
|
||||
role.summary_fields.user_capabilities.unattach = false;
|
||||
wrapper = mountWithContexts(
|
||||
<UserRolesListItem
|
||||
role={role}
|
||||
detailUrl="/templates/job_template/15/details"
|
||||
/>
|
||||
<table>
|
||||
<tbody>
|
||||
<UserRolesListItem
|
||||
role={role}
|
||||
detailUrl="/templates/job_template/15/details"
|
||||
/>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
expect(wrapper.find('Chip').prop('isReadOnly')).toBe(true);
|
||||
});
|
||||
|
||||
test('should display System as name when no resource_name is present in summary_fields', () => {
|
||||
wrapper = mountWithContexts(
|
||||
<UserRolesListItem
|
||||
role={{
|
||||
...role,
|
||||
summary_fields: {
|
||||
user_capabilities: { unattach: false },
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<table>
|
||||
<tbody>
|
||||
<UserRolesListItem
|
||||
role={{
|
||||
...role,
|
||||
summary_fields: {
|
||||
user_capabilities: { unattach: false },
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import React from 'react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { i18n } from '@lingui/core';
|
||||
import { en } from 'make-plural/plurals';
|
||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||
@ -14,8 +12,8 @@ i18n.activate('en');
|
||||
describe('<UserTeamListItem />', () => {
|
||||
test('should render item', () => {
|
||||
const wrapper = mountWithContexts(
|
||||
<I18nProvider i18n={i18n}>
|
||||
<MemoryRouter initialEntries={['/teams']} initialIndex={0}>
|
||||
<table>
|
||||
<tbody>
|
||||
<UserTeamListItem
|
||||
team={{
|
||||
id: 1,
|
||||
@ -32,14 +30,14 @@ describe('<UserTeamListItem />', () => {
|
||||
isSelected={false}
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
|
||||
const cells = wrapper.find('DataListCell');
|
||||
expect(cells).toHaveLength(3);
|
||||
expect(cells.at(0).text()).toEqual('Team 1');
|
||||
expect(cells.at(1).text()).toEqual('Organization The Org');
|
||||
expect(cells.at(2).text()).toEqual('something something team');
|
||||
const cells = wrapper.find('Td');
|
||||
expect(cells).toHaveLength(4);
|
||||
expect(cells.at(1).text()).toEqual('Team 1');
|
||||
expect(cells.at(2).text()).toEqual('The Org');
|
||||
expect(cells.at(3).text()).toEqual('something something team');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user