pgadmin4/web/regression/javascript/dashboard/graphs_spec.js
Akshay Joshi 2556771c32 The following issues were fixed in Graph Visualiser:
1) Allow the user to set the row limit and chart line width.
2) Zoom should only be applied to X-axis, not both.
3) On clicking the 'Generate' button, the chart should return to its original zoom level.
4) Negative values are not displayed.

refs #7485
2022-06-23 14:52:11 +05:30

150 lines
4.1 KiB
JavaScript

import jasmineEnzyme from 'jasmine-enzyme';
import React from 'react';
import {mount} from 'enzyme';
import '../helper/enzyme.helper';
import { DATA_POINT_SIZE } from 'sources/chartjs';
import Graphs, {GraphsWrapper, X_AXIS_LENGTH, transformData,
getStatsUrl, statsReducer} from '../../../pgadmin/dashboard/static/js/Graphs';
describe('Graphs.js', ()=>{
it('transformData', ()=>{
expect(transformData({'Label1': [], 'Label2': []}, 1, false)).toEqual({
labels: [...Array(X_AXIS_LENGTH).keys()],
datasets: [{
label: 'Label1',
data: [],
borderColor: '#00BCD4',
backgroundColor: '#00BCD4',
pointHitRadius: DATA_POINT_SIZE,
pointStyle: 'circle',
},{
label: 'Label2',
data: [],
borderColor: '#9CCC65',
backgroundColor: '#9CCC65',
pointHitRadius: DATA_POINT_SIZE,
pointStyle: 'circle',
}],
refreshRate: 1,
});
});
describe('getStatsUrl', ()=>{
it('for server', ()=>{
expect(getStatsUrl(432, -1, ['chart1'])).toEqual('/dashboard/dashboard_stats/432?chart_names=chart1');
});
it('for database', ()=>{
expect(getStatsUrl(432, 123, ['chart1'])).toEqual('/dashboard/dashboard_stats/432/123?chart_names=chart1');
});
it('for multiple graphs', ()=>{
expect(getStatsUrl(432, 123, ['chart1', 'chart2'])).toEqual('/dashboard/dashboard_stats/432/123?chart_names=chart1,chart2');
});
});
describe('statsReducer', ()=>{
it('with incoming no counter', ()=>{
let state = {
'Label1': [], 'Label2': [],
};
let action = {
incoming: {
'Label1': 1, 'Label2': 2,
},
};
let newState = {
'Label1': [1], 'Label2': [2],
};
state = statsReducer(state, action);
expect(state).toEqual(newState);
});
it('with incoming with counter', ()=>{
let state = {
'Label1': [1], 'Label2': [2],
};
let action = {
incoming: {
'Label1': 1, 'Label2': 3,
},
counter: true,
counterData: {'Label1': 1, 'Label2': 2},
};
let newState = {
'Label1': [0, 1], 'Label2': [1, 2],
};
state = statsReducer(state, action);
expect(state).toEqual(newState);
});
it('with reset', ()=>{
let state = {
'Label1': [0, 1], 'Label2': [1, 2],
};
let action = {
reset: {
'Label1': [2], 'Label2': [2],
},
};
let newState = {
'Label1': [2], 'Label2': [2],
};
state = statsReducer(state, action);
expect(state).toEqual(newState);
});
});
describe('<Graphs /> component', ()=>{
let graphComp = null;
let sid = 1;
let did = 1;
beforeEach(()=>{
jasmineEnzyme();
let dashboardPref = {
session_stats_refresh: 1,
tps_stats_refresh: 1,
ti_stats_refresh: 1,
to_stats_refresh: 1,
bio_stats_refresh: 1,
show_graphs: true,
graph_data_points: true,
graph_mouse_track: true,
graph_line_border_width: 2
};
graphComp = mount(<Graphs preferences={dashboardPref} sid={sid} did={did} enablePoll={false} pageVisible={true} />);
});
it('GraphsWrapper is rendered', (done)=>{
let found = graphComp.find(GraphsWrapper);
expect(found.length).toBe(1);
done();
});
it('pollDelay is set', (done)=>{
let found = graphComp.find('[data-testid="graph-poll-delay"]');
expect(found).toHaveClassName('d-none');
expect(found).toHaveText('1000');
done();
});
it('pollDelay on preference update', (done)=>{
let dashboardPref = {
session_stats_refresh: 5,
tps_stats_refresh: 10,
ti_stats_refresh: 5,
to_stats_refresh: 10,
bio_stats_refresh: 10,
show_graphs: true,
graph_data_points: true,
graph_mouse_track: true,
graph_line_border_width: 2
};
graphComp.setProps({preferences: dashboardPref});
let found = graphComp.find('[data-testid="graph-poll-delay"]');
expect(found).toHaveText('5000');
done();
});
});
});