Adds Organization to Inventory List item

This commit is contained in:
Alex Corey
2020-11-03 10:49:53 -05:00
parent df54a1edb5
commit 68b399fdef
2 changed files with 161 additions and 131 deletions

View File

@@ -79,6 +79,7 @@ function InventoryListItem({
syncStatus = syncStatus =
inventory.inventory_sources_with_failures > 0 ? 'error' : 'success'; inventory.inventory_sources_with_failures > 0 ? 'error' : 'success';
} }
return ( return (
<DataListItem <DataListItem
key={inventory.id} key={inventory.id}
@@ -112,6 +113,13 @@ function InventoryListItem({
? i18n._(t`Smart Inventory`) ? i18n._(t`Smart Inventory`)
: i18n._(t`Inventory`)} : i18n._(t`Inventory`)}
</DataListCell>, </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"> <DataListCell key="groups-hosts-sources-counts">
<ListGroup> <ListGroup>
{i18n._(t`Groups`)} {i18n._(t`Groups`)}

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 { act } from 'react-dom/test-utils'; import { act } from 'react-dom/test-utils';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers'; import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import { InventoriesAPI } from '../../../api'; import { InventoriesAPI } from '../../../api';
@@ -11,8 +9,6 @@ jest.mock('../../../api/models/Inventories');
describe('<InventoryListItem />', () => { describe('<InventoryListItem />', () => {
test('initially renders succesfully', () => { test('initially renders succesfully', () => {
mountWithContexts( mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
<InventoryListItem <InventoryListItem
inventory={{ inventory={{
id: 1, id: 1,
@@ -31,14 +27,58 @@ describe('<InventoryListItem />', () => {
isSelected isSelected
onSelect={() => {}} onSelect={() => {}}
/> />
</MemoryRouter>
</I18nProvider>
); );
}); });
test('edit button shown to users with edit capabilities', () => {
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( const wrapper = mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
<InventoryListItem <InventoryListItem
inventory={{ inventory={{
id: 1, id: 1,
@@ -57,15 +97,11 @@ describe('<InventoryListItem />', () => {
isSelected isSelected
onSelect={() => {}} onSelect={() => {}}
/> />
</MemoryRouter>
</I18nProvider>
); );
expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy(); expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy();
}); });
test('edit button hidden from users without edit capabilities', () => { test('edit button hidden from users without edit capabilities', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
<InventoryListItem <InventoryListItem
inventory={{ inventory={{
id: 1, id: 1,
@@ -84,8 +120,6 @@ describe('<InventoryListItem />', () => {
isSelected isSelected
onSelect={() => {}} onSelect={() => {}}
/> />
</MemoryRouter>
</I18nProvider>
); );
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy(); expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
}); });
@@ -93,8 +127,6 @@ describe('<InventoryListItem />', () => {
InventoriesAPI.copy.mockResolvedValue(); InventoriesAPI.copy.mockResolvedValue();
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
<InventoryListItem <InventoryListItem
inventory={{ inventory={{
id: 1, id: 1,
@@ -114,8 +146,6 @@ describe('<InventoryListItem />', () => {
isSelected isSelected
onSelect={() => {}} onSelect={() => {}}
/> />
</MemoryRouter>
</I18nProvider>
); );
await act(async () => await act(async () =>
@@ -129,8 +159,6 @@ describe('<InventoryListItem />', () => {
InventoriesAPI.copy.mockRejectedValue(new Error()); InventoriesAPI.copy.mockRejectedValue(new Error());
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
<InventoryListItem <InventoryListItem
inventory={{ inventory={{
id: 1, id: 1,
@@ -150,8 +178,6 @@ describe('<InventoryListItem />', () => {
isSelected isSelected
onSelect={() => {}} onSelect={() => {}}
/> />
</MemoryRouter>
</I18nProvider>
); );
await act(async () => await act(async () =>
wrapper.find('Button[aria-label="Copy"]').prop('onClick')() wrapper.find('Button[aria-label="Copy"]').prop('onClick')()
@@ -163,8 +189,6 @@ describe('<InventoryListItem />', () => {
test('should not render copy button', async () => { test('should not render copy button', async () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<I18nProvider>
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
<InventoryListItem <InventoryListItem
inventory={{ inventory={{
id: 1, id: 1,
@@ -184,8 +208,6 @@ describe('<InventoryListItem />', () => {
isSelected isSelected
onSelect={() => {}} onSelect={() => {}}
/> />
</MemoryRouter>
</I18nProvider>
); );
expect(wrapper.find('CopyButton').length).toBe(0); expect(wrapper.find('CopyButton').length).toBe(0);
}); });