mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
* Add MetricFormat unit tests Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add App unit tests; Add debug script Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add Checkbox unit tests Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add SeriesName unit tests Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add QueryStatsView unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add Legend unit tests Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Remove unused utils/func Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add utils/urlParams unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add utils/timeFormat unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add ExpressionInput unit tests Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add GraphControls unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add TimeInput unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add DataTable unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add SanitizeHTML unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add Graph unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Extract utils/html Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add PanelList unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add Panel unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add react-ui test coverage report to CI Signed-off-by: Dustin Hooten <dhooten@splunk.com>
268 lines
7.9 KiB
TypeScript
Executable file
268 lines
7.9 KiB
TypeScript
Executable file
import * as React from 'react';
|
|
import { shallow } from 'enzyme';
|
|
import DataTable, { QueryResult } from './DataTable';
|
|
import { Alert, Table } from 'reactstrap';
|
|
import SeriesName from './SeriesName';
|
|
|
|
describe('DataTable', () => {
|
|
describe('when data is null', () => {
|
|
it('renders an alert', () => {
|
|
const table = shallow(<DataTable data={null} />);
|
|
const alert = table.find(Alert);
|
|
expect(Object.keys(alert.props())).toHaveLength(7);
|
|
expect(alert.prop('color')).toEqual('light');
|
|
expect(alert.prop('children')).toEqual('No data queried yet');
|
|
});
|
|
});
|
|
|
|
describe('when data.result is empty', () => {
|
|
it('renders an alert', () => {
|
|
const dataTableProps: QueryResult = {
|
|
data: {
|
|
resultType: 'vector',
|
|
result: [],
|
|
},
|
|
};
|
|
const table = shallow(<DataTable {...dataTableProps} />);
|
|
const alert = table.find(Alert);
|
|
expect(Object.keys(alert.props())).toHaveLength(7);
|
|
expect(alert.prop('color')).toEqual('secondary');
|
|
expect(alert.prop('children')).toEqual('Empty query result');
|
|
});
|
|
});
|
|
|
|
describe('when resultType is a vector with values', () => {
|
|
const dataTableProps: QueryResult = {
|
|
data: {
|
|
resultType: 'vector',
|
|
result: [
|
|
{
|
|
metric: {
|
|
__name__: 'metric_name_1',
|
|
label1: 'value_1',
|
|
labeln: 'value_n',
|
|
},
|
|
value: [1572098246.599, '0'],
|
|
},
|
|
{
|
|
metric: {
|
|
__name__: 'metric_name_2',
|
|
label1: 'value_1',
|
|
labeln: 'value_n',
|
|
},
|
|
value: [1572098246.599, '1'],
|
|
},
|
|
],
|
|
},
|
|
};
|
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
|
|
|
it('renders a table', () => {
|
|
const table = dataTable.find(Table);
|
|
expect(table.prop('hover')).toBe(true);
|
|
expect(table.prop('size')).toEqual('sm');
|
|
expect(table.prop('className')).toEqual('data-table');
|
|
expect(table.find('tbody')).toHaveLength(1);
|
|
});
|
|
|
|
it('renders rows', () => {
|
|
const table = dataTable.find(Table);
|
|
table.find('tr').forEach((row, idx) => {
|
|
expect(row.find(SeriesName)).toHaveLength(1);
|
|
expect(
|
|
row
|
|
.find('td')
|
|
.at(1)
|
|
.text()
|
|
).toEqual(`${idx}`);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when resultType is a vector with too many values', () => {
|
|
const dataTableProps: QueryResult = {
|
|
data: {
|
|
resultType: 'vector',
|
|
result: Array.from(Array(10001).keys()).map(i => {
|
|
return {
|
|
metric: {
|
|
__name__: `metric_name_${i}`,
|
|
label1: 'value_1',
|
|
labeln: 'value_n',
|
|
},
|
|
value: [1572098246.599, `${i}`],
|
|
};
|
|
}),
|
|
},
|
|
};
|
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
|
|
|
it('renders limited rows', () => {
|
|
const table = dataTable.find(Table);
|
|
expect(table.find('tr')).toHaveLength(10000);
|
|
});
|
|
|
|
it('renders a warning', () => {
|
|
const alert = dataTable.find(Alert);
|
|
expect(alert.render().text()).toEqual('Warning: Fetched 10001 metrics, only displaying first 10000.');
|
|
});
|
|
});
|
|
|
|
describe('when result type is a matrix', () => {
|
|
const dataTableProps: QueryResult = {
|
|
data: {
|
|
resultType: 'matrix',
|
|
result: [
|
|
{
|
|
metric: {
|
|
__name__: 'promhttp_metric_handler_requests_total',
|
|
code: '200',
|
|
instance: 'localhost:9090',
|
|
job: 'prometheus',
|
|
},
|
|
values: [
|
|
[1572097950.93, '9'],
|
|
[1572097965.931, '10'],
|
|
[1572097980.929, '11'],
|
|
[1572097995.931, '12'],
|
|
[1572098010.932, '13'],
|
|
[1572098025.933, '14'],
|
|
[1572098040.93, '15'],
|
|
[1572098055.93, '16'],
|
|
[1572098070.93, '17'],
|
|
[1572098085.936, '18'],
|
|
[1572098100.936, '19'],
|
|
[1572098115.933, '20'],
|
|
[1572098130.932, '21'],
|
|
[1572098145.932, '22'],
|
|
[1572098160.933, '23'],
|
|
[1572098175.934, '24'],
|
|
[1572098190.937, '25'],
|
|
[1572098205.934, '26'],
|
|
[1572098220.933, '27'],
|
|
[1572098235.934, '28'],
|
|
],
|
|
},
|
|
{
|
|
metric: {
|
|
__name__: 'promhttp_metric_handler_requests_total',
|
|
code: '500',
|
|
instance: 'localhost:9090',
|
|
job: 'prometheus',
|
|
},
|
|
values: [
|
|
[1572097950.93, '0'],
|
|
[1572097965.931, '0'],
|
|
[1572097980.929, '0'],
|
|
[1572097995.931, '0'],
|
|
[1572098010.932, '0'],
|
|
[1572098025.933, '0'],
|
|
[1572098040.93, '0'],
|
|
[1572098055.93, '0'],
|
|
[1572098070.93, '0'],
|
|
[1572098085.936, '0'],
|
|
[1572098100.936, '0'],
|
|
[1572098115.933, '0'],
|
|
[1572098130.932, '0'],
|
|
[1572098145.932, '0'],
|
|
[1572098160.933, '0'],
|
|
[1572098175.934, '0'],
|
|
[1572098190.937, '0'],
|
|
[1572098205.934, '0'],
|
|
[1572098220.933, '0'],
|
|
[1572098235.934, '0'],
|
|
],
|
|
},
|
|
{
|
|
metric: {
|
|
__name__: 'promhttp_metric_handler_requests_total',
|
|
code: '503',
|
|
instance: 'localhost:9090',
|
|
job: 'prometheus',
|
|
},
|
|
values: [
|
|
[1572097950.93, '0'],
|
|
[1572097965.931, '0'],
|
|
[1572097980.929, '0'],
|
|
[1572097995.931, '0'],
|
|
[1572098010.932, '0'],
|
|
[1572098025.933, '0'],
|
|
[1572098040.93, '0'],
|
|
[1572098055.93, '0'],
|
|
[1572098070.93, '0'],
|
|
[1572098085.936, '0'],
|
|
[1572098100.936, '0'],
|
|
[1572098115.933, '0'],
|
|
[1572098130.932, '0'],
|
|
[1572098145.932, '0'],
|
|
[1572098160.933, '0'],
|
|
[1572098175.934, '0'],
|
|
[1572098190.937, '0'],
|
|
[1572098205.934, '0'],
|
|
[1572098220.933, '0'],
|
|
[1572098235.934, '0'],
|
|
],
|
|
},
|
|
],
|
|
},
|
|
};
|
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
|
it('renders rows', () => {
|
|
const table = dataTable.find(Table);
|
|
const rows = table.find('tr');
|
|
expect(table.find('tr')).toHaveLength(3);
|
|
const row = rows.at(0);
|
|
expect(row.text()).toEqual(`<SeriesName />1 @1572097950.93
|
|
1 @1572097965.931
|
|
1 @1572097980.929
|
|
1 @1572097995.931
|
|
1 @1572098010.932
|
|
1 @1572098025.933
|
|
1 @1572098040.93
|
|
1 @1572098055.93
|
|
1 @1572098070.93
|
|
1 @1572098085.936
|
|
1 @1572098100.936
|
|
1 @1572098115.933
|
|
1 @1572098130.932
|
|
1 @1572098145.932
|
|
1 @1572098160.933
|
|
1 @1572098175.934
|
|
1 @1572098190.937
|
|
1 @1572098205.934
|
|
1 @1572098220.933
|
|
1 @1572098235.934`);
|
|
});
|
|
});
|
|
|
|
describe('when resultType is a scalar', () => {
|
|
const dataTableProps: QueryResult = {
|
|
data: {
|
|
resultType: 'scalar',
|
|
result: [1572098246.599, '5'],
|
|
},
|
|
};
|
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
|
it('renders a scalar row', () => {
|
|
const table = dataTable.find(Table);
|
|
const rows = table.find('tr');
|
|
expect(rows.text()).toEqual('scalar5');
|
|
});
|
|
});
|
|
|
|
describe('when resultType is a string', () => {
|
|
const dataTableProps: QueryResult = {
|
|
data: {
|
|
resultType: 'string',
|
|
result: 'string',
|
|
},
|
|
};
|
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
|
it('renders a string row', () => {
|
|
const table = dataTable.find(Table);
|
|
const rows = table.find('tr');
|
|
expect(rows.text()).toEqual('scalart');
|
|
});
|
|
});
|
|
});
|