-
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.
[FEATURE] Charts | Change charts time-unit to bigger timespan opensea…
…rch-project#164 (opensearch-project#204) (opensearch-project#205) * [FEATURE] Charts | Change charts time-unit to bigger timespan opensearch-project#164 Signed-off-by: Jovan Cvetkovic <[email protected]> * [FEATURE] Charts | Change charts time-unit to bigger timespan opensearch-project#164 Signed-off-by: Jovan Cvetkovic <[email protected]> Signed-off-by: Jovan Cvetkovic <[email protected]> (cherry picked from commit a915f85) Co-authored-by: Jovan Cvetkovic <[email protected]> Signed-off-by: AWSHurneyt <[email protected]>
- Loading branch information
1 parent
e815f34
commit dc87ec7
Showing
5 changed files
with
231 additions
and
32 deletions.
There are no files selected for viewing
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 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 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 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,59 @@ | ||
import { getChartTimeUnit, getDateFormatByTimeUnit } from './helpers'; | ||
import { TimeUnitsMap } from './constants'; | ||
|
||
describe('helper utilities spec', () => { | ||
describe('tests getDateFormatByTimeUnit function', () => { | ||
const yearFormat = '%Y-%m-%d'; | ||
const dayFormat = '%H:%M:%S'; | ||
const fullFormat = '%Y-%m-%d %H:%M'; | ||
|
||
const timeFormats: { | ||
[key: string]: string; | ||
} = { | ||
'now-15m': dayFormat, | ||
'now-15h': fullFormat, | ||
'now-15d': fullFormat, | ||
'now-2M': yearFormat, | ||
'now-2y': fullFormat, | ||
}; | ||
|
||
it(` - function should return default format ${fullFormat} if dates are not valid`, () => { | ||
expect(getDateFormatByTimeUnit('', '')).toBe(fullFormat); | ||
}); | ||
|
||
for (const [start, format] of Object.entries(timeFormats)) { | ||
it(` - function should return ${format} if start date is ${start}`, () => { | ||
expect(getDateFormatByTimeUnit(start, 'now')).toBe(format); | ||
}); | ||
} | ||
}); | ||
|
||
describe('tests getChartTimeUnit function', () => { | ||
const defaultTimeUnit = 'yearmonthdatehoursminutes'; | ||
it(' - function should return default timeUnit if fn params are invalid', () => { | ||
expect(getChartTimeUnit('', '')).toBe(defaultTimeUnit); | ||
}); | ||
|
||
it(' - function should return default timeUnit if one is passed as param', () => { | ||
const defaultFormat = 'yearmonthdate'; | ||
expect(getChartTimeUnit('', '', defaultFormat)).toBe(defaultFormat); | ||
}); | ||
|
||
const timeUnits: { | ||
[key: string]: string; | ||
} = { | ||
minutes: 'now-15m', | ||
hours: 'now-15h', | ||
days: 'now-15d', | ||
weeks: 'now-15w', | ||
months: 'now-5M', | ||
years: 'now-15y', | ||
}; | ||
|
||
for (const [unit, start] of Object.entries(timeUnits)) { | ||
it(` - function should return ${TimeUnitsMap[unit]} if unit is ${unit}`, () => { | ||
expect(getChartTimeUnit(start, 'now')).toBe(TimeUnitsMap[unit]); | ||
}); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.