mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* Toast notifications: ignore undefined options
* just use omitBy
(cherry picked from commit 2cabe1a68f
)
Co-authored-by: Pierre Gayvallet <pierre.gayvallet@elastic.co>
This commit is contained in:
parent
758a776458
commit
704dcafc5c
2 changed files with 34 additions and 3 deletions
|
@ -19,13 +19,13 @@ async function getCurrentToasts(toasts: ToastsApi) {
|
|||
|
||||
function uiSettingsMock() {
|
||||
const mock = uiSettingsServiceMock.createSetupContract();
|
||||
mock.get.mockImplementation(() => (config: string) => {
|
||||
mock.get.mockImplementation((config: string) => {
|
||||
switch (config) {
|
||||
case 'notifications:lifetime:info':
|
||||
return 5000;
|
||||
case 'notifications:lifetime:warning':
|
||||
return 10000;
|
||||
case 'notification:lifetime:error':
|
||||
case 'notifications:lifetime:error':
|
||||
return 30000;
|
||||
default:
|
||||
throw new Error(`Accessing ${config} is not supported in the mock.`);
|
||||
|
@ -113,6 +113,12 @@ describe('#add()', () => {
|
|||
const toasts = new ToastsApi(toastDeps());
|
||||
expect(toasts.add('foo')).toHaveProperty('title', 'foo');
|
||||
});
|
||||
|
||||
it('fallbacks to default values for undefined properties', async () => {
|
||||
const toasts = new ToastsApi(toastDeps());
|
||||
const toast = toasts.add({ title: 'foo', toastLifeTimeMs: undefined });
|
||||
expect(toast.toastLifeTimeMs).toEqual(5000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#remove()', () => {
|
||||
|
@ -145,6 +151,12 @@ describe('#addInfo()', () => {
|
|||
expect(currentToasts[0].toastLifeTimeMs).toBe(1);
|
||||
expect(currentToasts[0]).toBe(toast);
|
||||
});
|
||||
|
||||
it('fallbacks to default values for undefined properties', async () => {
|
||||
const toasts = new ToastsApi(toastDeps());
|
||||
const toast = toasts.addInfo({ title: 'foo', toastLifeTimeMs: undefined });
|
||||
expect(toast.toastLifeTimeMs).toEqual(5000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addSuccess()', () => {
|
||||
|
@ -159,6 +171,12 @@ describe('#addSuccess()', () => {
|
|||
const currentToasts = await getCurrentToasts(toasts);
|
||||
expect(currentToasts[0]).toBe(toast);
|
||||
});
|
||||
|
||||
it('fallbacks to default values for undefined properties', async () => {
|
||||
const toasts = new ToastsApi(toastDeps());
|
||||
const toast = toasts.addSuccess({ title: 'foo', toastLifeTimeMs: undefined });
|
||||
expect(toast.toastLifeTimeMs).toEqual(5000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addWarning()', () => {
|
||||
|
@ -173,6 +191,12 @@ describe('#addWarning()', () => {
|
|||
const currentToasts = await getCurrentToasts(toasts);
|
||||
expect(currentToasts[0]).toBe(toast);
|
||||
});
|
||||
|
||||
it('fallbacks to default values for undefined properties', async () => {
|
||||
const toasts = new ToastsApi(toastDeps());
|
||||
const toast = toasts.addWarning({ title: 'foo', toastLifeTimeMs: undefined });
|
||||
expect(toast.toastLifeTimeMs).toEqual(10000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addDanger()', () => {
|
||||
|
@ -187,6 +211,12 @@ describe('#addDanger()', () => {
|
|||
const currentToasts = await getCurrentToasts(toasts);
|
||||
expect(currentToasts[0]).toBe(toast);
|
||||
});
|
||||
|
||||
it('fallbacks to default values for undefined properties', async () => {
|
||||
const toasts = new ToastsApi(toastDeps());
|
||||
const toast = toasts.addDanger({ title: 'foo', toastLifeTimeMs: undefined });
|
||||
expect(toast.toastLifeTimeMs).toEqual(10000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addError', () => {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import { EuiGlobalToastListToast as EuiToast } from '@elastic/eui';
|
||||
import React from 'react';
|
||||
import * as Rx from 'rxjs';
|
||||
import { omitBy, isUndefined } from 'lodash';
|
||||
|
||||
import { ErrorToast } from './error_toast';
|
||||
import { MountPoint } from '../../types';
|
||||
|
@ -75,7 +76,7 @@ const normalizeToast = (toastOrTitle: ToastInput): ToastInputFields => {
|
|||
title: toastOrTitle,
|
||||
};
|
||||
}
|
||||
return toastOrTitle;
|
||||
return omitBy(toastOrTitle, isUndefined);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue