2020-01-28 02:13:56 -06:00
|
|
|
import {
|
|
|
|
DataQuery,
|
|
|
|
DataSourceApi,
|
|
|
|
dateTime,
|
2020-04-20 00:37:38 -05:00
|
|
|
ExploreMode,
|
2020-01-28 02:13:56 -06:00
|
|
|
LoadingState,
|
|
|
|
LogsDedupStrategy,
|
2020-02-06 06:34:52 -06:00
|
|
|
RawTimeRange,
|
2020-04-20 00:37:38 -05:00
|
|
|
UrlQueryMap,
|
2020-06-30 07:51:04 -05:00
|
|
|
ExploreUrlState,
|
2020-01-28 02:13:56 -06:00
|
|
|
} from '@grafana/data';
|
2020-01-13 01:03:22 -06:00
|
|
|
|
2019-03-25 06:49:15 -05:00
|
|
|
import {
|
2020-01-13 01:03:22 -06:00
|
|
|
createEmptyQueryResponse,
|
|
|
|
exploreReducer,
|
|
|
|
initialExploreState,
|
2019-03-25 06:49:15 -05:00
|
|
|
itemReducer,
|
|
|
|
makeExploreItemState,
|
|
|
|
makeInitialUpdateState,
|
|
|
|
} from './reducers';
|
2020-06-30 07:51:04 -05:00
|
|
|
import { ExploreId, ExploreItemState, ExploreState } from 'app/types/explore';
|
2019-02-04 00:47:10 -06:00
|
|
|
import { reducerTester } from 'test/core/redux/reducerTester';
|
2019-04-01 00:38:00 -05:00
|
|
|
import {
|
2020-01-13 01:03:22 -06:00
|
|
|
changeRangeAction,
|
|
|
|
changeRefreshIntervalAction,
|
|
|
|
scanStartAction,
|
2019-06-03 07:54:32 -05:00
|
|
|
scanStopAction,
|
2020-01-13 01:03:22 -06:00
|
|
|
splitCloseAction,
|
|
|
|
splitOpenAction,
|
|
|
|
updateDatasourceInstanceAction,
|
2020-06-04 05:33:16 -05:00
|
|
|
addQueryRowAction,
|
|
|
|
removeQueryRowAction,
|
2019-04-01 00:38:00 -05:00
|
|
|
} from './actionTypes';
|
2020-01-13 01:03:22 -06:00
|
|
|
import { updateLocation } from '../../../core/actions';
|
2020-06-30 07:51:04 -05:00
|
|
|
import { serializeStateToUrlParam } from '@grafana/data/src/utils/url';
|
2019-01-23 08:05:54 -06:00
|
|
|
|
2020-08-26 04:38:39 -05:00
|
|
|
const QUERY_KEY_REGEX = /Q-(?:[a-z0-9]+-){5}(?:[0-9]+)/;
|
2020-06-04 05:33:16 -05:00
|
|
|
|
2019-01-23 08:05:54 -06:00
|
|
|
describe('Explore item reducer', () => {
|
|
|
|
describe('scanning', () => {
|
2019-05-17 05:45:11 -05:00
|
|
|
it('should start scanning', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const initialState = {
|
2019-02-04 00:47:10 -06:00
|
|
|
...makeExploreItemState(),
|
|
|
|
scanning: false,
|
2019-01-23 08:05:54 -06:00
|
|
|
};
|
2019-02-04 00:47:10 -06:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreItemState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(itemReducer, initialState)
|
2019-06-28 05:07:55 -05:00
|
|
|
.whenActionIsDispatched(scanStartAction({ exploreId: ExploreId.left }))
|
2019-02-04 00:47:10 -06:00
|
|
|
.thenStateShouldEqual({
|
2019-10-23 06:54:20 -05:00
|
|
|
...makeExploreItemState(),
|
2019-02-04 00:47:10 -06:00
|
|
|
scanning: true,
|
|
|
|
});
|
2019-01-23 08:05:54 -06:00
|
|
|
});
|
2019-05-17 05:45:11 -05:00
|
|
|
it('should stop scanning', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const initialState = {
|
2019-02-04 00:47:10 -06:00
|
|
|
...makeExploreItemState(),
|
|
|
|
scanning: true,
|
2020-01-28 02:13:56 -06:00
|
|
|
scanRange: {} as RawTimeRange,
|
2019-01-23 08:05:54 -06:00
|
|
|
};
|
2019-02-04 00:47:10 -06:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreItemState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(itemReducer, initialState)
|
2019-02-04 00:47:10 -06:00
|
|
|
.whenActionIsDispatched(scanStopAction({ exploreId: ExploreId.left }))
|
|
|
|
.thenStateShouldEqual({
|
2019-10-23 06:54:20 -05:00
|
|
|
...makeExploreItemState(),
|
2019-02-04 00:47:10 -06:00
|
|
|
scanning: false,
|
|
|
|
scanRange: undefined,
|
|
|
|
});
|
2019-01-23 08:05:54 -06:00
|
|
|
});
|
|
|
|
});
|
2019-04-01 00:38:00 -05:00
|
|
|
|
2019-10-29 05:37:36 -05:00
|
|
|
describe('changing datasource', () => {
|
2019-04-01 00:38:00 -05:00
|
|
|
describe('when updateDatasourceInstanceAction is dispatched', () => {
|
|
|
|
describe('and datasourceInstance supports graph, logs, table and has a startpage', () => {
|
|
|
|
it('then it should set correct state', () => {
|
|
|
|
const StartPage = {};
|
|
|
|
const datasourceInstance = {
|
|
|
|
meta: {
|
2019-05-17 05:45:11 -05:00
|
|
|
metrics: true,
|
|
|
|
logs: true,
|
2019-04-01 00:38:00 -05:00
|
|
|
},
|
2019-04-04 11:30:15 -05:00
|
|
|
components: {
|
2019-04-01 00:38:00 -05:00
|
|
|
ExploreStartPage: StartPage,
|
|
|
|
},
|
|
|
|
} as DataSourceApi;
|
|
|
|
const queries: DataQuery[] = [];
|
|
|
|
const queryKeys: string[] = [];
|
2020-01-28 02:13:56 -06:00
|
|
|
const initialState: ExploreItemState = ({
|
2019-04-01 00:38:00 -05:00
|
|
|
datasourceInstance: null,
|
|
|
|
queries,
|
|
|
|
queryKeys,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreItemState;
|
2019-07-30 08:49:32 -05:00
|
|
|
const expectedState: any = {
|
2019-04-01 00:38:00 -05:00
|
|
|
datasourceInstance,
|
|
|
|
queries,
|
|
|
|
queryKeys,
|
2019-08-30 08:22:36 -05:00
|
|
|
graphResult: null,
|
|
|
|
logsResult: null,
|
|
|
|
tableResult: null,
|
2019-05-16 02:52:22 -05:00
|
|
|
supportedModes: [ExploreMode.Metrics, ExploreMode.Logs],
|
2019-05-17 05:45:11 -05:00
|
|
|
latency: 0,
|
2019-09-03 02:55:20 -05:00
|
|
|
loading: false,
|
|
|
|
queryResponse: createEmptyQueryResponse(),
|
2019-04-01 00:38:00 -05:00
|
|
|
};
|
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreItemState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(itemReducer, initialState)
|
2019-04-01 00:38:00 -05:00
|
|
|
.whenActionIsDispatched(updateDatasourceInstanceAction({ exploreId: ExploreId.left, datasourceInstance }))
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-09-12 10:28:46 -05:00
|
|
|
|
2019-10-23 06:54:20 -05:00
|
|
|
describe('changing refresh intervals', () => {
|
|
|
|
it("should result in 'streaming' state, when live-tailing is active", () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const initialState = makeExploreItemState();
|
2019-10-23 06:54:20 -05:00
|
|
|
const expectedState = {
|
|
|
|
...makeExploreItemState(),
|
|
|
|
refreshInterval: 'LIVE',
|
|
|
|
isLive: true,
|
|
|
|
loading: true,
|
|
|
|
logsResult: {
|
|
|
|
hasUniqueLabels: false,
|
|
|
|
rows: [] as any[],
|
|
|
|
},
|
|
|
|
queryResponse: {
|
|
|
|
...makeExploreItemState().queryResponse,
|
|
|
|
state: LoadingState.Streaming,
|
|
|
|
},
|
|
|
|
};
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreItemState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(itemReducer, initialState)
|
2019-10-23 06:54:20 -05:00
|
|
|
.whenActionIsDispatched(changeRefreshIntervalAction({ exploreId: ExploreId.left, refreshInterval: 'LIVE' }))
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should result in 'done' state, when live-tailing is stopped", () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const initialState = makeExploreItemState();
|
2019-10-23 06:54:20 -05:00
|
|
|
const expectedState = {
|
|
|
|
...makeExploreItemState(),
|
|
|
|
refreshInterval: '',
|
|
|
|
logsResult: {
|
|
|
|
hasUniqueLabels: false,
|
|
|
|
rows: [] as any[],
|
|
|
|
},
|
|
|
|
queryResponse: {
|
|
|
|
...makeExploreItemState().queryResponse,
|
|
|
|
state: LoadingState.Done,
|
|
|
|
},
|
|
|
|
};
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreItemState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(itemReducer, initialState)
|
2019-10-23 06:54:20 -05:00
|
|
|
.whenActionIsDispatched(changeRefreshIntervalAction({ exploreId: ExploreId.left, refreshInterval: '' }))
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-16 07:17:33 -05:00
|
|
|
describe('changing range', () => {
|
|
|
|
describe('when changeRangeAction is dispatched', () => {
|
|
|
|
it('then it should set correct state', () => {
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreItemState>()
|
|
|
|
.givenReducer(itemReducer, ({
|
2019-09-16 07:17:33 -05:00
|
|
|
update: { ...makeInitialUpdateState(), range: true },
|
|
|
|
range: null,
|
|
|
|
absoluteRange: null,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreItemState)
|
2019-09-16 07:17:33 -05:00
|
|
|
.whenActionIsDispatched(
|
|
|
|
changeRangeAction({
|
|
|
|
exploreId: ExploreId.left,
|
|
|
|
absoluteRange: { from: 1546297200000, to: 1546383600000 },
|
|
|
|
range: { from: dateTime('2019-01-01'), to: dateTime('2019-01-02'), raw: { from: 'now-1d', to: 'now' } },
|
|
|
|
})
|
|
|
|
)
|
2020-01-28 02:13:56 -06:00
|
|
|
.thenStateShouldEqual(({
|
2019-09-16 07:17:33 -05:00
|
|
|
update: { ...makeInitialUpdateState(), range: false },
|
|
|
|
absoluteRange: { from: 1546297200000, to: 1546383600000 },
|
|
|
|
range: { from: dateTime('2019-01-01'), to: dateTime('2019-01-02'), raw: { from: 'now-1d', to: 'now' } },
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreItemState);
|
2019-09-16 07:17:33 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-06-04 05:33:16 -05:00
|
|
|
|
|
|
|
describe('query rows', () => {
|
|
|
|
it('adds a new query row', () => {
|
|
|
|
reducerTester<ExploreItemState>()
|
|
|
|
.givenReducer(itemReducer, ({
|
|
|
|
queries: [],
|
|
|
|
} as unknown) as ExploreItemState)
|
|
|
|
.whenActionIsDispatched(
|
|
|
|
addQueryRowAction({
|
|
|
|
exploreId: ExploreId.left,
|
|
|
|
query: { refId: 'A', key: 'mockKey' },
|
|
|
|
index: 0,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStateShouldEqual(({
|
|
|
|
queries: [{ refId: 'A', key: 'mockKey' }],
|
|
|
|
queryKeys: ['mockKey-0'],
|
|
|
|
} as unknown) as ExploreItemState);
|
|
|
|
});
|
|
|
|
it('removes a query row', () => {
|
|
|
|
reducerTester<ExploreItemState>()
|
|
|
|
.givenReducer(itemReducer, ({
|
|
|
|
queries: [
|
|
|
|
{ refId: 'A', key: 'mockKey' },
|
|
|
|
{ refId: 'B', key: 'mockKey' },
|
|
|
|
],
|
|
|
|
queryKeys: ['mockKey-0', 'mockKey-1'],
|
|
|
|
} as unknown) as ExploreItemState)
|
|
|
|
.whenActionIsDispatched(
|
|
|
|
removeQueryRowAction({
|
|
|
|
exploreId: ExploreId.left,
|
|
|
|
index: 0,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStatePredicateShouldEqual((resultingState: ExploreItemState) => {
|
|
|
|
expect(resultingState.queries.length).toBe(1);
|
|
|
|
expect(resultingState.queries[0].refId).toBe('A');
|
|
|
|
expect(resultingState.queries[0].key).toMatch(QUERY_KEY_REGEX);
|
|
|
|
expect(resultingState.queryKeys[0]).toMatch(QUERY_KEY_REGEX);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('reassigns query refId after removing a query to keep queries in order', () => {
|
|
|
|
reducerTester<ExploreItemState>()
|
|
|
|
.givenReducer(itemReducer, ({
|
|
|
|
queries: [{ refId: 'A' }, { refId: 'B' }, { refId: 'C' }],
|
|
|
|
queryKeys: ['undefined-0', 'undefined-1', 'undefined-2'],
|
|
|
|
} as unknown) as ExploreItemState)
|
|
|
|
.whenActionIsDispatched(
|
|
|
|
removeQueryRowAction({
|
|
|
|
exploreId: ExploreId.left,
|
|
|
|
index: 0,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStatePredicateShouldEqual((resultingState: ExploreItemState) => {
|
|
|
|
expect(resultingState.queries.length).toBe(2);
|
|
|
|
const queriesRefIds = resultingState.queries.map(query => query.refId);
|
|
|
|
const queriesKeys = resultingState.queries.map(query => query.key);
|
|
|
|
expect(queriesRefIds).toEqual(['A', 'B']);
|
|
|
|
queriesKeys.forEach(queryKey => {
|
|
|
|
expect(queryKey).toMatch(QUERY_KEY_REGEX);
|
|
|
|
});
|
|
|
|
resultingState.queryKeys.forEach(queryKey => {
|
|
|
|
expect(queryKey).toMatch(QUERY_KEY_REGEX);
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-01-23 08:05:54 -06:00
|
|
|
});
|
2019-03-22 09:24:30 -05:00
|
|
|
|
|
|
|
export const setup = (urlStateOverrides?: any) => {
|
|
|
|
const update = makeInitialUpdateState();
|
|
|
|
const urlStateDefaults: ExploreUrlState = {
|
|
|
|
datasource: 'some-datasource',
|
|
|
|
queries: [],
|
|
|
|
range: {
|
|
|
|
from: '',
|
|
|
|
to: '',
|
|
|
|
},
|
|
|
|
ui: {
|
|
|
|
dedupStrategy: LogsDedupStrategy.none,
|
|
|
|
showingGraph: false,
|
|
|
|
showingTable: false,
|
|
|
|
showingLogs: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const urlState: ExploreUrlState = { ...urlStateDefaults, ...urlStateOverrides };
|
|
|
|
const serializedUrlState = serializeStateToUrlParam(urlState);
|
2020-01-28 02:13:56 -06:00
|
|
|
const initialState = ({
|
|
|
|
split: false,
|
|
|
|
left: { urlState, update },
|
|
|
|
right: { urlState, update },
|
|
|
|
} as unknown) as ExploreState;
|
2019-03-22 09:24:30 -05:00
|
|
|
|
|
|
|
return {
|
2020-01-13 01:03:22 -06:00
|
|
|
initialState,
|
2019-03-22 09:24:30 -05:00
|
|
|
serializedUrlState,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Explore reducer', () => {
|
2019-03-25 06:49:15 -05:00
|
|
|
describe('split view', () => {
|
|
|
|
it("should make right pane a duplicate of the given item's state on split open", () => {
|
2020-01-28 02:13:56 -06:00
|
|
|
const leftItemMock = ({
|
2019-03-25 06:49:15 -05:00
|
|
|
containerWidth: 100,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreItemState;
|
2019-03-25 06:49:15 -05:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
const initialState = ({
|
2019-03-25 06:49:15 -05:00
|
|
|
split: null,
|
|
|
|
left: leftItemMock as ExploreItemState,
|
|
|
|
right: makeExploreItemState(),
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreState;
|
2019-03-25 06:49:15 -05:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(exploreReducer, initialState)
|
2019-03-25 06:49:15 -05:00
|
|
|
.whenActionIsDispatched(splitOpenAction({ itemState: leftItemMock }))
|
2020-01-28 02:13:56 -06:00
|
|
|
.thenStateShouldEqual(({
|
2019-03-25 06:49:15 -05:00
|
|
|
split: true,
|
|
|
|
left: leftItemMock,
|
|
|
|
right: leftItemMock,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreState);
|
2019-03-25 06:49:15 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('split close', () => {
|
|
|
|
it('should keep right pane as left when left is closed', () => {
|
2020-01-28 02:13:56 -06:00
|
|
|
const leftItemMock = ({
|
2019-03-25 06:49:15 -05:00
|
|
|
containerWidth: 100,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreItemState;
|
2019-03-25 06:49:15 -05:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
const rightItemMock = ({
|
2019-03-25 06:49:15 -05:00
|
|
|
containerWidth: 200,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreItemState;
|
2019-03-25 06:49:15 -05:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
const initialState = ({
|
2019-03-25 06:49:15 -05:00
|
|
|
split: null,
|
|
|
|
left: leftItemMock,
|
|
|
|
right: rightItemMock,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreState;
|
2019-03-25 06:49:15 -05:00
|
|
|
|
|
|
|
// closing left item
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(exploreReducer, initialState)
|
2019-03-25 06:49:15 -05:00
|
|
|
.whenActionIsDispatched(splitCloseAction({ itemId: ExploreId.left }))
|
2020-01-28 02:13:56 -06:00
|
|
|
.thenStateShouldEqual(({
|
2019-03-25 06:49:15 -05:00
|
|
|
split: false,
|
|
|
|
left: rightItemMock,
|
|
|
|
right: initialExploreState.right,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreState);
|
2019-03-25 06:49:15 -05:00
|
|
|
});
|
|
|
|
it('should reset right pane when it is closed ', () => {
|
2020-01-28 02:13:56 -06:00
|
|
|
const leftItemMock = ({
|
2019-03-25 06:49:15 -05:00
|
|
|
containerWidth: 100,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreItemState;
|
2019-03-25 06:49:15 -05:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
const rightItemMock = ({
|
2019-03-25 06:49:15 -05:00
|
|
|
containerWidth: 200,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreItemState;
|
2019-03-25 06:49:15 -05:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
const initialState = ({
|
2019-03-25 06:49:15 -05:00
|
|
|
split: null,
|
|
|
|
left: leftItemMock,
|
|
|
|
right: rightItemMock,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreState;
|
2019-03-25 06:49:15 -05:00
|
|
|
|
|
|
|
// closing left item
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(exploreReducer, initialState)
|
2019-03-25 06:49:15 -05:00
|
|
|
.whenActionIsDispatched(splitCloseAction({ itemId: ExploreId.right }))
|
2020-01-28 02:13:56 -06:00
|
|
|
.thenStateShouldEqual(({
|
2019-03-25 06:49:15 -05:00
|
|
|
split: false,
|
|
|
|
left: leftItemMock,
|
|
|
|
right: initialExploreState.right,
|
2020-01-28 02:13:56 -06:00
|
|
|
} as unknown) as ExploreState);
|
2019-03-25 06:49:15 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-22 09:24:30 -05:00
|
|
|
describe('when updateLocation is dispatched', () => {
|
|
|
|
describe('and payload does not contain a query', () => {
|
|
|
|
it('then it should just return state', () => {
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
|
|
|
.givenReducer(exploreReducer, ({} as unknown) as ExploreState)
|
|
|
|
.whenActionIsDispatched(updateLocation({ query: (null as unknown) as UrlQueryMap }))
|
|
|
|
.thenStateShouldEqual(({} as unknown) as ExploreState);
|
2019-03-22 09:24:30 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('and payload contains a query', () => {
|
|
|
|
describe("but does not contain 'left'", () => {
|
|
|
|
it('then it should just return state', () => {
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
|
|
|
.givenReducer(exploreReducer, ({} as unknown) as ExploreState)
|
2019-03-22 09:24:30 -05:00
|
|
|
.whenActionIsDispatched(updateLocation({ query: {} }))
|
2020-01-28 02:13:56 -06:00
|
|
|
.thenStateShouldEqual(({} as unknown) as ExploreState);
|
2019-03-22 09:24:30 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and query contains a 'right'", () => {
|
|
|
|
it('then it should add split in state', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const { initialState, serializedUrlState } = setup();
|
|
|
|
const expectedState = { ...initialState, split: true };
|
2019-03-22 09:24:30 -05:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(exploreReducer, initialState)
|
2019-03-22 09:24:30 -05:00
|
|
|
.whenActionIsDispatched(
|
|
|
|
updateLocation({
|
|
|
|
query: {
|
|
|
|
left: serializedUrlState,
|
|
|
|
right: serializedUrlState,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and query contains a 'left'", () => {
|
|
|
|
describe('but urlState is not set in state', () => {
|
|
|
|
it('then it should just add urlState and update in state', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const { initialState, serializedUrlState } = setup();
|
2020-01-28 02:13:56 -06:00
|
|
|
const urlState: ExploreUrlState = (null as unknown) as ExploreUrlState;
|
|
|
|
const stateWithoutUrlState = ({ ...initialState, left: { urlState } } as unknown) as ExploreState;
|
2020-01-13 01:03:22 -06:00
|
|
|
const expectedState = { ...initialState };
|
2019-03-22 09:24:30 -05:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2019-03-22 09:24:30 -05:00
|
|
|
.givenReducer(exploreReducer, stateWithoutUrlState)
|
|
|
|
.whenActionIsDispatched(
|
|
|
|
updateLocation({
|
|
|
|
query: {
|
|
|
|
left: serializedUrlState,
|
|
|
|
},
|
|
|
|
path: '/explore',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("but '/explore' is missing in path", () => {
|
|
|
|
it('then it should just add urlState and update in state', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const { initialState, serializedUrlState } = setup();
|
|
|
|
const expectedState = { ...initialState };
|
2019-03-22 09:24:30 -05:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(exploreReducer, initialState)
|
2019-03-22 09:24:30 -05:00
|
|
|
.whenActionIsDispatched(
|
|
|
|
updateLocation({
|
|
|
|
query: {
|
|
|
|
left: serializedUrlState,
|
|
|
|
},
|
|
|
|
path: '/dashboard',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and '/explore' is in path", () => {
|
|
|
|
describe('and datasource differs', () => {
|
|
|
|
it('then it should return update datasource', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const { initialState, serializedUrlState } = setup();
|
2019-03-22 09:24:30 -05:00
|
|
|
const expectedState = {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState,
|
2019-03-22 09:24:30 -05:00
|
|
|
left: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left,
|
2019-03-22 09:24:30 -05:00
|
|
|
update: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left.update,
|
2019-03-22 09:24:30 -05:00
|
|
|
datasource: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
const stateWithDifferentDataSource: any = {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState,
|
2019-03-22 09:24:30 -05:00
|
|
|
left: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left,
|
2019-03-22 09:24:30 -05:00
|
|
|
urlState: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left.urlState,
|
2019-03-22 09:24:30 -05:00
|
|
|
datasource: 'different datasource',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2019-03-22 09:24:30 -05:00
|
|
|
.givenReducer(exploreReducer, stateWithDifferentDataSource)
|
|
|
|
.whenActionIsDispatched(
|
|
|
|
updateLocation({
|
|
|
|
query: {
|
|
|
|
left: serializedUrlState,
|
|
|
|
},
|
|
|
|
path: '/explore',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('and range differs', () => {
|
|
|
|
it('then it should return update range', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const { initialState, serializedUrlState } = setup();
|
2019-03-22 09:24:30 -05:00
|
|
|
const expectedState = {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState,
|
2019-03-22 09:24:30 -05:00
|
|
|
left: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left,
|
2019-03-22 09:24:30 -05:00
|
|
|
update: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left.update,
|
2019-03-22 09:24:30 -05:00
|
|
|
range: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
const stateWithDifferentDataSource: any = {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState,
|
2019-03-22 09:24:30 -05:00
|
|
|
left: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left,
|
2019-03-22 09:24:30 -05:00
|
|
|
urlState: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left.urlState,
|
2019-03-22 09:24:30 -05:00
|
|
|
range: {
|
|
|
|
from: 'now',
|
|
|
|
to: 'now-6h',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2019-03-22 09:24:30 -05:00
|
|
|
.givenReducer(exploreReducer, stateWithDifferentDataSource)
|
|
|
|
.whenActionIsDispatched(
|
|
|
|
updateLocation({
|
|
|
|
query: {
|
|
|
|
left: serializedUrlState,
|
|
|
|
},
|
|
|
|
path: '/explore',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('and queries differs', () => {
|
|
|
|
it('then it should return update queries', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const { initialState, serializedUrlState } = setup();
|
2019-03-22 09:24:30 -05:00
|
|
|
const expectedState = {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState,
|
2019-03-22 09:24:30 -05:00
|
|
|
left: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left,
|
2019-03-22 09:24:30 -05:00
|
|
|
update: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left.update,
|
2019-03-22 09:24:30 -05:00
|
|
|
queries: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
const stateWithDifferentDataSource: any = {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState,
|
2019-03-22 09:24:30 -05:00
|
|
|
left: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left,
|
2019-03-22 09:24:30 -05:00
|
|
|
urlState: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left.urlState,
|
2019-03-22 09:24:30 -05:00
|
|
|
queries: [{ expr: '{__filename__="some.log"}' }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2019-03-22 09:24:30 -05:00
|
|
|
.givenReducer(exploreReducer, stateWithDifferentDataSource)
|
|
|
|
.whenActionIsDispatched(
|
|
|
|
updateLocation({
|
|
|
|
query: {
|
|
|
|
left: serializedUrlState,
|
|
|
|
},
|
|
|
|
path: '/explore',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('and ui differs', () => {
|
|
|
|
it('then it should return update ui', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const { initialState, serializedUrlState } = setup();
|
2019-03-22 09:24:30 -05:00
|
|
|
const expectedState = {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState,
|
2019-03-22 09:24:30 -05:00
|
|
|
left: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left,
|
2019-03-22 09:24:30 -05:00
|
|
|
update: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left.update,
|
2019-03-22 09:24:30 -05:00
|
|
|
ui: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
const stateWithDifferentDataSource: any = {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState,
|
2019-03-22 09:24:30 -05:00
|
|
|
left: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left,
|
2019-03-22 09:24:30 -05:00
|
|
|
urlState: {
|
2020-01-13 01:03:22 -06:00
|
|
|
...initialState.left.urlState,
|
2019-03-22 09:24:30 -05:00
|
|
|
ui: {
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
...initialState.left.urlState!.ui,
|
2019-03-22 09:24:30 -05:00
|
|
|
showingGraph: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2019-03-22 09:24:30 -05:00
|
|
|
.givenReducer(exploreReducer, stateWithDifferentDataSource)
|
|
|
|
.whenActionIsDispatched(
|
2019-04-16 02:15:23 -05:00
|
|
|
updateLocation({
|
|
|
|
query: {
|
|
|
|
left: serializedUrlState,
|
|
|
|
},
|
|
|
|
path: '/explore',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-22 09:24:30 -05:00
|
|
|
describe('and nothing differs', () => {
|
2019-05-17 05:45:11 -05:00
|
|
|
it('then it should return update ui', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
const { initialState, serializedUrlState } = setup();
|
|
|
|
const expectedState = { ...initialState };
|
2019-03-22 09:24:30 -05:00
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<ExploreState>()
|
2020-01-13 01:03:22 -06:00
|
|
|
.givenReducer(exploreReducer, initialState)
|
2019-03-22 09:24:30 -05:00
|
|
|
.whenActionIsDispatched(
|
|
|
|
updateLocation({
|
|
|
|
query: {
|
|
|
|
left: serializedUrlState,
|
|
|
|
},
|
|
|
|
path: '/explore',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|