Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Oct 30, 2020
1 parent 382f71e commit c2de739
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
44 changes: 33 additions & 11 deletions src/plugins/charts/common/palette.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
* under the License.
*/

import { palette, defaultCustomColors } from './palette';
import { ExecutionContext } from '../../expressions/common';
import {
palette,
defaultCustomColors,
systemPalette,
PaletteOutput,
CustomPaletteState,
} from './palette';
import { functionWrapper } from 'src/plugins/expressions/common/expression_functions/specs/tests/utils';

describe('palette', () => {
const fn = (
const fn = functionWrapper(palette()) as (
context: null,
args: { color?: string[]; gradient?: boolean; reverse?: boolean } = {}
) => {
return palette().fn(
context,
{ gradient: false, reverse: false, ...args },
{} as ExecutionContext
);
};
args?: { color?: string[]; gradient?: boolean; reverse?: boolean }
) => PaletteOutput<CustomPaletteState>;

it('results a palette', () => {
const result = fn(null);
Expand Down Expand Up @@ -83,3 +83,25 @@ describe('palette', () => {
});
});
});

describe('system_palette', () => {
const fn = functionWrapper(systemPalette()) as (
context: null,
args: { name: string; params?: unknown }
) => PaletteOutput<unknown>;

it('results a palette', () => {
const result = fn(null, { name: 'test' });
expect(result).toHaveProperty('type', 'palette');
});

it('returns the name', () => {
const result = fn(null, { name: 'test' });
expect(result).toHaveProperty('name', 'test');
});

it('passes params through', () => {
const result = fn(null, { name: 'test', params: { customProp: 123 } });
expect(result).toHaveProperty('params', { customProp: 123 });
});
});
15 changes: 14 additions & 1 deletion src/plugins/charts/common/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface CustomPaletteState {

export interface SystemPaletteArguments {
name: string;
params: unknown;
params?: unknown;
}

export interface PaletteOutput<T = unknown> {
Expand Down Expand Up @@ -144,6 +144,19 @@ export function systemPalette(): ExpressionFunctionDefinition<
help: i18n.translate('charts.functions.systemPalette.args.nameHelpText', {
defaultMessage: 'Name of the palette in the palette list',
}),
options: [
'default',
'kibana_palette',
'custom',
'status',
'temperature',
'complimentary',
'negative',
'positive',
'cool',
'warm',
'gray',
],
},
params: {
help: i18n.translate('charts.functions.systemPalette.args.paramsHelpText', {
Expand Down

0 comments on commit c2de739

Please sign in to comment.