From 3050653cc6b93bd83ff29697fc6d6f9fb5988dbf Mon Sep 17 00:00:00 2001 From: blaipr Date: Tue, 16 Jun 2026 12:04:03 +0200 Subject: [PATCH 1/2] Convert HostMetrics screen tests from enzyme to React Testing Library Migrate the HostMetrics screen's test suite off enzyme/mountWithContexts onto renderWithContexts (React Testing Library). Behaviour and assertions are preserved; interactions go through accessible roles and real user events. --- .../screens/HostMetrics/HostMetrics.test.js | 46 ++++++++----------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/awx/ui/src/screens/HostMetrics/HostMetrics.test.js b/awx/ui/src/screens/HostMetrics/HostMetrics.test.js index 78d8c2bbd..3030dd3c3 100644 --- a/awx/ui/src/screens/HostMetrics/HostMetrics.test.js +++ b/awx/ui/src/screens/HostMetrics/HostMetrics.test.js @@ -1,10 +1,7 @@ import React from 'react'; -import { act } from 'react-dom/test-utils'; +import { screen, waitFor } from '@testing-library/react'; import { HostMetricsAPI } from 'api'; -import { - mountWithContexts, - waitForElement, -} from '../../../testUtils/enzymeHelpers'; +import { renderWithContexts } from '../../../testUtils/rtlContexts'; import HostMetrics from './HostMetrics'; @@ -23,14 +20,6 @@ const mockHostMetrics = [ }, ]; -function waitForLoaded(wrapper) { - return waitForElement( - wrapper, - 'HostList', - (el) => el.find('ContentLoading').length === 0 - ); -} - describe('', () => { beforeEach(() => { HostMetricsAPI.read.mockResolvedValue({ @@ -46,24 +35,27 @@ describe('', () => { }); test('initially renders successfully', async () => { - await act(async () => { - mountWithContexts( - - ); - }); + renderWithContexts( + + ); + await waitFor(() => + expect(screen.queryByRole('progressbar')).not.toBeInTheDocument() + ); }); test('HostMetrics are retrieved from the api and the components finishes loading', async () => { - let wrapper; - await act(async () => { - wrapper = mountWithContexts(); - }); - await waitForLoaded(wrapper); + renderWithContexts(); + await waitFor(() => + expect(screen.queryByRole('progressbar')).not.toBeInTheDocument() + ); expect(HostMetricsAPI.read).toHaveBeenCalled(); - expect(wrapper.find('HostMetricsListItem')).toHaveLength(1); + expect(screen.getByText('Host name')).toBeInTheDocument(); + expect( + document.querySelectorAll('[id^="host_metrics-row-"]') + ).toHaveLength(1); }); }); From e18a630434dc2958db1dde1bc7a5eb9962830f47 Mon Sep 17 00:00:00 2001 From: blaipr Date: Wed, 17 Jun 2026 09:57:17 +0200 Subject: [PATCH 2/2] Address Copilot review comments --- awx/ui/src/screens/HostMetrics/HostMetrics.test.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/awx/ui/src/screens/HostMetrics/HostMetrics.test.js b/awx/ui/src/screens/HostMetrics/HostMetrics.test.js index 3030dd3c3..648033c16 100644 --- a/awx/ui/src/screens/HostMetrics/HostMetrics.test.js +++ b/awx/ui/src/screens/HostMetrics/HostMetrics.test.js @@ -35,12 +35,7 @@ describe('', () => { }); test('initially renders successfully', async () => { - renderWithContexts( - - ); + renderWithContexts(); await waitFor(() => expect(screen.queryByRole('progressbar')).not.toBeInTheDocument() ); @@ -54,8 +49,6 @@ describe('', () => { expect(HostMetricsAPI.read).toHaveBeenCalled(); expect(screen.getByText('Host name')).toBeInTheDocument(); - expect( - document.querySelectorAll('[id^="host_metrics-row-"]') - ).toHaveLength(1); + expect(screen.getAllByRole('cell', { name: 'Host name' })).toHaveLength(1); }); });