mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Clear sessions when unmounting app (#155712)
Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
parent
fb68f2075a
commit
4dda8cf995
2 changed files with 75 additions and 42 deletions
|
@ -28,54 +28,61 @@ describe('renderApp', () => {
|
|||
global.console = originalConsole;
|
||||
});
|
||||
|
||||
it('renders', async () => {
|
||||
const plugins = {
|
||||
usageCollection: { reportUiCounter: noop },
|
||||
data: {
|
||||
query: {
|
||||
const mockSearchSessionClear = jest.fn();
|
||||
|
||||
const plugins = {
|
||||
usageCollection: { reportUiCounter: noop },
|
||||
data: {
|
||||
query: {
|
||||
timefilter: {
|
||||
timefilter: {
|
||||
timefilter: {
|
||||
setTime: jest.fn(),
|
||||
getTime: jest.fn().mockReturnValue({}),
|
||||
getTimeDefaults: jest.fn().mockReturnValue({}),
|
||||
getRefreshInterval: jest.fn().mockReturnValue({}),
|
||||
getRefreshIntervalDefaults: jest.fn().mockReturnValue({}),
|
||||
},
|
||||
setTime: jest.fn(),
|
||||
getTime: jest.fn().mockReturnValue({}),
|
||||
getTimeDefaults: jest.fn().mockReturnValue({}),
|
||||
getRefreshInterval: jest.fn().mockReturnValue({}),
|
||||
getRefreshIntervalDefaults: jest.fn().mockReturnValue({}),
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ObservabilityPublicPluginsStart;
|
||||
|
||||
const core = {
|
||||
application: { currentAppId$: new Observable(), navigateToUrl: noop },
|
||||
chrome: {
|
||||
docTitle: { change: noop },
|
||||
setBreadcrumbs: noop,
|
||||
setHelpExtension: noop,
|
||||
},
|
||||
i18n: { Context: ({ children }: { children: React.ReactNode }) => children },
|
||||
uiSettings: { get: () => false },
|
||||
http: { basePath: { prepend: (path: string) => path } },
|
||||
theme: themeServiceMock.createStartContract(),
|
||||
} as unknown as CoreStart;
|
||||
|
||||
const params = {
|
||||
element: window.document.createElement('div'),
|
||||
history: createMemoryHistory(),
|
||||
setHeaderActionMenu: noop,
|
||||
theme$: themeServiceMock.createTheme$(),
|
||||
} as unknown as AppMountParameters;
|
||||
|
||||
const config = {
|
||||
unsafe: {
|
||||
alertDetails: {
|
||||
logs: { enabled: false },
|
||||
metrics: { enabled: false },
|
||||
uptime: { enabled: false },
|
||||
search: {
|
||||
session: {
|
||||
clear: mockSearchSessionClear,
|
||||
},
|
||||
},
|
||||
} as ConfigSchema;
|
||||
},
|
||||
} as unknown as ObservabilityPublicPluginsStart;
|
||||
|
||||
const core = {
|
||||
application: { currentAppId$: new Observable(), navigateToUrl: noop },
|
||||
chrome: {
|
||||
docTitle: { change: noop },
|
||||
setBreadcrumbs: noop,
|
||||
setHelpExtension: noop,
|
||||
},
|
||||
i18n: { Context: ({ children }: { children: React.ReactNode }) => children },
|
||||
uiSettings: { get: () => false },
|
||||
http: { basePath: { prepend: (path: string) => path } },
|
||||
theme: themeServiceMock.createStartContract(),
|
||||
} as unknown as CoreStart;
|
||||
|
||||
const params = {
|
||||
element: window.document.createElement('div'),
|
||||
history: createMemoryHistory(),
|
||||
setHeaderActionMenu: noop,
|
||||
theme$: themeServiceMock.createTheme$(),
|
||||
} as unknown as AppMountParameters;
|
||||
|
||||
const config = {
|
||||
unsafe: {
|
||||
alertDetails: {
|
||||
logs: { enabled: false },
|
||||
metrics: { enabled: false },
|
||||
uptime: { enabled: false },
|
||||
},
|
||||
},
|
||||
} as ConfigSchema;
|
||||
|
||||
it('renders', async () => {
|
||||
expect(() => {
|
||||
const unmount = renderApp({
|
||||
core,
|
||||
|
@ -90,9 +97,30 @@ describe('renderApp', () => {
|
|||
},
|
||||
reportUiCounter: jest.fn(),
|
||||
},
|
||||
kibanaVersion: '8.7.0',
|
||||
kibanaVersion: '8.8.0',
|
||||
});
|
||||
unmount();
|
||||
}).not.toThrowError();
|
||||
});
|
||||
|
||||
it('should clear search sessions when unmounting', () => {
|
||||
const unmount = renderApp({
|
||||
core,
|
||||
config,
|
||||
plugins,
|
||||
appMountParameters: params,
|
||||
observabilityRuleTypeRegistry: createObservabilityRuleTypeRegistryMock(),
|
||||
ObservabilityPageTemplate: KibanaPageTemplate,
|
||||
usageCollection: {
|
||||
components: {
|
||||
ApplicationUsageTrackingProvider: (props) => null,
|
||||
},
|
||||
reportUiCounter: jest.fn(),
|
||||
},
|
||||
kibanaVersion: '8.8.0',
|
||||
});
|
||||
unmount();
|
||||
|
||||
expect(mockSearchSessionClear).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -128,6 +128,11 @@ export const renderApp = ({
|
|||
element
|
||||
);
|
||||
return () => {
|
||||
// This needs to be present to fix https://github.com/elastic/kibana/issues/155704
|
||||
// as the Overview page renders the UX Section component. That component renders a Lens embeddable
|
||||
// via the ExploratoryView app, which uses search sessions. Therefore on unmounting we need to clear
|
||||
// these sessions.
|
||||
plugins.data.search.session.clear();
|
||||
ReactDOM.unmountComponentAtNode(element);
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue