Skip to content

Commit

Permalink
Merge remote-tracking branch 'dej611/lens/formula-field-message' into…
Browse files Browse the repository at this point in the history
… lens/formula-editor
  • Loading branch information
wylieconlon committed Jun 4, 2021
2 parents 1d16ef9 + 5cd99fe commit 5bf9c14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,19 @@ invalid: "
).toEqual(['Use only one of kql= or lucene=, not both']);
});

it("returns a clear error when there's a missing field for a function", () => {
for (const fn of ['average', 'terms', 'max', 'sum']) {
expect(
formulaOperation.getErrorMessage!(
getNewLayerWithFormula(`${fn}()`),
'col1',
indexPattern,
operationDefinitionMap
)
).toEqual([`The first argument for ${fn} should be a field name. Found no field`]);
}
});

it('returns no error if a math operation is passed to fullReference operations', () => {
const formulas = [
'derivative(7+1)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,11 @@ function runFullASTValidation(
values: {
operation: node.name,
type: 'field',
argument: getValueOrName(firstArg),
argument:
getValueOrName(firstArg) ||
i18n.translate('xpack.lens.indexPattern.formulaNoFieldForOperation', {
defaultMessage: 'no field',
}),
},
locations: node.location ? [node.location] : [],
})
Expand Down

0 comments on commit 5bf9c14

Please sign in to comment.