Skip to content
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

[Fleet] Fix flaky package policy actions tests #193459

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,123 +114,126 @@ describe('PackagePolicyActionsMenu', () => {
useMultipleAgentPoliciesMock.mockReturnValue({ canUseMultipleAgentPolicies: false });
});

it('Should disable upgrade button if package does not have upgrade', async () => {
const agentPolicies = createMockAgentPolicies();
const packagePolicy = createMockPackagePolicy({ hasUpgrade: false });
const { utils } = renderMenu({ agentPolicies, packagePolicy });
await act(async () => {
const upgradeButton = utils.getByText('Upgrade integration policy').closest('button');
expect(upgradeButton).toBeDisabled();
for (let i = 0; i < 100; i++) {
it('Should disable upgrade button if package does not have upgrade', async () => {
const agentPolicies = createMockAgentPolicies();
const packagePolicy = createMockPackagePolicy({ hasUpgrade: false });
const { utils } = renderMenu({ agentPolicies, packagePolicy });

await act(async () => {
const upgradeButton = utils.getByText('Upgrade integration policy').closest('button');
expect(upgradeButton).toBeDisabled();
});
});
});

it('Should enable upgrade button if package has upgrade', async () => {
const agentPolicies = createMockAgentPolicies();
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true });
const { utils } = renderMenu({ agentPolicies, packagePolicy });
it('Should enable upgrade button if package has upgrade', async () => {
const agentPolicies = createMockAgentPolicies();
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true });
const { utils } = renderMenu({ agentPolicies, packagePolicy });

await act(async () => {
const upgradeButton = utils.getByTestId('PackagePolicyActionsUpgradeItem');
expect(upgradeButton).not.toBeDisabled();
await act(async () => {
const upgradeButton = utils.getByTestId('PackagePolicyActionsUpgradeItem');
expect(upgradeButton).not.toBeDisabled();
});
});
});

it('Should not be able to delete integration from a managed policy', async () => {
const agentPolicies = createMockAgentPolicies({ is_managed: true });
const packagePolicy = createMockPackagePolicy();
const { utils } = renderMenu({ agentPolicies, packagePolicy });
await act(async () => {
expect(utils.queryByText('Delete integration')).toBeNull();
it('Should not be able to delete integration from a managed policy', async () => {
const agentPolicies = createMockAgentPolicies({ is_managed: true });
const packagePolicy = createMockPackagePolicy();
const { utils } = renderMenu({ agentPolicies, packagePolicy });
await act(async () => {
expect(utils.queryByText('Delete integration')).toBeNull();
});
});
});

it('Should be able to delete integration from a non-managed policy', async () => {
const agentPolicies = createMockAgentPolicies({ is_managed: false });
const packagePolicy = createMockPackagePolicy();
const { utils } = renderMenu({ agentPolicies, packagePolicy });
await act(async () => {
expect(utils.queryByText('Delete integration')).not.toBeNull();
it('Should be able to delete integration from a non-managed policy', async () => {
const agentPolicies = createMockAgentPolicies({ is_managed: false });
const packagePolicy = createMockPackagePolicy();
const { utils } = renderMenu({ agentPolicies, packagePolicy });
await act(async () => {
expect(utils.queryByText('Delete integration')).not.toBeNull();
});
});
});

it('Should be able to delete integration from a managed agentless policy', async () => {
const agentPolicies = createMockAgentPolicies({ is_managed: true, supports_agentless: true });
const packagePolicy = createMockPackagePolicy();
const { utils } = renderMenu({ agentPolicies, packagePolicy });
await act(async () => {
expect(utils.queryByText('Delete integration')).not.toBeNull();
it('Should be able to delete integration from a managed agentless policy', async () => {
const agentPolicies = createMockAgentPolicies({ is_managed: true, supports_agentless: true });
const packagePolicy = createMockPackagePolicy();
const { utils } = renderMenu({ agentPolicies, packagePolicy });
await act(async () => {
expect(utils.queryByText('Delete integration')).not.toBeNull();
});
});
});

it('Should navigate on delete integration when having an agentless policy', async () => {
const agentPolicies = createMockAgentPolicies({ is_managed: true, supports_agentless: true });
const packagePolicy = createMockPackagePolicy();
const { utils } = renderMenu({ agentPolicies, packagePolicy });
it('Should navigate on delete integration when having an agentless policy', async () => {
const agentPolicies = createMockAgentPolicies({ is_managed: true, supports_agentless: true });
const packagePolicy = createMockPackagePolicy();
const { utils } = renderMenu({ agentPolicies, packagePolicy });

await act(async () => {
fireEvent.click(utils.getByTestId('PackagePolicyActionsDeleteItem'));
});
await act(async () => {
fireEvent.click(utils.getByTestId('confirmModalConfirmButton'));
await act(async () => {
fireEvent.click(utils.getByTestId('PackagePolicyActionsDeleteItem'));
});
await act(async () => {
fireEvent.click(utils.getByTestId('confirmModalConfirmButton'));
});
expect(useStartServices().application.navigateToApp as jest.Mock).toHaveBeenCalledWith(
'fleet',
{ path: '/policies' }
);
});
expect(useStartServices().application.navigateToApp as jest.Mock).toHaveBeenCalledWith(
'fleet',
{ path: '/policies' }
);
});

it('Should show add button if the policy is not managed and showAddAgent=true', async () => {
const agentPolicies = createMockAgentPolicies();
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true });
const { utils } = renderMenu({ agentPolicies, packagePolicy, showAddAgent: true });
await act(async () => {
expect(utils.queryByText('Add agent')).not.toBeNull();
it('Should show add button if the policy is not managed and showAddAgent=true', async () => {
const agentPolicies = createMockAgentPolicies();
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true });
const { utils } = renderMenu({ agentPolicies, packagePolicy, showAddAgent: true });
await act(async () => {
expect(utils.queryByText('Add agent')).not.toBeNull();
});
});
});

it('Should not show add button if the policy is managed and showAddAgent=true', async () => {
const agentPolicies = createMockAgentPolicies({ is_managed: true });
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true });
const { utils } = renderMenu({ agentPolicies, packagePolicy, showAddAgent: true });
await act(async () => {
expect(utils.queryByText('Add agent')).toBeNull();
it('Should not show add button if the policy is managed and showAddAgent=true', async () => {
const agentPolicies = createMockAgentPolicies({ is_managed: true });
const packagePolicy = createMockPackagePolicy({ hasUpgrade: true });
const { utils } = renderMenu({ agentPolicies, packagePolicy, showAddAgent: true });
await act(async () => {
expect(utils.queryByText('Add agent')).toBeNull();
});
});
});

it('Should show Edit integration with correct href when agentPolicy is defined', async () => {
const agentPolicies = createMockAgentPolicies();
const packagePolicy = createMockPackagePolicy();
const { utils } = renderMenu({ agentPolicies, packagePolicy });
await act(async () => {
const editButton = utils.getByTestId('PackagePolicyActionsEditItem');
expect(editButton).not.toHaveAttribute('disabled');
expect(editButton).toHaveAttribute('href');
expect(useLink().getHref as jest.Mock).toHaveBeenCalledWith('edit_integration', {
policyId: 'some-uuid1',
packagePolicyId: 'some-uuid2',
it('Should show Edit integration with correct href when agentPolicy is defined', async () => {
const agentPolicies = createMockAgentPolicies();
const packagePolicy = createMockPackagePolicy();
const { utils } = renderMenu({ agentPolicies, packagePolicy });
await act(async () => {
const editButton = utils.getByTestId('PackagePolicyActionsEditItem');
expect(editButton).not.toHaveAttribute('disabled');
expect(editButton).toHaveAttribute('href');
expect(useLink().getHref as jest.Mock).toHaveBeenCalledWith('edit_integration', {
policyId: 'some-uuid1',
packagePolicyId: 'some-uuid2',
});
expect(editButton).toHaveAttribute(
'href',
'/mock/app/fleet/policies/some-uuid1/edit-integration/some-uuid2'
);
});
expect(editButton).toHaveAttribute(
'href',
'/mock/app/fleet/policies/some-uuid1/edit-integration/some-uuid2'
);
});
});

it('Should show Edit integration with correct href when there is no agent policy', async () => {
const packagePolicy = createMockPackagePolicy({
policy_ids: [],
});
const { utils } = renderMenu({
agentPolicies: [],
packagePolicy,
});
await act(async () => {
const editButton = utils.getByTestId('PackagePolicyActionsEditItem');
expect(editButton).not.toHaveAttribute('disabled');
expect(editButton).toHaveAttribute('href');
expect(useLink().getHref as jest.Mock).toHaveBeenCalledWith('integration_policy_edit', {
packagePolicyId: 'some-uuid2',
it('Should show Edit integration with correct href when there is no agent policy', async () => {
const packagePolicy = createMockPackagePolicy({
policy_ids: [],
});
const { utils } = renderMenu({
agentPolicies: [],
packagePolicy,
});
await act(async () => {
const editButton = utils.getByTestId('PackagePolicyActionsEditItem');
expect(editButton).not.toHaveAttribute('disabled');
expect(editButton).toHaveAttribute('href');
expect(useLink().getHref as jest.Mock).toHaveBeenCalledWith('integration_policy_edit', {
packagePolicyId: 'some-uuid2',
});
});
});
});
}
});