Skip to content

Commit

Permalink
[Cases] Break long titles in toaster (#150257)
Browse files Browse the repository at this point in the history
## Summary

In some toasters, the title of the toaster is set from user input. It is
possible for long titles to overflow the toaster. This PR fixes this
issue by forcing long titles to break. Uses the EUI CSS utility class
`eui-textBreakWord`.

Fixes: #149485

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
cnasikas and kibanamachine authored Feb 7, 2023
1 parent b42bb18 commit ce6bde1
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 41 deletions.
5 changes: 4 additions & 1 deletion x-pack/plugins/cases/public/common/use_cases_toast.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ describe('Use cases toast hook', () => {

result.current.showSuccessToast('my title');

expect(successMock).toHaveBeenCalledWith('my title');
expect(successMock).toHaveBeenCalledWith({
className: 'eui-textBreakWord',
title: 'my title',
});
});
});
});
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/common/use_cases_toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const useCasesToast = () => {
}
},
showSuccessToast: (title: string) => {
toasts.addSuccess(title);
toasts.addSuccess({ title, className: 'eui-textBreakWord' });
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ describe('useAssigneesAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
'Edited case'
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: 'Edited case',
className: 'eui-textBreakWord',
});
});
});

Expand All @@ -136,9 +137,10 @@ describe('useAssigneesAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
'Edited 2 cases'
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: 'Edited 2 cases',
className: 'eui-textBreakWord',
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ describe('useCopyIDAction', () => {

await waitFor(() => {
expect(onActionSuccess).toHaveBeenCalled();
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
'Copied Case ID to clipboard'
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: 'Copied Case ID to clipboard',
className: 'eui-textBreakWord',
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ describe('useDeleteAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
'Deleted case'
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: 'Deleted case',
className: 'eui-textBreakWord',
});
});
});

Expand All @@ -180,9 +181,10 @@ describe('useDeleteAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
'Deleted 2 cases'
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: 'Deleted 2 cases',
className: 'eui-textBreakWord',
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ describe('useSeverityAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
expectedMessage
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: expectedMessage,
className: 'eui-textBreakWord',
});
});
}
);
Expand Down Expand Up @@ -168,9 +169,10 @@ describe('useSeverityAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
expectedMessage
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: expectedMessage,
className: 'eui-textBreakWord',
});
});
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ describe('useStatusAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
expectedMessage
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: expectedMessage,
className: 'eui-textBreakWord',
});
});
}
);
Expand Down Expand Up @@ -157,9 +158,10 @@ describe('useStatusAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
expectedMessage
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: expectedMessage,
className: 'eui-textBreakWord',
});
});
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ describe('useTagsAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
'Edited case'
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: 'Edited case',
className: 'eui-textBreakWord',
});
});
});

Expand All @@ -130,9 +131,10 @@ describe('useTagsAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
'Edited 2 cases'
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: 'Edited 2 cases',
className: 'eui-textBreakWord',
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ describe('useItemsAction', () => {
});

await waitFor(() => {
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith(
'My toaster title'
);
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({
title: 'My toaster title',
className: 'eui-textBreakWord',
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ describe('useUpdateCases', () => {

await waitForNextUpdate();

expect(addSuccess).toHaveBeenCalledWith('Success title');
expect(addSuccess).toHaveBeenCalledWith({
title: 'Success title',
className: 'eui-textBreakWord',
});
});

it('shows a toast error when the api return an error', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ describe('useDeleteCases', () => {

await waitForNextUpdate();

expect(addSuccess).toHaveBeenCalledWith('Success title');
expect(addSuccess).toHaveBeenCalledWith({
title: 'Success title',
className: 'eui-textBreakWord',
});
});

it('shows a toast error when the api return an error', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export const usePostPushToService = (): UsePostPushToService => {

if (!cancel.current) {
dispatch({ type: 'FETCH_SUCCESS' });
toasts.addSuccess(i18n.SUCCESS_SEND_TO_EXTERNAL_SERVICE(connector.name));
toasts.addSuccess({
title: i18n.SUCCESS_SEND_TO_EXTERNAL_SERVICE(connector.name),
className: 'eui-textBreakWord',
});
}

return response;
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/cases/public/containers/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('utils', () => {

expect(toast).toEqual({
title: 'Alerts in "My case" have been synced',
className: 'eui-textBreakWord',
});
});

Expand All @@ -74,6 +75,7 @@ describe('utils', () => {

expect(toast).toEqual({
title: 'Updated "My case"',
className: 'eui-textBreakWord',
});
});

Expand All @@ -85,6 +87,7 @@ describe('utils', () => {

expect(toast).toEqual({
title: 'Updated "My case"',
className: 'eui-textBreakWord',
});
});

Expand All @@ -100,6 +103,7 @@ describe('utils', () => {
expect(toast).toEqual({
title: 'Updated "My case"',
text: 'Updated the statuses of attached alerts.',
className: 'eui-textBreakWord',
});
});

Expand All @@ -114,6 +118,7 @@ describe('utils', () => {

expect(toast).toEqual({
title: 'Updated "My case"',
className: 'eui-textBreakWord',
});
});

Expand All @@ -128,6 +133,7 @@ describe('utils', () => {

expect(toast).toEqual({
title: 'Updated "My case"',
className: 'eui-textBreakWord',
});
});

Expand All @@ -142,6 +148,7 @@ describe('utils', () => {

expect(toast).toEqual({
title: 'Updated "My case"',
className: 'eui-textBreakWord',
});
});
});
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cases/public/containers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const createUpdateSuccessToaster = (

const toast: ToastInputFields = {
title: i18n.UPDATED_CASE(caseAfterUpdate.title),
className: 'eui-textBreakWord',
};

if (valueToUpdateIsSettings(key, value) && value?.syncAlerts && caseHasAlerts) {
Expand Down

0 comments on commit ce6bde1

Please sign in to comment.