mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
✅ add more unit tests for the annotation type switch operation (#141241)
This commit is contained in:
parent
3433f5d112
commit
6f1be65f1e
1 changed files with 212 additions and 0 deletions
|
@ -372,6 +372,218 @@ describe('AnnotationsPanel', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should avoid to retain specific manual configurations when switching to query based annotations', () => {
|
||||
const state = testState();
|
||||
const indexPattern = createMockedIndexPattern();
|
||||
state.layers[0] = {
|
||||
annotations: [customLineStaticAnnotation],
|
||||
layerId: 'annotation',
|
||||
layerType: 'annotations',
|
||||
ignoreGlobalFilters: true,
|
||||
indexPatternId: indexPattern.id,
|
||||
};
|
||||
const frameMock = createMockFramePublicAPI({
|
||||
datasourceLayers: {},
|
||||
dataViews: createMockDataViewsState({
|
||||
indexPatterns: { [indexPattern.id]: indexPattern },
|
||||
}),
|
||||
});
|
||||
|
||||
const setState = jest.fn();
|
||||
|
||||
const component = mount(
|
||||
<AnnotationsPanel
|
||||
layerId={state.layers[0].layerId}
|
||||
frame={frameMock}
|
||||
setState={setState}
|
||||
accessor="ann1"
|
||||
groupId="left"
|
||||
state={state}
|
||||
datatableUtilities={datatableUtilities}
|
||||
formatFactory={jest.fn()}
|
||||
paletteService={chartPluginMock.createPaletteRegistry()}
|
||||
panelRef={React.createRef()}
|
||||
/>
|
||||
);
|
||||
|
||||
act(() => {
|
||||
component
|
||||
.find(`[data-test-subj="lns-xyAnnotation-placementType"]`)
|
||||
.find(EuiButtonGroup)
|
||||
.prop('onChange')!('lens_xyChart_annotation_query');
|
||||
});
|
||||
component.update();
|
||||
|
||||
expect(setState).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
layers: [
|
||||
expect.objectContaining({
|
||||
annotations: [
|
||||
expect.objectContaining({
|
||||
key: expect.not.objectContaining({ timestamp: expect.any('string') }),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('should avoid to retain range manual configurations when switching to query based annotations', () => {
|
||||
const state = testState();
|
||||
const indexPattern = createMockedIndexPattern();
|
||||
state.layers[0] = {
|
||||
annotations: [
|
||||
{
|
||||
color: 'red',
|
||||
icon: 'triangle',
|
||||
id: 'ann1',
|
||||
type: 'manual',
|
||||
isHidden: undefined,
|
||||
key: {
|
||||
endTimestamp: '2022-03-21T10:49:00.000Z',
|
||||
timestamp: '2022-03-18T08:25:00.000Z',
|
||||
type: 'range',
|
||||
},
|
||||
label: 'Event range',
|
||||
lineStyle: 'dashed',
|
||||
lineWidth: 3,
|
||||
},
|
||||
],
|
||||
layerId: 'annotation',
|
||||
layerType: 'annotations',
|
||||
ignoreGlobalFilters: true,
|
||||
indexPatternId: indexPattern.id,
|
||||
};
|
||||
const frameMock = createMockFramePublicAPI({
|
||||
datasourceLayers: {},
|
||||
dataViews: createMockDataViewsState({
|
||||
indexPatterns: { [indexPattern.id]: indexPattern },
|
||||
}),
|
||||
});
|
||||
|
||||
const setState = jest.fn();
|
||||
|
||||
const component = mount(
|
||||
<AnnotationsPanel
|
||||
layerId={state.layers[0].layerId}
|
||||
frame={frameMock}
|
||||
setState={setState}
|
||||
accessor="ann1"
|
||||
groupId="left"
|
||||
state={state}
|
||||
datatableUtilities={datatableUtilities}
|
||||
formatFactory={jest.fn()}
|
||||
paletteService={chartPluginMock.createPaletteRegistry()}
|
||||
panelRef={React.createRef()}
|
||||
/>
|
||||
);
|
||||
|
||||
act(() => {
|
||||
component
|
||||
.find(`[data-test-subj="lns-xyAnnotation-placementType"]`)
|
||||
.find(EuiButtonGroup)
|
||||
.prop('onChange')!('lens_xyChart_annotation_query');
|
||||
});
|
||||
component.update();
|
||||
|
||||
expect(setState).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
layers: [
|
||||
expect.objectContaining({
|
||||
annotations: [
|
||||
expect.objectContaining({ label: expect.not.stringContaining('Event range') }),
|
||||
],
|
||||
}),
|
||||
],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('should set a default tiemstamp when switching from query based to manual annotations', () => {
|
||||
const state = testState();
|
||||
const indexPattern = createMockedIndexPattern();
|
||||
state.layers[0] = {
|
||||
annotations: [
|
||||
{
|
||||
color: 'red',
|
||||
icon: 'triangle',
|
||||
id: 'ann1',
|
||||
type: 'query',
|
||||
isHidden: undefined,
|
||||
timeField: 'timestamp',
|
||||
key: {
|
||||
type: 'point_in_time',
|
||||
},
|
||||
label: 'Query based event',
|
||||
lineStyle: 'dashed',
|
||||
lineWidth: 3,
|
||||
filter: { type: 'kibana_query', query: '', language: 'kuery' },
|
||||
},
|
||||
],
|
||||
layerId: 'annotation',
|
||||
layerType: 'annotations',
|
||||
indexPatternId: indexPattern.id,
|
||||
ignoreGlobalFilters: true,
|
||||
};
|
||||
const frameMock = createMockFramePublicAPI({
|
||||
datasourceLayers: {},
|
||||
dataViews: createMockDataViewsState({
|
||||
indexPatterns: { [indexPattern.id]: indexPattern },
|
||||
}),
|
||||
});
|
||||
|
||||
const setState = jest.fn();
|
||||
|
||||
const component = mount(
|
||||
<AnnotationsPanel
|
||||
layerId={state.layers[0].layerId}
|
||||
frame={frameMock}
|
||||
setState={setState}
|
||||
accessor="ann1"
|
||||
groupId="left"
|
||||
state={state}
|
||||
datatableUtilities={datatableUtilities}
|
||||
formatFactory={jest.fn()}
|
||||
paletteService={chartPluginMock.createPaletteRegistry()}
|
||||
panelRef={React.createRef()}
|
||||
/>
|
||||
);
|
||||
|
||||
act(() => {
|
||||
component
|
||||
.find(`[data-test-subj="lns-xyAnnotation-placementType"]`)
|
||||
.find(EuiButtonGroup)
|
||||
.prop('onChange')!('lens_xyChart_annotation_manual');
|
||||
});
|
||||
component.update();
|
||||
|
||||
expect(setState).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
layers: [
|
||||
expect.objectContaining({
|
||||
annotations: [
|
||||
expect.objectContaining({
|
||||
key: { type: 'point_in_time', timestamp: expect.any(String) },
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
})
|
||||
);
|
||||
|
||||
// also check query specific props are not carried over
|
||||
expect(setState).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
layers: [
|
||||
expect.objectContaining({
|
||||
annotations: [expect.not.objectContaining({ timeField: 'timestamp' })],
|
||||
}),
|
||||
],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('should fallback to the first date field available in the dataView if not time-based', () => {
|
||||
const state = testState();
|
||||
const indexPattern = createMockedIndexPattern({ timeFieldName: '' });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue