-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
131 additions
and
13 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...eet/sections/agent_policy/create_package_policy_page/components/datastream_hooks.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useRouteMatch } from 'react-router-dom'; | ||
|
||
import { createFleetTestRendererMock } from '../../../../../../mock'; | ||
|
||
import { usePackagePolicyEditorPageUrl } from './datastream_hooks'; | ||
|
||
const mockedUseRouteMatch = useRouteMatch as jest.MockedFunction<typeof useRouteMatch>; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useRouteMatch: jest.fn(), | ||
})); | ||
|
||
describe('usePackagePolicyEditorPageUrl', () => { | ||
it('should render an integration url if no policy id is provided', () => { | ||
const renderer = createFleetTestRendererMock(); | ||
mockedUseRouteMatch.mockReturnValue({ | ||
params: { packagePolicyId: 'test-package-policy-id' }, | ||
} as any); | ||
const { result } = renderer.renderHook(() => usePackagePolicyEditorPageUrl()); | ||
expect(result.current).toBe('/mock/app/integrations/edit-integration/test-package-policy-id'); | ||
}); | ||
|
||
it('should render a fleet url if a policy id is provided', () => { | ||
const renderer = createFleetTestRendererMock(); | ||
mockedUseRouteMatch.mockReturnValue({ | ||
params: { policyId: 'policy1', packagePolicyId: 'test-package-policy-id' }, | ||
} as any); | ||
const { result } = renderer.renderHook(() => usePackagePolicyEditorPageUrl()); | ||
expect(result.current).toBe( | ||
'/mock/app/fleet/policies/policy1/edit-integration/test-package-policy-id' | ||
); | ||
}); | ||
|
||
it('should add datastream Id if provided', () => { | ||
const renderer = createFleetTestRendererMock(); | ||
mockedUseRouteMatch.mockReturnValue({ | ||
params: { policyId: 'policy1', packagePolicyId: 'test-package-policy-id' }, | ||
} as any); | ||
const { result } = renderer.renderHook(() => | ||
usePackagePolicyEditorPageUrl('test-datastream-id') | ||
); | ||
expect(result.current).toBe( | ||
'/mock/app/fleet/policies/policy1/edit-integration/test-package-policy-id?datastreamId=test-datastream-id' | ||
); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
...reate_package_policy_page/components/steps/components/package_policy_input_panel.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { shouldShowStreamsByDefault } from './package_policy_input_panel'; | ||
|
||
describe('shouldShowStreamsByDefault', () => { | ||
it('should return true if a datastreamId is provided and contained in the input', () => { | ||
const res = shouldShowStreamsByDefault( | ||
{} as any, | ||
[], | ||
{ | ||
enabled: true, | ||
streams: [ | ||
{ | ||
id: 'datastream-id', | ||
}, | ||
], | ||
} as any, | ||
'datastream-id' | ||
); | ||
expect(res).toBeTruthy(); | ||
}); | ||
|
||
it('should return false if a datastreamId is provided but not contained in the input', () => { | ||
const res = shouldShowStreamsByDefault( | ||
{} as any, | ||
[], | ||
{ | ||
enabled: true, | ||
streams: [ | ||
{ | ||
id: 'datastream-1', | ||
}, | ||
], | ||
} as any, | ||
'datastream-id' | ||
); | ||
expect(res).toBeFalsy(); | ||
}); | ||
|
||
it('should return false if a datastreamId is provided but the input is disabled', () => { | ||
const res = shouldShowStreamsByDefault( | ||
{} as any, | ||
[], | ||
{ | ||
enabled: false, | ||
streams: [ | ||
{ | ||
id: 'datastream-id', | ||
}, | ||
], | ||
} as any, | ||
'datastream-id' | ||
); | ||
expect(res).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters