@ -71,6 +71,26 @@ const fakeEmptyTSDBStatusResponse: {
} ,
} ,
} ;
} ;
const fakeInvalidTimestampTSDBStatusResponse : {
status : string ;
data : TSDBMap ;
} = {
status : 'success' ,
data : {
headStats : {
numSeries : 1 ,
numLabelPairs : 0 ,
chunkCount : 0 ,
minTime : 9223372036854776000 ,
maxTime : - 9223372036854776000 ,
} ,
labelValueCountByLabelName : [ ] ,
seriesCountByMetricName : [ ] ,
memoryInBytesByLabelName : [ ] ,
seriesCountByLabelValuePair : [ ] ,
} ,
} ;
describe ( 'TSDB Stats' , ( ) = > {
describe ( 'TSDB Stats' , ( ) = > {
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
fetchMock . resetMocks ( ) ;
fetchMock . resetMocks ( ) ;
@ -130,36 +150,65 @@ describe('TSDB Stats', () => {
}
}
}
}
} ) ;
} ) ;
} ) ;
it ( 'No Data' , async ( ) = > {
it ( 'No Data' , async ( ) = > {
const mock = fetchMock . mockResponse ( JSON . stringify ( fakeEmptyTSDBStatusResponse ) ) ;
const mock = fetchMock . mockResponse ( JSON . stringify ( fakeEmptyTSDBStatusResponse ) ) ;
let page : any ;
let page : any ;
await act ( async ( ) = > {
await act ( async ( ) = > {
page = mount (
page = mount (
< PathPrefixContext.Provider value = "/path/prefix" >
< PathPrefixContext.Provider value = "/path/prefix" >
< TSDBStatus / >
< TSDBStatus / >
< / PathPrefixContext.Provider >
< / PathPrefixContext.Provider >
) ;
) ;
} ) ;
} ) ;
page . update ( ) ;
page . update ( ) ;
expect ( mock ) . toHaveBeenCalledWith ( '/path/prefix/api/v1/status/tsdb' , {
expect ( mock ) . toHaveBeenCalledWith ( '/path/prefix/api/v1/status/tsdb' , {
cache : 'no-store' ,
cache : 'no-store' ,
credentials : 'same-origin' ,
credentials : 'same-origin' ,
} ) ;
} ) ;
expect ( page . find ( 'h2' ) . text ( ) ) . toEqual ( 'TSDB Status' ) ;
expect ( page . find ( 'h2' ) . text ( ) ) . toEqual ( 'TSDB Status' ) ;
const headStats = page
const headStats = page
. find ( Table )
. find ( Table )
. at ( 0 )
. at ( 0 )
. find ( 'tbody' )
. find ( 'tbody' )
. find ( 'td' ) ;
. find ( 'td' ) ;
[ '0' , '0' , '0' , 'Error parsing time (9223372036854776000)' , 'Error parsing time (-9223372036854776000)' ] . forEach (
[ '0' , '0' , '0' , 'No datapoints yet' , 'No datapoints yet' ] . forEach ( ( value , i ) = > {
( value , i ) = > {
expect ( headStats . at ( i ) . text ( ) ) . toEqual ( value ) ;
expect ( headStats . at ( i ) . text ( ) ) . toEqual ( value ) ;
}
} ) ;
) ;
} ) ;
it ( 'Invalid min/max Timestamp' , async ( ) = > {
const mock = fetchMock . mockResponse ( JSON . stringify ( fakeInvalidTimestampTSDBStatusResponse ) ) ;
let page : any ;
await act ( async ( ) = > {
page = mount (
< PathPrefixContext.Provider value = "/path/prefix" >
< TSDBStatus / >
< / PathPrefixContext.Provider >
) ;
} ) ;
page . update ( ) ;
expect ( mock ) . toHaveBeenCalledWith ( '/path/prefix/api/v1/status/tsdb' , {
cache : 'no-store' ,
credentials : 'same-origin' ,
} ) ;
expect ( page . find ( 'h2' ) . text ( ) ) . toEqual ( 'TSDB Status' ) ;
const headStats = page
. find ( Table )
. at ( 0 )
. find ( 'tbody' )
. find ( 'td' ) ;
[ '1' , '0' , '0' , 'Error parsing time (9223372036854776000)' , 'Error parsing time (-9223372036854776000)' ] . forEach (
( value , i ) = > {
expect ( headStats . at ( i ) . text ( ) ) . toEqual ( value ) ;
}
) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;