-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Collect VisLayers in VisualizeEmbeddable render flow
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
- Loading branch information
Showing
17 changed files
with
356 additions
and
84 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './types'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Vis } from '../../../visualizations/public'; | ||
import { | ||
buildPipelineFromAugmentVisSavedObjs, | ||
getAugmentVisSavedObjs, | ||
isEligibleForVisLayers, | ||
} from './utils'; | ||
import { VisLayerTypes, ISavedAugmentVis, VisLayerExpressionFn } from '../types'; | ||
import { | ||
createSavedAugmentVisLoader, | ||
SavedObjectOpenSearchDashboardsServicesWithAugmentVis, | ||
getMockAugmentVisSavedObjectClient, | ||
generateAugmentVisSavedObject, | ||
} from '../saved_augment_vis'; | ||
|
||
describe('utils', () => { | ||
// TODO: redo / update this test suite when eligibility is finalized. | ||
// Tracked in https://github.com/opensearch-project/OpenSearch-Dashboards/issues/3268 | ||
describe('isEligibleForVisLayers', () => { | ||
it('vis is ineligible with invalid type', async () => { | ||
const vis = ({ | ||
params: { | ||
type: 'not-line', | ||
}, | ||
} as unknown) as Vis; | ||
expect(isEligibleForVisLayers(vis)).toEqual(false); | ||
}); | ||
it('vis is eligible with valid type', async () => { | ||
const vis = ({ | ||
params: { | ||
type: 'line', | ||
}, | ||
} as unknown) as Vis; | ||
expect(isEligibleForVisLayers(vis)).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('getAugmentVisSavedObjs', () => { | ||
const fn = { | ||
type: VisLayerTypes.PointInTimeEvents, | ||
name: 'test-fn', | ||
args: { | ||
testArg: 'test-value', | ||
}, | ||
} as VisLayerExpressionFn; | ||
const visId1 = 'test-vis-id-1'; | ||
const visId2 = 'test-vis-id-2'; | ||
const visId3 = 'test-vis-id-3'; | ||
const obj1 = generateAugmentVisSavedObject('valid-obj-id-1', fn, visId1); | ||
const obj2 = generateAugmentVisSavedObject('valid-obj-id-2', fn, visId1); | ||
const obj3 = generateAugmentVisSavedObject('valid-obj-id-3', fn, visId2); | ||
|
||
it('returns no matching saved objs with filtering', async () => { | ||
const loader = createSavedAugmentVisLoader({ | ||
savedObjectsClient: getMockAugmentVisSavedObjectClient([obj1, obj2, obj3]), | ||
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); | ||
expect((await getAugmentVisSavedObjs(visId3, loader)).length).toEqual(0); | ||
}); | ||
it('returns no matching saved objs when client returns empty list', async () => { | ||
const loader = createSavedAugmentVisLoader({ | ||
savedObjectsClient: getMockAugmentVisSavedObjectClient([]), | ||
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); | ||
expect((await getAugmentVisSavedObjs(visId1, loader)).length).toEqual(0); | ||
}); | ||
it('returns one matching saved obj', async () => { | ||
const loader = createSavedAugmentVisLoader({ | ||
savedObjectsClient: getMockAugmentVisSavedObjectClient([obj1]), | ||
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); | ||
expect((await getAugmentVisSavedObjs(visId1, loader)).length).toEqual(1); | ||
}); | ||
it('returns multiple matching saved objs without filtering', async () => { | ||
const loader = createSavedAugmentVisLoader({ | ||
savedObjectsClient: getMockAugmentVisSavedObjectClient([obj1, obj2]), | ||
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); | ||
expect((await getAugmentVisSavedObjs(visId1, loader)).length).toEqual(2); | ||
}); | ||
it('returns multiple matching saved objs with filtering', async () => { | ||
const loader = createSavedAugmentVisLoader({ | ||
savedObjectsClient: getMockAugmentVisSavedObjectClient([obj1, obj2, obj3]), | ||
} as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); | ||
expect((await getAugmentVisSavedObjs(visId1, loader)).length).toEqual(2); | ||
}); | ||
}); | ||
|
||
describe('buildPipelineFromAugmentVisSavedObjs', () => { | ||
const obj1 = { | ||
title: 'obj1', | ||
pluginResourceId: 'obj-1-resource-id', | ||
visLayerExpressionFn: { | ||
type: VisLayerTypes.PointInTimeEvents, | ||
name: 'fn-1', | ||
args: { | ||
arg1: 'value-1', | ||
}, | ||
}, | ||
} as ISavedAugmentVis; | ||
const obj2 = { | ||
title: 'obj2', | ||
pluginResourceId: 'obj-2-resource-id', | ||
visLayerExpressionFn: { | ||
type: VisLayerTypes.PointInTimeEvents, | ||
name: 'fn-2', | ||
args: { | ||
arg2: 'value-2', | ||
}, | ||
}, | ||
} as ISavedAugmentVis; | ||
it('catches error with empty array', async () => { | ||
try { | ||
buildPipelineFromAugmentVisSavedObjs([]); | ||
} catch (e: any) { | ||
expect( | ||
e.message.includes( | ||
'Expression function from augment-vis saved objects could not be generated' | ||
) | ||
); | ||
} | ||
}); | ||
it('builds with one saved obj', async () => { | ||
const str = buildPipelineFromAugmentVisSavedObjs([obj1]); | ||
expect(str).toEqual('fn-1 arg1="value-1"'); | ||
}); | ||
it('builds with multiple saved objs', async () => { | ||
const str = buildPipelineFromAugmentVisSavedObjs([obj1, obj2]); | ||
expect(str).toEqual(`fn-1 arg1="value-1"\n| fn-2 arg2="value-2"`); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.