mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 02:19:58 -03:30
Adds Organization to Inventory List item
This commit is contained in:
parent
df54a1edb5
commit
68b399fdef
@ -79,6 +79,7 @@ function InventoryListItem({
|
||||
syncStatus =
|
||||
inventory.inventory_sources_with_failures > 0 ? 'error' : 'success';
|
||||
}
|
||||
|
||||
return (
|
||||
<DataListItem
|
||||
key={inventory.id}
|
||||
@ -112,6 +113,13 @@ function InventoryListItem({
|
||||
? i18n._(t`Smart Inventory`)
|
||||
: i18n._(t`Inventory`)}
|
||||
</DataListCell>,
|
||||
<DataListCell key="organization">
|
||||
<Link
|
||||
to={`/organizations/${inventory.summary_fields.organization.id}/details`}
|
||||
>
|
||||
{inventory.summary_fields.organization.name}
|
||||
</Link>
|
||||
</DataListCell>,
|
||||
<DataListCell key="groups-hosts-sources-counts">
|
||||
<ListGroup>
|
||||
{i18n._(t`Groups`)}
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import React from 'react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||
import { InventoriesAPI } from '../../../api';
|
||||
@ -11,81 +9,117 @@ jest.mock('../../../api/models/Inventories');
|
||||
describe('<InventoryListItem />', () => {
|
||||
test('initially renders succesfully', () => {
|
||||
mountWithContexts(
|
||||
<I18nProvider>
|
||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: true,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: true,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
test('should render prompt list item data', () => {
|
||||
const wrapper = mountWithContexts(
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: true,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
);
|
||||
expect(
|
||||
wrapper
|
||||
.find('DataListCell')
|
||||
.at(1)
|
||||
.text()
|
||||
).toBe('Inventory');
|
||||
expect(
|
||||
wrapper
|
||||
.find('DataListCell')
|
||||
.at(2)
|
||||
.text()
|
||||
).toBe('Inventory');
|
||||
expect(
|
||||
wrapper
|
||||
.find('DataListCell')
|
||||
.at(3)
|
||||
.text()
|
||||
).toBe('Default');
|
||||
expect(
|
||||
wrapper
|
||||
.find('DataListCell')
|
||||
.at(4)
|
||||
.text()
|
||||
).toBe('GroupsHostsSources');
|
||||
});
|
||||
|
||||
test('edit button shown to users with edit capabilities', () => {
|
||||
const wrapper = mountWithContexts(
|
||||
<I18nProvider>
|
||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: true,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: true,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
);
|
||||
expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy();
|
||||
});
|
||||
test('edit button hidden from users without edit capabilities', () => {
|
||||
const wrapper = mountWithContexts(
|
||||
<I18nProvider>
|
||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: false,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: false,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
);
|
||||
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
||||
});
|
||||
@ -93,29 +127,25 @@ describe('<InventoryListItem />', () => {
|
||||
InventoriesAPI.copy.mockResolvedValue();
|
||||
|
||||
const wrapper = mountWithContexts(
|
||||
<I18nProvider>
|
||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: false,
|
||||
copy: true,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: false,
|
||||
copy: true,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
);
|
||||
|
||||
await act(async () =>
|
||||
@ -129,29 +159,25 @@ describe('<InventoryListItem />', () => {
|
||||
InventoriesAPI.copy.mockRejectedValue(new Error());
|
||||
|
||||
const wrapper = mountWithContexts(
|
||||
<I18nProvider>
|
||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: false,
|
||||
copy: true,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: false,
|
||||
copy: true,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
);
|
||||
await act(async () =>
|
||||
wrapper.find('Button[aria-label="Copy"]').prop('onClick')()
|
||||
@ -163,29 +189,25 @@ describe('<InventoryListItem />', () => {
|
||||
|
||||
test('should not render copy button', async () => {
|
||||
const wrapper = mountWithContexts(
|
||||
<I18nProvider>
|
||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
<InventoryListItem
|
||||
inventory={{
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Inventory',
|
||||
summary_fields: {
|
||||
organization: {
|
||||
id: 1,
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: false,
|
||||
copy: false,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
name: 'Default',
|
||||
},
|
||||
user_capabilities: {
|
||||
edit: false,
|
||||
copy: false,
|
||||
},
|
||||
},
|
||||
}}
|
||||
detailUrl="/inventories/inventory/1"
|
||||
isSelected
|
||||
onSelect={() => {}}
|
||||
/>
|
||||
);
|
||||
expect(wrapper.find('CopyButton').length).toBe(0);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user