pgadmin4/web/regression/javascript/dashboard/charting_spec.js
Aditya Toshniwal f16498a8a7 Optimize Webpack to improve overall performance.
Changes include:
1) Remove underscore-string and sprintf-js packages as we were using only %s. Instead, added a function to do the same. Also changed gettext to behave like sprintf directly.
2) backgrid.sizeable.columns was not used anywhere, removed. @babel/polyfill is deprecated, replaced it with core-js.
3) Moved few css to make sure they get minified and bundled.
4) Added Flask-Compress to send static files as compressed gzip. This will reduce network traffic and improve initial load time for pgAdmin.
5) Split few JS files to make code reusable.
6) Lazy load few modules like leaflet, wkx is required only if geometry viewer is opened. snapsvg loaded only when explain plan is executed. This will improve sqleditor initial opening time.

Reviewed By: Khushboo Vashi
Fixes #4701
2019-10-10 12:05:28 +05:30

101 lines
2.6 KiB
JavaScript

/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2019, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import $ from 'jquery';
import {Chart} from 'top/dashboard/static/js/charting';
describe('In charting related testcases', ()=> {
let chartObj = undefined,
chartDiv = undefined,
options = {};
beforeEach(()=> {
$('body').append(
'<div id="charting-test-container"></div>'
);
chartDiv = $('#charting-test-container')[0];
chartObj = new Chart(chartDiv, options);
});
it('Return the correct container', ()=>{
expect(chartObj.getContainer()).toEqual(chartDiv);
});
it('Returns the container dimensions', ()=>{
let dim = chartObj.getContainerDimensions();
expect(dim.height).toBeDefined();
expect(dim.width).toBeDefined();
});
it('Check if options are set', ()=>{
chartObj.setOptions({
mouse: {
track:true,
},
});
let opt = chartObj.getOptions();
expect(opt.mouse).toBeDefined();
});
it('Check if options are set with mergeOptions false', ()=>{
let overOpt = {
mouse: {
track:true,
},
};
chartObj.setOptions(overOpt, false);
let newOptShouldBe = {...chartObj._defaultOptions, ...overOpt};
let opt = chartObj.getOptions();
expect(JSON.stringify(opt)).toEqual(JSON.stringify(newOptShouldBe));
});
it('Check if other data is set', ()=>{
chartObj.setOtherData('some_val', 1);
expect(chartObj._otherData['some_val']).toEqual(1);
});
it('Check if other data is get', ()=>{
chartObj.setOtherData('some_val', 1);
expect(chartObj.getOtherData('some_val')).toEqual(1);
});
it('Check if other data returns undefined for not set', ()=>{
expect(chartObj.getOtherData('some_val_not_set')).toEqual(undefined);
});
it('Check if isVisible returns correct', ()=>{
let dimSpy = spyOn(chartObj, 'getContainerDimensions');
dimSpy.and.returnValue({
height: 1, width: 1,
});
expect(chartObj.isVisible()).toEqual(true);
dimSpy.and.stub();
dimSpy.and.returnValue({
height: 0, width: 0,
});
expect(chartObj.isVisible()).toEqual(false);
});
it('Check if isInPage returns correct', ()=>{
expect(chartObj.isInPage()).toEqual(true);
$('body').find('#charting-test-container').remove();
expect(chartObj.isInPage()).toEqual(false);
});
afterEach(()=>{
$('body').find('#charting-test-container').remove();
});
});