-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Endpoint] add policy data to Host list UI #69202
Changes from 4 commits
3d916d5
39d29d4
d5be032
9a1f17c
af11a72
1605736
c0bdfea
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 |
---|---|---|
|
@@ -23,3 +23,11 @@ export const POLICY_STATUS_TO_HEALTH_COLOR = Object.freeze< | |
warning: 'warning', | ||
failure: 'danger', | ||
}); | ||
|
||
export const POLICY_STATUS_TO_TEXT = Object.freeze< | ||
{ [key in keyof typeof HostPolicyResponseActionStatus]: string } | ||
>({ | ||
success: 'Success', | ||
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. need to 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. good catch, corrected |
||
warning: 'Warning', | ||
failure: 'Failure', | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import { | |
} from '../../../../../common/endpoint/types'; | ||
import { EndpointDocGenerator } from '../../../../../common/endpoint/generate_data'; | ||
import { AppAction } from '../../../../common/store/actions'; | ||
import { POLICY_STATUS_TO_HEALTH_COLOR, POLICY_STATUS_TO_TEXT } from './host_constants'; | ||
|
||
describe('when on the hosts page', () => { | ||
const docGenerator = new EndpointDocGenerator(); | ||
|
@@ -47,15 +48,23 @@ describe('when on the hosts page', () => { | |
}); | ||
}); | ||
describe('when list data loads', () => { | ||
const generatedPolicyStatuses: Array< | ||
HostInfo['metadata']['endpoint']['policy']['applied']['status'] | ||
> = []; | ||
let firstPolicyID: string; | ||
beforeEach(() => { | ||
reactTestingLibrary.act(() => { | ||
const hostListData = mockHostResultList({ total: 3 }); | ||
firstPolicyID = hostListData.hosts[0].metadata.endpoint.policy.applied.id; | ||
[HostStatus.ERROR, HostStatus.ONLINE, HostStatus.OFFLINE].forEach((status, index) => { | ||
hostListData.hosts[index] = { | ||
metadata: hostListData.hosts[index].metadata, | ||
host_status: status, | ||
}; | ||
}); | ||
hostListData.hosts.forEach((item, index) => { | ||
generatedPolicyStatuses[index] = item.metadata.endpoint.policy.applied.status; | ||
}); | ||
const action: AppAction = { | ||
type: 'serverReturnedHostList', | ||
payload: hostListData, | ||
|
@@ -92,6 +101,29 @@ describe('when on the hosts page', () => { | |
).not.toBeNull(); | ||
}); | ||
|
||
it('should display correct policy status', async () => { | ||
const renderResult = render(); | ||
const policyStatuses = await renderResult.findAllByTestId('rowPolicyStatus'); | ||
|
||
policyStatuses.forEach((status, index) => { | ||
expect(status.textContent).toEqual(POLICY_STATUS_TO_TEXT[generatedPolicyStatuses[index]]); | ||
expect( | ||
status.querySelector( | ||
`[data-euiicon-type][color=${ | ||
POLICY_STATUS_TO_HEALTH_COLOR[generatedPolicyStatuses[index]] | ||
}]` | ||
) | ||
).not.toBeNull(); | ||
}); | ||
}); | ||
|
||
it('should display policy name as a link', async () => { | ||
const renderResult = render(); | ||
const firstPolicyName = (await renderResult.findAllByTestId('policyNameCellLink'))[0]; | ||
expect(firstPolicyName).not.toBeNull(); | ||
expect(firstPolicyName.getAttribute('href')).toContain(`policy/${firstPolicyID}`); | ||
}); | ||
|
||
describe('when the user clicks the first hostname in the table', () => { | ||
let renderResult: reactTestingLibrary.RenderResult; | ||
beforeEach(async () => { | ||
|
@@ -197,6 +229,26 @@ describe('when on the hosts page', () => { | |
expect(flyout).not.toBeNull(); | ||
}); | ||
}); | ||
it('should display policy name value as a link', 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. spacing between the ITs 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. spaces added for readability |
||
const renderResult = render(); | ||
const policyDetailsLink = await renderResult.findByTestId('policyDetailsValue'); | ||
expect(policyDetailsLink).not.toBeNull(); | ||
expect(policyDetailsLink.getAttribute('href')).toEqual( | ||
`#/management/policy/${hostDetails.metadata.endpoint.policy.applied.id}` | ||
); | ||
}); | ||
it('should update the URL when policy name link is clicked', async () => { | ||
const renderResult = render(); | ||
const policyDetailsLink = await renderResult.findByTestId('policyDetailsValue'); | ||
const userChangedUrlChecker = middlewareSpy.waitForAction('userChangedUrl'); | ||
reactTestingLibrary.act(() => { | ||
reactTestingLibrary.fireEvent.click(policyDetailsLink); | ||
}); | ||
const changedUrlAction = await userChangedUrlChecker; | ||
expect(changedUrlAction.payload.pathname).toEqual( | ||
`/management/policy/${hostDetails.metadata.endpoint.policy.applied.id}` | ||
); | ||
}); | ||
it('should display policy status value as a link', async () => { | ||
const renderResult = render(); | ||
const policyStatusLink = await renderResult.findByTestId('policyStatusValue'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ export const policyDetailsMiddlewareFactory: ImmutableMiddlewareFactory<PolicyDe | |
|
||
// Until we get the Default configuration into the Endpoint package so that the datasource has | ||
// the expected data structure, we will add it here manually. | ||
if (!policyItem.inputs.length) { | ||
if (policyItem && !policyItem.inputs.length) { | ||
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. checks for unit tests 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. Oh... I see why this is needed. Case 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. that's correct |
||
policyItem.inputs = [ | ||
{ | ||
type: 'endpoint', | ||
|
@@ -69,7 +69,7 @@ export const policyDetailsMiddlewareFactory: ImmutableMiddlewareFactory<PolicyDe | |
|
||
// Agent summary is secondary data, so its ok for it to come after the details | ||
// page is populated with the main content | ||
if (policyItem.config_id) { | ||
if (policyItem && policyItem.config_id) { | ||
const { results } = await sendGetFleetAgentStatusForConfig(http, policyItem.config_id); | ||
dispatch({ | ||
type: 'serverReturnedPolicyDetailsAgentSummaryData', | ||
|
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.
are the names switched here?
*Path
I normally associate with the router path*Uri
or*Url
I normally associated with an Href type of prop.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.
They were, corrected them - my mistake