TimePicker: Fixes issues with "Recently used absolute ranges" section (#66281)
* TimePicker: Fixes issues with "Recently used absolute ranges" section Squashed commit of the following: commit 99d5076ce1fadde1f22ed372f372656b58efa1c4 Author: Joao Silva <joao.silva@grafana.com> Date: Tue Apr 11 14:06:27 2023 +0100 user essentials mob! 🔱 lastFile:public/app/core/components/TimePicker/TimePickerWithHistory.tsx commit cad0201df452f956a422b030d5b15e8ba4aed9a9 Author: eledobleefe <laura.fernandez@grafana.com> Date: Tue Apr 11 11:44:34 2023 +0200 user essentials mob! 🔱 lastFile:public/app/core/components/TimePicker/TimePickerWithHistory.tsx Co-authored-by: eledobleefe <laura.fernandez@grafana.com> * TimePicker: Add correct date format * Add convertRawToRange tests * Rename test variables * RTL tests * Proper RTL tests * Apply suggestions from code review Co-authored-by: Joao Silva <100691367+JoaoSilvaGrafana@users.noreply.github.com> * Remove commented line * Fix linting --------- Co-authored-by: eledobleefe <laura.fernandez@grafana.com> Co-authored-by: Tobias Skarhed <tobias.skarhed@gmail.com> Co-authored-by: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com>
This commit is contained in:
co-authored by
eledobleefe
Tobias Skarhed
Tobias Skarhed
parent
ab08b4f7f2
commit
73f1cd7bad
@@ -1,10 +1,57 @@
|
||||
import { TimeRange } from '../types/time';
|
||||
import { RawTimeRange, TimeRange } from '../types/time';
|
||||
|
||||
import { timeRangeToRelative } from './rangeutil';
|
||||
|
||||
import { dateTime, rangeUtil } from './index';
|
||||
|
||||
describe('Range Utils', () => {
|
||||
// These tests probably wrap the dateTimeParser tests to some extent
|
||||
describe('convertRawToRange', () => {
|
||||
const DEFAULT_DATE_VALUE = '1996-07-30 16:00:00'; // Default format YYYY-MM-DD HH:mm:ss
|
||||
const DEFAULT_DATE_VALUE_FORMATTED = '1996-07-30T16:00:00-06:00';
|
||||
const defaultRawTimeRange = {
|
||||
from: DEFAULT_DATE_VALUE,
|
||||
to: '1996-07-30 16:20:00',
|
||||
};
|
||||
|
||||
it('should serialize the default format by default', () => {
|
||||
const deserialized = rangeUtil.convertRawToRange(defaultRawTimeRange);
|
||||
expect(deserialized.from.format()).toBe(DEFAULT_DATE_VALUE_FORMATTED);
|
||||
});
|
||||
|
||||
it('should serialize using custom formats', () => {
|
||||
const NON_DEFAULT_FORMAT = 'DD-MM-YYYY HH:mm:ss';
|
||||
const nonDefaultRawTimeRange: RawTimeRange = {
|
||||
from: '30-07-1996 16:00:00',
|
||||
to: '30-07-1996 16:20:00',
|
||||
};
|
||||
|
||||
const deserializedTimeRange = rangeUtil.convertRawToRange(
|
||||
nonDefaultRawTimeRange,
|
||||
undefined,
|
||||
undefined,
|
||||
NON_DEFAULT_FORMAT
|
||||
);
|
||||
expect(deserializedTimeRange.from.format()).toBe(DEFAULT_DATE_VALUE_FORMATTED);
|
||||
});
|
||||
|
||||
it('should take timezone into account', () => {
|
||||
const deserializedTimeRange = rangeUtil.convertRawToRange(defaultRawTimeRange, 'UTC');
|
||||
expect(deserializedTimeRange.from.format()).toBe('1996-07-30T16:00:00Z');
|
||||
});
|
||||
|
||||
it('should leave the raw part intact if it has calulactions', () => {
|
||||
const timeRange = {
|
||||
from: DEFAULT_DATE_VALUE,
|
||||
to: 'now',
|
||||
};
|
||||
|
||||
const deserialized = rangeUtil.convertRawToRange(timeRange);
|
||||
expect(deserialized.raw).toStrictEqual(timeRange);
|
||||
expect(deserialized.to.toString()).not.toBe(deserialized.raw.to);
|
||||
});
|
||||
});
|
||||
|
||||
describe('relative time', () => {
|
||||
it('should identify absolute vs relative', () => {
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user