From 3dfe062cae698cfbf202b812acd96d2176866cce Mon Sep 17 00:00:00 2001 From: Julia Bardi <90178898+juliaElastic@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:53:36 +0100 Subject: [PATCH] [Fleet] fix create package policy test (#199477) ## Summary Enabling flaky create package policy test, fixing failures Closes https://github.com/elastic/kibana/issues/196463 Closes https://github.com/elastic/kibana/issues/196464 Closes https://github.com/elastic/kibana/issues/196465 Closes https://github.com/elastic/kibana/issues/196466 Closes https://github.com/elastic/kibana/issues/196467 Closes https://github.com/elastic/kibana/issues/196468 Closes https://github.com/elastic/kibana/issues/196469 --- .../single_page_layout/index.test.tsx | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/index.test.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/index.test.tsx index ff89db3e0c842..db223fee26bf2 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/index.test.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/index.test.tsx @@ -52,7 +52,7 @@ jest.mock('../../../../hooks', () => { sendGetStatus: jest .fn() .mockResolvedValue({ data: { isReady: true, missing_requirements: [] } }), - sendGetAgentStatus: jest.fn().mockResolvedValue({ data: { results: { total: 0 } } }), + sendGetAgentStatus: jest.fn().mockResolvedValue({ data: { results: { active: 0 } } }), useGetAgentPolicies: jest.fn().mockReturnValue({ data: { items: [ @@ -154,14 +154,7 @@ afterAll(() => { consoleDebugMock.mockRestore(); }); -// FLAKY: https://github.com/elastic/kibana/issues/196463 -// FLAKY: https://github.com/elastic/kibana/issues/196464 -// FLAKY: https://github.com/elastic/kibana/issues/196465 -// FLAKY: https://github.com/elastic/kibana/issues/196466 -// FLAKY: https://github.com/elastic/kibana/issues/196467 -// FLAKY: https://github.com/elastic/kibana/issues/196468 -// FLAKY: https://github.com/elastic/kibana/issues/196469 -describe.skip('When on the package policy create page', () => { +describe('When on the package policy create page', () => { afterEach(() => { jest.clearAllMocks(); }); @@ -534,7 +527,7 @@ describe.skip('When on the package policy create page', () => { (sendCreateAgentPolicy as jest.MockedFunction).mockClear(); (sendCreatePackagePolicy as jest.MockedFunction).mockClear(); (sendGetAgentStatus as jest.MockedFunction).mockResolvedValue({ - data: { results: { total: 0 } }, + data: { results: { active: 0 } }, }); }); @@ -584,7 +577,7 @@ describe.skip('When on the package policy create page', () => { test('should show modal if agent policy has agents', async () => { (sendGetAgentStatus as jest.MockedFunction).mockResolvedValue({ - data: { results: { total: 1 } }, + data: { results: { active: 1 } }, }); await act(async () => { @@ -787,7 +780,7 @@ describe.skip('When on the package policy create page', () => { test('should not show confirmation modal', async () => { (sendGetAgentStatus as jest.MockedFunction).mockResolvedValueOnce({ - data: { results: { total: 1 } }, + data: { results: { active: 1 } }, }); await act(async () => { @@ -854,8 +847,8 @@ describe.skip('When on the package policy create page', () => { expect(sendGetOneAgentPolicy).not.toHaveBeenCalled(); expect(sendCreateAgentPolicy).toHaveBeenCalledWith( expect.objectContaining({ - monitoring_enabled: ['logs', 'metrics', 'traces'], - name: 'Agent policy 1', + monitoring_enabled: ['logs', 'metrics'], + name: 'Agentless policy for nginx-1', }), { withSysMonitoring: true } ); @@ -868,7 +861,7 @@ describe.skip('When on the package policy create page', () => { test('should create agentless agent policy and package policy when in cloud and agentless API url is set', async () => { fireEvent.click(renderResult.getByTestId(SETUP_TECHNOLOGY_SELECTOR_TEST_SUBJ)); - fireEvent.click(renderResult.getByText('Agentless')); + fireEvent.click(renderResult.getAllByText('Agentless')[0]); await act(async () => { fireEvent.click(renderResult.getByText(/Save and continue/).closest('button')!); }); @@ -879,7 +872,7 @@ describe.skip('When on the package policy create page', () => { name: 'Agentless policy for nginx-1', supports_agentless: true, }), - { withSysMonitoring: false } + { withSysMonitoring: true } ); expect(sendCreatePackagePolicy).toHaveBeenCalled(); @@ -894,7 +887,7 @@ describe.skip('When on the package policy create page', () => { const mockApiCalls = (http: MockedFleetStartServices['http']) => { http.get.mockImplementation(async (path: any) => { if (path === '/api/fleet/agents/setup') { - return Promise.resolve({ data: { results: { total: 0 } } }); + return Promise.resolve({ data: { results: { active: 0 } } }); } if (path === '/api/fleet/package_policies') { return Promise.resolve({ data: { items: [] } });