Skip to content

Commit

Permalink
add basic mock for redux embeddable package
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Jul 21, 2022
1 parent bcbcc00 commit 6364cb9
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { stubLogstashDataView } from '@kbn/data-views-plugin/common/data_view.st
import { pluginServices } from '../../services';
import { TestScheduler } from 'rxjs/testing';
import { buildRangeFilter } from '@kbn/es-query';
import { ReduxEmbeddablePackage } from '@kbn/presentation-util-plugin/public';

const buildFilter = (range: [number | null, number | null]) => {
const filterPieces: Record<string, number> = {};
Expand Down Expand Up @@ -62,6 +63,10 @@ const baseInput: TimeSliderControlEmbeddableInput = {
dataViewId: stubLogstashDataView.id!,
};

const mockReduxEmbeddablePackage = {
createTools: () => {},
} as unknown as ReduxEmbeddablePackage;

describe('Time Slider Control Embeddable', () => {
const services = pluginServices.getServices();
const fetchRange = jest.spyOn(services.data, 'fetchFieldRange');
Expand Down Expand Up @@ -99,7 +104,7 @@ describe('Time Slider Control Embeddable', () => {
b: expectedFilterAfterRangeFetch ? [expectedFilterAfterRangeFetch] : undefined,
};

const embeddable = new TimeSliderControlEmbeddable(input, {});
const embeddable = new TimeSliderControlEmbeddable(mockReduxEmbeddablePackage, input, {});
const source$ = embeddable.getOutput$().pipe(map((o) => o.filters));

expectObservable(source$).toBe(expectedMarbles, expectedValues);
Expand Down Expand Up @@ -196,7 +201,11 @@ describe('Time Slider Control Embeddable', () => {
b: mockRange,
};

const embeddable = new TimeSliderControlEmbeddable(baseInput, {});
const embeddable = new TimeSliderControlEmbeddable(
mockReduxEmbeddablePackage,
baseInput,
{}
);
const source$ = embeddable.getComponentState$().pipe(map((state) => state.range));

const { fieldName, ...inputForFetch } = baseInput;
Expand All @@ -221,7 +230,11 @@ describe('Time Slider Control Embeddable', () => {
const mockRange = { min: 1, max: 2 };
fetchRange$.mockReturnValue(cold('a', { a: mockRange }));

const embeddable = new TimeSliderControlEmbeddable(baseInput, {});
const embeddable = new TimeSliderControlEmbeddable(
mockReduxEmbeddablePackage,
baseInput,
{}
);
const updatedInput = { ...baseInput, fieldName: '@timestamp' };

embeddable.updateInput(updatedInput);
Expand All @@ -247,7 +260,7 @@ describe('Time Slider Control Embeddable', () => {
timeRange: {} as any,
};

new TimeSliderControlEmbeddable(input, {});
new TimeSliderControlEmbeddable(mockReduxEmbeddablePackage, input, {});

expect(fetchRange$).toBeCalledTimes(1);
const args = fetchRange$.mock.calls[0][2];
Expand All @@ -274,7 +287,7 @@ describe('Time Slider Control Embeddable', () => {
ignoreParentSettings: { ignoreFilters: true, ignoreQuery: true, ignoreTimerange: true },
};

new TimeSliderControlEmbeddable(input, {});
new TimeSliderControlEmbeddable(mockReduxEmbeddablePackage, input, {});

expect(fetchRange$).toBeCalledTimes(1);
const args = fetchRange$.mock.calls[0][2];
Expand Down

0 comments on commit 6364cb9

Please sign in to comment.