-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spike for unusual test timeout for fleet #201443
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
*/ | ||
|
||
import React from 'react'; | ||
import { fireEvent, act } from '@testing-library/react'; | ||
import { fireEvent, waitFor } from '@testing-library/react'; | ||
|
||
import { createFleetTestRendererMock } from '../../../../../../mock'; | ||
|
||
|
@@ -44,13 +44,11 @@ test('it should allow to add a new host', async () => { | |
test('it should allow to remove an host', async () => { | ||
const { utils, mockOnChange } = renderInput(['http://host1.com', 'http://host2.com']); | ||
|
||
await act(async () => { | ||
const deleteRowEl = await utils.container.querySelector('[aria-label="Delete row"]'); | ||
if (!deleteRowEl) { | ||
throw new Error('Delete row button not found'); | ||
} | ||
fireEvent.click(deleteRowEl); | ||
}); | ||
const deleteRowEl = await utils.container.querySelector('[aria-label="Delete row"]'); | ||
if (!deleteRowEl) { | ||
throw new Error('Delete row button not found'); | ||
} | ||
fireEvent.click(deleteRowEl); | ||
|
||
expect(mockOnChange).toHaveBeenCalledWith(['http://host2.com']); | ||
}); | ||
|
@@ -95,7 +93,7 @@ test('Should display errors in order', async () => { | |
{ message: 'Error 3', index: 2 }, | ||
] | ||
); | ||
await act(async () => { | ||
await waitFor(async () => { | ||
const errors = await utils.queryAllByText(/Error [1-3]/); | ||
expect(errors[0]).toHaveTextContent('Error 1'); | ||
expect(errors[1]).toHaveTextContent('Error 2'); | ||
|
@@ -126,18 +124,16 @@ test('Should remove error when item deleted', async () => { | |
); | ||
}); | ||
|
||
await act(async () => { | ||
const deleteRowButtons = await utils.container.querySelectorAll('[aria-label="Delete row"]'); | ||
if (deleteRowButtons.length !== 3) { | ||
throw new Error('Delete row buttons not found'); | ||
} | ||
const deleteRowButtons = await utils.container.querySelectorAll('[aria-label="Delete row"]'); | ||
if (deleteRowButtons.length !== 3) { | ||
throw new Error('Delete row buttons not found'); | ||
} | ||
Comment on lines
+128
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be an assertion |
||
|
||
fireEvent.click(deleteRowButtons[1]); | ||
expect(mockOnChange).toHaveBeenCalled(); | ||
fireEvent.click(deleteRowButtons[1]); | ||
expect(mockOnChange).toHaveBeenCalled(); | ||
|
||
const renderedErrors = await utils.queryAllByText(/Error [1-3]/); | ||
expect(renderedErrors).toHaveLength(2); | ||
expect(renderedErrors[0]).toHaveTextContent('Error 1'); | ||
expect(renderedErrors[1]).toHaveTextContent('Error 3'); | ||
}); | ||
const renderedErrors = await utils.queryAllByText(/Error [1-3]/); | ||
expect(renderedErrors).toHaveLength(2); | ||
expect(renderedErrors[0]).toHaveTextContent('Error 1'); | ||
expect(renderedErrors[1]).toHaveTextContent('Error 3'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
import './agent_enrollment_flyout.test.mocks'; | ||
|
||
import React from 'react'; | ||
import { act, cleanup, fireEvent, waitFor } from '@testing-library/react'; | ||
import { fireEvent, waitFor } from '@testing-library/react'; | ||
import type { RenderResult } from '@testing-library/react'; | ||
|
||
import { createFleetTestRendererMock } from '../../mock'; | ||
|
@@ -23,11 +23,8 @@ import type { FlyOutProps } from './types'; | |
import { AgentEnrollmentFlyout } from '.'; | ||
|
||
const render = (props?: Partial<FlyOutProps>) => { | ||
cleanup(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't be cleaning up just before test starts, what's more with jest this is handled automatically for us |
||
const renderer = createFleetTestRendererMock(); | ||
const results = renderer.render(<AgentEnrollmentFlyout onClose={jest.fn()} {...props} />); | ||
|
||
return results; | ||
return renderer.render(<AgentEnrollmentFlyout onClose={jest.fn()} {...props} />); | ||
}; | ||
|
||
const testAgentPolicy: AgentPolicy = { | ||
|
@@ -46,7 +43,7 @@ const testAgentPolicy: AgentPolicy = { | |
describe('<AgentEnrollmentFlyout />', () => { | ||
let results: RenderResult; | ||
|
||
beforeEach(async () => { | ||
beforeEach(() => { | ||
jest.mocked(useAuthz).mockReturnValue({ | ||
fleet: { | ||
readAgentPolicies: true, | ||
|
@@ -88,10 +85,6 @@ describe('<AgentEnrollmentFlyout />', () => { | |
agentPolicies: [{ id: 'fleet-server-policy' } as AgentPolicy], | ||
refreshAgentPolicies: jest.fn(), | ||
}); | ||
|
||
act(() => { | ||
results = render(); | ||
}); | ||
Comment on lines
-92
to
-94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also there's no need to render here, if we still invoke render again in each test suite |
||
}); | ||
|
||
afterEach(() => { | ||
|
@@ -113,6 +106,8 @@ describe('<AgentEnrollmentFlyout />', () => { | |
|
||
describe('managed instructions', () => { | ||
it('uses the agent policy selection step', () => { | ||
results = render(); | ||
|
||
expect(results.queryByTestId('agentEnrollmentFlyout')).not.toBeNull(); | ||
expect(results.queryByTestId('agent-policy-selection-step')).not.toBeNull(); | ||
expect(results.queryByTestId('agent-enrollment-key-selection-step')).toBeNull(); | ||
|
@@ -154,24 +149,22 @@ describe('<AgentEnrollmentFlyout />', () => { | |
|
||
describe('standalone instructions', () => { | ||
function goToStandaloneTab() { | ||
act(() => { | ||
fireEvent.click(results.getByTestId('standaloneTab')); | ||
}); | ||
Comment on lines
-157
to
-159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to wrap fireEvent in act |
||
fireEvent.click(results.getByTestId('standaloneTab')); | ||
} | ||
|
||
beforeEach(() => { | ||
it('uses the agent policy selection step', async () => { | ||
results = render({ | ||
isIntegrationFlow: true, | ||
}); | ||
}); | ||
|
||
it('uses the agent policy selection step', async () => { | ||
goToStandaloneTab(); | ||
|
||
expect(results.queryByTestId('agentEnrollmentFlyout')).not.toBeNull(); | ||
expect(results.queryByTestId('agent-policy-selection-step')).not.toBeNull(); | ||
expect(results.queryByTestId('agent-enrollment-key-selection-step')).toBeNull(); | ||
expect(results.queryByTestId('configure-standalone-step')).not.toBeNull(); | ||
await waitFor(() => { | ||
expect(results.queryByTestId('agentEnrollmentFlyout')).not.toBeNull(); | ||
expect(results.queryByTestId('agent-policy-selection-step')).not.toBeNull(); | ||
expect(results.queryByTestId('agent-enrollment-key-selection-step')).toBeNull(); | ||
expect(results.queryByTestId('configure-standalone-step')).not.toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('with a specific policy', () => { | ||
|
@@ -185,13 +178,15 @@ describe('<AgentEnrollmentFlyout />', () => { | |
}); | ||
}); | ||
|
||
it('does not use either of the agent policy selection or enrollment key steps', () => { | ||
it('does not use either of the agent policy selection or enrollment key steps', async () => { | ||
goToStandaloneTab(); | ||
|
||
expect(results.queryByTestId('agentEnrollmentFlyout')).not.toBeNull(); | ||
expect(results.queryByTestId('agent-policy-selection-step')).toBeNull(); | ||
expect(results.queryByTestId('agent-enrollment-key-selection-step')).toBeNull(); | ||
expect(results.queryByTestId('configure-standalone-step')).not.toBeNull(); | ||
await waitFor(() => { | ||
expect(results.queryByTestId('agentEnrollmentFlyout')).not.toBeNull(); | ||
expect(results.queryByTestId('agent-policy-selection-step')).toBeNull(); | ||
expect(results.queryByTestId('agent-enrollment-key-selection-step')).toBeNull(); | ||
expect(results.queryByTestId('configure-standalone-step')).not.toBeNull(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,14 @@ | |
|
||
import React from 'react'; | ||
|
||
import { cleanup, waitFor } from '@testing-library/react'; | ||
import { waitFor } from '@testing-library/react'; | ||
|
||
import { createFleetTestRendererMock } from '../../mock'; | ||
|
||
import { RootPrivilegesCallout } from './root_privileges_callout'; | ||
|
||
describe('RootPrivilegesCallout', () => { | ||
function render(rootIntegrations?: Array<{ name: string; title: string }>) { | ||
cleanup(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const renderer = createFleetTestRendererMock(); | ||
const results = renderer.render(<RootPrivilegesCallout rootIntegrations={rootIntegrations} />); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
import React from 'react'; | ||
|
||
import { act } from '@testing-library/react'; | ||
import { waitFor } from '@testing-library/react'; | ||
|
||
import type { AgentPolicy, InMemoryPackagePolicy } from '../types'; | ||
import { createIntegrationsTestRendererMock } from '../mock'; | ||
|
@@ -118,7 +118,8 @@ describe('PackagePolicyActionsMenu', () => { | |
const agentPolicies = createMockAgentPolicies(); | ||
const packagePolicy = createMockPackagePolicy({ hasUpgrade: false }); | ||
const { utils } = renderMenu({ agentPolicies, packagePolicy }); | ||
await act(async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's no need to have assertions run within an act function |
||
|
||
await waitFor(() => { | ||
const upgradeButton = utils.getByTestId('PackagePolicyActionsUpgradeItem'); | ||
expect(upgradeButton).toBeDisabled(); | ||
}); | ||
|
@@ -129,7 +130,7 @@ describe('PackagePolicyActionsMenu', () => { | |
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true }); | ||
const { utils } = renderMenu({ agentPolicies, packagePolicy }); | ||
|
||
await act(async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
await waitFor(() => { | ||
const upgradeButton = utils.getByTestId('PackagePolicyActionsUpgradeItem'); | ||
expect(upgradeButton).not.toBeDisabled(); | ||
}); | ||
|
@@ -140,7 +141,7 @@ describe('PackagePolicyActionsMenu', () => { | |
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true }); | ||
const { utils } = renderMenu({ agentPolicies, packagePolicy }); | ||
|
||
await act(async () => { | ||
await waitFor(() => { | ||
const upgradeButton = utils.getByTestId('PackagePolicyActionsUpgradeItem'); | ||
expect(upgradeButton).toBeDisabled(); | ||
}); | ||
|
@@ -150,7 +151,7 @@ describe('PackagePolicyActionsMenu', () => { | |
const agentPolicies = createMockAgentPolicies({ is_managed: true }); | ||
const packagePolicy = createMockPackagePolicy(); | ||
const { utils } = renderMenu({ agentPolicies, packagePolicy }); | ||
await act(async () => { | ||
await waitFor(() => { | ||
expect(utils.queryByText('Delete integration')).toBeNull(); | ||
}); | ||
}); | ||
|
@@ -159,7 +160,7 @@ describe('PackagePolicyActionsMenu', () => { | |
const agentPolicies = createMockAgentPolicies({ is_managed: false }); | ||
const packagePolicy = createMockPackagePolicy(); | ||
const { utils } = renderMenu({ agentPolicies, packagePolicy }); | ||
await act(async () => { | ||
await waitFor(() => { | ||
expect(utils.queryByText('Delete integration')).not.toBeNull(); | ||
}); | ||
}); | ||
|
@@ -168,7 +169,7 @@ describe('PackagePolicyActionsMenu', () => { | |
const agentPolicies = createMockAgentPolicies({ is_managed: false, supports_agentless: true }); | ||
const packagePolicy = createMockPackagePolicy(); | ||
const { utils } = renderMenu({ agentPolicies, packagePolicy }); | ||
await act(async () => { | ||
await waitFor(() => { | ||
expect(utils.queryByText('Delete integration')).not.toBeNull(); | ||
}); | ||
}); | ||
|
@@ -177,7 +178,7 @@ describe('PackagePolicyActionsMenu', () => { | |
const agentPolicies = createMockAgentPolicies(); | ||
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true }); | ||
const { utils } = renderMenu({ agentPolicies, packagePolicy, showAddAgent: true }); | ||
await act(async () => { | ||
await waitFor(() => { | ||
expect(utils.queryByText('Add agent')).not.toBeNull(); | ||
}); | ||
}); | ||
|
@@ -186,7 +187,7 @@ describe('PackagePolicyActionsMenu', () => { | |
const agentPolicies = createMockAgentPolicies({ is_managed: true }); | ||
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true }); | ||
const { utils } = renderMenu({ agentPolicies, packagePolicy, showAddAgent: true }); | ||
await act(async () => { | ||
await waitFor(() => { | ||
expect(utils.queryByText('Add agent')).toBeNull(); | ||
}); | ||
}); | ||
|
@@ -195,7 +196,7 @@ describe('PackagePolicyActionsMenu', () => { | |
const agentPolicies = createMockAgentPolicies({ supports_agentless: true }); | ||
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true }); | ||
const { utils } = renderMenu({ agentPolicies, packagePolicy, showAddAgent: true }); | ||
await act(async () => { | ||
await waitFor(() => { | ||
expect(utils.queryByText('Add agent')).toBeNull(); | ||
}); | ||
}); | ||
|
@@ -204,7 +205,7 @@ describe('PackagePolicyActionsMenu', () => { | |
const agentPolicies = createMockAgentPolicies(); | ||
const packagePolicy = createMockPackagePolicy(); | ||
const { utils } = renderMenu({ agentPolicies, packagePolicy }); | ||
await act(async () => { | ||
await waitFor(() => { | ||
const editButton = utils.getByTestId('PackagePolicyActionsEditItem'); | ||
expect(editButton).not.toHaveAttribute('disabled'); | ||
expect(editButton).toHaveAttribute('href'); | ||
|
@@ -227,7 +228,7 @@ describe('PackagePolicyActionsMenu', () => { | |
agentPolicies: [], | ||
packagePolicy, | ||
}); | ||
await act(async () => { | ||
await waitFor(() => { | ||
const editButton = utils.getByTestId('PackagePolicyActionsEditItem'); | ||
expect(editButton).not.toHaveAttribute('disabled'); | ||
expect(editButton).toHaveAttribute('href'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should actually be an assertion