2019-09-17 20:57:53 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
2021-02-04 03:12:39 +01:00
|
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
|
|
* 2.0.
|
2019-09-17 20:57:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2020-06-10 18:28:00 +02:00
|
|
|
import { Observable } from 'rxjs';
|
2019-10-03 17:24:45 +02:00
|
|
|
import { ReactWrapper } from 'enzyme';
|
|
|
|
import { act } from 'react-dom/test-utils';
|
2019-09-17 20:57:53 +02:00
|
|
|
import { App } from './app';
|
2020-09-23 23:40:52 +02:00
|
|
|
import { LensAppProps, LensAppServices } from './types';
|
2021-01-21 11:00:57 +01:00
|
|
|
import { EditorFrameInstance, EditorFrameProps } from '../types';
|
2020-10-19 17:21:25 +02:00
|
|
|
import { Document } from '../persistence';
|
|
|
|
import { DOC_TYPE } from '../../common';
|
2019-09-17 20:57:53 +02:00
|
|
|
import { mount } from 'enzyme';
|
2020-09-23 23:40:52 +02:00
|
|
|
import { I18nProvider } from '@kbn/i18n/react';
|
2020-06-10 18:28:00 +02:00
|
|
|
import {
|
|
|
|
SavedObjectSaveModal,
|
|
|
|
checkForDuplicateTitle,
|
|
|
|
} from '../../../../../src/plugins/saved_objects/public';
|
2020-09-23 23:40:52 +02:00
|
|
|
import { createMemoryHistory } from 'history';
|
2020-01-21 22:33:53 +01:00
|
|
|
import {
|
2020-09-23 23:40:52 +02:00
|
|
|
DataPublicPluginStart,
|
2020-01-21 22:33:53 +01:00
|
|
|
esFilters,
|
|
|
|
FilterManager,
|
|
|
|
IFieldType,
|
|
|
|
IIndexPattern,
|
2020-06-05 09:55:42 +02:00
|
|
|
UI_SETTINGS,
|
2020-04-15 12:22:37 +02:00
|
|
|
} from '../../../../../src/plugins/data/public';
|
|
|
|
import { navigationPluginMock } from '../../../../../src/plugins/navigation/public/mocks';
|
|
|
|
import { TopNavMenuData } from '../../../../../src/plugins/navigation/public';
|
2019-09-17 20:57:53 +02:00
|
|
|
import { coreMock } from 'src/core/public/mocks';
|
2020-09-23 23:40:52 +02:00
|
|
|
import {
|
|
|
|
LensByValueInput,
|
|
|
|
LensSavedObjectAttributes,
|
|
|
|
LensByReferenceInput,
|
|
|
|
} from '../editor_frame_service/embeddable/embeddable';
|
|
|
|
import { SavedObjectReference } from '../../../../../src/core/types';
|
2020-12-15 19:18:36 +01:00
|
|
|
import {
|
|
|
|
mockAttributeService,
|
|
|
|
createEmbeddableStateTransferMock,
|
|
|
|
} from '../../../../../src/plugins/embeddable/public/mocks';
|
2020-09-23 23:40:52 +02:00
|
|
|
import { LensAttributeService } from '../lens_attribute_service';
|
|
|
|
import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public';
|
2020-12-15 19:18:36 +01:00
|
|
|
import { EmbeddableStateTransfer } from '../../../../../src/plugins/embeddable/public';
|
2021-01-21 11:00:57 +01:00
|
|
|
import { NativeRenderer } from '../native_renderer';
|
|
|
|
import moment from 'moment';
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-08-21 18:08:25 +02:00
|
|
|
jest.mock('../editor_frame_service/editor_frame/expression_helpers');
|
2019-09-17 20:57:53 +02:00
|
|
|
jest.mock('src/core/public');
|
2020-06-10 18:28:00 +02:00
|
|
|
jest.mock('../../../../../src/plugins/saved_objects/public', () => {
|
2020-11-18 18:23:08 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
2020-06-10 18:28:00 +02:00
|
|
|
const { SavedObjectSaveModal, SavedObjectSaveModalOrigin } = jest.requireActual(
|
|
|
|
'../../../../../src/plugins/saved_objects/public'
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
SavedObjectSaveModal,
|
|
|
|
SavedObjectSaveModalOrigin,
|
|
|
|
checkForDuplicateTitle: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-04-15 12:22:37 +02:00
|
|
|
const navigationStartMock = navigationPluginMock.createStartContract();
|
|
|
|
|
|
|
|
jest.spyOn(navigationStartMock.ui.TopNavMenu.prototype, 'constructor').mockImplementation(() => {
|
|
|
|
return <div className="topNavMenu" />;
|
|
|
|
});
|
2019-12-16 14:56:51 +01:00
|
|
|
|
2020-04-15 12:22:37 +02:00
|
|
|
const { TopNavMenu } = navigationStartMock.ui;
|
2019-12-16 14:56:51 +01:00
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
function createMockFrame(): jest.Mocked<EditorFrameInstance> {
|
|
|
|
return {
|
2021-03-29 18:33:05 +02:00
|
|
|
mount: jest.fn(async (el, props) => {}),
|
2019-09-17 20:57:53 +02:00
|
|
|
unmount: jest.fn(() => {}),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-29 14:18:30 +01:00
|
|
|
function createMockSearchService() {
|
|
|
|
let sessionIdCounter = 1;
|
|
|
|
return {
|
|
|
|
session: {
|
|
|
|
start: jest.fn(() => `sessionId-${sessionIdCounter++}`),
|
|
|
|
clear: jest.fn(),
|
2021-03-10 09:00:01 +01:00
|
|
|
getSessionId: jest.fn(() => `sessionId-${sessionIdCounter}`),
|
2020-12-29 14:18:30 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-03 17:24:45 +02:00
|
|
|
function createMockFilterManager() {
|
|
|
|
const unsubscribe = jest.fn();
|
|
|
|
|
|
|
|
let subscriber: () => void;
|
|
|
|
let filters: unknown = [];
|
|
|
|
|
|
|
|
return {
|
|
|
|
getUpdates$: () => ({
|
|
|
|
subscribe: ({ next }: { next: () => void }) => {
|
|
|
|
subscriber = next;
|
|
|
|
return unsubscribe;
|
|
|
|
},
|
|
|
|
}),
|
2020-02-03 17:19:41 +01:00
|
|
|
setFilters: jest.fn((newFilters: unknown[]) => {
|
2019-10-03 17:24:45 +02:00
|
|
|
filters = newFilters;
|
2020-02-03 17:19:41 +01:00
|
|
|
if (subscriber) subscriber();
|
|
|
|
}),
|
|
|
|
setAppFilters: jest.fn((newFilters: unknown[]) => {
|
|
|
|
filters = newFilters;
|
|
|
|
if (subscriber) subscriber();
|
|
|
|
}),
|
2019-10-03 17:24:45 +02:00
|
|
|
getFilters: () => filters,
|
2020-01-21 22:33:53 +01:00
|
|
|
getGlobalFilters: () => {
|
|
|
|
// @ts-ignore
|
|
|
|
return filters.filter(esFilters.isFilterPinned);
|
|
|
|
},
|
2019-10-03 17:24:45 +02:00
|
|
|
removeAll: () => {
|
|
|
|
filters = [];
|
|
|
|
subscriber();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-29 09:48:23 +02:00
|
|
|
function createMockQueryString() {
|
|
|
|
return {
|
|
|
|
getQuery: jest.fn(() => ({ query: '', language: 'kuery' })),
|
|
|
|
setQuery: jest.fn(),
|
|
|
|
getDefaultQuery: jest.fn(() => ({ query: '', language: 'kuery' })),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-03-24 20:51:00 +01:00
|
|
|
function createMockTimefilter() {
|
|
|
|
const unsubscribe = jest.fn();
|
|
|
|
|
2020-12-29 14:18:30 +01:00
|
|
|
let timeFilter = { from: 'now-7d', to: 'now' };
|
|
|
|
let subscriber: () => void;
|
2020-03-24 20:51:00 +01:00
|
|
|
return {
|
2020-12-29 14:18:30 +01:00
|
|
|
getTime: jest.fn(() => timeFilter),
|
|
|
|
setTime: jest.fn((newTimeFilter) => {
|
|
|
|
timeFilter = newTimeFilter;
|
|
|
|
if (subscriber) {
|
|
|
|
subscriber();
|
|
|
|
}
|
|
|
|
}),
|
2020-03-24 20:51:00 +01:00
|
|
|
getTimeUpdate$: () => ({
|
|
|
|
subscribe: ({ next }: { next: () => void }) => {
|
2020-12-29 14:18:30 +01:00
|
|
|
subscriber = next;
|
2020-03-24 20:51:00 +01:00
|
|
|
return unsubscribe;
|
|
|
|
},
|
|
|
|
}),
|
2021-01-21 11:00:57 +01:00
|
|
|
calculateBounds: jest.fn(() => ({
|
|
|
|
min: moment('2021-01-10T04:00:00.000Z'),
|
|
|
|
max: moment('2021-01-10T08:00:00.000Z'),
|
|
|
|
})),
|
|
|
|
getBounds: jest.fn(() => timeFilter),
|
2020-06-10 15:44:59 +02:00
|
|
|
getRefreshInterval: () => {},
|
|
|
|
getRefreshIntervalDefaults: () => {},
|
2021-04-08 13:00:11 +02:00
|
|
|
getAutoRefreshFetch$: () => new Observable(),
|
2020-03-24 20:51:00 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
describe('Lens App', () => {
|
|
|
|
let core: ReturnType<typeof coreMock['createStart']>;
|
2020-09-23 23:40:52 +02:00
|
|
|
let defaultDoc: Document;
|
|
|
|
let defaultSavedObjectId: string;
|
|
|
|
|
|
|
|
const navMenuItems = {
|
|
|
|
expectedSaveButton: { emphasize: true, testId: 'lnsApp_saveButton' },
|
|
|
|
expectedSaveAsButton: { emphasize: false, testId: 'lnsApp_saveButton' },
|
|
|
|
expectedSaveAndReturnButton: { emphasize: true, testId: 'lnsApp_saveAndReturnButton' },
|
|
|
|
};
|
|
|
|
|
|
|
|
function makeAttributeService(): LensAttributeService {
|
|
|
|
const attributeServiceMock = mockAttributeService<
|
|
|
|
LensSavedObjectAttributes,
|
|
|
|
LensByValueInput,
|
|
|
|
LensByReferenceInput
|
|
|
|
>(
|
|
|
|
DOC_TYPE,
|
|
|
|
{
|
2020-10-06 09:31:55 +02:00
|
|
|
saveMethod: jest.fn(),
|
|
|
|
unwrapMethod: jest.fn(),
|
|
|
|
checkForDuplicateTitle: jest.fn(),
|
2020-09-23 23:40:52 +02:00
|
|
|
},
|
|
|
|
core
|
|
|
|
);
|
|
|
|
attributeServiceMock.unwrapAttributes = jest.fn().mockResolvedValue(defaultDoc);
|
|
|
|
attributeServiceMock.wrapAttributes = jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue({ savedObjectId: defaultSavedObjectId });
|
|
|
|
return attributeServiceMock;
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeDefaultProps(): jest.Mocked<LensAppProps> {
|
|
|
|
return {
|
2019-09-17 20:57:53 +02:00
|
|
|
editorFrame: createMockFrame(),
|
2020-09-23 23:40:52 +02:00
|
|
|
history: createMemoryHistory(),
|
|
|
|
redirectTo: jest.fn(),
|
|
|
|
redirectToOrigin: jest.fn(),
|
|
|
|
onAppLeave: jest.fn(),
|
|
|
|
setHeaderActionMenu: jest.fn(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeDefaultServices(): jest.Mocked<LensAppServices> {
|
|
|
|
return {
|
|
|
|
http: core.http,
|
|
|
|
chrome: core.chrome,
|
|
|
|
overlays: core.overlays,
|
|
|
|
uiSettings: core.uiSettings,
|
|
|
|
navigation: navigationStartMock,
|
|
|
|
notifications: core.notifications,
|
|
|
|
attributeService: makeAttributeService(),
|
|
|
|
savedObjectsClient: core.savedObjects.client,
|
|
|
|
dashboardFeatureFlag: { allowByValueEmbeddables: false },
|
2020-12-15 19:18:36 +01:00
|
|
|
stateTransfer: createEmbeddableStateTransferMock() as EmbeddableStateTransfer,
|
2020-09-23 23:40:52 +02:00
|
|
|
getOriginatingAppName: jest.fn(() => 'defaultOriginatingApp'),
|
|
|
|
application: {
|
|
|
|
...core.application,
|
|
|
|
capabilities: {
|
|
|
|
...core.application.capabilities,
|
|
|
|
visualize: { save: true, saveQuery: true, show: true },
|
2019-10-03 17:24:45 +02:00
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
getUrlForApp: jest.fn((appId: string) => `/testbasepath/app/${appId}#/`),
|
2019-10-03 17:24:45 +02:00
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
data: ({
|
2019-10-29 10:55:24 +01:00
|
|
|
query: {
|
|
|
|
filterManager: createMockFilterManager(),
|
2019-11-20 12:06:53 +01:00
|
|
|
timefilter: {
|
2020-03-24 20:51:00 +01:00
|
|
|
timefilter: createMockTimefilter(),
|
2019-11-20 12:06:53 +01:00
|
|
|
},
|
2020-07-29 09:48:23 +02:00
|
|
|
queryString: createMockQueryString(),
|
2020-06-10 15:44:59 +02:00
|
|
|
state$: new Observable(),
|
2019-10-29 10:55:24 +01:00
|
|
|
},
|
2019-10-03 17:24:45 +02:00
|
|
|
indexPatterns: {
|
2020-05-22 09:08:58 +02:00
|
|
|
get: jest.fn((id) => {
|
|
|
|
return new Promise((resolve) => resolve({ id }));
|
2019-12-09 12:31:49 +01:00
|
|
|
}),
|
2019-10-03 17:24:45 +02:00
|
|
|
},
|
2020-12-29 14:18:30 +01:00
|
|
|
search: createMockSearchService(),
|
2021-01-21 11:00:57 +01:00
|
|
|
nowProvider: {
|
|
|
|
get: jest.fn(),
|
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
} as unknown) as DataPublicPluginStart,
|
2019-10-29 13:16:08 +01:00
|
|
|
storage: {
|
2019-09-17 20:57:53 +02:00
|
|
|
get: jest.fn(),
|
2020-09-23 23:40:52 +02:00
|
|
|
set: jest.fn(),
|
|
|
|
remove: jest.fn(),
|
|
|
|
clear: jest.fn(),
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mountWith({
|
|
|
|
props: incomingProps,
|
|
|
|
services: incomingServices,
|
|
|
|
}: {
|
|
|
|
props?: jest.Mocked<LensAppProps>;
|
|
|
|
services?: jest.Mocked<LensAppServices>;
|
|
|
|
}) {
|
|
|
|
const props = incomingProps ?? makeDefaultProps();
|
|
|
|
const services = incomingServices ?? makeDefaultServices();
|
|
|
|
const wrappingComponent: React.FC<{
|
|
|
|
children: React.ReactNode;
|
|
|
|
}> = ({ children }) => {
|
|
|
|
return (
|
|
|
|
<I18nProvider>
|
|
|
|
<KibanaContextProvider services={services}>{children}</KibanaContextProvider>
|
|
|
|
</I18nProvider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
const frame = props.editorFrame as ReturnType<typeof createMockFrame>;
|
|
|
|
const component = mount(<App {...props} />, { wrappingComponent });
|
|
|
|
return { component, frame, props, services };
|
2019-09-17 20:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-10-24 17:59:45 +02:00
|
|
|
core = coreMock.createStart({ basePath: '/testbasepath' });
|
2020-09-23 23:40:52 +02:00
|
|
|
defaultSavedObjectId = '1234';
|
|
|
|
defaultDoc = ({
|
|
|
|
savedObjectId: defaultSavedObjectId,
|
|
|
|
title: 'An extremely cool default document!',
|
|
|
|
expression: 'definitely a valid expression',
|
|
|
|
state: {
|
|
|
|
query: 'kuery',
|
|
|
|
filters: [{ query: { match_phrase: { src: 'test' } } }],
|
|
|
|
},
|
|
|
|
references: [{ type: 'index-pattern', id: '1', name: 'index-pattern-0' }],
|
|
|
|
} as unknown) as Document;
|
2019-09-17 20:57:53 +02:00
|
|
|
|
|
|
|
core.uiSettings.get.mockImplementation(
|
2020-05-22 09:08:58 +02:00
|
|
|
jest.fn((type) => {
|
2020-08-03 23:43:34 +02:00
|
|
|
if (type === UI_SETTINGS.TIMEPICKER_TIME_DEFAULTS) {
|
2019-09-17 20:57:53 +02:00
|
|
|
return { from: 'now-7d', to: 'now' };
|
2020-06-05 09:55:42 +02:00
|
|
|
} else if (type === UI_SETTINGS.SEARCH_QUERY_LANGUAGE) {
|
2019-09-17 20:57:53 +02:00
|
|
|
return 'kuery';
|
2020-06-10 15:44:59 +02:00
|
|
|
} else if (type === 'state:storeInSessionStorage') {
|
|
|
|
return false;
|
2019-09-17 20:57:53 +02:00
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the editor frame', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { frame } = mountWith({});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
|
|
|
expect(frame.mount.mock.calls).toMatchInlineSnapshot(`
|
|
|
|
Array [
|
|
|
|
Array [
|
|
|
|
<div
|
2019-09-23 20:57:35 +02:00
|
|
|
class="lnsApp__frame"
|
2019-09-17 20:57:53 +02:00
|
|
|
/>,
|
|
|
|
Object {
|
|
|
|
"dateRange": Object {
|
2021-01-21 11:00:57 +01:00
|
|
|
"fromDate": "2021-01-10T04:00:00.000Z",
|
|
|
|
"toDate": "2021-01-10T08:00:00.000Z",
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
"doc": undefined,
|
2019-10-03 17:24:45 +02:00
|
|
|
"filters": Array [],
|
2020-10-06 10:15:41 +02:00
|
|
|
"initialContext": undefined,
|
2019-09-17 20:57:53 +02:00
|
|
|
"onChange": [Function],
|
|
|
|
"onError": [Function],
|
|
|
|
"query": Object {
|
|
|
|
"language": "kuery",
|
|
|
|
"query": "",
|
|
|
|
},
|
2019-10-03 17:24:45 +02:00
|
|
|
"savedQuery": undefined,
|
2020-12-29 14:18:30 +01:00
|
|
|
"searchSessionId": "sessionId-1",
|
2020-07-01 10:08:37 +02:00
|
|
|
"showNoDataPopover": [Function],
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
]
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
|
2020-02-03 17:19:41 +01:00
|
|
|
it('clears app filters on load', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { services } = mountWith({});
|
|
|
|
expect(services.data.query.filterManager.setAppFilters).toHaveBeenCalledWith([]);
|
2020-02-03 17:19:41 +01:00
|
|
|
});
|
|
|
|
|
2020-07-31 18:59:51 +02:00
|
|
|
it('passes global filters to frame', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const services = makeDefaultServices();
|
2020-07-31 18:59:51 +02:00
|
|
|
const indexPattern = ({ id: 'index1' } as unknown) as IIndexPattern;
|
|
|
|
const pinnedField = ({ name: 'pinnedField' } as unknown) as IFieldType;
|
|
|
|
const pinnedFilter = esFilters.buildExistsFilter(pinnedField, indexPattern);
|
2020-09-23 23:40:52 +02:00
|
|
|
services.data.query.filterManager.getFilters = jest.fn().mockImplementation(() => {
|
2020-11-24 13:26:54 +01:00
|
|
|
return [];
|
|
|
|
});
|
|
|
|
services.data.query.filterManager.getGlobalFilters = jest.fn().mockImplementation(() => {
|
2020-07-31 18:59:51 +02:00
|
|
|
return [pinnedFilter];
|
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame } = mountWith({ services });
|
|
|
|
|
2020-07-31 18:59:51 +02:00
|
|
|
component.update();
|
2020-09-23 23:40:52 +02:00
|
|
|
|
2020-07-31 18:59:51 +02:00
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
2021-01-21 11:00:57 +01:00
|
|
|
dateRange: { fromDate: '2021-01-10T04:00:00.000Z', toDate: '2021-01-10T08:00:00.000Z' },
|
2020-07-31 18:59:51 +02:00
|
|
|
query: { query: '', language: 'kuery' },
|
|
|
|
filters: [pinnedFilter],
|
|
|
|
})
|
|
|
|
);
|
2020-11-24 13:26:54 +01:00
|
|
|
expect(services.data.query.filterManager.getFilters).not.toHaveBeenCalled();
|
2020-07-31 18:59:51 +02:00
|
|
|
});
|
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
it('displays errors from the frame in a toast', () => {
|
|
|
|
const { component, frame, services } = mountWith({});
|
|
|
|
const onError = frame.mount.mock.calls[0][1].onError;
|
|
|
|
onError({ message: 'error' });
|
|
|
|
component.update();
|
|
|
|
expect(services.notifications.toasts.addDanger).toHaveBeenCalled();
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
describe('breadcrumbs', () => {
|
|
|
|
const breadcrumbDocSavedObjectId = defaultSavedObjectId;
|
|
|
|
const breadcrumbDoc = ({
|
|
|
|
savedObjectId: breadcrumbDocSavedObjectId,
|
2019-09-17 20:57:53 +02:00
|
|
|
title: 'Daaaaaaadaumching!',
|
|
|
|
state: {
|
|
|
|
query: 'fake query',
|
2020-08-21 18:08:25 +02:00
|
|
|
filters: [],
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
2020-08-21 18:08:25 +02:00
|
|
|
references: [],
|
2020-09-23 23:40:52 +02:00
|
|
|
} as unknown) as Document;
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
it('sets breadcrumbs when the document title changes', async () => {
|
|
|
|
const { component, services } = mountWith({});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.chrome.setBreadcrumbs).toHaveBeenCalledWith([
|
2021-02-11 19:46:35 +01:00
|
|
|
{
|
|
|
|
text: 'Visualize Library',
|
|
|
|
href: '/testbasepath/app/visualize#/',
|
|
|
|
onClick: expect.anything(),
|
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
{ text: 'Create' },
|
|
|
|
]);
|
2020-09-14 19:52:14 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
services.attributeService.unwrapAttributes = jest.fn().mockResolvedValue(breadcrumbDoc);
|
|
|
|
await act(async () => {
|
|
|
|
component.setProps({ initialInput: { savedObjectId: breadcrumbDocSavedObjectId } });
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(services.chrome.setBreadcrumbs).toHaveBeenCalledWith([
|
2021-02-11 19:46:35 +01:00
|
|
|
{
|
|
|
|
text: 'Visualize Library',
|
|
|
|
href: '/testbasepath/app/visualize#/',
|
|
|
|
onClick: expect.anything(),
|
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
{ text: 'Daaaaaaadaumching!' },
|
|
|
|
]);
|
2020-09-14 19:52:14 +02:00
|
|
|
});
|
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
it('sets originatingApp breadcrumb when the document title changes', async () => {
|
|
|
|
const props = makeDefaultProps();
|
|
|
|
const services = makeDefaultServices();
|
|
|
|
props.incomingState = { originatingApp: 'coolContainer' };
|
|
|
|
services.getOriginatingAppName = jest.fn(() => 'The Coolest Container Ever Made');
|
|
|
|
const { component } = mountWith({ props, services });
|
|
|
|
|
|
|
|
expect(services.chrome.setBreadcrumbs).toHaveBeenCalledWith([
|
|
|
|
{ text: 'The Coolest Container Ever Made', onClick: expect.anything() },
|
2021-02-11 19:46:35 +01:00
|
|
|
{
|
|
|
|
text: 'Visualize Library',
|
|
|
|
href: '/testbasepath/app/visualize#/',
|
|
|
|
onClick: expect.anything(),
|
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
{ text: 'Create' },
|
|
|
|
]);
|
2020-08-21 16:18:14 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
services.attributeService.unwrapAttributes = jest.fn().mockResolvedValue(breadcrumbDoc);
|
|
|
|
await act(async () => {
|
|
|
|
component.setProps({ initialInput: { savedObjectId: breadcrumbDocSavedObjectId } });
|
|
|
|
});
|
2020-08-21 16:18:14 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.chrome.setBreadcrumbs).toHaveBeenCalledWith([
|
|
|
|
{ text: 'The Coolest Container Ever Made', onClick: expect.anything() },
|
2021-02-11 19:46:35 +01:00
|
|
|
{
|
|
|
|
text: 'Visualize Library',
|
|
|
|
href: '/testbasepath/app/visualize#/',
|
|
|
|
onClick: expect.anything(),
|
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
{ text: 'Daaaaaaadaumching!' },
|
|
|
|
]);
|
2020-08-21 16:18:14 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
describe('persistence', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
it('does not load a document if there is no initial input', () => {
|
|
|
|
const { services } = mountWith({});
|
|
|
|
expect(services.attributeService.unwrapAttributes).not.toHaveBeenCalled();
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
it('loads a document and uses query and filters if initial input is provided', async () => {
|
|
|
|
const { component, frame, services } = mountWith({});
|
|
|
|
services.attributeService.unwrapAttributes = jest.fn().mockResolvedValue({
|
|
|
|
savedObjectId: defaultSavedObjectId,
|
2019-09-17 20:57:53 +02:00
|
|
|
state: {
|
|
|
|
query: 'fake query',
|
2020-02-03 17:19:41 +01:00
|
|
|
filters: [{ query: { match_phrase: { src: 'test' } } }],
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
2020-08-21 18:08:25 +02:00
|
|
|
references: [{ type: 'index-pattern', id: '1', name: 'index-pattern-0' }],
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2020-03-10 22:10:35 +01:00
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
|
2020-03-10 22:10:35 +01:00
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.attributeService.unwrapAttributes).toHaveBeenCalledWith({
|
|
|
|
savedObjectId: defaultSavedObjectId,
|
|
|
|
});
|
|
|
|
expect(services.data.indexPatterns.get).toHaveBeenCalledWith('1');
|
|
|
|
expect(services.data.query.filterManager.setAppFilters).toHaveBeenCalledWith([
|
2020-02-03 17:19:41 +01:00
|
|
|
{ query: { match_phrase: { src: 'test' } } },
|
|
|
|
]);
|
2019-10-03 17:24:45 +02:00
|
|
|
expect(TopNavMenu).toHaveBeenCalledWith(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
|
|
|
query: 'fake query',
|
2019-10-03 17:24:45 +02:00
|
|
|
indexPatterns: [{ id: '1' }],
|
2019-09-17 20:57:53 +02:00
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
2020-08-21 18:08:25 +02:00
|
|
|
doc: expect.objectContaining({
|
2020-09-23 23:40:52 +02:00
|
|
|
savedObjectId: defaultSavedObjectId,
|
2020-08-21 18:08:25 +02:00
|
|
|
state: expect.objectContaining({
|
2019-09-17 20:57:53 +02:00
|
|
|
query: 'fake query',
|
2020-02-03 17:19:41 +01:00
|
|
|
filters: [{ query: { match_phrase: { src: 'test' } } }],
|
2020-08-21 18:08:25 +02:00
|
|
|
}),
|
|
|
|
}),
|
2019-09-17 20:57:53 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not load documents on sequential renders unless the id changes', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { services, component } = mountWith({});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-03-10 22:10:35 +01:00
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
|
2020-03-10 22:10:35 +01:00
|
|
|
});
|
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
|
2020-03-10 22:10:35 +01:00
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.attributeService.unwrapAttributes).toHaveBeenCalledTimes(1);
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-03-10 22:10:35 +01:00
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.setProps({ initialInput: { savedObjectId: '5678' } });
|
2020-03-10 22:10:35 +01:00
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.attributeService.unwrapAttributes).toHaveBeenCalledTimes(2);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles document load errors', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const services = makeDefaultServices();
|
|
|
|
services.attributeService.unwrapAttributes = jest.fn().mockRejectedValue('failed to load');
|
|
|
|
const { component, props } = mountWith({ services });
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-03-10 22:10:35 +01:00
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
|
2020-03-10 22:10:35 +01:00
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.attributeService.unwrapAttributes).toHaveBeenCalledWith({
|
|
|
|
savedObjectId: defaultSavedObjectId,
|
|
|
|
});
|
|
|
|
expect(services.notifications.toasts.addDanger).toHaveBeenCalled();
|
|
|
|
expect(props.redirectTo).toHaveBeenCalled();
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
it('adds to the recently accessed list on load', async () => {
|
|
|
|
const { component, services } = mountWith({});
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
|
|
|
|
});
|
|
|
|
expect(services.chrome.recentlyAccessed.add).toHaveBeenCalledWith(
|
|
|
|
'/app/lens#/edit/1234',
|
|
|
|
'An extremely cool default document!',
|
|
|
|
'1234'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('save buttons', () => {
|
2019-10-16 01:40:30 +02:00
|
|
|
interface SaveProps {
|
|
|
|
newCopyOnSave: boolean;
|
2020-05-05 22:58:36 +02:00
|
|
|
returnToOrigin?: boolean;
|
2019-10-16 01:40:30 +02:00
|
|
|
newTitle: string;
|
|
|
|
}
|
|
|
|
|
2020-03-10 22:10:35 +01:00
|
|
|
function getButton(inst: ReactWrapper): TopNavMenuData {
|
|
|
|
return (inst
|
2019-10-03 17:24:45 +02:00
|
|
|
.find('[data-test-subj="lnsApp_topNav"]')
|
|
|
|
.prop('config') as TopNavMenuData[]).find(
|
2020-05-22 09:08:58 +02:00
|
|
|
(button) => button.testId === 'lnsApp_saveButton'
|
2019-10-03 17:24:45 +02:00
|
|
|
)!;
|
|
|
|
}
|
|
|
|
|
2020-03-10 22:10:35 +01:00
|
|
|
async function testSave(inst: ReactWrapper, saveProps: SaveProps) {
|
|
|
|
await getButton(inst).run(inst.getDOMNode());
|
|
|
|
inst.update();
|
2020-11-03 10:33:18 +01:00
|
|
|
const handler = inst.find('SavedObjectSaveModalOrigin').prop('onSave') as (
|
2019-10-16 01:40:30 +02:00
|
|
|
p: unknown
|
2019-11-13 17:00:02 +01:00
|
|
|
) => void;
|
2019-10-16 01:40:30 +02:00
|
|
|
handler(saveProps);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function save({
|
2020-08-21 18:08:25 +02:00
|
|
|
lastKnownDoc = {
|
|
|
|
references: [],
|
|
|
|
state: {
|
|
|
|
filters: [],
|
|
|
|
},
|
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
initialSavedObjectId,
|
2019-10-16 01:40:30 +02:00
|
|
|
...saveProps
|
|
|
|
}: SaveProps & {
|
2020-02-13 13:59:27 +01:00
|
|
|
lastKnownDoc?: object;
|
2020-09-23 23:40:52 +02:00
|
|
|
initialSavedObjectId?: string;
|
2019-10-16 01:40:30 +02:00
|
|
|
}) {
|
2020-09-23 23:40:52 +02:00
|
|
|
const props = {
|
|
|
|
...makeDefaultProps(),
|
|
|
|
initialInput: initialSavedObjectId
|
|
|
|
? { savedObjectId: initialSavedObjectId, id: '5678' }
|
|
|
|
: undefined,
|
2019-10-16 01:40:30 +02:00
|
|
|
};
|
2020-09-23 23:40:52 +02:00
|
|
|
|
|
|
|
const services = makeDefaultServices();
|
|
|
|
services.attributeService.wrapAttributes = jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(async ({ savedObjectId }) => ({
|
|
|
|
savedObjectId: savedObjectId || 'aaa',
|
|
|
|
}));
|
|
|
|
services.attributeService.unwrapAttributes = jest.fn().mockResolvedValue({
|
|
|
|
savedObjectId: initialSavedObjectId ?? 'aaa',
|
2020-08-21 18:08:25 +02:00
|
|
|
references: [],
|
2019-10-16 01:40:30 +02:00
|
|
|
state: {
|
|
|
|
query: 'fake query',
|
2020-02-13 13:59:27 +01:00
|
|
|
filters: [],
|
2019-10-16 01:40:30 +02:00
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
} as jest.ResolvedValue<Document>);
|
2019-10-16 01:40:30 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
let frame: jest.Mocked<EditorFrameInstance> = {} as jest.Mocked<EditorFrameInstance>;
|
|
|
|
let component: ReactWrapper = {} as ReactWrapper;
|
2020-03-10 22:10:35 +01:00
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { frame: newFrame, component: newComponent } = mountWith({ services, props });
|
|
|
|
frame = newFrame;
|
|
|
|
component = newComponent;
|
2020-03-10 22:10:35 +01:00
|
|
|
});
|
2019-10-16 01:40:30 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
if (initialSavedObjectId) {
|
|
|
|
expect(services.attributeService.unwrapAttributes).toHaveBeenCalledTimes(1);
|
2019-10-16 01:40:30 +02:00
|
|
|
} else {
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.attributeService.unwrapAttributes).not.toHaveBeenCalled();
|
2019-10-16 01:40:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
2020-09-23 23:40:52 +02:00
|
|
|
|
2020-02-13 13:59:27 +01:00
|
|
|
act(() =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-09-23 23:40:52 +02:00
|
|
|
doc: { savedObjectId: initialSavedObjectId, ...lastKnownDoc } as Document,
|
2020-08-21 18:08:25 +02:00
|
|
|
isSaveable: true,
|
2020-02-13 13:59:27 +01:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
|
|
|
expect(getButton(component).disableButton).toEqual(false);
|
2020-03-10 22:10:35 +01:00
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
testSave(component, { ...saveProps });
|
2020-03-10 22:10:35 +01:00
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
return { props, services, component, frame };
|
2019-10-16 01:40:30 +02:00
|
|
|
}
|
|
|
|
|
2019-10-03 17:24:45 +02:00
|
|
|
it('shows a disabled save button when the user does not have permissions', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const services = makeDefaultServices();
|
|
|
|
services.application = {
|
|
|
|
...services.application,
|
2019-10-03 17:24:45 +02:00
|
|
|
capabilities: {
|
2020-09-23 23:40:52 +02:00
|
|
|
...services.application.capabilities,
|
2019-10-15 21:03:12 +02:00
|
|
|
visualize: { save: false, saveQuery: false, show: true },
|
2019-10-03 17:24:45 +02:00
|
|
|
},
|
|
|
|
};
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame } = mountWith({ services });
|
|
|
|
expect(getButton(component).disableButton).toEqual(true);
|
2019-10-03 17:24:45 +02:00
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
2020-02-13 13:59:27 +01:00
|
|
|
act(() =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-09-23 23:40:52 +02:00
|
|
|
doc: ({ savedObjectId: 'will save this' } as unknown) as Document,
|
2020-08-21 18:08:25 +02:00
|
|
|
isSaveable: true,
|
2020-02-13 13:59:27 +01:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
|
|
|
expect(getButton(component).disableButton).toEqual(true);
|
2019-12-24 09:21:38 +01:00
|
|
|
});
|
2019-10-03 17:24:45 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
it('shows a save button that is enabled when the frame has provided its state and does not show save and return or save as', async () => {
|
|
|
|
const { component, frame } = mountWith({});
|
|
|
|
expect(getButton(component).disableButton).toEqual(true);
|
2019-09-17 20:57:53 +02:00
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
2020-02-13 13:59:27 +01:00
|
|
|
act(() =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-09-23 23:40:52 +02:00
|
|
|
doc: ({ savedObjectId: 'will save this' } as unknown) as Document,
|
2020-08-21 18:08:25 +02:00
|
|
|
isSaveable: true,
|
2020-02-13 13:59:27 +01:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
|
|
|
expect(getButton(component).disableButton).toEqual(false);
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
await act(async () => {
|
|
|
|
const topNavMenuConfig = component.find(TopNavMenu).prop('config');
|
|
|
|
expect(topNavMenuConfig).not.toContainEqual(
|
|
|
|
expect.objectContaining(navMenuItems.expectedSaveAndReturnButton)
|
|
|
|
);
|
|
|
|
expect(topNavMenuConfig).not.toContainEqual(
|
|
|
|
expect.objectContaining(navMenuItems.expectedSaveAsButton)
|
|
|
|
);
|
|
|
|
expect(topNavMenuConfig).toContainEqual(
|
|
|
|
expect.objectContaining(navMenuItems.expectedSaveButton)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-08 22:39:24 +01:00
|
|
|
it('Shows Save and Return and Save As buttons in create by value mode with originating app', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const props = makeDefaultProps();
|
|
|
|
const services = makeDefaultServices();
|
|
|
|
services.dashboardFeatureFlag = { allowByValueEmbeddables: true };
|
|
|
|
props.incomingState = {
|
|
|
|
originatingApp: 'ultraDashboard',
|
|
|
|
valueInput: {
|
|
|
|
id: 'whatchaGonnaDoWith',
|
|
|
|
attributes: {
|
|
|
|
title:
|
|
|
|
'whatcha gonna do with all these references? All these references in your value Input',
|
|
|
|
references: [] as SavedObjectReference[],
|
|
|
|
},
|
|
|
|
} as LensByValueInput,
|
|
|
|
};
|
|
|
|
|
|
|
|
const { component } = mountWith({ props, services });
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
const topNavMenuConfig = component.find(TopNavMenu).prop('config');
|
|
|
|
expect(topNavMenuConfig).toContainEqual(
|
|
|
|
expect.objectContaining(navMenuItems.expectedSaveAndReturnButton)
|
|
|
|
);
|
|
|
|
expect(topNavMenuConfig).toContainEqual(
|
|
|
|
expect.objectContaining(navMenuItems.expectedSaveAsButton)
|
|
|
|
);
|
|
|
|
expect(topNavMenuConfig).not.toContainEqual(
|
|
|
|
expect.objectContaining(navMenuItems.expectedSaveButton)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Shows Save and Return and Save As buttons in edit by reference mode', async () => {
|
|
|
|
const props = makeDefaultProps();
|
|
|
|
props.initialInput = { savedObjectId: defaultSavedObjectId, id: '5678' };
|
|
|
|
props.incomingState = {
|
|
|
|
originatingApp: 'ultraDashboard',
|
|
|
|
};
|
|
|
|
|
|
|
|
const { component } = mountWith({ props });
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
const topNavMenuConfig = component.find(TopNavMenu).prop('config');
|
|
|
|
expect(topNavMenuConfig).toContainEqual(
|
|
|
|
expect.objectContaining(navMenuItems.expectedSaveAndReturnButton)
|
|
|
|
);
|
|
|
|
expect(topNavMenuConfig).toContainEqual(
|
|
|
|
expect.objectContaining(navMenuItems.expectedSaveAsButton)
|
|
|
|
);
|
|
|
|
expect(topNavMenuConfig).not.toContainEqual(
|
|
|
|
expect.objectContaining(navMenuItems.expectedSaveButton)
|
|
|
|
);
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-10-16 01:40:30 +02:00
|
|
|
it('saves new docs', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { props, services } = await save({
|
|
|
|
initialSavedObjectId: undefined,
|
2019-10-16 01:40:30 +02:00
|
|
|
newCopyOnSave: false,
|
|
|
|
newTitle: 'hello there',
|
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.attributeService.wrapAttributes).toHaveBeenCalledWith(
|
2020-08-21 18:08:25 +02:00
|
|
|
expect.objectContaining({
|
2020-09-23 23:40:52 +02:00
|
|
|
savedObjectId: undefined,
|
2020-08-21 18:08:25 +02:00
|
|
|
title: 'hello there',
|
2020-09-23 23:40:52 +02:00
|
|
|
}),
|
|
|
|
true,
|
|
|
|
undefined
|
2020-08-21 18:08:25 +02:00
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(props.redirectTo).toHaveBeenCalledWith('aaa');
|
2020-10-20 13:46:10 +02:00
|
|
|
expect(services.notifications.toasts.addSuccess).toHaveBeenCalledWith(
|
|
|
|
"Saved 'hello there'"
|
|
|
|
);
|
2019-10-16 01:40:30 +02:00
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
it('adds to the recently accessed list on save', async () => {
|
|
|
|
const { services } = await save({
|
|
|
|
initialSavedObjectId: undefined,
|
2020-09-14 19:52:14 +02:00
|
|
|
newCopyOnSave: false,
|
|
|
|
newTitle: 'hello there',
|
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.chrome.recentlyAccessed.add).toHaveBeenCalledWith(
|
2020-09-14 19:52:14 +02:00
|
|
|
'/app/lens#/edit/aaa',
|
|
|
|
'hello there',
|
|
|
|
'aaa'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-10-16 01:40:30 +02:00
|
|
|
it('saves the latest doc as a copy', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { props, services, component } = await save({
|
|
|
|
initialSavedObjectId: defaultSavedObjectId,
|
2019-10-16 01:40:30 +02:00
|
|
|
newCopyOnSave: true,
|
|
|
|
newTitle: 'hello there',
|
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.attributeService.wrapAttributes).toHaveBeenCalledWith(
|
2020-08-21 18:08:25 +02:00
|
|
|
expect.objectContaining({
|
|
|
|
title: 'hello there',
|
2020-09-23 23:40:52 +02:00
|
|
|
}),
|
|
|
|
true,
|
|
|
|
undefined
|
2020-08-21 18:08:25 +02:00
|
|
|
);
|
2020-11-02 19:35:33 +01:00
|
|
|
expect(props.redirectTo).toHaveBeenCalledWith(defaultSavedObjectId);
|
2020-09-23 23:40:52 +02:00
|
|
|
await act(async () => {
|
2020-11-02 19:35:33 +01:00
|
|
|
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
|
2020-09-23 23:40:52 +02:00
|
|
|
});
|
|
|
|
expect(services.attributeService.wrapAttributes).toHaveBeenCalledTimes(1);
|
2020-10-20 13:46:10 +02:00
|
|
|
expect(services.notifications.toasts.addSuccess).toHaveBeenCalledWith(
|
|
|
|
"Saved 'hello there'"
|
|
|
|
);
|
2019-10-16 01:40:30 +02:00
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2019-10-16 01:40:30 +02:00
|
|
|
it('saves existing docs', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { props, services, component } = await save({
|
|
|
|
initialSavedObjectId: defaultSavedObjectId,
|
2019-10-16 01:40:30 +02:00
|
|
|
newCopyOnSave: false,
|
|
|
|
newTitle: 'hello there',
|
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.attributeService.wrapAttributes).toHaveBeenCalledWith(
|
2020-08-21 18:08:25 +02:00
|
|
|
expect.objectContaining({
|
2020-09-23 23:40:52 +02:00
|
|
|
savedObjectId: defaultSavedObjectId,
|
2020-08-21 18:08:25 +02:00
|
|
|
title: 'hello there',
|
2020-09-23 23:40:52 +02:00
|
|
|
}),
|
|
|
|
true,
|
|
|
|
{ id: '5678', savedObjectId: defaultSavedObjectId }
|
2020-08-21 18:08:25 +02:00
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(props.redirectTo).not.toHaveBeenCalled();
|
|
|
|
await act(async () => {
|
|
|
|
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
|
|
|
|
});
|
|
|
|
expect(services.attributeService.unwrapAttributes).toHaveBeenCalledTimes(1);
|
2020-10-20 13:46:10 +02:00
|
|
|
expect(services.notifications.toasts.addSuccess).toHaveBeenCalledWith(
|
|
|
|
"Saved 'hello there'"
|
|
|
|
);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles save failure by showing a warning, but still allows another save', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const services = makeDefaultServices();
|
|
|
|
services.attributeService.wrapAttributes = jest
|
|
|
|
.fn()
|
|
|
|
.mockRejectedValue({ message: 'failed' });
|
|
|
|
const { component, props, frame } = mountWith({ services });
|
2019-09-17 20:57:53 +02:00
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
2020-02-13 13:59:27 +01:00
|
|
|
act(() =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-08-21 18:08:25 +02:00
|
|
|
doc: ({ id: undefined } as unknown) as Document,
|
|
|
|
isSaveable: true,
|
2020-02-13 13:59:27 +01:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-03-10 22:10:35 +01:00
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
testSave(component, { newCopyOnSave: false, newTitle: 'hello there' });
|
2020-03-10 22:10:35 +01:00
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(props.redirectTo).not.toHaveBeenCalled();
|
|
|
|
expect(getButton(component).disableButton).toEqual(false);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
2020-01-13 18:38:47 +01:00
|
|
|
|
2020-05-05 22:58:36 +02:00
|
|
|
it('saves new doc and redirects to originating app', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { props, services } = await save({
|
|
|
|
initialSavedObjectId: undefined,
|
2020-05-05 22:58:36 +02:00
|
|
|
returnToOrigin: true,
|
2020-01-13 18:38:47 +01:00
|
|
|
newCopyOnSave: false,
|
|
|
|
newTitle: 'hello there',
|
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.attributeService.wrapAttributes).toHaveBeenCalledWith(
|
2020-08-21 18:08:25 +02:00
|
|
|
expect.objectContaining({
|
2020-09-23 23:40:52 +02:00
|
|
|
savedObjectId: undefined,
|
2020-08-21 18:08:25 +02:00
|
|
|
title: 'hello there',
|
2020-09-23 23:40:52 +02:00
|
|
|
}),
|
|
|
|
true,
|
|
|
|
undefined
|
2020-08-21 18:08:25 +02:00
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(props.redirectToOrigin).toHaveBeenCalledWith({
|
|
|
|
input: { savedObjectId: 'aaa' },
|
|
|
|
isCopied: false,
|
|
|
|
});
|
2020-01-13 18:38:47 +01:00
|
|
|
});
|
2020-02-13 13:59:27 +01:00
|
|
|
|
|
|
|
it('saves app filters and does not save pinned filters', async () => {
|
|
|
|
const indexPattern = ({ id: 'index1' } as unknown) as IIndexPattern;
|
|
|
|
const field = ({ name: 'myfield' } as unknown) as IFieldType;
|
|
|
|
const pinnedField = ({ name: 'pinnedField' } as unknown) as IFieldType;
|
|
|
|
const unpinned = esFilters.buildExistsFilter(field, indexPattern);
|
|
|
|
const pinned = esFilters.buildExistsFilter(pinnedField, indexPattern);
|
2020-03-10 22:10:35 +01:00
|
|
|
await act(async () => {
|
|
|
|
FilterManager.setFiltersStore([pinned], esFilters.FilterStateStore.GLOBAL_STATE);
|
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
const { services } = await save({
|
|
|
|
initialSavedObjectId: defaultSavedObjectId,
|
2020-02-13 13:59:27 +01:00
|
|
|
newCopyOnSave: false,
|
|
|
|
newTitle: 'hello there2',
|
|
|
|
lastKnownDoc: {
|
|
|
|
expression: 'kibana 3',
|
|
|
|
state: {
|
|
|
|
filters: [pinned, unpinned],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
expect(services.attributeService.wrapAttributes).toHaveBeenCalledWith(
|
|
|
|
{
|
|
|
|
savedObjectId: defaultSavedObjectId,
|
|
|
|
title: 'hello there2',
|
|
|
|
expression: 'kibana 3',
|
|
|
|
state: {
|
|
|
|
filters: [unpinned],
|
|
|
|
},
|
2020-02-13 13:59:27 +01:00
|
|
|
},
|
2020-09-23 23:40:52 +02:00
|
|
|
true,
|
|
|
|
{ id: '5678', savedObjectId: defaultSavedObjectId }
|
|
|
|
);
|
2020-02-13 13:59:27 +01:00
|
|
|
});
|
2020-04-15 20:57:44 +02:00
|
|
|
|
2020-06-10 18:28:00 +02:00
|
|
|
it('checks for duplicate title before saving', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const services = makeDefaultServices();
|
|
|
|
services.attributeService.wrapAttributes = jest
|
|
|
|
.fn()
|
|
|
|
.mockReturnValue(Promise.resolve({ savedObjectId: '123' }));
|
|
|
|
const { component, frame } = mountWith({ services });
|
2020-06-10 18:28:00 +02:00
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
|
|
|
await act(async () =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-09-23 23:40:52 +02:00
|
|
|
doc: ({ savedObjectId: '123' } as unknown) as Document,
|
2020-08-21 18:08:25 +02:00
|
|
|
isSaveable: true,
|
2020-06-10 18:28:00 +02:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
2020-06-10 18:28:00 +02:00
|
|
|
await act(async () => {
|
2020-11-02 19:35:33 +01:00
|
|
|
component.setProps({ initialInput: { savedObjectId: '123' } });
|
2020-09-23 23:40:52 +02:00
|
|
|
getButton(component).run(component.getDOMNode());
|
2020-06-10 18:28:00 +02:00
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
2020-06-10 18:28:00 +02:00
|
|
|
const onTitleDuplicate = jest.fn();
|
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.find(SavedObjectSaveModal).prop('onSave')({
|
2020-06-10 18:28:00 +02:00
|
|
|
onTitleDuplicate,
|
|
|
|
isTitleDuplicateConfirmed: false,
|
|
|
|
newCopyOnSave: false,
|
|
|
|
newDescription: '',
|
|
|
|
newTitle: 'test',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
expect(checkForDuplicateTitle).toHaveBeenCalledWith(
|
2020-11-02 19:35:33 +01:00
|
|
|
expect.objectContaining({ id: '123' }),
|
2020-06-10 18:28:00 +02:00
|
|
|
false,
|
|
|
|
onTitleDuplicate,
|
|
|
|
expect.anything()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-15 20:57:44 +02:00
|
|
|
it('does not show the copy button on first save', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame } = mountWith({});
|
2020-04-15 20:57:44 +02:00
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
|
|
|
await act(async () =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-08-21 18:08:25 +02:00
|
|
|
doc: ({} as unknown) as Document,
|
|
|
|
isSaveable: true,
|
2020-04-15 20:57:44 +02:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
|
|
|
await act(async () => getButton(component).run(component.getDOMNode()));
|
|
|
|
component.update();
|
|
|
|
expect(component.find(SavedObjectSaveModal).prop('showCopyOnSave')).toEqual(false);
|
2020-04-15 20:57:44 +02:00
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-24 12:37:27 +01:00
|
|
|
describe('download button', () => {
|
|
|
|
function getButton(inst: ReactWrapper): TopNavMenuData {
|
|
|
|
return (inst
|
|
|
|
.find('[data-test-subj="lnsApp_topNav"]')
|
|
|
|
.prop('config') as TopNavMenuData[]).find(
|
|
|
|
(button) => button.testId === 'lnsApp_downloadCSVButton'
|
|
|
|
)!;
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should be disabled when no data is available', async () => {
|
|
|
|
const { component, frame } = mountWith({});
|
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
|
|
|
await act(async () =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
|
|
|
doc: ({} as unknown) as Document,
|
|
|
|
isSaveable: true,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
component.update();
|
|
|
|
expect(getButton(component).disableButton).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should disable download when not saveable', async () => {
|
|
|
|
const { component, frame } = mountWith({});
|
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
|
|
|
|
|
|
|
await act(async () =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
|
|
|
doc: ({} as unknown) as Document,
|
|
|
|
isSaveable: false,
|
|
|
|
activeData: { layer1: { type: 'datatable', columns: [], rows: [] } },
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
component.update();
|
|
|
|
expect(getButton(component).disableButton).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should still be enabled even if the user is missing save permissions', async () => {
|
|
|
|
const services = makeDefaultServices();
|
|
|
|
services.application = {
|
|
|
|
...services.application,
|
|
|
|
capabilities: {
|
|
|
|
...services.application.capabilities,
|
|
|
|
visualize: { save: false, saveQuery: false, show: true },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const { component, frame } = mountWith({ services });
|
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
|
|
|
await act(async () =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
|
|
|
doc: ({} as unknown) as Document,
|
|
|
|
isSaveable: true,
|
|
|
|
activeData: { layer1: { type: 'datatable', columns: [], rows: [] } },
|
|
|
|
})
|
|
|
|
);
|
|
|
|
component.update();
|
|
|
|
expect(getButton(component).disableButton).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
describe('query bar state management', () => {
|
|
|
|
it('uses the default time and query language settings', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { frame } = mountWith({});
|
2019-10-03 17:24:45 +02:00
|
|
|
expect(TopNavMenu).toHaveBeenCalledWith(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
|
|
|
query: { query: '', language: 'kuery' },
|
2019-10-28 20:04:03 +01:00
|
|
|
dateRangeFrom: 'now-7d',
|
|
|
|
dateRangeTo: 'now',
|
2019-09-17 20:57:53 +02:00
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
2021-01-21 11:00:57 +01:00
|
|
|
dateRange: { fromDate: '2021-01-10T04:00:00.000Z', toDate: '2021-01-10T08:00:00.000Z' },
|
2019-09-17 20:57:53 +02:00
|
|
|
query: { query: '', language: 'kuery' },
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-10-03 17:24:45 +02:00
|
|
|
it('updates the index patterns when the editor frame is changed', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame } = mountWith({});
|
2019-10-03 17:24:45 +02:00
|
|
|
expect(TopNavMenu).toHaveBeenCalledWith(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
|
|
|
indexPatterns: [],
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
2020-03-10 22:10:35 +01:00
|
|
|
await act(async () => {
|
2020-02-13 13:59:27 +01:00
|
|
|
onChange({
|
2020-08-21 18:08:25 +02:00
|
|
|
filterableIndexPatterns: ['1'],
|
|
|
|
doc: ({ id: undefined } as unknown) as Document,
|
|
|
|
isSaveable: true,
|
2020-03-10 22:10:35 +01:00
|
|
|
});
|
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
2019-10-03 17:24:45 +02:00
|
|
|
expect(TopNavMenu).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
indexPatterns: [{ id: '1' }],
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
// Do it again to verify that the dirty checking is done right
|
2020-03-10 22:10:35 +01:00
|
|
|
await act(async () => {
|
2020-02-13 13:59:27 +01:00
|
|
|
onChange({
|
2020-08-21 18:08:25 +02:00
|
|
|
filterableIndexPatterns: ['2'],
|
|
|
|
doc: ({ id: undefined } as unknown) as Document,
|
|
|
|
isSaveable: true,
|
2020-03-10 22:10:35 +01:00
|
|
|
});
|
|
|
|
});
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
2019-10-03 17:24:45 +02:00
|
|
|
expect(TopNavMenu).toHaveBeenLastCalledWith(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-10-03 17:24:45 +02:00
|
|
|
indexPatterns: [{ id: '2' }],
|
2019-09-17 20:57:53 +02:00
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
it('updates the editor frame when the user changes query or time in the search bar', () => {
|
2021-01-21 11:00:57 +01:00
|
|
|
const { component, frame, services } = mountWith({});
|
|
|
|
(services.data.query.timefilter.timefilter.calculateBounds as jest.Mock).mockReturnValue({
|
|
|
|
min: moment('2021-01-09T04:00:00.000Z'),
|
|
|
|
max: moment('2021-01-09T08:00:00.000Z'),
|
|
|
|
});
|
2020-02-13 13:59:27 +01:00
|
|
|
act(() =>
|
2020-09-23 23:40:52 +02:00
|
|
|
component.find(TopNavMenu).prop('onQuerySubmit')!({
|
2020-02-13 13:59:27 +01:00
|
|
|
dateRange: { from: 'now-14d', to: 'now-7d' },
|
|
|
|
query: { query: 'new', language: 'lucene' },
|
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
2019-10-03 17:24:45 +02:00
|
|
|
expect(TopNavMenu).toHaveBeenCalledWith(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
|
|
|
query: { query: 'new', language: 'lucene' },
|
2019-10-28 20:04:03 +01:00
|
|
|
dateRangeFrom: 'now-14d',
|
|
|
|
dateRangeTo: 'now-7d',
|
2019-09-17 20:57:53 +02:00
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
2021-01-21 11:00:57 +01:00
|
|
|
expect(services.data.query.timefilter.timefilter.setTime).toHaveBeenCalledWith({
|
|
|
|
from: 'now-14d',
|
|
|
|
to: 'now-7d',
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
2021-01-21 11:00:57 +01:00
|
|
|
dateRange: { fromDate: '2021-01-09T04:00:00.000Z', toDate: '2021-01-09T08:00:00.000Z' },
|
2019-09-17 20:57:53 +02:00
|
|
|
query: { query: 'new', language: 'lucene' },
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2019-10-03 17:24:45 +02:00
|
|
|
|
|
|
|
it('updates the filters when the user changes them', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame, services } = mountWith({});
|
2019-11-15 21:35:21 +01:00
|
|
|
const indexPattern = ({ id: 'index1' } as unknown) as IIndexPattern;
|
|
|
|
const field = ({ name: 'myfield' } as unknown) as IFieldType;
|
2020-02-13 13:59:27 +01:00
|
|
|
act(() =>
|
2020-09-23 23:40:52 +02:00
|
|
|
services.data.query.filterManager.setFilters([
|
|
|
|
esFilters.buildExistsFilter(field, indexPattern),
|
|
|
|
])
|
2020-02-13 13:59:27 +01:00
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
2019-10-03 17:24:45 +02:00
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
2019-11-15 21:35:21 +01:00
|
|
|
filters: [esFilters.buildExistsFilter(field, indexPattern)],
|
2019-10-03 17:24:45 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2020-12-29 14:18:30 +01:00
|
|
|
|
|
|
|
it('updates the searchSessionId when the user changes query or time in the search bar', () => {
|
|
|
|
const { component, frame, services } = mountWith({});
|
|
|
|
act(() =>
|
|
|
|
component.find(TopNavMenu).prop('onQuerySubmit')!({
|
|
|
|
dateRange: { from: 'now-14d', to: 'now-7d' },
|
|
|
|
query: { query: '', language: 'lucene' },
|
|
|
|
})
|
|
|
|
);
|
|
|
|
component.update();
|
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
|
|
|
searchSessionId: `sessionId-1`,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
// trigger again, this time changing just the query
|
|
|
|
act(() =>
|
|
|
|
component.find(TopNavMenu).prop('onQuerySubmit')!({
|
|
|
|
dateRange: { from: 'now-14d', to: 'now-7d' },
|
|
|
|
query: { query: 'new', language: 'lucene' },
|
|
|
|
})
|
|
|
|
);
|
|
|
|
component.update();
|
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
|
|
|
searchSessionId: `sessionId-2`,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
const indexPattern = ({ id: 'index1' } as unknown) as IIndexPattern;
|
|
|
|
const field = ({ name: 'myfield' } as unknown) as IFieldType;
|
|
|
|
act(() =>
|
|
|
|
services.data.query.filterManager.setFilters([
|
|
|
|
esFilters.buildExistsFilter(field, indexPattern),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
component.update();
|
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
|
|
|
searchSessionId: `sessionId-3`,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2019-10-03 17:24:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('saved query handling', () => {
|
|
|
|
it('does not allow saving when the user is missing the saveQuery permission', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const services = makeDefaultServices();
|
|
|
|
services.application = {
|
|
|
|
...services.application,
|
2019-10-03 17:24:45 +02:00
|
|
|
capabilities: {
|
2020-09-23 23:40:52 +02:00
|
|
|
...services.application.capabilities,
|
2019-10-15 21:03:12 +02:00
|
|
|
visualize: { save: false, saveQuery: false, show: true },
|
2019-10-03 17:24:45 +02:00
|
|
|
},
|
|
|
|
};
|
2020-09-23 23:40:52 +02:00
|
|
|
mountWith({ services });
|
2019-10-03 17:24:45 +02:00
|
|
|
expect(TopNavMenu).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({ showSaveQuery: false }),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('persists the saved query ID when the query is saved', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component } = mountWith({});
|
2019-10-03 17:24:45 +02:00
|
|
|
expect(TopNavMenu).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
showSaveQuery: true,
|
|
|
|
savedQuery: undefined,
|
|
|
|
onSaved: expect.any(Function),
|
|
|
|
onSavedQueryUpdated: expect.any(Function),
|
|
|
|
onClearSavedQuery: expect.any(Function),
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
act(() => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.find(TopNavMenu).prop('onSaved')!({
|
2019-10-03 17:24:45 +02:00
|
|
|
id: '1',
|
|
|
|
attributes: {
|
|
|
|
title: '',
|
|
|
|
description: '',
|
|
|
|
query: { query: '', language: 'lucene' },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
expect(TopNavMenu).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
savedQuery: {
|
|
|
|
id: '1',
|
|
|
|
attributes: {
|
|
|
|
title: '',
|
|
|
|
description: '',
|
|
|
|
query: { query: '', language: 'lucene' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('changes the saved query ID when the query is updated', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component } = mountWith({});
|
2019-10-03 17:24:45 +02:00
|
|
|
act(() => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.find(TopNavMenu).prop('onSaved')!({
|
2019-10-03 17:24:45 +02:00
|
|
|
id: '1',
|
|
|
|
attributes: {
|
|
|
|
title: '',
|
|
|
|
description: '',
|
|
|
|
query: { query: '', language: 'lucene' },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
act(() => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.find(TopNavMenu).prop('onSavedQueryUpdated')!({
|
2019-10-03 17:24:45 +02:00
|
|
|
id: '2',
|
|
|
|
attributes: {
|
|
|
|
title: 'new title',
|
|
|
|
description: '',
|
|
|
|
query: { query: '', language: 'lucene' },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
expect(TopNavMenu).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
savedQuery: {
|
|
|
|
id: '2',
|
|
|
|
attributes: {
|
|
|
|
title: 'new title',
|
|
|
|
description: '',
|
|
|
|
query: { query: '', language: 'lucene' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-01-21 11:00:57 +01:00
|
|
|
it('clears all existing unpinned filters when the active saved query is cleared', () => {
|
|
|
|
const { component, frame, services } = mountWith({});
|
|
|
|
act(() =>
|
|
|
|
component.find(TopNavMenu).prop('onQuerySubmit')!({
|
|
|
|
dateRange: { from: 'now-14d', to: 'now-7d' },
|
|
|
|
query: { query: 'new', language: 'lucene' },
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const indexPattern = ({ id: 'index1' } as unknown) as IIndexPattern;
|
|
|
|
const field = ({ name: 'myfield' } as unknown) as IFieldType;
|
|
|
|
const pinnedField = ({ name: 'pinnedField' } as unknown) as IFieldType;
|
|
|
|
const unpinned = esFilters.buildExistsFilter(field, indexPattern);
|
|
|
|
const pinned = esFilters.buildExistsFilter(pinnedField, indexPattern);
|
|
|
|
FilterManager.setFiltersStore([pinned], esFilters.FilterStateStore.GLOBAL_STATE);
|
|
|
|
act(() => services.data.query.filterManager.setFilters([pinned, unpinned]));
|
|
|
|
component.update();
|
|
|
|
act(() => component.find(TopNavMenu).prop('onClearSavedQuery')!());
|
|
|
|
component.update();
|
|
|
|
expect(frame.mount).toHaveBeenLastCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
|
|
|
filters: [pinned],
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('search session id management', () => {
|
2020-12-29 14:18:30 +01:00
|
|
|
it('updates the searchSessionId when the query is updated', () => {
|
|
|
|
const { component, frame } = mountWith({});
|
|
|
|
act(() => {
|
|
|
|
component.find(TopNavMenu).prop('onSaved')!({
|
|
|
|
id: '1',
|
|
|
|
attributes: {
|
|
|
|
title: '',
|
|
|
|
description: '',
|
|
|
|
query: { query: '', language: 'lucene' },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
act(() => {
|
|
|
|
component.find(TopNavMenu).prop('onSavedQueryUpdated')!({
|
|
|
|
id: '2',
|
|
|
|
attributes: {
|
|
|
|
title: 'new title',
|
|
|
|
description: '',
|
|
|
|
query: { query: '', language: 'lucene' },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
component.update();
|
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
2021-01-21 11:00:57 +01:00
|
|
|
searchSessionId: `sessionId-2`,
|
2020-12-29 14:18:30 +01:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-01-21 11:00:57 +01:00
|
|
|
it('updates the searchSessionId when the active saved query is cleared', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame, services } = mountWith({});
|
2020-02-13 13:59:27 +01:00
|
|
|
act(() =>
|
2020-09-23 23:40:52 +02:00
|
|
|
component.find(TopNavMenu).prop('onQuerySubmit')!({
|
2020-02-13 13:59:27 +01:00
|
|
|
dateRange: { from: 'now-14d', to: 'now-7d' },
|
|
|
|
query: { query: 'new', language: 'lucene' },
|
|
|
|
})
|
|
|
|
);
|
2019-11-15 21:35:21 +01:00
|
|
|
const indexPattern = ({ id: 'index1' } as unknown) as IIndexPattern;
|
|
|
|
const field = ({ name: 'myfield' } as unknown) as IFieldType;
|
2020-01-21 22:33:53 +01:00
|
|
|
const pinnedField = ({ name: 'pinnedField' } as unknown) as IFieldType;
|
|
|
|
const unpinned = esFilters.buildExistsFilter(field, indexPattern);
|
|
|
|
const pinned = esFilters.buildExistsFilter(pinnedField, indexPattern);
|
|
|
|
FilterManager.setFiltersStore([pinned], esFilters.FilterStateStore.GLOBAL_STATE);
|
2020-09-23 23:40:52 +02:00
|
|
|
act(() => services.data.query.filterManager.setFilters([pinned, unpinned]));
|
|
|
|
component.update();
|
|
|
|
act(() => component.find(TopNavMenu).prop('onClearSavedQuery')!());
|
|
|
|
component.update();
|
2021-01-21 11:00:57 +01:00
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
2019-10-03 17:24:45 +02:00
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
2021-01-21 11:00:57 +01:00
|
|
|
searchSessionId: `sessionId-2`,
|
2019-10-03 17:24:45 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2020-12-29 14:18:30 +01:00
|
|
|
|
2021-01-21 11:00:57 +01:00
|
|
|
const mockUpdate = {
|
|
|
|
filterableIndexPatterns: [],
|
|
|
|
doc: {
|
|
|
|
title: '',
|
|
|
|
description: '',
|
|
|
|
visualizationType: '',
|
|
|
|
state: {
|
|
|
|
datasourceStates: {},
|
|
|
|
visualization: {},
|
|
|
|
filters: [],
|
|
|
|
query: { query: '', language: 'lucene' },
|
|
|
|
},
|
|
|
|
references: [],
|
|
|
|
},
|
|
|
|
isSaveable: true,
|
|
|
|
activeData: undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
it('does not update the searchSessionId when the state changes', () => {
|
|
|
|
const { component, frame } = mountWith({});
|
|
|
|
act(() => {
|
|
|
|
(component.find(NativeRenderer).prop('nativeProps') as EditorFrameProps).onChange(
|
|
|
|
mockUpdate
|
|
|
|
);
|
|
|
|
});
|
|
|
|
component.update();
|
|
|
|
expect(frame.mount).not.toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
|
|
|
searchSessionId: `sessionId-2`,
|
2020-12-29 14:18:30 +01:00
|
|
|
})
|
|
|
|
);
|
2021-01-21 11:00:57 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does update the searchSessionId when the state changes and too much time passed', () => {
|
|
|
|
const { component, frame, services } = mountWith({});
|
|
|
|
|
|
|
|
// time range is 100,000ms ago to 30,000ms ago (that's a lag of 30 percent)
|
|
|
|
(services.data.nowProvider.get as jest.Mock).mockReturnValue(new Date(Date.now() - 30000));
|
|
|
|
(services.data.query.timefilter.timefilter.getTime as jest.Mock).mockReturnValue({
|
|
|
|
from: 'now-2m',
|
|
|
|
to: 'now',
|
|
|
|
});
|
|
|
|
(services.data.query.timefilter.timefilter.getBounds as jest.Mock).mockReturnValue({
|
|
|
|
min: moment(Date.now() - 100000),
|
|
|
|
max: moment(Date.now() - 30000),
|
|
|
|
});
|
|
|
|
|
|
|
|
act(() => {
|
|
|
|
(component.find(NativeRenderer).prop('nativeProps') as EditorFrameProps).onChange(
|
|
|
|
mockUpdate
|
|
|
|
);
|
|
|
|
});
|
2020-12-29 14:18:30 +01:00
|
|
|
component.update();
|
|
|
|
expect(frame.mount).toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
|
|
|
searchSessionId: `sessionId-2`,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2021-01-21 11:00:57 +01:00
|
|
|
|
|
|
|
it('does not update the searchSessionId when the state changes and too little time has passed', () => {
|
|
|
|
const { component, frame, services } = mountWith({});
|
|
|
|
|
|
|
|
// time range is 100,000ms ago to 300ms ago (that's a lag of .3 percent, not enough to trigger a session update)
|
|
|
|
(services.data.nowProvider.get as jest.Mock).mockReturnValue(new Date(Date.now() - 300));
|
|
|
|
(services.data.query.timefilter.timefilter.getTime as jest.Mock).mockReturnValue({
|
|
|
|
from: 'now-2m',
|
|
|
|
to: 'now',
|
|
|
|
});
|
|
|
|
(services.data.query.timefilter.timefilter.getBounds as jest.Mock).mockReturnValue({
|
|
|
|
min: moment(Date.now() - 100000),
|
|
|
|
max: moment(Date.now() - 300),
|
|
|
|
});
|
|
|
|
|
|
|
|
act(() => {
|
|
|
|
(component.find(NativeRenderer).prop('nativeProps') as EditorFrameProps).onChange(
|
|
|
|
mockUpdate
|
|
|
|
);
|
|
|
|
});
|
|
|
|
component.update();
|
|
|
|
expect(frame.mount).not.toHaveBeenCalledWith(
|
|
|
|
expect.any(Element),
|
|
|
|
expect.objectContaining({
|
|
|
|
searchSessionId: `sessionId-2`,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2020-06-01 21:05:27 +02:00
|
|
|
describe('showing a confirm message when leaving', () => {
|
|
|
|
let defaultLeave: jest.Mock;
|
|
|
|
let confirmLeave: jest.Mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
defaultLeave = jest.fn();
|
|
|
|
confirmLeave = jest.fn();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not show a confirm message if there is no expression to save', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { props } = mountWith({});
|
|
|
|
const lastCall = props.onAppLeave.mock.calls[props.onAppLeave.mock.calls.length - 1][0];
|
2020-06-01 21:05:27 +02:00
|
|
|
lastCall({ default: defaultLeave, confirm: confirmLeave });
|
|
|
|
expect(defaultLeave).toHaveBeenCalled();
|
|
|
|
expect(confirmLeave).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not confirm if the user is missing save permissions', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const services = makeDefaultServices();
|
|
|
|
services.application = {
|
|
|
|
...services.application,
|
2020-06-01 21:05:27 +02:00
|
|
|
capabilities: {
|
2020-09-23 23:40:52 +02:00
|
|
|
...services.application.capabilities,
|
2020-06-01 21:05:27 +02:00
|
|
|
visualize: { save: false, saveQuery: false, show: true },
|
|
|
|
},
|
|
|
|
};
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame, props } = mountWith({ services });
|
2020-06-01 21:05:27 +02:00
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
|
|
|
act(() =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-08-21 18:08:25 +02:00
|
|
|
doc: ({
|
2020-09-23 23:40:52 +02:00
|
|
|
savedObjectId: undefined,
|
2020-08-21 18:08:25 +02:00
|
|
|
references: [],
|
|
|
|
} as unknown) as Document,
|
|
|
|
isSaveable: true,
|
2020-06-01 21:05:27 +02:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
|
|
|
const lastCall = props.onAppLeave.mock.calls[props.onAppLeave.mock.calls.length - 1][0];
|
2020-06-01 21:05:27 +02:00
|
|
|
lastCall({ default: defaultLeave, confirm: confirmLeave });
|
|
|
|
expect(defaultLeave).toHaveBeenCalled();
|
|
|
|
expect(confirmLeave).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should confirm when leaving with an unsaved doc', () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame, props } = mountWith({});
|
2020-06-01 21:05:27 +02:00
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
|
|
|
act(() =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-09-23 23:40:52 +02:00
|
|
|
doc: ({ savedObjectId: undefined, state: {} } as unknown) as Document,
|
2020-08-21 18:08:25 +02:00
|
|
|
isSaveable: true,
|
2020-06-01 21:05:27 +02:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
|
|
|
const lastCall = props.onAppLeave.mock.calls[props.onAppLeave.mock.calls.length - 1][0];
|
2020-06-01 21:05:27 +02:00
|
|
|
lastCall({ default: defaultLeave, confirm: confirmLeave });
|
|
|
|
expect(confirmLeave).toHaveBeenCalled();
|
|
|
|
expect(defaultLeave).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should confirm when leaving with unsaved changes to an existing doc', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame, props } = mountWith({});
|
2020-06-01 21:05:27 +02:00
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
|
2020-06-01 21:05:27 +02:00
|
|
|
});
|
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
|
|
|
act(() =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-08-21 18:08:25 +02:00
|
|
|
doc: ({
|
2020-09-23 23:40:52 +02:00
|
|
|
savedObjectId: defaultSavedObjectId,
|
2020-08-21 18:08:25 +02:00
|
|
|
references: [],
|
|
|
|
} as unknown) as Document,
|
|
|
|
isSaveable: true,
|
2020-06-01 21:05:27 +02:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
|
|
|
const lastCall = props.onAppLeave.mock.calls[props.onAppLeave.mock.calls.length - 1][0];
|
2020-06-01 21:05:27 +02:00
|
|
|
lastCall({ default: defaultLeave, confirm: confirmLeave });
|
|
|
|
expect(confirmLeave).toHaveBeenCalled();
|
|
|
|
expect(defaultLeave).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not confirm when changes are saved', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame, props } = mountWith({});
|
2020-06-01 21:05:27 +02:00
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
|
2020-06-01 21:05:27 +02:00
|
|
|
});
|
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
|
|
|
act(() =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-09-23 23:40:52 +02:00
|
|
|
doc: defaultDoc,
|
2020-08-21 18:08:25 +02:00
|
|
|
isSaveable: true,
|
2020-06-01 21:05:27 +02:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
|
|
|
const lastCall = props.onAppLeave.mock.calls[props.onAppLeave.mock.calls.length - 1][0];
|
2020-06-01 21:05:27 +02:00
|
|
|
lastCall({ default: defaultLeave, confirm: confirmLeave });
|
|
|
|
expect(defaultLeave).toHaveBeenCalled();
|
|
|
|
expect(confirmLeave).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should confirm when the latest doc is invalid', async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
const { component, frame, props } = mountWith({});
|
2020-06-01 21:05:27 +02:00
|
|
|
await act(async () => {
|
2020-09-23 23:40:52 +02:00
|
|
|
component.setProps({ initialInput: { savedObjectId: defaultSavedObjectId } });
|
2020-06-01 21:05:27 +02:00
|
|
|
});
|
|
|
|
const onChange = frame.mount.mock.calls[0][1].onChange;
|
|
|
|
act(() =>
|
|
|
|
onChange({
|
|
|
|
filterableIndexPatterns: [],
|
2020-09-23 23:40:52 +02:00
|
|
|
doc: ({ savedObjectId: defaultSavedObjectId, references: [] } as unknown) as Document,
|
2020-08-21 18:08:25 +02:00
|
|
|
isSaveable: true,
|
2020-06-01 21:05:27 +02:00
|
|
|
})
|
|
|
|
);
|
2020-09-23 23:40:52 +02:00
|
|
|
component.update();
|
|
|
|
const lastCall = props.onAppLeave.mock.calls[props.onAppLeave.mock.calls.length - 1][0];
|
2020-06-01 21:05:27 +02:00
|
|
|
lastCall({ default: defaultLeave, confirm: confirmLeave });
|
|
|
|
expect(confirmLeave).toHaveBeenCalled();
|
|
|
|
expect(defaultLeave).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|