mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Discover] Remove kbnUrlStateStorage of Discover main state container (#158225)
The exposed kbnUrlStateStorage property of `DiscoverStateContainer` is removed. It was just used for testing and is replaced with `await new Promise(process.nextTick);`
This commit is contained in:
parent
3800ce4c9c
commit
84d070d2f7
2 changed files with 33 additions and 34 deletions
|
@ -86,7 +86,7 @@ describe('Test discover state', () => {
|
|||
});
|
||||
test('setting app state and syncing to URL', async () => {
|
||||
state.appState.update({ index: 'modified' });
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
await new Promise(process.nextTick);
|
||||
expect(getCurrentUrl()).toMatchInlineSnapshot(
|
||||
`"/#?_a=(columns:!(default_column),index:modified,interval:auto,sort:!())"`
|
||||
);
|
||||
|
@ -171,7 +171,7 @@ describe('Test discover state with legacy migration', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('createSearchSessionRestorationDataProvider', () => {
|
||||
describe('Test createSearchSessionRestorationDataProvider', () => {
|
||||
let mockSavedSearch: SavedSearch = {} as unknown as SavedSearch;
|
||||
const history = createBrowserHistory();
|
||||
const mockDataPlugin = dataPluginMock.createStartContract();
|
||||
|
@ -237,7 +237,7 @@ describe('createSearchSessionRestorationDataProvider', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('searchSessionManager', () => {
|
||||
describe('Test discover searchSessionManager', () => {
|
||||
test('getting the next session id', async () => {
|
||||
const { state } = await getState();
|
||||
const nextId = 'id';
|
||||
|
@ -247,7 +247,7 @@ describe('searchSessionManager', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('actions', () => {
|
||||
describe('Test discover state actions', () => {
|
||||
beforeEach(async () => {
|
||||
discoverServiceMock.data.query.timefilter.timefilter.getTime = jest.fn(() => {
|
||||
return { from: 'now-15d', to: 'now' };
|
||||
|
@ -319,7 +319,7 @@ describe('actions', () => {
|
|||
const newSavedSearch = await state.actions.loadSavedSearch();
|
||||
expect(newSavedSearch?.id).toBeUndefined();
|
||||
const unsubscribe = state.actions.initializeAndSync();
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
await new Promise(process.nextTick);
|
||||
expect(getCurrentUrl()).toMatchInlineSnapshot(
|
||||
`"/#?_g=(refreshInterval:(pause:!t,value:1000),time:(from:now-15d,to:now))&_a=(columns:!(default_column),index:the-data-view-id,interval:auto,sort:!())"`
|
||||
);
|
||||
|
@ -346,7 +346,7 @@ describe('actions', () => {
|
|||
const newSavedSearch = await state.actions.loadSavedSearch();
|
||||
expect(newSavedSearch?.id).toBeUndefined();
|
||||
const unsubscribe = state.actions.initializeAndSync();
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
await new Promise(process.nextTick);
|
||||
expect(getCurrentUrl()).toMatchInlineSnapshot(
|
||||
`"/#?_g=(refreshInterval:(pause:!t,value:1000),time:(from:now-15d,to:now))&_a=(columns:!(default_column),index:the-data-view-id,interval:auto,sort:!())"`
|
||||
);
|
||||
|
@ -360,7 +360,7 @@ describe('actions', () => {
|
|||
const newSavedSearch = await state.actions.loadSavedSearch({ useAppState: true });
|
||||
expect(newSavedSearch?.id).toBeUndefined();
|
||||
const unsubscribe = state.actions.initializeAndSync();
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
await new Promise(process.nextTick);
|
||||
expect(getCurrentUrl()).toMatchInlineSnapshot(
|
||||
`"/#?_a=(columns:!(bytes),index:the-data-view-id,interval:month,sort:!())&_g=()"`
|
||||
);
|
||||
|
@ -374,7 +374,7 @@ describe('actions', () => {
|
|||
const newSavedSearch = await state.actions.loadSavedSearch({ useAppState: true });
|
||||
expect(newSavedSearch?.id).toBeUndefined();
|
||||
const unsubscribe = state.actions.initializeAndSync();
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
await new Promise(process.nextTick);
|
||||
expect(getCurrentUrl()).toMatchInlineSnapshot(
|
||||
`"/#?_a=(columns:!(bytes),index:the-data-view-id,interval:month,sort:!())&_g=()"`
|
||||
);
|
||||
|
@ -387,7 +387,7 @@ describe('actions', () => {
|
|||
savedSearchId: 'the-saved-search-id',
|
||||
});
|
||||
const unsubscribe = state.actions.initializeAndSync();
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
await new Promise(process.nextTick);
|
||||
expect(newSavedSearch?.id).toBe('the-saved-search-id');
|
||||
expect(getCurrentUrl()).toMatchInlineSnapshot(
|
||||
`"/#?_g=(refreshInterval:(pause:!t,value:1000),time:(from:now-15d,to:now))&_a=(columns:!(default_column),index:the-data-view-id,interval:auto,sort:!())"`
|
||||
|
@ -400,7 +400,7 @@ describe('actions', () => {
|
|||
const { state, getCurrentUrl } = await getState(url, savedSearchMock);
|
||||
await state.actions.loadSavedSearch({ savedSearchId: savedSearchMock.id, useAppState: true });
|
||||
const unsubscribe = state.actions.initializeAndSync();
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
await new Promise(process.nextTick);
|
||||
expect(getCurrentUrl()).toMatchInlineSnapshot(
|
||||
`"/#?_a=(columns:!(message),index:the-data-view-id,interval:month,sort:!())&_g=()"`
|
||||
);
|
||||
|
@ -533,23 +533,28 @@ describe('actions', () => {
|
|||
|
||||
test('onChangeDataView', async () => {
|
||||
const { state, getCurrentUrl } = await getState('/', savedSearchMock);
|
||||
await state.actions.loadSavedSearch({ savedSearchId: savedSearchMock.id });
|
||||
expect(state.savedSearchState.getState().searchSource.getField('index')!.id).toBe(
|
||||
dataViewMock.id
|
||||
);
|
||||
const unsubscribe = state.actions.initializeAndSync();
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
expect(getCurrentUrl()).toMatchInlineSnapshot(
|
||||
`"/#?_g=(refreshInterval:(pause:!t,value:1000),time:(from:now-15d,to:now))&_a=(columns:!(default_column),index:the-data-view-id,interval:auto,sort:!())"`
|
||||
);
|
||||
await state.actions.onChangeDataView(dataViewComplexMock.id!);
|
||||
await waitFor(() => {
|
||||
expect(state.internalState.getState().dataView?.id).toBe(dataViewComplexMock.id);
|
||||
});
|
||||
expect(state.appState.get().index).toBe(dataViewComplexMock.id);
|
||||
expect(state.savedSearchState.getState().searchSource.getField('index')!.id).toBe(
|
||||
const { actions, savedSearchState, dataState, appState } = state;
|
||||
|
||||
await actions.loadSavedSearch({ savedSearchId: savedSearchMock.id });
|
||||
const unsubscribe = actions.initializeAndSync();
|
||||
await new Promise(process.nextTick);
|
||||
// test initial state
|
||||
expect(dataState.fetch).toHaveBeenCalledTimes(0);
|
||||
expect(savedSearchState.getState().searchSource.getField('index')!.id).toBe(dataViewMock.id);
|
||||
expect(getCurrentUrl()).toContain(dataViewMock.id);
|
||||
|
||||
// change data view
|
||||
await actions.onChangeDataView(dataViewComplexMock.id!);
|
||||
await new Promise(process.nextTick);
|
||||
|
||||
// test changed state, fetch should be called once and URL should be updated
|
||||
expect(dataState.fetch).toHaveBeenCalledTimes(1);
|
||||
expect(appState.get().index).toBe(dataViewComplexMock.id);
|
||||
expect(savedSearchState.getState().searchSource.getField('index')!.id).toBe(
|
||||
dataViewComplexMock.id
|
||||
);
|
||||
// check if the changed data view is reflected in the URL
|
||||
expect(getCurrentUrl()).toContain(dataViewComplexMock.id);
|
||||
unsubscribe();
|
||||
});
|
||||
test('onDataViewCreated - persisted data view', async () => {
|
||||
|
@ -649,7 +654,7 @@ describe('actions', () => {
|
|||
// Load a given persisted saved search
|
||||
await state.actions.loadSavedSearch({ savedSearchId: savedSearchMock.id });
|
||||
const unsubscribe = state.actions.initializeAndSync();
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
await new Promise(process.nextTick);
|
||||
const initialUrlState =
|
||||
'/#?_g=(refreshInterval:(pause:!t,value:1000),time:(from:now-15d,to:now))&_a=(columns:!(default_column),index:the-data-view-id,interval:auto,sort:!())';
|
||||
expect(getCurrentUrl()).toBe(initialUrlState);
|
||||
|
@ -657,7 +662,7 @@ describe('actions', () => {
|
|||
|
||||
// Change the data view, this should change the URL and trigger a fetch
|
||||
await state.actions.onChangeDataView(dataViewComplexMock.id!);
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
await new Promise(process.nextTick);
|
||||
expect(getCurrentUrl()).toMatchInlineSnapshot(
|
||||
`"/#?_g=(refreshInterval:(pause:!t,value:1000),time:(from:now-15d,to:now))&_a=(columns:!(default_column),index:data-view-with-various-field-types-id,interval:auto,sort:!(!(data,desc)))"`
|
||||
);
|
||||
|
@ -668,7 +673,7 @@ describe('actions', () => {
|
|||
|
||||
// Undo all changes to the saved search, this should trigger a fetch, again
|
||||
await state.actions.undoSavedSearchChanges();
|
||||
state.kbnUrlStateStorage.kbnUrlControls.flush();
|
||||
await new Promise(process.nextTick);
|
||||
expect(getCurrentUrl()).toBe(initialUrlState);
|
||||
await waitFor(() => {
|
||||
expect(state.dataState.fetch).toHaveBeenCalledTimes(2);
|
||||
|
|
|
@ -10,7 +10,6 @@ import { i18n } from '@kbn/i18n';
|
|||
import { History } from 'history';
|
||||
import {
|
||||
createKbnUrlStateStorage,
|
||||
IKbnUrlStateStorage,
|
||||
StateContainer,
|
||||
withNotifyOnErrors,
|
||||
} from '@kbn/kibana-utils-plugin/public';
|
||||
|
@ -100,10 +99,6 @@ export interface DiscoverStateContainer {
|
|||
* Internal shared state that's used at several places in the UI
|
||||
*/
|
||||
internalState: DiscoverInternalStateContainer;
|
||||
/**
|
||||
* kbnUrlStateStorage - it keeps the state in sync with the URL
|
||||
*/
|
||||
kbnUrlStateStorage: IKbnUrlStateStorage;
|
||||
/**
|
||||
* State of saved search, the saved object of Discover
|
||||
*/
|
||||
|
@ -449,7 +444,6 @@ export function getDiscoverStateContainer({
|
|||
};
|
||||
|
||||
return {
|
||||
kbnUrlStateStorage: stateStorage,
|
||||
appState: appStateContainer,
|
||||
internalState: internalStateContainer,
|
||||
dataState: dataStateContainer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue