2019-11-12 02:15:20 -08:00
|
|
|
import * as React from 'react';
|
|
|
|
import { mount, shallow, ReactWrapper } from 'enzyme';
|
|
|
|
import { act } from 'react-dom/test-utils';
|
2019-11-13 05:58:45 -08:00
|
|
|
import { Alert, Table } from 'reactstrap';
|
2019-11-12 02:15:20 -08:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import { faSpinner } from '@fortawesome/free-solid-svg-icons';
|
2020-01-14 10:34:48 -08:00
|
|
|
import { TSDBStatus } from '..';
|
2019-11-13 05:58:45 -08:00
|
|
|
import { TSDBMap } from './TSDBStatus';
|
2019-11-12 02:15:20 -08:00
|
|
|
|
|
|
|
const fakeTSDBStatusResponse: {
|
|
|
|
status: string;
|
|
|
|
data: TSDBMap;
|
|
|
|
} = {
|
|
|
|
status: 'success',
|
|
|
|
data: {
|
|
|
|
labelValueCountByLabelName: [
|
|
|
|
{
|
|
|
|
name: '__name__',
|
|
|
|
value: 5,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
seriesCountByMetricName: [
|
|
|
|
{
|
|
|
|
name: 'scrape_duration_seconds',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'scrape_samples_scraped',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
memoryInBytesByLabelName: [
|
|
|
|
{
|
|
|
|
name: '__name__',
|
|
|
|
value: 103,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
seriesCountByLabelValuePair: [
|
|
|
|
{
|
|
|
|
name: 'instance=localhost:9100',
|
|
|
|
value: 5,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('TSDB Stats', () => {
|
|
|
|
beforeEach(() => {
|
2019-11-13 05:58:45 -08:00
|
|
|
fetchMock.resetMocks();
|
2019-11-12 02:15:20 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('before data is returned', () => {
|
|
|
|
const tsdbStatus = shallow(<TSDBStatus />);
|
|
|
|
const icon = tsdbStatus.find(FontAwesomeIcon);
|
|
|
|
expect(icon.prop('icon')).toEqual(faSpinner);
|
|
|
|
expect(icon.prop('spin')).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when an error is returned', () => {
|
|
|
|
it('displays an alert', async () => {
|
2019-11-13 05:58:45 -08:00
|
|
|
const mock = fetchMock.mockReject(new Error('error loading tsdb status'));
|
2019-11-12 02:15:20 -08:00
|
|
|
|
2019-11-13 05:58:45 -08:00
|
|
|
let page: any;
|
2019-11-12 02:15:20 -08:00
|
|
|
await act(async () => {
|
|
|
|
page = mount(<TSDBStatus pathPrefix="/path/prefix" />);
|
|
|
|
});
|
|
|
|
page.update();
|
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', undefined);
|
|
|
|
const alert = page.find(Alert);
|
|
|
|
expect(alert.prop('color')).toBe('danger');
|
|
|
|
expect(alert.text()).toContain('error loading tsdb status');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Table Data Validation', () => {
|
|
|
|
it('Table Test', async () => {
|
|
|
|
const tables = [
|
|
|
|
{
|
|
|
|
data: fakeTSDBStatusResponse.data.labelValueCountByLabelName,
|
|
|
|
table_index: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: fakeTSDBStatusResponse.data.seriesCountByMetricName,
|
|
|
|
table_index: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: fakeTSDBStatusResponse.data.memoryInBytesByLabelName,
|
|
|
|
table_index: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: fakeTSDBStatusResponse.data.seriesCountByLabelValuePair,
|
|
|
|
table_index: 3,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-11-13 05:58:45 -08:00
|
|
|
const mock = fetchMock.mockResponse(JSON.stringify(fakeTSDBStatusResponse));
|
|
|
|
let page: any;
|
2019-11-12 02:15:20 -08:00
|
|
|
await act(async () => {
|
|
|
|
page = mount(<TSDBStatus pathPrefix="/path/prefix" />);
|
|
|
|
});
|
|
|
|
page.update();
|
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', undefined);
|
|
|
|
|
|
|
|
for (let i = 0; i < tables.length; i++) {
|
2019-11-13 05:58:45 -08:00
|
|
|
const data = tables[i].data;
|
|
|
|
const table = page
|
2019-11-12 02:15:20 -08:00
|
|
|
.find(Table)
|
|
|
|
.at(tables[i].table_index)
|
|
|
|
.find('tbody');
|
2019-11-13 05:58:45 -08:00
|
|
|
const rows = table.find('tr');
|
2019-11-12 02:15:20 -08:00
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
const firstRowColumns = rows
|
|
|
|
.at(i)
|
|
|
|
.find('td')
|
2019-11-13 05:58:45 -08:00
|
|
|
.map((column: ReactWrapper) => column.text());
|
2019-11-12 02:15:20 -08:00
|
|
|
expect(rows.length).toBe(data.length);
|
|
|
|
expect(firstRowColumns[0]).toBe(data[i].name);
|
|
|
|
expect(firstRowColumns[1]).toBe(data[i].value.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|