mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
Adds Organization to Inventory List item
This commit is contained in:
@@ -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`)}
|
||||||
|
|||||||
@@ -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,81 +9,117 @@ jest.mock('../../../api/models/Inventories');
|
|||||||
describe('<InventoryListItem />', () => {
|
describe('<InventoryListItem />', () => {
|
||||||
test('initially renders succesfully', () => {
|
test('initially renders succesfully', () => {
|
||||||
mountWithContexts(
|
mountWithContexts(
|
||||||
<I18nProvider>
|
<InventoryListItem
|
||||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
inventory={{
|
||||||
<InventoryListItem
|
id: 1,
|
||||||
inventory={{
|
name: 'Inventory',
|
||||||
|
summary_fields: {
|
||||||
|
organization: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'Inventory',
|
name: 'Default',
|
||||||
summary_fields: {
|
},
|
||||||
organization: {
|
user_capabilities: {
|
||||||
id: 1,
|
edit: true,
|
||||||
name: 'Default',
|
},
|
||||||
},
|
},
|
||||||
user_capabilities: {
|
}}
|
||||||
edit: true,
|
detailUrl="/inventories/inventory/1"
|
||||||
},
|
isSelected
|
||||||
},
|
onSelect={() => {}}
|
||||||
}}
|
/>
|
||||||
detailUrl="/inventories/inventory/1"
|
|
||||||
isSelected
|
|
||||||
onSelect={() => {}}
|
|
||||||
/>
|
|
||||||
</MemoryRouter>
|
|
||||||
</I18nProvider>
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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', () => {
|
test('edit button shown to users with edit capabilities', () => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<I18nProvider>
|
<InventoryListItem
|
||||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
inventory={{
|
||||||
<InventoryListItem
|
id: 1,
|
||||||
inventory={{
|
name: 'Inventory',
|
||||||
|
summary_fields: {
|
||||||
|
organization: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'Inventory',
|
name: 'Default',
|
||||||
summary_fields: {
|
},
|
||||||
organization: {
|
user_capabilities: {
|
||||||
id: 1,
|
edit: true,
|
||||||
name: 'Default',
|
},
|
||||||
},
|
},
|
||||||
user_capabilities: {
|
}}
|
||||||
edit: true,
|
detailUrl="/inventories/inventory/1"
|
||||||
},
|
isSelected
|
||||||
},
|
onSelect={() => {}}
|
||||||
}}
|
/>
|
||||||
detailUrl="/inventories/inventory/1"
|
|
||||||
isSelected
|
|
||||||
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>
|
<InventoryListItem
|
||||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
inventory={{
|
||||||
<InventoryListItem
|
id: 1,
|
||||||
inventory={{
|
name: 'Inventory',
|
||||||
|
summary_fields: {
|
||||||
|
organization: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'Inventory',
|
name: 'Default',
|
||||||
summary_fields: {
|
},
|
||||||
organization: {
|
user_capabilities: {
|
||||||
id: 1,
|
edit: false,
|
||||||
name: 'Default',
|
},
|
||||||
},
|
},
|
||||||
user_capabilities: {
|
}}
|
||||||
edit: false,
|
detailUrl="/inventories/inventory/1"
|
||||||
},
|
isSelected
|
||||||
},
|
onSelect={() => {}}
|
||||||
}}
|
/>
|
||||||
detailUrl="/inventories/inventory/1"
|
|
||||||
isSelected
|
|
||||||
onSelect={() => {}}
|
|
||||||
/>
|
|
||||||
</MemoryRouter>
|
|
||||||
</I18nProvider>
|
|
||||||
);
|
);
|
||||||
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
|
||||||
});
|
});
|
||||||
@@ -93,29 +127,25 @@ describe('<InventoryListItem />', () => {
|
|||||||
InventoriesAPI.copy.mockResolvedValue();
|
InventoriesAPI.copy.mockResolvedValue();
|
||||||
|
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<I18nProvider>
|
<InventoryListItem
|
||||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
inventory={{
|
||||||
<InventoryListItem
|
id: 1,
|
||||||
inventory={{
|
name: 'Inventory',
|
||||||
|
summary_fields: {
|
||||||
|
organization: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'Inventory',
|
name: 'Default',
|
||||||
summary_fields: {
|
},
|
||||||
organization: {
|
user_capabilities: {
|
||||||
id: 1,
|
edit: false,
|
||||||
name: 'Default',
|
copy: true,
|
||||||
},
|
},
|
||||||
user_capabilities: {
|
},
|
||||||
edit: false,
|
}}
|
||||||
copy: true,
|
detailUrl="/inventories/inventory/1"
|
||||||
},
|
isSelected
|
||||||
},
|
onSelect={() => {}}
|
||||||
}}
|
/>
|
||||||
detailUrl="/inventories/inventory/1"
|
|
||||||
isSelected
|
|
||||||
onSelect={() => {}}
|
|
||||||
/>
|
|
||||||
</MemoryRouter>
|
|
||||||
</I18nProvider>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await act(async () =>
|
await act(async () =>
|
||||||
@@ -129,29 +159,25 @@ describe('<InventoryListItem />', () => {
|
|||||||
InventoriesAPI.copy.mockRejectedValue(new Error());
|
InventoriesAPI.copy.mockRejectedValue(new Error());
|
||||||
|
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<I18nProvider>
|
<InventoryListItem
|
||||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
inventory={{
|
||||||
<InventoryListItem
|
id: 1,
|
||||||
inventory={{
|
name: 'Inventory',
|
||||||
|
summary_fields: {
|
||||||
|
organization: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'Inventory',
|
name: 'Default',
|
||||||
summary_fields: {
|
},
|
||||||
organization: {
|
user_capabilities: {
|
||||||
id: 1,
|
edit: false,
|
||||||
name: 'Default',
|
copy: true,
|
||||||
},
|
},
|
||||||
user_capabilities: {
|
},
|
||||||
edit: false,
|
}}
|
||||||
copy: true,
|
detailUrl="/inventories/inventory/1"
|
||||||
},
|
isSelected
|
||||||
},
|
onSelect={() => {}}
|
||||||
}}
|
/>
|
||||||
detailUrl="/inventories/inventory/1"
|
|
||||||
isSelected
|
|
||||||
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,29 +189,25 @@ describe('<InventoryListItem />', () => {
|
|||||||
|
|
||||||
test('should not render copy button', async () => {
|
test('should not render copy button', async () => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<I18nProvider>
|
<InventoryListItem
|
||||||
<MemoryRouter initialEntries={['/inventories']} initialIndex={0}>
|
inventory={{
|
||||||
<InventoryListItem
|
id: 1,
|
||||||
inventory={{
|
name: 'Inventory',
|
||||||
|
summary_fields: {
|
||||||
|
organization: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'Inventory',
|
name: 'Default',
|
||||||
summary_fields: {
|
},
|
||||||
organization: {
|
user_capabilities: {
|
||||||
id: 1,
|
edit: false,
|
||||||
name: 'Default',
|
copy: false,
|
||||||
},
|
},
|
||||||
user_capabilities: {
|
},
|
||||||
edit: false,
|
}}
|
||||||
copy: false,
|
detailUrl="/inventories/inventory/1"
|
||||||
},
|
isSelected
|
||||||
},
|
onSelect={() => {}}
|
||||||
}}
|
/>
|
||||||
detailUrl="/inventories/inventory/1"
|
|
||||||
isSelected
|
|
||||||
onSelect={() => {}}
|
|
||||||
/>
|
|
||||||
</MemoryRouter>
|
|
||||||
</I18nProvider>
|
|
||||||
);
|
);
|
||||||
expect(wrapper.find('CopyButton').length).toBe(0);
|
expect(wrapper.find('CopyButton').length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user