Skip to content

Commit

Permalink
add UT for reassignment link
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlog committed Jun 29, 2020
1 parent eabf90b commit 24c31dc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const HostDetails = memo(({ details }: { details: HostMetadata }) => {
}, [details.host.id, formatUrl, queryParams]);

const agentDetailsWithFlyoutPath = `${agentDetailsAppPath}${openReassignFlyoutSearch}`;
const agentDetailsWithFlyoutUrl = `${agentDetailsUrl}${openReassignFlyoutSearch};`;
const agentDetailsWithFlyoutUrl = `${agentDetailsUrl}${openReassignFlyoutSearch}`;
const handleReassignEndpointsClick = useNavigateToAppEventHandler<
AgentDetailsReassignConfigAction
>(ingestAppId, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ describe('when on the hosts page', () => {

describe('when there is a selected host in the url', () => {
let hostDetails: HostInfo;
let agentId: string;
const dispatchServerReturnedHostPolicyResponse = (
overallStatus: HostPolicyResponseActionStatus = HostPolicyResponseActionStatus.success
) => {
Expand Down Expand Up @@ -274,6 +275,8 @@ describe('when on the hosts page', () => {
},
};

agentId = hostDetails.metadata.elastic.agent.id;

coreStart.http.get.mockReturnValue(Promise.resolve(hostDetails));
coreStart.application.getUrlForApp.mockReturnValue('/app/logs');

Expand Down Expand Up @@ -404,6 +407,32 @@ describe('when on the hosts page', () => {
).not.toBeNull();
});

it('should include the link to reassignment in Ingest', async () => {
coreStart.application.getUrlForApp.mockReturnValue('/app/ingestManager');
const renderResult = render();
const linkToLogs = await renderResult.findByTestId('hostDetailsLinkToIngest');
expect(linkToLogs).not.toBeNull();
expect(linkToLogs.textContent).toEqual('Reassign Policy');
expect(linkToLogs.getAttribute('href')).toEqual(
`/app/ingestManager#/fleet/agents/${agentId}/activity?openReassignFlyout=true`
);
});

describe('when link to reassignment in Ingest is clicked', () => {
beforeEach(async () => {
coreStart.application.getUrlForApp.mockReturnValue('/app/ingestManager');
const renderResult = render();
const linkToLogs = await renderResult.findByTestId('hostDetailsLinkToIngest');
reactTestingLibrary.act(() => {
reactTestingLibrary.fireEvent.click(linkToLogs);
});
});

it('should navigate to logs without full page refresh', () => {
expect(coreStart.application.navigateToApp.mock.calls).toHaveLength(1);
});
});

it('should include the link to logs', async () => {
const renderResult = render();
const linkToLogs = await renderResult.findByTestId('hostDetailsLinkToLogs');
Expand Down

0 comments on commit 24c31dc

Please sign in to comment.