Skip to content

Commit

Permalink
[Fleet] fix abort agent singular (elastic#142696)
Browse files Browse the repository at this point in the history
* fix abort agent singular

* changed toast message to tag(s) updated

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
2 people authored and WafaaNasr committed Oct 14, 2022
1 parent 57ec4b6 commit be7c18e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,23 @@ describe('useActionStatus', () => {
});
expect(mockSendPostCancelAction).toHaveBeenCalledWith('action1');
expect(mockOnAbortSuccess).toHaveBeenCalled();
expect(mockOpenConfirm).toHaveBeenCalledWith('This action will abort upgrade of 1 agents', {
expect(mockOpenConfirm).toHaveBeenCalledWith('This action will abort upgrade of 1 agent', {
title: 'Abort upgrade?',
});
});

it('should post abort and invoke callback on abort upgrade - plural', async () => {
mockSendPostCancelAction.mockResolvedValue({});
let result: any | undefined;
await act(async () => {
({ result } = renderHook(() => useActionStatus(mockOnAbortSuccess, false)));
});
await act(async () => {
await result.current.abortUpgrade({ ...mockActionStatuses[0], nbAgentsAck: 0 });
});
expect(mockSendPostCancelAction).toHaveBeenCalledWith('action1');
expect(mockOnAbortSuccess).toHaveBeenCalled();
expect(mockOpenConfirm).toHaveBeenCalledWith('This action will abort upgrade of 2 agents', {
title: 'Abort upgrade?',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export function useActionStatus(onAbortSuccess: () => void, refreshAgentActivity
try {
const confirmRes = await overlays.openConfirm(
i18n.translate('xpack.fleet.currentUpgrade.confirmDescription', {
defaultMessage: 'This action will abort upgrade of {nbAgents} agents',
defaultMessage:
'This action will abort upgrade of {nbAgents, plural, one {# agent} other {# agents}}',
values: {
nbAgents: action.nbAgentsActioned - action.nbAgentsAck,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('useUpdateTags', () => {
await act(() => result.current.updateTags('agent1', ['tag1'], mockOnSuccess));
expect(mockOnSuccess).toHaveBeenCalled();
expect(useStartServices().notifications.toasts.addSuccess as jest.Mock).toHaveBeenCalledWith(
'Tags updated'
'Tag(s) updated'
);
});

Expand All @@ -57,7 +57,7 @@ describe('useUpdateTags', () => {
expect(mockOnSuccess).not.toHaveBeenCalled();
expect(useStartServices().notifications.toasts.addError as jest.Mock).toHaveBeenCalledWith(
'error',
{ title: 'Tags update failed' }
{ title: 'Tag(s) update failed' }
);
});

Expand All @@ -68,7 +68,7 @@ describe('useUpdateTags', () => {
await act(() => result.current.bulkUpdateTags('query', ['tag1'], [], mockOnSuccess));
expect(mockOnSuccess).toHaveBeenCalled();
expect(useStartServices().notifications.toasts.addSuccess as jest.Mock).toHaveBeenCalledWith(
'Tags updated'
'Tag(s) updated'
);
});

Expand All @@ -80,7 +80,7 @@ describe('useUpdateTags', () => {
expect(mockOnSuccess).not.toHaveBeenCalled();
expect(useStartServices().notifications.toasts.addError as jest.Mock).toHaveBeenCalledWith(
'error',
{ title: 'Tags update failed' }
{ title: 'Tag(s) update failed' }
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useUpdateTags = () => {
const message =
successMessage ??
i18n.translate('xpack.fleet.updateAgentTags.successNotificationTitle', {
defaultMessage: 'Tags updated',
defaultMessage: 'Tag(s) updated',
});
notifications.toasts.addSuccess(message);

Expand All @@ -43,7 +43,7 @@ export const useUpdateTags = () => {
const errorTitle =
errorMessage ??
i18n.translate('xpack.fleet.updateAgentTags.errorNotificationTitle', {
defaultMessage: 'Tags update failed',
defaultMessage: 'Tag(s) update failed',
});
notifications.toasts.addError(error, { title: errorTitle });
}
Expand Down

0 comments on commit be7c18e

Please sign in to comment.