Skip to content

Commit

Permalink
[Lens] Show generic error for invalid time shift string (#120077)
Browse files Browse the repository at this point in the history
* 🐛 Show generic error for invalid string

* ✅ add unit test
  • Loading branch information
dej611 authored Dec 2, 2021
1 parent acbee9b commit 9814a81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,23 @@ describe('IndexPatternDimensionEditorPanel', () => {
},
});
});

it('should report a generic error for invalid shift string', () => {
const props = getProps({
timeShift: '5 months',
});
wrapper = mount(<IndexPatternDimensionEditorComponent {...props} />);

expect(wrapper.find(TimeShift).find(EuiComboBox).prop('isInvalid')).toBeTruthy();

expect(
wrapper
.find(TimeShift)
.find('[data-test-subj="indexPattern-dimension-time-shift-row"]')
.first()
.prop('error')
).toBe('Time shift value is not valid.');
});
});

describe('filtering', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export function TimeShift({
<EuiFormRow
display="columnCompressed"
fullWidth
data-test-subj="indexPattern-dimension-time-shift-row"
label={i18n.translate('xpack.lens.indexPattern.timeShift.label', {
defaultMessage: 'Time shift',
})}
Expand All @@ -145,6 +146,10 @@ export function TimeShift({
i18n.translate('xpack.lens.indexPattern.timeShift.noMultipleHelp', {
defaultMessage:
'Time shift should be a multiple of the date histogram interval. Either adjust time shift or date histogram interval',
})) ||
(isLocalValueInvalid &&
i18n.translate('xpack.lens.indexPattern.timeShift.genericInvalidHelp', {
defaultMessage: 'Time shift value is not valid.',
}))
}
isInvalid={Boolean(isLocalValueInvalid || localValueTooSmall || localValueNotMultiple)}
Expand Down

0 comments on commit 9814a81

Please sign in to comment.