From 3bf1ad3028cd59a8e08e3350456a3031e0ddba5e Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Wed, 26 Feb 2020 23:00:12 -0500 Subject: [PATCH] Move HostToggle into shared components directory --- .../HostToggle}/HostToggle.jsx | 0 .../HostToggle}/HostToggle.test.jsx | 0 .../src/components/HostToggle/index.js | 1 + .../screens/Host/HostDetail/HostDetail.jsx | 2 +- .../screens/Host/HostList/HostList.test.jsx | 15 ++++- .../screens/Host/HostList/HostListItem.jsx | 2 +- .../Host/HostList/HostListItem.test.jsx | 6 +- .../InventoryHosts/InventoryHostItem.jsx | 37 +------------ .../InventoryHosts/InventoryHostItem.test.jsx | 55 +++++++------------ .../InventoryHosts/InventoryHostList.jsx | 35 ------------ .../InventoryHosts/InventoryHostList.test.jsx | 9 ++- 11 files changed, 50 insertions(+), 112 deletions(-) rename awx/ui_next/src/{screens/Host/shared => components/HostToggle}/HostToggle.jsx (100%) rename awx/ui_next/src/{screens/Host/shared => components/HostToggle}/HostToggle.test.jsx (100%) create mode 100644 awx/ui_next/src/components/HostToggle/index.js diff --git a/awx/ui_next/src/screens/Host/shared/HostToggle.jsx b/awx/ui_next/src/components/HostToggle/HostToggle.jsx similarity index 100% rename from awx/ui_next/src/screens/Host/shared/HostToggle.jsx rename to awx/ui_next/src/components/HostToggle/HostToggle.jsx diff --git a/awx/ui_next/src/screens/Host/shared/HostToggle.test.jsx b/awx/ui_next/src/components/HostToggle/HostToggle.test.jsx similarity index 100% rename from awx/ui_next/src/screens/Host/shared/HostToggle.test.jsx rename to awx/ui_next/src/components/HostToggle/HostToggle.test.jsx diff --git a/awx/ui_next/src/components/HostToggle/index.js b/awx/ui_next/src/components/HostToggle/index.js new file mode 100644 index 0000000000..4a772fa95e --- /dev/null +++ b/awx/ui_next/src/components/HostToggle/index.js @@ -0,0 +1 @@ +export { default } from './HostToggle'; diff --git a/awx/ui_next/src/screens/Host/HostDetail/HostDetail.jsx b/awx/ui_next/src/screens/Host/HostDetail/HostDetail.jsx index 7e03abc736..92924886b5 100644 --- a/awx/ui_next/src/screens/Host/HostDetail/HostDetail.jsx +++ b/awx/ui_next/src/screens/Host/HostDetail/HostDetail.jsx @@ -12,7 +12,7 @@ import { VariablesDetail } from '@components/CodeMirrorInput'; import Sparkline from '@components/Sparkline'; import DeleteButton from '@components/DeleteButton'; import { HostsAPI } from '@api'; -import HostToggle from '../shared/HostToggle'; +import HostToggle from '@components/HostToggle'; function HostDetail({ host, i18n, onUpdateHost }) { const { diff --git a/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx b/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx index dbd6199a92..89bc038deb 100644 --- a/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx +++ b/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx @@ -121,7 +121,7 @@ describe('', () => { expect(wrapper.find('HostListItem')).toHaveLength(3); }); - test('should select single item', async () => { + test('should select and deselect a single item', async () => { let wrapper; await act(async () => { wrapper = mountWithContexts(); @@ -141,6 +141,19 @@ describe('', () => { .first() .prop('isSelected') ).toEqual(true); + act(() => { + wrapper + .find('input#select-host-1') + .closest('DataListCheck') + .invoke('onChange')(); + }); + wrapper.update(); + expect( + wrapper + .find('HostListItem') + .first() + .prop('isSelected') + ).toEqual(false); }); test('should select all items', async () => { diff --git a/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx b/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx index 21c238fb23..fec58640a6 100644 --- a/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx +++ b/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx @@ -18,7 +18,7 @@ import { PencilAltIcon } from '@patternfly/react-icons'; import Sparkline from '@components/Sparkline'; import { Host } from '@types'; import styled from 'styled-components'; -import HostToggle from '../shared/HostToggle'; +import HostToggle from '@components/HostToggle'; const DataListAction = styled(_DataListAction)` align-items: center; diff --git a/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx b/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx index c4958e11c2..a241f319cb 100644 --- a/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx +++ b/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx @@ -3,8 +3,6 @@ import { mountWithContexts } from '@testUtils/enzymeHelpers'; import HostsListItem from './HostListItem'; -const onToggleHost = jest.fn(); - const mockHost = { id: 1, name: 'Host 1', @@ -32,13 +30,12 @@ describe('', () => { detailUrl="/host/1" onSelect={() => {}} host={mockHost} - onToggleHost={onToggleHost} /> ); }); afterEach(() => { - jest.clearAllMocks(); + wrapper.unmount(); }); test('edit button shown to users with edit capabilities', () => { @@ -54,7 +51,6 @@ describe('', () => { detailUrl="/host/1" onSelect={() => {}} host={copyMockHost} - onToggleHost={onToggleHost} /> ); expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy(); diff --git a/awx/ui_next/src/screens/Inventory/InventoryHosts/InventoryHostItem.jsx b/awx/ui_next/src/screens/Inventory/InventoryHosts/InventoryHostItem.jsx index cf7678f0e3..863b5fb168 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryHosts/InventoryHostItem.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryHosts/InventoryHostItem.jsx @@ -10,11 +10,11 @@ import { DataListItem, DataListItemCells, DataListItemRow, - Switch, Tooltip, } from '@patternfly/react-core'; import { Link } from 'react-router-dom'; import { PencilAltIcon } from '@patternfly/react-icons'; +import HostToggle from '@components/HostToggle'; import Sparkline from '@components/Sparkline'; import { Host } from '@types'; import styled from 'styled-components'; @@ -27,16 +27,7 @@ const DataListAction = styled(_DataListAction)` `; function InventoryHostItem(props) { - const { - detailUrl, - editUrl, - host, - i18n, - isSelected, - onSelect, - toggleHost, - toggleLoading, - } = props; + const { detailUrl, editUrl, host, i18n, isSelected, onSelect } = props; const recentPlaybookJobs = host.summary_fields.recent_jobs.map(job => ({ ...job, @@ -71,27 +62,7 @@ function InventoryHostItem(props) { aria-labelledby={labelId} id={labelId} > - - toggleHost(host)} - aria-label={i18n._(t`Toggle host`)} - /> - + {host.summary_fields.user_capabilities?.edit && (