From 68b399fdef2f78a7df1b2226df2c80e8bfd3f94d Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Tue, 3 Nov 2020 10:49:53 -0500 Subject: [PATCH 1/2] Adds Organization to Inventory List item --- .../InventoryList/InventoryListItem.jsx | 8 + .../InventoryList/InventoryListItem.test.jsx | 284 ++++++++++-------- 2 files changed, 161 insertions(+), 131 deletions(-) diff --git a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx index 6d18102d40..5e644cde9d 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx @@ -79,6 +79,7 @@ function InventoryListItem({ syncStatus = inventory.inventory_sources_with_failures > 0 ? 'error' : 'success'; } + return ( , + + + {inventory.summary_fields.organization.name} + + , {i18n._(t`Groups`)} diff --git a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx index fc5bf838f2..7507f37cb1 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx @@ -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('', () => { test('initially renders succesfully', () => { mountWithContexts( - - - {}} - /> - - + name: 'Default', + }, + user_capabilities: { + edit: true, + }, + }, + }} + detailUrl="/inventories/inventory/1" + isSelected + onSelect={() => {}} + /> ); }); + + test('should render prompt list item data', () => { + const wrapper = mountWithContexts( + {}} + /> + ); + 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( - - - {}} - /> - - + 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( - - - {}} - /> - - + name: 'Default', + }, + user_capabilities: { + edit: false, + }, + }, + }} + detailUrl="/inventories/inventory/1" + isSelected + onSelect={() => {}} + /> ); expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy(); }); @@ -93,29 +127,25 @@ describe('', () => { InventoriesAPI.copy.mockResolvedValue(); const wrapper = mountWithContexts( - - - {}} - /> - - + name: 'Default', + }, + user_capabilities: { + edit: false, + copy: true, + }, + }, + }} + detailUrl="/inventories/inventory/1" + isSelected + onSelect={() => {}} + /> ); await act(async () => @@ -129,29 +159,25 @@ describe('', () => { InventoriesAPI.copy.mockRejectedValue(new Error()); const wrapper = mountWithContexts( - - - {}} - /> - - + 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('', () => { test('should not render copy button', async () => { const wrapper = mountWithContexts( - - - {}} - /> - - + name: 'Default', + }, + user_capabilities: { + edit: false, + copy: false, + }, + }, + }} + detailUrl="/inventories/inventory/1" + isSelected + onSelect={() => {}} + /> ); expect(wrapper.find('CopyButton').length).toBe(0); }); From e372f4f8f6b27343c4b0caa07ec5806c5cfe5c45 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Thu, 5 Nov 2020 16:54:48 -0500 Subject: [PATCH 2/2] Adds list item label --- .../screens/Inventory/InventoryList/InventoryListItem.jsx | 5 +++++ .../Inventory/InventoryList/InventoryListItem.test.jsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx index 5e644cde9d..7e3feaec33 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx @@ -39,6 +39,10 @@ const ListGroup = styled.div` display: inline-block; `; +const OrgLabel = styled.b` + margin-right: 20px; +`; + function InventoryListItem({ inventory, isSelected, @@ -114,6 +118,7 @@ function InventoryListItem({ : i18n._(t`Inventory`)} , + {i18n._(t`Organization`)} diff --git a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx index 7507f37cb1..b23878a651 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx @@ -68,7 +68,7 @@ describe('', () => { .find('DataListCell') .at(3) .text() - ).toBe('Default'); + ).toBe('OrganizationDefault'); expect( wrapper .find('DataListCell')