-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maps] fix data driven style properties not working when cloned layer…
… contains joins (#73124) * [maps] fix data driven style properties not working when cloned layer contains joins * tslint * handle case where metrics is not provided * tslint
- Loading branch information
Showing
3 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
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
128 changes: 128 additions & 0 deletions
128
x-pack/plugins/maps/public/classes/layers/layer.test.ts
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,128 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
/* eslint-disable max-classes-per-file */ | ||
|
||
import { AbstractLayer } from './layer'; | ||
import { ISource } from '../sources/source'; | ||
import { IStyle } from '../styles/style'; | ||
import { AGG_TYPE, FIELD_ORIGIN, LAYER_STYLE_TYPE, VECTOR_STYLES } from '../../../common/constants'; | ||
import { ESTermSourceDescriptor, VectorStyleDescriptor } from '../../../common/descriptor_types'; | ||
import { getDefaultDynamicProperties } from '../styles/vector/vector_style_defaults'; | ||
|
||
jest.mock('uuid/v4', () => { | ||
return function () { | ||
return '12345'; | ||
}; | ||
}); | ||
|
||
class MockLayer extends AbstractLayer {} | ||
|
||
class MockSource { | ||
cloneDescriptor() { | ||
return {}; | ||
} | ||
|
||
getDisplayName() { | ||
return 'mySource'; | ||
} | ||
} | ||
|
||
class MockStyle {} | ||
|
||
describe('cloneDescriptor', () => { | ||
describe('with joins', () => { | ||
const styleDescriptor = { | ||
type: LAYER_STYLE_TYPE.VECTOR, | ||
properties: { | ||
...getDefaultDynamicProperties(), | ||
}, | ||
} as VectorStyleDescriptor; | ||
// @ts-expect-error | ||
styleDescriptor.properties[VECTOR_STYLES.FILL_COLOR].options.field = { | ||
name: '__kbnjoin__count__557d0f15', | ||
origin: FIELD_ORIGIN.JOIN, | ||
}; | ||
// @ts-expect-error | ||
styleDescriptor.properties[VECTOR_STYLES.LINE_COLOR].options.field = { | ||
name: 'bytes', | ||
origin: FIELD_ORIGIN.SOURCE, | ||
}; | ||
// @ts-expect-error | ||
styleDescriptor.properties[VECTOR_STYLES.LABEL_BORDER_COLOR].options.field = { | ||
name: '__kbnjoin__count__6666666666', | ||
origin: FIELD_ORIGIN.JOIN, | ||
}; | ||
|
||
test('Should update data driven styling properties using join fields', async () => { | ||
const layerDescriptor = AbstractLayer.createDescriptor({ | ||
style: styleDescriptor, | ||
joins: [ | ||
{ | ||
leftField: 'iso2', | ||
right: { | ||
id: '557d0f15', | ||
indexPatternId: 'myIndexPattern', | ||
indexPatternTitle: 'logs-*', | ||
metrics: [{ type: AGG_TYPE.COUNT }], | ||
term: 'myTermField', | ||
type: 'joinSource', | ||
}, | ||
}, | ||
], | ||
}); | ||
const layer = new MockLayer({ | ||
layerDescriptor, | ||
source: (new MockSource() as unknown) as ISource, | ||
style: (new MockStyle() as unknown) as IStyle, | ||
}); | ||
const clonedDescriptor = await layer.cloneDescriptor(); | ||
const clonedStyleProps = (clonedDescriptor.style as VectorStyleDescriptor).properties; | ||
// Should update style field belonging to join | ||
// @ts-expect-error | ||
expect(clonedStyleProps[VECTOR_STYLES.FILL_COLOR].options.field.name).toEqual( | ||
'__kbnjoin__count__12345' | ||
); | ||
// Should not update style field belonging to source | ||
// @ts-expect-error | ||
expect(clonedStyleProps[VECTOR_STYLES.LINE_COLOR].options.field.name).toEqual('bytes'); | ||
// Should not update style feild belonging to different join | ||
// @ts-expect-error | ||
expect(clonedStyleProps[VECTOR_STYLES.LABEL_BORDER_COLOR].options.field.name).toEqual( | ||
'__kbnjoin__count__6666666666' | ||
); | ||
}); | ||
|
||
test('Should update data driven styling properties using join fields when metrics are not provided', async () => { | ||
const layerDescriptor = AbstractLayer.createDescriptor({ | ||
style: styleDescriptor, | ||
joins: [ | ||
{ | ||
leftField: 'iso2', | ||
right: ({ | ||
id: '557d0f15', | ||
indexPatternId: 'myIndexPattern', | ||
indexPatternTitle: 'logs-*', | ||
term: 'myTermField', | ||
type: 'joinSource', | ||
} as unknown) as ESTermSourceDescriptor, | ||
}, | ||
], | ||
}); | ||
const layer = new MockLayer({ | ||
layerDescriptor, | ||
source: (new MockSource() as unknown) as ISource, | ||
style: (new MockStyle() as unknown) as IStyle, | ||
}); | ||
const clonedDescriptor = await layer.cloneDescriptor(); | ||
const clonedStyleProps = (clonedDescriptor.style as VectorStyleDescriptor).properties; | ||
// Should update style field belonging to join | ||
// @ts-expect-error | ||
expect(clonedStyleProps[VECTOR_STYLES.FILL_COLOR].options.field.name).toEqual( | ||
'__kbnjoin__count__12345' | ||
); | ||
}); | ||
}); | ||
}); |
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