grafana/public/app/core/specs/rangeutil.test.ts

108 lines
3.6 KiB
TypeScript
Raw Normal View History

import { rangeUtil, dateTime } from '@grafana/data';
2017-12-20 05:33:33 -06:00
describe('rangeUtil', () => {
describe('Can get range text described', () => {
it('should handle simple old expression with only amount and unit', () => {
const info = rangeUtil.describeTextRange('5m');
2017-12-20 05:33:33 -06:00
expect(info.display).toBe('Last 5 minutes');
});
2017-12-20 05:33:33 -06:00
it('should have singular when amount is 1', () => {
const info = rangeUtil.describeTextRange('1h');
2017-12-20 05:33:33 -06:00
expect(info.display).toBe('Last 1 hour');
});
2017-12-20 05:33:33 -06:00
it('should handle non default amount', () => {
const info = rangeUtil.describeTextRange('13h');
2017-12-20 05:33:33 -06:00
expect(info.display).toBe('Last 13 hours');
expect(info.from).toBe('now-13h');
});
2017-12-20 05:33:33 -06:00
it('should handle non default future amount', () => {
const info = rangeUtil.describeTextRange('+3h');
2017-12-20 05:33:33 -06:00
expect(info.display).toBe('Next 3 hours');
expect(info.from).toBe('now');
expect(info.to).toBe('now+3h');
2016-10-18 05:11:46 -05:00
});
2017-12-20 05:33:33 -06:00
it('should handle now/d', () => {
const info = rangeUtil.describeTextRange('now/d');
2017-12-20 05:33:33 -06:00
expect(info.display).toBe('Today so far');
});
2017-12-20 05:33:33 -06:00
it('should handle now/w', () => {
const info = rangeUtil.describeTextRange('now/w');
2017-12-20 05:33:33 -06:00
expect(info.display).toBe('This week so far');
});
2017-12-20 05:33:33 -06:00
it('should handle now/M', () => {
const info = rangeUtil.describeTextRange('now/M');
2017-12-20 05:33:33 -06:00
expect(info.display).toBe('This month so far');
});
2017-12-20 05:33:33 -06:00
it('should handle now/y', () => {
const info = rangeUtil.describeTextRange('now/y');
2017-12-20 05:33:33 -06:00
expect(info.display).toBe('This year so far');
});
});
2017-12-20 05:33:33 -06:00
describe('Can get date range described', () => {
it('Date range with simple ranges', () => {
const text = rangeUtil.describeTimeRange({ from: 'now-1h', to: 'now' });
2017-12-20 05:33:33 -06:00
expect(text).toBe('Last 1 hour');
});
2017-12-20 05:33:33 -06:00
it('Date range with rounding ranges', () => {
const text = rangeUtil.describeTimeRange({ from: 'now/d+6h', to: 'now' });
2017-12-20 05:33:33 -06:00
expect(text).toBe('now/d+6h to now');
});
2017-12-20 05:33:33 -06:00
it('Date range with absolute to now', () => {
const text = rangeUtil.describeTimeRange({
from: dateTime([2014, 10, 10, 2, 3, 4]),
2017-12-20 05:33:33 -06:00
to: 'now',
});
TimePicker: New time picker dropdown & custom range UI (#16811) * feat: Add new picker to DashNavTimeControls * chore: noImplicitAny limit reached * chore: noImplicityAny fix * chore: Add momentUtc helper to avoid the isUtc conditionals * chore: Move getRaw from Explore's time picker to grafana/ui utils and rename to getRawRange * feat: Use helper functions to convert utc to browser time * fix: Dont Select current value when pressing tab when using Time Picker * fix: Add tabIndex to time range inputs so tab works smoothly and prevent mouseDown event to propagate to react-select * fix: Add spacing to custom range labels * fix: Updated snapshot * fix: Re-adding getRaw() temporary to fix the build * fix: Disable scroll event in Popper when we're using the TimePicker so the popup wont "follow" the menu * fix: Move all "Last xxxx" quick ranges to the menu and show a "UTC" text when applicable * fix: Add zoom functionality * feat: Add logic to mark selected option as active * fix: Add tooltip to zoom button * fix: lint fix after rebase * chore: Remove old time picker from DashNav * TimePicker: minor design update * chore: Move all time picker quick ranges to the menu * fix: Remove the popover border-right, since the quick ranges are gone * chore: Remove function not in use * Fix: Close time picker on resize event * Fix: Remove border bottom * Fix: Use fa icons on prev/next arrows * Fix: Pass ref from TimePicker to TimePickerOptionGroup so the popover will align as it should * Fix: time picker ui adjustments to get better touch area on buttons * Fix: Dont increase line height on large screens * TimePicker: style updates * Fix: Add more prominent colors for selected dates and fade out dates in previous/next month * TimePicker: style updates2 * TimePicker: Big refactorings and style changes * Removed use of Popper not sure we need that here? * Made active selected item in the list have the "selected" checkmark * Changed design of popover * Changed design of and implementation of the Custom selection in the dropdown it did not feel like a item you could select like the rest now the list is just a normal list * TimePicker: Refactoring & style changes * TimePicker: use same date format everywhere * TimePicker: Calendar style updates * TimePicker: fixed unit test * fixed unit test * TimeZone: refactoring time zone type * TimePicker: refactoring * TimePicker: finally to UTC to work * TimePicker: better way to handle calendar utc dates * TimePicker: Fixed tooltip issues * Updated snapshot * TimePicker: moved tooltip from DashNavControls into TimePicker
2019-06-24 07:39:59 -05:00
expect(text).toBe('2014-11-10 02:03:04 to a few seconds ago');
});
2017-12-20 05:33:33 -06:00
it('Date range with absolute to relative', () => {
const text = rangeUtil.describeTimeRange({
from: dateTime([2014, 10, 10, 2, 3, 4]),
2017-12-20 05:33:33 -06:00
to: 'now-1d',
});
TimePicker: New time picker dropdown & custom range UI (#16811) * feat: Add new picker to DashNavTimeControls * chore: noImplicitAny limit reached * chore: noImplicityAny fix * chore: Add momentUtc helper to avoid the isUtc conditionals * chore: Move getRaw from Explore's time picker to grafana/ui utils and rename to getRawRange * feat: Use helper functions to convert utc to browser time * fix: Dont Select current value when pressing tab when using Time Picker * fix: Add tabIndex to time range inputs so tab works smoothly and prevent mouseDown event to propagate to react-select * fix: Add spacing to custom range labels * fix: Updated snapshot * fix: Re-adding getRaw() temporary to fix the build * fix: Disable scroll event in Popper when we're using the TimePicker so the popup wont "follow" the menu * fix: Move all "Last xxxx" quick ranges to the menu and show a "UTC" text when applicable * fix: Add zoom functionality * feat: Add logic to mark selected option as active * fix: Add tooltip to zoom button * fix: lint fix after rebase * chore: Remove old time picker from DashNav * TimePicker: minor design update * chore: Move all time picker quick ranges to the menu * fix: Remove the popover border-right, since the quick ranges are gone * chore: Remove function not in use * Fix: Close time picker on resize event * Fix: Remove border bottom * Fix: Use fa icons on prev/next arrows * Fix: Pass ref from TimePicker to TimePickerOptionGroup so the popover will align as it should * Fix: time picker ui adjustments to get better touch area on buttons * Fix: Dont increase line height on large screens * TimePicker: style updates * Fix: Add more prominent colors for selected dates and fade out dates in previous/next month * TimePicker: style updates2 * TimePicker: Big refactorings and style changes * Removed use of Popper not sure we need that here? * Made active selected item in the list have the "selected" checkmark * Changed design of popover * Changed design of and implementation of the Custom selection in the dropdown it did not feel like a item you could select like the rest now the list is just a normal list * TimePicker: Refactoring & style changes * TimePicker: use same date format everywhere * TimePicker: Calendar style updates * TimePicker: fixed unit test * fixed unit test * TimeZone: refactoring time zone type * TimePicker: refactoring * TimePicker: finally to UTC to work * TimePicker: better way to handle calendar utc dates * TimePicker: Fixed tooltip issues * Updated snapshot * TimePicker: moved tooltip from DashNavControls into TimePicker
2019-06-24 07:39:59 -05:00
expect(text).toBe('2014-11-10 02:03:04 to a day ago');
});
2017-12-20 05:33:33 -06:00
it('Date range with relative to absolute', () => {
const text = rangeUtil.describeTimeRange({
2017-12-20 05:33:33 -06:00
from: 'now-7d',
to: dateTime([2014, 10, 10, 2, 3, 4]),
});
TimePicker: New time picker dropdown & custom range UI (#16811) * feat: Add new picker to DashNavTimeControls * chore: noImplicitAny limit reached * chore: noImplicityAny fix * chore: Add momentUtc helper to avoid the isUtc conditionals * chore: Move getRaw from Explore's time picker to grafana/ui utils and rename to getRawRange * feat: Use helper functions to convert utc to browser time * fix: Dont Select current value when pressing tab when using Time Picker * fix: Add tabIndex to time range inputs so tab works smoothly and prevent mouseDown event to propagate to react-select * fix: Add spacing to custom range labels * fix: Updated snapshot * fix: Re-adding getRaw() temporary to fix the build * fix: Disable scroll event in Popper when we're using the TimePicker so the popup wont "follow" the menu * fix: Move all "Last xxxx" quick ranges to the menu and show a "UTC" text when applicable * fix: Add zoom functionality * feat: Add logic to mark selected option as active * fix: Add tooltip to zoom button * fix: lint fix after rebase * chore: Remove old time picker from DashNav * TimePicker: minor design update * chore: Move all time picker quick ranges to the menu * fix: Remove the popover border-right, since the quick ranges are gone * chore: Remove function not in use * Fix: Close time picker on resize event * Fix: Remove border bottom * Fix: Use fa icons on prev/next arrows * Fix: Pass ref from TimePicker to TimePickerOptionGroup so the popover will align as it should * Fix: time picker ui adjustments to get better touch area on buttons * Fix: Dont increase line height on large screens * TimePicker: style updates * Fix: Add more prominent colors for selected dates and fade out dates in previous/next month * TimePicker: style updates2 * TimePicker: Big refactorings and style changes * Removed use of Popper not sure we need that here? * Made active selected item in the list have the "selected" checkmark * Changed design of popover * Changed design of and implementation of the Custom selection in the dropdown it did not feel like a item you could select like the rest now the list is just a normal list * TimePicker: Refactoring & style changes * TimePicker: use same date format everywhere * TimePicker: Calendar style updates * TimePicker: fixed unit test * fixed unit test * TimeZone: refactoring time zone type * TimePicker: refactoring * TimePicker: finally to UTC to work * TimePicker: better way to handle calendar utc dates * TimePicker: Fixed tooltip issues * Updated snapshot * TimePicker: moved tooltip from DashNavControls into TimePicker
2019-06-24 07:39:59 -05:00
expect(text).toBe('7 days ago to 2014-11-10 02:03:04');
});
2017-12-20 05:33:33 -06:00
it('Date range with non matching default ranges', () => {
const text = rangeUtil.describeTimeRange({ from: 'now-13h', to: 'now' });
2017-12-20 05:33:33 -06:00
expect(text).toBe('Last 13 hours');
});
2017-12-20 05:33:33 -06:00
it('Date range with from and to both are in now-* format', () => {
const text = rangeUtil.describeTimeRange({ from: 'now-6h', to: 'now-3h' });
2017-12-20 05:33:33 -06:00
expect(text).toBe('now-6h to now-3h');
});
2017-12-20 05:33:33 -06:00
it('Date range with from and to both are either in now-* or now/* format', () => {
const text = rangeUtil.describeTimeRange({
2017-12-20 05:33:33 -06:00
from: 'now/d+6h',
to: 'now-3h',
});
2017-12-20 05:33:33 -06:00
expect(text).toBe('now/d+6h to now-3h');
});
2017-12-20 05:33:33 -06:00
it('Date range with from and to both are either in now-* or now+* format', () => {
const text = rangeUtil.describeTimeRange({ from: 'now-6h', to: 'now+1h' });
2017-12-20 05:33:33 -06:00
expect(text).toBe('now-6h to now+1h');
});
});
});