diff --git a/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx b/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx index fc17602df1..09dfe7ed54 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryDetail/InventoryDetail.jsx @@ -80,19 +80,21 @@ function InventoryDetail({ inventory, i18n }) { } /> - - {instanceGroups.map(ig => ( - - {ig.name} - - ))} - - } - /> + {instanceGroups && instanceGroups.length > 0 && ( + + {instanceGroups.map(ig => ( + + {ig.name} + + ))} + + } + /> + )} ', () => { test('should render details', async () => { + InventoriesAPI.readInstanceGroups.mockResolvedValue({ + data: { + results: associatedInstanceGroups, + }, + }); + let wrapper; await act(async () => { wrapper = mountWithContexts( @@ -105,6 +106,12 @@ describe('', () => { }); test('should load instance groups', async () => { + InventoriesAPI.readInstanceGroups.mockResolvedValue({ + data: { + results: associatedInstanceGroups, + }, + }); + let wrapper; await act(async () => { wrapper = mountWithContexts( @@ -119,4 +126,24 @@ describe('', () => { expect(chip.prop('isReadOnly')).toEqual(true); expect(chip.prop('children')).toEqual('Foo'); }); + + test('should not load instance groups', async () => { + InventoriesAPI.readInstanceGroups.mockResolvedValue({ + data: { + results: [], + }, + }); + + let wrapper; + await act(async () => { + wrapper = mountWithContexts( + + ); + }); + wrapper.update(); + expect(InventoriesAPI.readInstanceGroups).toHaveBeenCalledWith( + mockInventory.id + ); + expect(wrapper.find(`Detail[label="Instance Groups"]`)).toHaveLength(0); + }); });