chore(ui): refactor fluxPeriodFromRangeSeconds

pull/5852/head
Pavel Zavora 2022-02-08 10:03:56 +01:00
parent 1fd18b582c
commit 2beec584b2
2 changed files with 6 additions and 48 deletions

View File

@ -15,6 +15,11 @@ describe('fluxQueryBuilder/util/timeRangeWindowPeriod', () => {
seconds: undefined,
expect: '1s',
},
{
name: 'NaN',
seconds: Number.NaN,
expect: '1s',
},
{
name: '1 hour',
seconds: 3600,

View File

@ -1,7 +1,4 @@
import templateReplace, {
fluxPeriodFromRangeSeconds,
replaceInterval,
} from 'src/tempVars/utils/replace'
import templateReplace, {replaceInterval} from 'src/tempVars/utils/replace'
import {TemplateType, TemplateValueType} from 'src/types/tempVars'
describe('templates.utils.replace', () => {
@ -492,48 +489,4 @@ describe('templates.utils.replace', () => {
expect(templateReplace(query, templates.reverse())).toEqual(expected)
})
})
describe('fluxPeriodFromRangeSeconds', () => {
;[
{
seconds: 0,
expected: '1s',
},
{
seconds: Number.NaN,
expected: '1s',
},
{
seconds: 359,
expected: '1s',
},
{
seconds: 900,
expected: '3s',
},
{
seconds: 6 * 3600,
expected: '1m',
},
{
seconds: 24 * 3600,
expected: '4m',
},
{
seconds: 7 * 24 * 3600,
expected: '28m',
},
{
seconds: 30 * 24 * 3600,
expected: '2h',
},
{
seconds: 37 * 24 * 3600 + 900,
expected: '2h28m3s',
},
].forEach(test => {
it(`returns ${test.expected} having ${test.seconds} on input`, () => {
expect(fluxPeriodFromRangeSeconds(test.seconds)).toEqual(test.expected)
})
})
})
})