[Fleet] fix abort agent singular (#142696)

* fix abort agent singular

* changed toast message to tag(s) updated

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Julia Bardi 2022-10-05 13:01:47 +02:00 committed by GitHub
parent 4019d378f6
commit c46a624d91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 8 deletions

View file

@ -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?',
});
});

View file

@ -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,
},

View file

@ -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'
);
});
@ -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' }
);
});
@ -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'
);
});
@ -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' }
);
});
});

View file

@ -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);
@ -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 });
}