forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] [Inventory] Fixing entity links (elastic#195625) (elastic#195667)
# Backport This will backport the following commits from `main` to `8.x`: - [[Inventory] Fixing entity links (elastic#195625)](elastic#195625) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Cauê Marcondes","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-09T18:19:49Z","message":"[Inventory] Fixing entity links (elastic#195625)\n\nRegression from https://github.com/elastic/kibana/pull/195204","sha":"d2644ffe49ea732e5f048957a51350efbc321687","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","v8.16.0"],"title":"[Inventory] Fixing entity links","number":195625,"url":"https://github.com/elastic/kibana/pull/195625","mergeCommit":{"message":"[Inventory] Fixing entity links (elastic#195625)\n\nRegression from https://github.com/elastic/kibana/pull/195204","sha":"d2644ffe49ea732e5f048957a51350efbc321687"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195625","number":195625,"mergeCommit":{"message":"[Inventory] Fixing entity links (elastic#195625)\n\nRegression from https://github.com/elastic/kibana/pull/195204","sha":"d2644ffe49ea732e5f048957a51350efbc321687"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Cauê Marcondes <[email protected]>
- Loading branch information
1 parent
8fdf77d
commit a3da125
Showing
3 changed files
with
167 additions
and
10 deletions.
There are no files selected for viewing
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
152 changes: 152 additions & 0 deletions
152
...ility_solution/inventory/public/components/entities_grid/entity_name/entity_name.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,152 @@ | ||
/* | ||
* 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 { type KibanaReactContextValue } from '@kbn/kibana-react-plugin/public'; | ||
import * as useKibana from '../../../hooks/use_kibana'; | ||
import { EntityName } from '.'; | ||
import { ContainerEntity, HostEntity, ServiceEntity } from '../../../../common/entities'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { ASSET_DETAILS_LOCATOR_ID } from '@kbn/observability-shared-plugin/common/locators/infra/asset_details_locator'; | ||
|
||
describe('EntityName', () => { | ||
jest.spyOn(useKibana, 'useKibana').mockReturnValue({ | ||
services: { | ||
share: { | ||
url: { | ||
locators: { | ||
get: (locatorId: string) => { | ||
return { | ||
getRedirectUrl: (params: { [key: string]: any }) => { | ||
if (locatorId === ASSET_DETAILS_LOCATOR_ID) { | ||
return `assets_url/${params.assetType}/${params.assetId}`; | ||
} | ||
return `services_url/${params.serviceName}?environment=${params.environment}`; | ||
}, | ||
}; | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} as unknown as KibanaReactContextValue<useKibana.InventoryKibanaContext>); | ||
|
||
afterAll(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('returns host link', () => { | ||
const entity: HostEntity = { | ||
'entity.lastSeenTimestamp': 'foo', | ||
'entity.id': '1', | ||
'entity.type': 'host', | ||
'entity.displayName': 'foo', | ||
'entity.identityFields': 'host.name', | ||
'host.name': 'foo', | ||
'entity.definitionId': 'host', | ||
'cloud.provider': null, | ||
}; | ||
render(<EntityName entity={entity} />); | ||
expect(screen.queryByTestId('entityNameLink')?.getAttribute('href')).toEqual( | ||
'assets_url/host/foo' | ||
); | ||
expect(screen.queryByTestId('entityNameDisplayName')?.textContent).toEqual('foo'); | ||
}); | ||
|
||
it('returns container link', () => { | ||
const entity: ContainerEntity = { | ||
'entity.lastSeenTimestamp': 'foo', | ||
'entity.id': '1', | ||
'entity.type': 'container', | ||
'entity.displayName': 'foo', | ||
'entity.identityFields': 'container.id', | ||
'container.id': 'foo', | ||
'entity.definitionId': 'container', | ||
'cloud.provider': null, | ||
}; | ||
render(<EntityName entity={entity} />); | ||
expect(screen.queryByTestId('entityNameLink')?.getAttribute('href')).toEqual( | ||
'assets_url/container/foo' | ||
); | ||
expect(screen.queryByTestId('entityNameDisplayName')?.textContent).toEqual('foo'); | ||
}); | ||
|
||
it('returns service link without environment', () => { | ||
const entity: ServiceEntity = { | ||
'entity.lastSeenTimestamp': 'foo', | ||
'entity.id': '1', | ||
'entity.type': 'service', | ||
'entity.displayName': 'foo', | ||
'entity.identityFields': 'service.name', | ||
'service.name': 'foo', | ||
'entity.definitionId': 'service', | ||
'agent.name': 'bar', | ||
}; | ||
render(<EntityName entity={entity} />); | ||
expect(screen.queryByTestId('entityNameLink')?.getAttribute('href')).toEqual( | ||
'services_url/foo?environment=undefined' | ||
); | ||
expect(screen.queryByTestId('entityNameDisplayName')?.textContent).toEqual('foo'); | ||
}); | ||
|
||
it('returns service link with environment', () => { | ||
const entity: ServiceEntity = { | ||
'entity.lastSeenTimestamp': 'foo', | ||
'entity.id': '1', | ||
'entity.type': 'service', | ||
'entity.displayName': 'foo', | ||
'entity.identityFields': 'service.name', | ||
'service.name': 'foo', | ||
'entity.definitionId': 'service', | ||
'agent.name': 'bar', | ||
'service.environment': 'baz', | ||
}; | ||
render(<EntityName entity={entity} />); | ||
expect(screen.queryByTestId('entityNameLink')?.getAttribute('href')).toEqual( | ||
'services_url/foo?environment=baz' | ||
); | ||
expect(screen.queryByTestId('entityNameDisplayName')?.textContent).toEqual('foo'); | ||
}); | ||
|
||
it('returns service link with first environment when it is an array', () => { | ||
const entity: ServiceEntity = { | ||
'entity.lastSeenTimestamp': 'foo', | ||
'entity.id': '1', | ||
'entity.type': 'service', | ||
'entity.displayName': 'foo', | ||
'entity.identityFields': 'service.name', | ||
'service.name': 'foo', | ||
'entity.definitionId': 'service', | ||
'agent.name': 'bar', | ||
'service.environment': ['baz', 'bar', 'foo'], | ||
}; | ||
render(<EntityName entity={entity} />); | ||
expect(screen.queryByTestId('entityNameLink')?.getAttribute('href')).toEqual( | ||
'services_url/foo?environment=baz' | ||
); | ||
expect(screen.queryByTestId('entityNameDisplayName')?.textContent).toEqual('foo'); | ||
}); | ||
|
||
it('returns service link identity fields is an array', () => { | ||
const entity: ServiceEntity = { | ||
'entity.lastSeenTimestamp': 'foo', | ||
'entity.id': '1', | ||
'entity.type': 'service', | ||
'entity.displayName': 'foo', | ||
'entity.identityFields': ['service.name', 'service.environment'], | ||
'service.name': 'foo', | ||
'entity.definitionId': 'service', | ||
'agent.name': 'bar', | ||
'service.environment': 'baz', | ||
}; | ||
render(<EntityName entity={entity} />); | ||
expect(screen.queryByTestId('entityNameLink')?.getAttribute('href')).toEqual( | ||
'services_url/foo?environment=baz' | ||
); | ||
expect(screen.queryByTestId('entityNameDisplayName')?.textContent).toEqual('foo'); | ||
}); | ||
}); |
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