Skip to content

Commit

Permalink
adding default namespace test
Browse files Browse the repository at this point in the history
  • Loading branch information
opauloh committed Nov 5, 2024
1 parent 5c59070 commit 536a4ad
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ describe('StepDefinePackagePolicy', () => {
let testRenderer: TestRenderer;
let renderResult: ReturnType<typeof testRenderer.render>;

const render = () =>
const render = (namespacePlaceholder = getInheritedNamespace(agentPolicies)) =>
(renderResult = testRenderer.render(
<StepDefinePackagePolicy
namespacePlaceholder={getInheritedNamespace(agentPolicies)}
namespacePlaceholder={namespacePlaceholder}
packageInfo={packageInfo}
packagePolicy={packagePolicy}
updatePackagePolicy={mockUpdatePackagePolicy}
Expand All @@ -100,7 +100,7 @@ describe('StepDefinePackagePolicy', () => {
packagePolicy = {
name: '',
description: 'desc',
namespace: '',
namespace: 'package-policy-ns',
enabled: true,
policy_id: '',
policy_ids: [''],
Expand Down Expand Up @@ -143,24 +143,40 @@ describe('StepDefinePackagePolicy', () => {

await waitFor(() => {
expect(renderResult.getByRole('switch', { name: 'Advanced var' })).toBeInTheDocument();
expect(renderResult.getByTestId('packagePolicyNamespaceInput')).toHaveTextContent(
'package-policy-ns'
);
});
});

it(`should display namespace from agent policy when there's no package policy namespace`, async () => {
packagePolicy.namespace = '';
act(() => {
render();
});

await userEvent.click(renderResult.getByText('Advanced options').closest('button')!);

await waitFor(() => {
expect(renderResult.getByTestId('comboBoxSearchInput')).toHaveAttribute(
'placeholder',
'ns'
);
});
});

it('should display namespace from package policy', async () => {
packagePolicy.namespace = 'package-policy-ns';
it(`should fallback to the default namespace when namespace is not set in package policy and there's no agent policy`, async () => {
packagePolicy.namespace = '';
act(() => {
render();
render(getInheritedNamespace([]));
});

await userEvent.click(renderResult.getByText('Advanced options').closest('button')!);

await waitFor(() => {
expect(renderResult.getByTestId('packagePolicyNamespaceInput')).toHaveTextContent(
'package-policy-ns'
expect(renderResult.getByTestId('comboBoxSearchInput')).toHaveAttribute(
'placeholder',
'default'
);
});
});
Expand Down

0 comments on commit 536a4ad

Please sign in to comment.