Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Apr 6, 2020
1 parent 37b8510 commit 732e990
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ describe('Flyout', () => {
expect(resolveIndexPatternConflicts).toHaveBeenCalledWith(
component.instance().resolutions,
mockConflictedIndexPatterns,
true
true,
defaultProps.indexPatterns
);
expect(saveObjects).toHaveBeenCalledWith(
mockConflictedSavedObjectsLinkedToSavedSearches,
Expand Down
1 change: 1 addition & 0 deletions src/legacy/ui/public/new_platform/set_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function setStartServices(npStart: NpStart) {
visualizationsServices.setAggs(npStart.plugins.data.search.aggs);
visualizationsServices.setOverlays(npStart.core.overlays);
visualizationsServices.setChrome(npStart.core.chrome);
visualizationsServices.setSearch(npStart.plugins.data.search);
const savedVisualizationsLoader = createSavedVisLoader({
savedObjectsClient: npStart.core.savedObjects.client,
indexPatterns: npStart.plugins.data.indexPatterns,
Expand Down
52 changes: 24 additions & 28 deletions src/plugins/saved_objects/public/saved_object/saved_object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ describe('Saved Object', () => {
}

beforeEach(() => {
(dataStartMock.search.parseSearchSource as jest.Mock).mockReset();
SavedObjectClass = createSavedObjectClass({
savedObjectsClient: savedObjectsClientStub,
indexPatterns: dataStartMock.indexPatterns,
search: dataStartMock.search,
} as SavedObjectKibanaServices);
});

Expand Down Expand Up @@ -269,7 +271,7 @@ describe('Saved Object', () => {
);
});

it('when index exists in searchSourceJSON', () => {
it('when search source references saved object', () => {
const id = '123';
stubESResponse(getMockedDocResponse(id));
return createInitializedSavedObject({ type: 'dashboard', searchSource: true }).then(
Expand Down Expand Up @@ -409,18 +411,17 @@ describe('Saved Object', () => {
});
});

it('throws error invalid JSON is detected', async () => {
it('forwards thrown exceptions from parseSearchSource', async () => {
(dataStartMock.search.parseSearchSource as jest.Mock).mockImplementation(() => {
throw new InvalidJSONProperty('');
});
const savedObject = await createInitializedSavedObject({
type: 'dashboard',
searchSource: true,
});
const response = {
found: true,
_source: {
kibanaSavedObjectMeta: {
searchSourceJSON: '"{\\n \\"filter\\": []\\n}"',
},
},
_source: {},
};

try {
Expand Down Expand Up @@ -586,23 +587,24 @@ describe('Saved Object', () => {
});
});

it('injects references from searchSourceJSON', async () => {
it('passes references to search source parsing function', async () => {
const savedObject = new SavedObjectClass({ type: 'dashboard', searchSource: true });
return savedObject.init!().then(() => {
const searchSourceJSON = JSON.stringify({
indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.index',
filter: [
{
meta: {
indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.filter[0].meta.index',
},
},
],
});
const response = {
found: true,
_source: {
kibanaSavedObjectMeta: {
searchSourceJSON: JSON.stringify({
indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.index',
filter: [
{
meta: {
indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.filter[0].meta.index',
},
},
],
}),
searchSourceJSON,
},
},
references: [
Expand All @@ -619,16 +621,10 @@ describe('Saved Object', () => {
],
};
savedObject.applyESResp(response);
expect(savedObject.searchSource!.getFields()).toEqual({
index: 'my-index-1',
filter: [
{
meta: {
index: 'my-index-2',
},
},
],
});
expect(dataStartMock.search.parseSearchSource).toBeCalledWith(
searchSourceJSON,
response.references
);
});
});
});
Expand Down

0 comments on commit 732e990

Please sign in to comment.