-
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.
Browse files
Browse the repository at this point in the history
* [Canvas] Expression progress (#104457) * Added `expression_progress` plugin. Co-authored-by: Kibana Machine <[email protected]> # Conflicts: # packages/kbn-optimizer/limits.yml * Update limits.yml
- Loading branch information
1 parent
4e42e5d
commit 13ec91a
Showing
65 changed files
with
1,199 additions
and
696 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
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
*/ | ||
|
||
export { shapeFunction } from './shape_function'; | ||
export { progressFunction } from './progress_function'; |
213 changes: 213 additions & 0 deletions
213
src/plugins/expression_shape/common/expression_functions/progress_function.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,213 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ExecutionContext } from '../../../expressions'; | ||
import { functionWrapper, fontStyle } from '../../../presentation_util/common/lib'; | ||
import { progressFunction, errors } from './progress_function'; | ||
|
||
describe('progress', () => { | ||
const fn = functionWrapper(progressFunction); | ||
const value = 0.33; | ||
|
||
it('returns a render as progress', () => { | ||
const result = fn(0.2, {}, {} as ExecutionContext); | ||
expect(result).toHaveProperty('type', 'render'); | ||
expect(result).toHaveProperty('as', 'progress'); | ||
}); | ||
|
||
it('sets the progress to context', () => { | ||
const result = fn(0.58, {}, {} as ExecutionContext); | ||
expect(result.value).toHaveProperty('value', 0.58); | ||
}); | ||
|
||
it(`throws when context is outside of the valid range`, async () => { | ||
expect.assertions(1); | ||
try { | ||
await fn(3, {}, {} as ExecutionContext); | ||
} catch (e: any) { | ||
expect(e.message).toEqual(errors.invalidValue(3).message); | ||
} | ||
}); | ||
|
||
describe('args', () => { | ||
describe('shape', () => { | ||
it('sets the progress element shape', () => { | ||
const result = fn( | ||
value, | ||
{ | ||
shape: 'wheel', | ||
}, | ||
{} as ExecutionContext | ||
); | ||
expect(result.value).toHaveProperty('shape', 'wheel'); | ||
}); | ||
|
||
it(`defaults to 'gauge'`, () => { | ||
const result = fn(value, {}, {} as ExecutionContext); | ||
expect(result.value).toHaveProperty('shape', 'gauge'); | ||
}); | ||
}); | ||
|
||
describe('max', () => { | ||
it('sets the maximum value', () => { | ||
const result = fn( | ||
value, | ||
{ | ||
max: 2, | ||
}, | ||
{} as ExecutionContext | ||
); | ||
expect(result.value).toHaveProperty('max', 2); | ||
}); | ||
|
||
it('defaults to 1', () => { | ||
const result = fn(value, {}, {} as ExecutionContext); | ||
expect(result.value).toHaveProperty('max', 1); | ||
}); | ||
|
||
it('throws if max <= 0', async () => { | ||
expect.assertions(1); | ||
try { | ||
await fn(value, { max: -0.5 }, {} as ExecutionContext); | ||
} catch (e: any) { | ||
expect(e.message).toEqual(errors.invalidMaxValue(-0.5).message); | ||
} | ||
}); | ||
}); | ||
|
||
describe('valueColor', () => { | ||
it('sets the color of the progress bar', () => { | ||
const result = fn( | ||
value, | ||
{ | ||
valueColor: '#000000', | ||
}, | ||
{} as ExecutionContext | ||
); | ||
expect(result.value).toHaveProperty('valueColor', '#000000'); | ||
}); | ||
|
||
it(`defaults to '#1785b0'`, () => { | ||
const result = fn(value, {}, {} as ExecutionContext); | ||
expect(result.value).toHaveProperty('valueColor', '#1785b0'); | ||
}); | ||
}); | ||
|
||
describe('barColor', () => { | ||
it('sets the color of the background bar', () => { | ||
const result = fn( | ||
value, | ||
{ | ||
barColor: '#FFFFFF', | ||
}, | ||
{} as ExecutionContext | ||
); | ||
expect(result.value).toHaveProperty('barColor', '#FFFFFF'); | ||
}); | ||
|
||
it(`defaults to '#f0f0f0'`, () => { | ||
const result = fn(value, {}, {} as ExecutionContext); | ||
expect(result.value).toHaveProperty('barColor', '#f0f0f0'); | ||
}); | ||
}); | ||
|
||
describe('valueWeight', () => { | ||
it('sets the thickness of the bars', () => { | ||
const result = fn( | ||
value, | ||
{ | ||
valuWeight: 100, | ||
}, | ||
{} as ExecutionContext | ||
); | ||
|
||
expect(result.value).toHaveProperty('valuWeight', 100); | ||
}); | ||
|
||
it(`defaults to 20`, () => { | ||
const result = fn(value, {}, {} as ExecutionContext); | ||
expect(result.value).toHaveProperty('barWeight', 20); | ||
}); | ||
}); | ||
|
||
describe('barWeight', () => { | ||
it('sets the thickness of the bars', () => { | ||
const result = fn( | ||
value, | ||
{ | ||
barWeight: 50, | ||
}, | ||
{} as ExecutionContext | ||
); | ||
|
||
expect(result.value).toHaveProperty('barWeight', 50); | ||
}); | ||
|
||
it(`defaults to 20`, () => { | ||
const result = fn(value, {}, {} as ExecutionContext); | ||
expect(result.value).toHaveProperty('barWeight', 20); | ||
}); | ||
}); | ||
|
||
describe('label', () => { | ||
it('sets the label of the progress', () => { | ||
const result = fn(value, { label: 'foo' }, {} as ExecutionContext); | ||
|
||
expect(result.value).toHaveProperty('label', 'foo'); | ||
}); | ||
|
||
it('hides the label if false', () => { | ||
const result = fn( | ||
value, | ||
{ | ||
label: false, | ||
}, | ||
{} as ExecutionContext | ||
); | ||
expect(result.value).toHaveProperty('label', ''); | ||
}); | ||
|
||
it('defaults to true which sets the context as the label', () => { | ||
const result = fn(value, {}, {} as ExecutionContext); | ||
expect(result.value).toHaveProperty('label', '0.33'); | ||
}); | ||
}); | ||
|
||
describe('font', () => { | ||
it('sets the font style for the label', () => { | ||
const result = fn( | ||
value, | ||
{ | ||
font: fontStyle, | ||
}, | ||
{} as ExecutionContext | ||
); | ||
|
||
expect(result.value).toHaveProperty('font'); | ||
expect(Object.keys(result.value.font).sort()).toEqual(Object.keys(fontStyle).sort()); | ||
expect(Object.keys(result.value.font.spec).sort()).toEqual( | ||
Object.keys(fontStyle.spec).sort() | ||
); | ||
}); | ||
|
||
it('sets fill to color', () => { | ||
const result = fn( | ||
value, | ||
{ | ||
font: fontStyle, | ||
}, | ||
{} as ExecutionContext | ||
); | ||
expect(result.value.font.spec).toHaveProperty('fill', fontStyle.spec.color); | ||
}); | ||
|
||
// TODO: write test when using an instance of the interpreter | ||
// it("sets a default style for the label when not provided", () => {}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.