forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vis: Default editor] EUIficate date_ranges param editor (elastic#38647)
* EUIficate date_ranges param editor * Add unit tests * Move link before the list * Add validation * Fix comments # Conflicts: # src/legacy/ui/public/agg_types/controls/date_ranges.html
- Loading branch information
Showing
10 changed files
with
307 additions
and
270 deletions.
There are no files selected for viewing
88 changes: 0 additions & 88 deletions
88
src/legacy/ui/public/agg_types/__tests__/directives/validate_date_math.js
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
src/legacy/ui/public/agg_types/controls/date_ranges.test.tsx
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,92 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mountWithIntl } from 'test_utils/enzyme_helpers'; | ||
import { DateRangesParamEditor } from './date_ranges'; | ||
|
||
jest.mock('../../documentation_links', () => ({ | ||
getDocLink: jest.fn(), | ||
})); | ||
|
||
describe('DateRangesParamEditor component', () => { | ||
let setValue: jest.Mock; | ||
let setValidity: jest.Mock; | ||
let setTouched: jest.Mock; | ||
let defaultProps: any; | ||
|
||
beforeEach(() => { | ||
setValue = jest.fn(); | ||
setValidity = jest.fn(); | ||
setTouched = jest.fn(); | ||
|
||
defaultProps = { | ||
agg: {}, | ||
aggParam: { | ||
name: 'ranges', | ||
}, | ||
value: [], | ||
editorConfig: {}, | ||
showValidation: false, | ||
setValue, | ||
setValidity, | ||
setTouched, | ||
}; | ||
}); | ||
|
||
it('should add default range if there is an empty ininitial value', () => { | ||
mountWithIntl(<DateRangesParamEditor {...defaultProps} />); | ||
|
||
expect(setValue).toHaveBeenCalledWith([{}]); | ||
}); | ||
|
||
it('should validate range values with date math', function() { | ||
const component = mountWithIntl(<DateRangesParamEditor {...defaultProps} />); | ||
|
||
// should allow empty values | ||
expect(setValidity).toHaveBeenNthCalledWith(1, true); | ||
|
||
component.setProps({ value: [{ from: 'hello, world' }] }); | ||
expect(setValidity).toHaveBeenNthCalledWith(2, false); | ||
|
||
component.setProps({ value: [{ from: 'now' }] }); | ||
expect(setValidity).toHaveBeenNthCalledWith(3, true); | ||
|
||
component.setProps({ value: [{ from: 'now', to: 'Hello, Dan! =)' }] }); | ||
expect(setValidity).toHaveBeenNthCalledWith(4, false); | ||
|
||
component.setProps({ value: [{ from: '2012-02-28' }] }); | ||
expect(setValidity).toHaveBeenNthCalledWith(5, true); | ||
|
||
component.setProps({ value: [{ from: 'now+-5w', to: 'now-3d' }] }); | ||
expect(setValidity).toHaveBeenNthCalledWith(6, false); | ||
|
||
component.setProps({ value: [{ from: 'now-3M/M' }] }); | ||
expect(setValidity).toHaveBeenNthCalledWith(7, true); | ||
|
||
component.setProps({ value: [{ from: '2012-02-31', to: 'now-3d' }] }); | ||
expect(setValidity).toHaveBeenNthCalledWith(8, false); | ||
|
||
component.setProps({ value: [{ to: '2012-05-31||-3M/M' }] }); | ||
expect(setValidity).toHaveBeenNthCalledWith(9, true); | ||
|
||
component.setProps({ value: [{ from: '5/5/2005+3d' }] }); | ||
expect(setValidity).toHaveBeenNthCalledWith(10, false); | ||
}); | ||
}); |
Oops, something went wrong.