mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 08:46:39 -06:00
Fixed code smell 'Update this function so that its implementation is not identical' reported by SonarQube.
This commit is contained in:
parent
bc0b25d995
commit
b9e533e31a
@ -16,107 +16,65 @@ import '../../../pgadmin/misc/file_manager/static/js/select_dialogue.js';
|
||||
describe('fileSelectDialog', function () {
|
||||
|
||||
let params;
|
||||
|
||||
pgAdmin.Browser = {
|
||||
stdW: {
|
||||
sm: 500,
|
||||
md: 700,
|
||||
lg: 900,
|
||||
default: 500,
|
||||
calc: (passed_width) => {
|
||||
let iw = window.innerWidth;
|
||||
if(iw > passed_width){
|
||||
return passed_width;
|
||||
}else{
|
||||
if (iw > pgAdmin.Browser.stdW.lg)
|
||||
return pgAdmin.Browser.stdW.lg;
|
||||
else if (iw > pgAdmin.Browser.stdW.md)
|
||||
return pgAdmin.Browser.stdW.md;
|
||||
else if (iw > pgAdmin.Browser.stdW.sm)
|
||||
return pgAdmin.Browser.stdW.sm;
|
||||
else
|
||||
// if available screen resolution is still
|
||||
// less then return the width value as it
|
||||
return iw;
|
||||
}
|
||||
},
|
||||
},
|
||||
stdH: {
|
||||
sm: 200,
|
||||
md: 400,
|
||||
lg: 550,
|
||||
default: 550,
|
||||
calc: (passed_height) => {
|
||||
// We are excluding sm as it is too small for dialog
|
||||
let ih = window.innerHeight;
|
||||
if (ih > passed_height){
|
||||
return passed_height;
|
||||
}else{
|
||||
if (ih > pgAdmin.Browser.stdH.lg)
|
||||
return pgAdmin.Browser.stdH.lg;
|
||||
else if (ih > pgAdmin.Browser.stdH.md)
|
||||
return pgAdmin.Browser.stdH.md;
|
||||
else
|
||||
// if available screen resolution is still
|
||||
// less then return the height value as it
|
||||
return ih;
|
||||
}
|
||||
},
|
||||
},
|
||||
let calcWidth = (passed_width)=>{
|
||||
let iw = window.innerWidth;
|
||||
if (iw > passed_width){
|
||||
return passed_width;
|
||||
} else {
|
||||
if (iw > pgAdmin.Browser.stdW.lg)
|
||||
return pgAdmin.Browser.stdW.lg;
|
||||
else if (iw > pgAdmin.Browser.stdW.md)
|
||||
return pgAdmin.Browser.stdW.md;
|
||||
else if (iw > pgAdmin.Browser.stdW.sm)
|
||||
return pgAdmin.Browser.stdW.sm;
|
||||
else
|
||||
// if available screen resolution is still
|
||||
// less then return the width value as it
|
||||
return iw;
|
||||
}
|
||||
};
|
||||
|
||||
let calcHeight = (passed_height)=>{
|
||||
// We are excluding sm as it is too small for dialog
|
||||
let ih = window.innerHeight;
|
||||
if (ih > passed_height){
|
||||
return passed_height;
|
||||
}else{
|
||||
if (ih > pgAdmin.Browser.stdH.lg)
|
||||
return pgAdmin.Browser.stdH.lg;
|
||||
else if (ih > pgAdmin.Browser.stdH.md)
|
||||
return pgAdmin.Browser.stdH.md;
|
||||
else
|
||||
// if available screen resolution is still
|
||||
// less then return the height value as it
|
||||
return ih;
|
||||
}
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
pgAdmin.Browser = {
|
||||
stdW: {
|
||||
sm: 500,
|
||||
md: 700,
|
||||
lg: 900,
|
||||
default: 500,
|
||||
calc: (passed_width) => {
|
||||
calcWidth(passed_width);
|
||||
},
|
||||
},
|
||||
stdH: {
|
||||
sm: 200,
|
||||
md: 400,
|
||||
lg: 550,
|
||||
default: 550,
|
||||
calc: (passed_height) => {
|
||||
calcHeight(passed_height);
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('When dialog is called for', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
pgAdmin.Browser = {
|
||||
stdW: {
|
||||
sm: 500,
|
||||
md: 700,
|
||||
lg: 900,
|
||||
default: 500,
|
||||
calc: (passed_width) => {
|
||||
let iw = window.innerWidth;
|
||||
if(iw > passed_width){
|
||||
return passed_width;
|
||||
}else{
|
||||
if (iw > pgAdmin.Browser.stdW.lg)
|
||||
return pgAdmin.Browser.stdW.lg;
|
||||
else if (iw > pgAdmin.Browser.stdW.md)
|
||||
return pgAdmin.Browser.stdW.md;
|
||||
else if (iw > pgAdmin.Browser.stdW.sm)
|
||||
return pgAdmin.Browser.stdW.sm;
|
||||
else
|
||||
// if available screen resolution is still
|
||||
// less then return the width value as it
|
||||
return iw;
|
||||
}
|
||||
},
|
||||
},
|
||||
stdH: {
|
||||
sm: 200,
|
||||
md: 400,
|
||||
lg: 550,
|
||||
default: 550,
|
||||
calc: (passed_height) => {
|
||||
// We are excluding sm as it is too small for dialog
|
||||
let ih = window.innerHeight;
|
||||
if (ih > passed_height){
|
||||
return passed_height;
|
||||
}else{
|
||||
if (ih > pgAdmin.Browser.stdH.lg)
|
||||
return pgAdmin.Browser.stdH.lg;
|
||||
else if (ih > pgAdmin.Browser.stdH.md)
|
||||
return pgAdmin.Browser.stdH.md;
|
||||
else
|
||||
// if available screen resolution is still
|
||||
// less then return the height value as it
|
||||
return ih;
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('Select file', function() {
|
||||
params = {
|
||||
'dialog_title': 'Select file',
|
||||
@ -151,56 +109,6 @@ describe('fileSelectDialog', function () {
|
||||
});
|
||||
|
||||
describe('When dialog is called for storage file', () => {
|
||||
beforeEach(() => {
|
||||
pgAdmin.Browser = {
|
||||
stdW: {
|
||||
sm: 500,
|
||||
md: 700,
|
||||
lg: 900,
|
||||
default: 500,
|
||||
calc: (passed_width) => {
|
||||
let iw = window.innerWidth;
|
||||
if(iw > passed_width){
|
||||
return passed_width;
|
||||
}else{
|
||||
if (iw > pgAdmin.Browser.stdW.lg)
|
||||
return pgAdmin.Browser.stdW.lg;
|
||||
else if (iw > pgAdmin.Browser.stdW.md)
|
||||
return pgAdmin.Browser.stdW.md;
|
||||
else if (iw > pgAdmin.Browser.stdW.sm)
|
||||
return pgAdmin.Browser.stdW.sm;
|
||||
else
|
||||
// if available screen resolution is still
|
||||
// less then return the width value as it
|
||||
return iw;
|
||||
}
|
||||
},
|
||||
},
|
||||
stdH: {
|
||||
sm: 200,
|
||||
md: 400,
|
||||
lg: 550,
|
||||
default: 550,
|
||||
calc: (passed_height) => {
|
||||
// We are excluding sm as it is too small for dialog
|
||||
let ih = window.innerHeight;
|
||||
if (ih > passed_height){
|
||||
return passed_height;
|
||||
}else{
|
||||
if (ih > pgAdmin.Browser.stdH.lg)
|
||||
return pgAdmin.Browser.stdH.lg;
|
||||
else if (ih > pgAdmin.Browser.stdH.md)
|
||||
return pgAdmin.Browser.stdH.md;
|
||||
else
|
||||
// if available screen resolution is still
|
||||
// less then return the height value as it
|
||||
return ih;
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('Storage file dialog', function() {
|
||||
params = {
|
||||
'dialog_title': 'Storage Manager',
|
||||
|
@ -187,7 +187,7 @@ describe('QueryHistory', () => {
|
||||
jasmine.clock().tick(1499);
|
||||
});
|
||||
|
||||
it('should change the button text to \'Copied!\'', () => {
|
||||
it('1.5 seconds should change the button text to \'Copied!\'', () => {
|
||||
expect(copyAllButton().text()).toBe('Copied!');
|
||||
});
|
||||
|
||||
@ -201,7 +201,7 @@ describe('QueryHistory', () => {
|
||||
jasmine.clock().tick(1501);
|
||||
});
|
||||
|
||||
it('should change the button text back to \'Copy\'', () => {
|
||||
it('1.5 seconds should change the button text back to \'Copy\'', () => {
|
||||
expect(copyAllButton().text()).toBe('Copy');
|
||||
});
|
||||
});
|
||||
|
@ -41,6 +41,14 @@ describe('ExplainStatistics', () => {
|
||||
});
|
||||
});
|
||||
|
||||
let mouseClickAction = ()=> {
|
||||
// Trigger mouse over event
|
||||
var clickEvent = new $.Event('click');
|
||||
$('.pg-explain-stats-area').trigger(clickEvent);
|
||||
|
||||
expect(tooltipContainer.hasClass('d-none')).toBe(false);
|
||||
};
|
||||
|
||||
describe('JIT Statistics', () => {
|
||||
beforeEach(function() {
|
||||
$('body').append(statsDiv);
|
||||
@ -54,11 +62,7 @@ describe('ExplainStatistics', () => {
|
||||
});
|
||||
|
||||
it('Mouse click event should be trigger', () => {
|
||||
// Trigger mouse over event
|
||||
var clickEvent = new $.Event('click');
|
||||
$('.pg-explain-stats-area').trigger(clickEvent);
|
||||
|
||||
expect(tooltipContainer.hasClass('d-none')).toBe(false);
|
||||
mouseClickAction();
|
||||
});
|
||||
});
|
||||
|
||||
@ -75,11 +79,7 @@ describe('ExplainStatistics', () => {
|
||||
});
|
||||
|
||||
it('Mouse click event should be trigger', () => {
|
||||
// Trigger mouse over event
|
||||
var clickEvent = new $.Event('click');
|
||||
$('.pg-explain-stats-area').trigger(clickEvent);
|
||||
|
||||
expect(tooltipContainer.hasClass('d-none')).toBe(false);
|
||||
mouseClickAction();
|
||||
});
|
||||
});
|
||||
|
||||
@ -100,11 +100,7 @@ describe('ExplainStatistics', () => {
|
||||
});
|
||||
|
||||
it('Mouse click event should be trigger', () => {
|
||||
// Trigger mouse over event
|
||||
var clickEvent = new $.Event('click');
|
||||
$('.pg-explain-stats-area').trigger(clickEvent);
|
||||
|
||||
expect(tooltipContainer.hasClass('d-none')).toBe(false);
|
||||
mouseClickAction();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -13,6 +13,47 @@ import {
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {TreeFake} from '../../tree/tree_fake';
|
||||
|
||||
let beforeActionForSchema = (tree, pgBrowser)=> {
|
||||
let hierarchy = {
|
||||
id: 'root',
|
||||
children: [{
|
||||
id: 'level2',
|
||||
data: {_type: 'schema'},
|
||||
children: [{
|
||||
id: 'coll-table',
|
||||
data: {_type: 'coll-table'},
|
||||
children: [{
|
||||
id: 'table/1',
|
||||
data: {_type: 'table'},
|
||||
}],
|
||||
}],
|
||||
}],
|
||||
};
|
||||
|
||||
tree = TreeFake.build(hierarchy, pgBrowser);
|
||||
pgBrowser.tree = tree;
|
||||
};
|
||||
|
||||
let beforeActionForCatalog = (tree, pgBrowser)=> {
|
||||
let hierarchy = {
|
||||
id: 'root',
|
||||
children: [{
|
||||
id: 'level2',
|
||||
data: {_type: 'catalog'},
|
||||
children: [{
|
||||
id: 'coll-table',
|
||||
data: {_type: 'coll-table'},
|
||||
children: [{
|
||||
id: 'table/1',
|
||||
data: {_type: 'table'},
|
||||
}],
|
||||
}],
|
||||
}],
|
||||
};
|
||||
|
||||
tree = TreeFake.build(hierarchy, pgBrowser);
|
||||
pgBrowser.tree = tree;
|
||||
};
|
||||
|
||||
describe('#childCreateMenuEnabled', () => {
|
||||
let data,
|
||||
@ -86,24 +127,7 @@ describe('#childCreateMenuEnabled', () => {
|
||||
|
||||
describe(', on one of the child node under schema node ', () => {
|
||||
beforeEach(() => {
|
||||
let hierarchy = {
|
||||
id: 'root',
|
||||
children: [{
|
||||
id: 'level2',
|
||||
data: {_type: 'schema'},
|
||||
children: [{
|
||||
id: 'coll-table',
|
||||
data: {_type: 'coll-table'},
|
||||
children: [{
|
||||
id: 'table/1',
|
||||
data: {_type: 'table'},
|
||||
}],
|
||||
}],
|
||||
}],
|
||||
};
|
||||
|
||||
tree = TreeFake.build(hierarchy, pgBrowser);
|
||||
pgBrowser.tree = tree;
|
||||
beforeActionForSchema(tree, pgBrowser);
|
||||
});
|
||||
|
||||
it(' it is true', () => {
|
||||
@ -160,24 +184,7 @@ describe('#childCreateMenuEnabled', () => {
|
||||
|
||||
describe(', on one of the child node under catalog node ', () => {
|
||||
beforeEach(() => {
|
||||
let hierarchy = {
|
||||
id: 'root',
|
||||
children: [{
|
||||
id: 'level2',
|
||||
data: {_type: 'catalog'},
|
||||
children: [{
|
||||
id: 'coll-table',
|
||||
data: {_type: 'coll-table'},
|
||||
children: [{
|
||||
id: 'table/1',
|
||||
data: {_type: 'table'},
|
||||
}],
|
||||
}],
|
||||
}],
|
||||
};
|
||||
|
||||
tree = TreeFake.build(hierarchy, pgBrowser);
|
||||
pgBrowser.tree = tree;
|
||||
beforeActionForCatalog(tree, pgBrowser);
|
||||
});
|
||||
|
||||
it(' it is false', () => {
|
||||
@ -195,27 +202,9 @@ describe('#childDropMenuEnabled', () => {
|
||||
let tree,
|
||||
pgBrowser = pgAdmin.Browser;
|
||||
|
||||
|
||||
describe(' - the child node under schema node ', () => {
|
||||
beforeEach(() => {
|
||||
let hierarchy = {
|
||||
id: 'root',
|
||||
children: [{
|
||||
id: 'level2',
|
||||
data: {_type: 'schema'},
|
||||
children: [{
|
||||
id: 'coll-table',
|
||||
data: {_type: 'coll-table'},
|
||||
children: [{
|
||||
id: 'table/1',
|
||||
data: {_type: 'table'},
|
||||
}],
|
||||
}],
|
||||
}],
|
||||
};
|
||||
|
||||
tree = TreeFake.build(hierarchy, pgBrowser);
|
||||
pgBrowser.tree = tree;
|
||||
beforeActionForSchema(tree, pgBrowser);
|
||||
});
|
||||
|
||||
it(' it is true', () => {
|
||||
@ -227,24 +216,7 @@ describe('#childDropMenuEnabled', () => {
|
||||
|
||||
describe('- the child node under the catalog node ', () => {
|
||||
beforeEach(() => {
|
||||
let hierarchy = {
|
||||
id: 'root',
|
||||
children: [{
|
||||
id: 'level2',
|
||||
data: {_type: 'catalog'},
|
||||
children: [{
|
||||
id: 'coll-table',
|
||||
data: {_type: 'coll-table'},
|
||||
children: [{
|
||||
id: 'table/1',
|
||||
data: {_type: 'table'},
|
||||
}],
|
||||
}],
|
||||
}],
|
||||
};
|
||||
|
||||
tree = TreeFake.build(hierarchy, pgBrowser);
|
||||
pgBrowser.tree = tree;
|
||||
beforeActionForCatalog(tree, pgBrowser);
|
||||
});
|
||||
|
||||
it(' it is false', () => {
|
||||
|
@ -243,6 +243,11 @@ describe('FunctionSchema', ()=>{
|
||||
|
||||
});
|
||||
|
||||
let initDataProc = ()=>Promise.resolve({
|
||||
sysfunc: true,
|
||||
type: 'procedure',
|
||||
});
|
||||
|
||||
it('proiswindow visible', ()=>{
|
||||
|
||||
|
||||
@ -285,12 +290,7 @@ describe('FunctionSchema', ()=>{
|
||||
}
|
||||
);
|
||||
|
||||
let initData = ()=>Promise.resolve({
|
||||
sysfunc: true,
|
||||
type: 'procedure',
|
||||
});
|
||||
|
||||
mount(getEditView(editSchemaObj, initData));
|
||||
mount(getEditView(editSchemaObj, initDataProc));
|
||||
});
|
||||
|
||||
it('proiswindow visible', ()=>{
|
||||
@ -389,13 +389,7 @@ describe('FunctionSchema', ()=>{
|
||||
}
|
||||
);
|
||||
|
||||
let initData = ()=>Promise.resolve({
|
||||
sysfunc: true,
|
||||
type: 'procedure',
|
||||
});
|
||||
|
||||
mount(getEditView(editSchemaObj, initData));
|
||||
|
||||
mount(getEditView(editSchemaObj, initDataProc));
|
||||
});
|
||||
|
||||
it('probin visible', ()=>{
|
||||
|
@ -143,11 +143,15 @@ describe('SearchObjectsDialogWrapper', () => {
|
||||
spyOn(soDialogWrapper, 'setResultCount');
|
||||
});
|
||||
|
||||
let prepareAction = ()=> {
|
||||
spyOn(soDialogWrapper, 'prepareDialog');
|
||||
soDialogWrapper.prepare();
|
||||
expect(soDialogWrapper.prepareDialog).not.toHaveBeenCalled();
|
||||
};
|
||||
|
||||
context('no tree element is selected', () => {
|
||||
it('does not prepare dialog', () => {
|
||||
spyOn(soDialogWrapper, 'prepareDialog');
|
||||
soDialogWrapper.prepare();
|
||||
expect(soDialogWrapper.prepareDialog).not.toHaveBeenCalled();
|
||||
prepareAction();
|
||||
});
|
||||
});
|
||||
|
||||
@ -157,9 +161,7 @@ describe('SearchObjectsDialogWrapper', () => {
|
||||
});
|
||||
|
||||
it('does not prepare the dialog', () => {
|
||||
spyOn(soDialogWrapper, 'prepareDialog');
|
||||
soDialogWrapper.prepare();
|
||||
expect(soDialogWrapper.prepareDialog).not.toHaveBeenCalled();
|
||||
prepareAction();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -132,11 +132,16 @@ describe('ColumnSelector', function () {
|
||||
$('body').find(container).remove();
|
||||
});
|
||||
|
||||
let selectColumnAction = ()=> {
|
||||
container.find('.slick-header-column:contains(some-column-name)').click();
|
||||
|
||||
var selectedRanges = cellSelectionModel.getSelectedRanges();
|
||||
expectOnlyTheFirstColumnToBeSelected(selectedRanges);
|
||||
};
|
||||
|
||||
describe('when the user clicks a column header', function () {
|
||||
it('selects the column', function () {
|
||||
container.find('.slick-header-column:contains(some-column-name)').click();
|
||||
var selectedRanges = cellSelectionModel.getSelectedRanges();
|
||||
expectOnlyTheFirstColumnToBeSelected(selectedRanges);
|
||||
selectColumnAction();
|
||||
});
|
||||
|
||||
it('toggles a selected class to the header cell', function () {
|
||||
@ -287,10 +292,7 @@ describe('ColumnSelector', function () {
|
||||
});
|
||||
|
||||
it('deselects the non-column range', function () {
|
||||
container.find('.slick-header-column:contains(some-column-name)').click();
|
||||
|
||||
var selectedRanges = cellSelectionModel.getSelectedRanges();
|
||||
expectOnlyTheFirstColumnToBeSelected(selectedRanges);
|
||||
selectColumnAction();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -54,6 +54,35 @@ describe('#handleQueryOutputKeyboardEvent', function () {
|
||||
handleQueryOutputKeyboardEvent = HandleQueryOutputKeyboardEvent.bind(window);
|
||||
});
|
||||
|
||||
let selectEntireGridAction = ()=> {
|
||||
handleQueryOutputKeyboardEvent(event, slickEvent);
|
||||
|
||||
expect(RangeSelectionHelper.isEntireGridSelected(grid)).toBeTruthy();
|
||||
expect(grid.getSelectionModel().getSelectedRanges().length).toEqual(1);
|
||||
};
|
||||
|
||||
let commandAAction = ()=> {
|
||||
beforeEach(function () {
|
||||
event.metaKey = true;
|
||||
event.keyCode = 65;
|
||||
});
|
||||
|
||||
it('selects the entire grid to ranges', function () {
|
||||
selectEntireGridAction();
|
||||
});
|
||||
};
|
||||
|
||||
let ctrlAAction = ()=> {
|
||||
beforeEach(function () {
|
||||
event.ctrlKey = true;
|
||||
event.keyCode = 65;
|
||||
});
|
||||
|
||||
it('selects the entire grid to ranges', function () {
|
||||
selectEntireGridAction();
|
||||
});
|
||||
};
|
||||
|
||||
describe('when a range is selected', function () {
|
||||
beforeEach(function () {
|
||||
grid.getSelectionModel().setSelectedRanges([
|
||||
@ -62,17 +91,18 @@ describe('#handleQueryOutputKeyboardEvent', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
let copyCellContentAction = ()=> {
|
||||
handleQueryOutputKeyboardEvent(event, slickEvent);
|
||||
expect(clipboard.copyTextToClipboard).toHaveBeenCalledWith('\'0,0-cell-content\',\'0,1-cell-content\'\n\'2,0-cell-content\',\'2,1-cell-content\'');
|
||||
};
|
||||
|
||||
describe('pressing Command + C', function () {
|
||||
beforeEach(function () {
|
||||
event.metaKey = true;
|
||||
event.keyCode = 67;
|
||||
});
|
||||
|
||||
it('copies the cell content to the clipboard', function () {
|
||||
handleQueryOutputKeyboardEvent(event, slickEvent);
|
||||
|
||||
expect(clipboard.copyTextToClipboard).toHaveBeenCalledWith('\'0,0-cell-content\',\'0,1-cell-content\'\n\'2,0-cell-content\',\'2,1-cell-content\'');
|
||||
});
|
||||
it('copies the cell content to the clipboard', copyCellContentAction);
|
||||
});
|
||||
|
||||
describe('pressing Ctrl + C', function () {
|
||||
@ -81,69 +111,15 @@ describe('#handleQueryOutputKeyboardEvent', function () {
|
||||
event.keyCode = 67;
|
||||
});
|
||||
|
||||
it('copies the cell content to the clipboard', function () {
|
||||
handleQueryOutputKeyboardEvent(event, slickEvent);
|
||||
|
||||
expect(clipboard.copyTextToClipboard).toHaveBeenCalledWith('\'0,0-cell-content\',\'0,1-cell-content\'\n\'2,0-cell-content\',\'2,1-cell-content\'');
|
||||
});
|
||||
it('copies the cell content to the clipboard', copyCellContentAction);
|
||||
});
|
||||
|
||||
describe('pressing Command + A', function () {
|
||||
beforeEach(function () {
|
||||
event.metaKey = true;
|
||||
event.keyCode = 65;
|
||||
});
|
||||
|
||||
it('selects the entire grid to ranges', function () {
|
||||
handleQueryOutputKeyboardEvent(event, slickEvent);
|
||||
|
||||
expect(RangeSelectionHelper.isEntireGridSelected(grid)).toBeTruthy();
|
||||
expect(grid.getSelectionModel().getSelectedRanges().length).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pressing Ctrl + A', function () {
|
||||
beforeEach(function () {
|
||||
event.ctrlKey = true;
|
||||
event.keyCode = 65;
|
||||
});
|
||||
|
||||
it('selects the entire grid to ranges', function () {
|
||||
handleQueryOutputKeyboardEvent(event, slickEvent);
|
||||
|
||||
expect(RangeSelectionHelper.isEntireGridSelected(grid)).toBeTruthy();
|
||||
expect(grid.getSelectionModel().getSelectedRanges().length).toEqual(1);
|
||||
});
|
||||
});
|
||||
describe('pressing Command + A', commandAAction);
|
||||
describe('pressing Ctrl + A', ctrlAAction);
|
||||
});
|
||||
|
||||
describe('when no ranges are selected', function () {
|
||||
describe('pressing Command + A', function () {
|
||||
beforeEach(function () {
|
||||
event.metaKey = true;
|
||||
event.keyCode = 65;
|
||||
});
|
||||
|
||||
it('selects the entire grid to ranges', function () {
|
||||
handleQueryOutputKeyboardEvent(event, slickEvent);
|
||||
|
||||
expect(RangeSelectionHelper.isEntireGridSelected(grid)).toBeTruthy();
|
||||
expect(grid.getSelectionModel().getSelectedRanges().length).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pressing Ctrl + A', function () {
|
||||
beforeEach(function () {
|
||||
event.ctrlKey = true;
|
||||
event.keyCode = 65;
|
||||
});
|
||||
|
||||
it('selects the entire grid to ranges', function () {
|
||||
handleQueryOutputKeyboardEvent(event, slickEvent);
|
||||
|
||||
expect(RangeSelectionHelper.isEntireGridSelected(grid)).toBeTruthy();
|
||||
expect(grid.getSelectionModel().getSelectedRanges().length).toEqual(1);
|
||||
});
|
||||
});
|
||||
describe('pressing Command + A', commandAAction);
|
||||
describe('pressing Ctrl + A', ctrlAAction);
|
||||
});
|
||||
});
|
||||
|
@ -35,94 +35,98 @@ describe('#callRenderAfterPoll', () => {
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
let expectAction = (expectObj, callWithValue=null)=> {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
if (callWithValue !== null) {
|
||||
expect(expectObj).toHaveBeenCalledWith(callWithValue);
|
||||
} else {
|
||||
expect(expectObj).toHaveBeenCalledWith();
|
||||
}
|
||||
};
|
||||
|
||||
let queryResult1 = ()=>{
|
||||
queryResult = {
|
||||
rows_affected: 10,
|
||||
has_more_rows: false,
|
||||
colinfo: {},
|
||||
};
|
||||
};
|
||||
|
||||
let queryResult2 = ()=>{
|
||||
queryResult = {
|
||||
rows_affected: 10,
|
||||
has_more_rows: false,
|
||||
colinfo: undefined,
|
||||
result: 'Some result',
|
||||
};
|
||||
};
|
||||
|
||||
let displayNotificationAction = ()=> {
|
||||
sqlEditorSpy.info_notifier_timeout = 10;
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(Notify.success).toHaveBeenCalledWith(
|
||||
'Query returned successfully in 0 msec.',
|
||||
10
|
||||
);
|
||||
};
|
||||
|
||||
let saveAction = ()=> {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.update_msg_history).toHaveBeenCalledWith(
|
||||
true,
|
||||
'Some result\n\nQuery returned successfully in 0 msec.',
|
||||
false
|
||||
);
|
||||
};
|
||||
|
||||
describe('it is not a query tool', () => {
|
||||
beforeEach(() => {
|
||||
sqlEditorSpy.is_query_tool = false;
|
||||
});
|
||||
|
||||
describe('query was successful and have results', () => {
|
||||
beforeEach(() => {
|
||||
queryResult = {
|
||||
rows_affected: 10,
|
||||
has_more_rows: false,
|
||||
colinfo: {},
|
||||
};
|
||||
});
|
||||
beforeEach(queryResult1);
|
||||
|
||||
it('renders the editor', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy._render).toHaveBeenCalledWith(queryResult);
|
||||
expectAction(sqlEditorSpy._render, queryResult);
|
||||
});
|
||||
|
||||
it('inform sqleditor that the query stopped running', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.setIsQueryRunning).toHaveBeenCalledWith(false);
|
||||
expectAction(sqlEditorSpy.setIsQueryRunning, false);
|
||||
});
|
||||
|
||||
it('hides the loading icon', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.trigger).toHaveBeenCalledWith('pgadmin-sqleditor:loading-icon:hide');
|
||||
expectAction(sqlEditorSpy.trigger, 'pgadmin-sqleditor:loading-icon:hide');
|
||||
});
|
||||
});
|
||||
|
||||
describe('query was successful but had no result to display', () => {
|
||||
beforeEach(() => {
|
||||
queryResult = {
|
||||
rows_affected: 10,
|
||||
has_more_rows: false,
|
||||
colinfo: undefined,
|
||||
result: 'Some result',
|
||||
};
|
||||
});
|
||||
beforeEach(queryResult2);
|
||||
|
||||
it('saves execution information in the history', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.update_msg_history).toHaveBeenCalledWith(
|
||||
true,
|
||||
'Some result\n\nQuery returned successfully in 0 msec.',
|
||||
false
|
||||
);
|
||||
saveAction();
|
||||
});
|
||||
|
||||
it('resets the changed data store', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.reset_data_store).toHaveBeenCalled();
|
||||
expectAction(sqlEditorSpy.reset_data_store);
|
||||
});
|
||||
|
||||
it('inform sqleditor that the query stopped running', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.setIsQueryRunning).toHaveBeenCalledWith(false);
|
||||
expectAction(sqlEditorSpy.setIsQueryRunning, false);
|
||||
});
|
||||
|
||||
it('hides the loading icon', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.trigger).toHaveBeenCalledWith('pgadmin-sqleditor:loading-icon:hide');
|
||||
expectAction(sqlEditorSpy.trigger, 'pgadmin-sqleditor:loading-icon:hide');
|
||||
});
|
||||
|
||||
describe('notifications are enabled', () => {
|
||||
it('display notification', () => {
|
||||
sqlEditorSpy.info_notifier_timeout = 10;
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(Notify.success).toHaveBeenCalledWith(
|
||||
'Query returned successfully in 0 msec.',
|
||||
10
|
||||
);
|
||||
});
|
||||
it('display notification', displayNotificationAction);
|
||||
});
|
||||
|
||||
it('disables the save results button', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.enable_disable_download_btn).toHaveBeenCalledWith(true);
|
||||
|
||||
expectAction(sqlEditorSpy.enable_disable_download_btn, true);
|
||||
expect(sqlEditorSpy.trigger).toHaveBeenCalledWith('pgadmin-sqleditor:loading-icon:hide');
|
||||
});
|
||||
});
|
||||
@ -134,99 +138,54 @@ describe('#callRenderAfterPoll', () => {
|
||||
});
|
||||
|
||||
describe('query was successful and have results', () => {
|
||||
beforeEach(() => {
|
||||
queryResult = {
|
||||
rows_affected: 10,
|
||||
has_more_rows: false,
|
||||
colinfo: {},
|
||||
};
|
||||
});
|
||||
beforeEach(queryResult1);
|
||||
|
||||
it('renders the editor', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy._render).toHaveBeenCalledWith(queryResult);
|
||||
expectAction(sqlEditorSpy._render, queryResult);
|
||||
});
|
||||
|
||||
it('inform sqleditor that the query stopped running', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.setIsQueryRunning).toHaveBeenCalledWith(false);
|
||||
expectAction(sqlEditorSpy.setIsQueryRunning, false);
|
||||
});
|
||||
|
||||
it('hides the loading icon', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.trigger).toHaveBeenCalledWith('pgadmin-sqleditor:loading-icon:hide');
|
||||
expectAction(sqlEditorSpy.trigger, 'pgadmin-sqleditor:loading-icon:hide');
|
||||
});
|
||||
|
||||
it('enables sqleditor tools buttons', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.disable_tool_buttons).toHaveBeenCalledWith(false);
|
||||
expectAction(sqlEditorSpy.disable_tool_buttons, false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('query was successful but had no result to display', () => {
|
||||
beforeEach(() => {
|
||||
queryResult = {
|
||||
rows_affected: 10,
|
||||
has_more_rows: false,
|
||||
colinfo: undefined,
|
||||
result: 'Some result',
|
||||
};
|
||||
});
|
||||
beforeEach(queryResult2);
|
||||
|
||||
it('saves execution information in the history', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.update_msg_history).toHaveBeenCalledWith(
|
||||
true,
|
||||
'Some result\n\nQuery returned successfully in 0 msec.',
|
||||
false
|
||||
);
|
||||
saveAction();
|
||||
});
|
||||
|
||||
it('resets the changed data store', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.reset_data_store).toHaveBeenCalled();
|
||||
expectAction(sqlEditorSpy.reset_data_store);
|
||||
});
|
||||
|
||||
it('inform sqleditor that the query stopped running', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.setIsQueryRunning).toHaveBeenCalledWith(false);
|
||||
expectAction(sqlEditorSpy.setIsQueryRunning, false);
|
||||
});
|
||||
|
||||
it('hides the loading icon', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.trigger).toHaveBeenCalledWith('pgadmin-sqleditor:loading-icon:hide');
|
||||
expectAction(sqlEditorSpy.trigger, 'pgadmin-sqleditor:loading-icon:hide');
|
||||
});
|
||||
|
||||
it('enables sqleditor tools buttons', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.disable_tool_buttons).toHaveBeenCalledWith(false);
|
||||
expectAction(sqlEditorSpy.disable_tool_buttons, false);
|
||||
});
|
||||
|
||||
describe('notifications are enabled', () => {
|
||||
it('display notification', () => {
|
||||
sqlEditorSpy.info_notifier_timeout = 10;
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(Notify.success).toHaveBeenCalledWith(
|
||||
'Query returned successfully in 0 msec.',
|
||||
10
|
||||
);
|
||||
});
|
||||
it('display notification', displayNotificationAction);
|
||||
});
|
||||
|
||||
it('disables the save results button', () => {
|
||||
callRenderAfterPoll(sqlEditorSpy, Notify, queryResult);
|
||||
|
||||
expect(sqlEditorSpy.enable_disable_download_btn).toHaveBeenCalledWith(true);
|
||||
expectAction(sqlEditorSpy.enable_disable_download_btn, true);
|
||||
|
||||
expect(sqlEditorSpy.trigger).toHaveBeenCalledWith('pgadmin-sqleditor:loading-icon:hide');
|
||||
});
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -149,6 +149,35 @@ describe('the keyboard shortcuts', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
let doesNothingTestCase = ()=> {
|
||||
it('does nothing', () => {
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
|
||||
expect(queryToolActionsSpy.commentLineCode).not.toHaveBeenCalled();
|
||||
});
|
||||
};
|
||||
|
||||
let beforeEachWindows = ()=> {
|
||||
windowsKeysSetup();
|
||||
event.which = FWD_SLASH_KEY;
|
||||
event.shiftKey = true;
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
};
|
||||
|
||||
let beforeEachMAC = ()=> {
|
||||
macKeysSetup();
|
||||
event.which = FWD_SLASH_KEY;
|
||||
event.shiftKey = true;
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
describe('when the key is not handled by the function', function () {
|
||||
|
||||
beforeEach(() => {
|
||||
@ -395,13 +424,7 @@ describe('the keyboard shortcuts', () => {
|
||||
event.which = FWD_SLASH_KEY;
|
||||
});
|
||||
|
||||
it('does nothing', () => {
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
|
||||
expect(queryToolActionsSpy.commentLineCode).not.toHaveBeenCalled();
|
||||
});
|
||||
doesNothingTestCase();
|
||||
});
|
||||
|
||||
describe('and the system is a Windows', () => {
|
||||
@ -410,13 +433,7 @@ describe('the keyboard shortcuts', () => {
|
||||
event.which = FWD_SLASH_KEY;
|
||||
});
|
||||
|
||||
it('does nothing', () => {
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
|
||||
expect(queryToolActionsSpy.commentLineCode).not.toHaveBeenCalled();
|
||||
});
|
||||
doesNothingTestCase();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -465,12 +482,7 @@ describe('the keyboard shortcuts', () => {
|
||||
event.which = PERIOD_KEY;
|
||||
});
|
||||
|
||||
it('does nothing', () => {
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
expect(queryToolActionsSpy.uncommentLineCode).not.toHaveBeenCalled();
|
||||
});
|
||||
doesNothingTestCase();
|
||||
});
|
||||
describe('and the system is a Windows', () => {
|
||||
beforeEach(() => {
|
||||
@ -478,13 +490,7 @@ describe('the keyboard shortcuts', () => {
|
||||
event.which = PERIOD_KEY;
|
||||
});
|
||||
|
||||
it('does nothing', () => {
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
|
||||
expect(queryToolActionsSpy.uncommentLineCode).not.toHaveBeenCalled();
|
||||
});
|
||||
doesNothingTestCase();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -492,14 +498,7 @@ describe('the keyboard shortcuts', () => {
|
||||
describe('blockComment', () => {
|
||||
describe('when there is not a query already running', () => {
|
||||
describe('and the system is a Mac', () => {
|
||||
beforeEach(() => {
|
||||
macKeysSetup();
|
||||
event.which = FWD_SLASH_KEY;
|
||||
event.shiftKey = true;
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
});
|
||||
beforeEach(beforeEachMAC);
|
||||
|
||||
it('should comment out the block selection', () => {
|
||||
expect(queryToolActionsSpy.commentBlockCode).toHaveBeenCalledWith(sqlEditorControllerSpy);
|
||||
@ -511,14 +510,7 @@ describe('the keyboard shortcuts', () => {
|
||||
|
||||
describe('when there is not a query already running', () => {
|
||||
describe('and the system is a Windows', () => {
|
||||
beforeEach(() => {
|
||||
windowsKeysSetup();
|
||||
event.which = FWD_SLASH_KEY;
|
||||
event.shiftKey = true;
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
});
|
||||
beforeEach(beforeEachWindows);
|
||||
|
||||
it('should comment out the block selection', () => {
|
||||
expect(queryToolActionsSpy.commentBlockCode).toHaveBeenCalledWith(sqlEditorControllerSpy);
|
||||
@ -533,27 +525,13 @@ describe('the keyboard shortcuts', () => {
|
||||
sqlEditorControllerSpy.isQueryRunning.and.returnValue(true);
|
||||
});
|
||||
describe('and the system is a Mac', () => {
|
||||
beforeEach(() => {
|
||||
macKeysSetup();
|
||||
event.which = FWD_SLASH_KEY;
|
||||
event.shiftKey = true;
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
});
|
||||
beforeEach(beforeEachMAC);
|
||||
it('does nothing', () => {
|
||||
expect(queryToolActionsSpy.commentBlockCode).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
describe('and the system is a Windows', () => {
|
||||
beforeEach(() => {
|
||||
windowsKeysSetup();
|
||||
event.which = FWD_SLASH_KEY;
|
||||
event.shiftKey = true;
|
||||
keyboardShortcuts.processEventQueryTool(
|
||||
sqlEditorControllerSpy, queryToolActionsSpy, event
|
||||
);
|
||||
});
|
||||
beforeEach(beforeEachWindows);
|
||||
it('does nothing', () => {
|
||||
expect(queryToolActionsSpy.commentBlockCode).not.toHaveBeenCalled();
|
||||
});
|
||||
|
@ -14,6 +14,27 @@ describe('queryToolActions', () => {
|
||||
selectedQueryString, entireQueryString,
|
||||
replaceSelectionSpy;
|
||||
|
||||
let executeFunctionCall = ()=>{
|
||||
queryToolActions.executeQuery(sqlEditorController);
|
||||
expect(sqlEditorController.check_data_changes_to_execute_query).toHaveBeenCalled();
|
||||
};
|
||||
|
||||
let toggleSelectionStringUpperCase = ()=> {
|
||||
it('toggle the selection and string should be in upper case', () => {
|
||||
queryToolActions.toggleCaseOfSelectedText(sqlEditorController);
|
||||
expect(replaceSelectionSpy
|
||||
).toHaveBeenCalledWith('STRING');
|
||||
});
|
||||
};
|
||||
|
||||
let beforeEachEmptySelection = ()=> {
|
||||
setUpSpies('', 'a string\nddd\nsss');
|
||||
|
||||
sqlEditorController.gridView.query_tool_obj.getCursor = () => {
|
||||
return 3;
|
||||
};
|
||||
};
|
||||
|
||||
describe('executeQuery', () => {
|
||||
describe('when the command is being run from the query tool', () => {
|
||||
beforeEach(() => {
|
||||
@ -27,11 +48,7 @@ describe('queryToolActions', () => {
|
||||
expect(queryToolActions._clearMessageTab).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls the execute function on the sqlEditorController', () => {
|
||||
queryToolActions.executeQuery(sqlEditorController);
|
||||
|
||||
expect(sqlEditorController.check_data_changes_to_execute_query).toHaveBeenCalled();
|
||||
});
|
||||
it('calls the execute function on the sqlEditorController', executeFunctionCall);
|
||||
});
|
||||
describe('when the command is being run from the view data view', () => {
|
||||
beforeEach(() => {
|
||||
@ -39,11 +56,7 @@ describe('queryToolActions', () => {
|
||||
sqlEditorController.is_query_tool = false;
|
||||
});
|
||||
|
||||
it('it calls the check_data_changes_to_execute_query function on the sqlEditorController', () => {
|
||||
queryToolActions.executeQuery(sqlEditorController);
|
||||
|
||||
expect(sqlEditorController.check_data_changes_to_execute_query).toHaveBeenCalled();
|
||||
});
|
||||
it('it calls the check_data_changes_to_execute_query function on the sqlEditorController', executeFunctionCall);
|
||||
});
|
||||
});
|
||||
|
||||
@ -279,29 +292,34 @@ describe('queryToolActions', () => {
|
||||
});
|
||||
|
||||
describe('when the table was opened through the queryTool', () => {
|
||||
describe('when the query tool object has a selection', () => {
|
||||
let time;
|
||||
let time;
|
||||
let spyCall = ()=> {
|
||||
time = 'rightNow';
|
||||
spyOn(window, 'Date').and.callFake(() => ({
|
||||
getTime: () => {
|
||||
return time;
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
let callCSVDownload = ()=> {
|
||||
let filename = 'data-' + time + '.csv';
|
||||
|
||||
queryToolActions.download(sqlEditorController);
|
||||
|
||||
expect(sqlEditorController.trigger_csv_download).toHaveBeenCalledWith(filename);
|
||||
};
|
||||
|
||||
describe('when the query tool object has a selection', () => {
|
||||
beforeEach(() => {
|
||||
entireQueryString = 'include some more of that yummy string cheese;';
|
||||
selectedQueryString = 'some silly string cheese';
|
||||
setUpSpies(selectedQueryString, entireQueryString);
|
||||
|
||||
time = 'rightNow';
|
||||
spyOn(window, 'Date').and.callFake(() => ({
|
||||
getTime: () => {
|
||||
return time;
|
||||
},
|
||||
}));
|
||||
spyCall();
|
||||
});
|
||||
|
||||
it('calls trigger_csv_download with filename having .csv extension', () => {
|
||||
let filename = 'data-' + time + '.csv';
|
||||
|
||||
queryToolActions.download(sqlEditorController);
|
||||
|
||||
expect(sqlEditorController.trigger_csv_download).toHaveBeenCalledWith(filename);
|
||||
});
|
||||
it('calls trigger_csv_download with filename having .csv extension', callCSVDownload);
|
||||
|
||||
it('calls trigger_csv_download filename having .txt extension', () => {
|
||||
sqlEditorController.preferences.csv_field_separator = ';';
|
||||
@ -314,29 +332,14 @@ describe('queryToolActions', () => {
|
||||
});
|
||||
|
||||
describe('when there is no selection', () => {
|
||||
let time;
|
||||
|
||||
beforeEach(() => {
|
||||
selectedQueryString = '';
|
||||
entireQueryString = 'include some more of that yummy string cheese;';
|
||||
|
||||
setUpSpies(selectedQueryString, entireQueryString);
|
||||
|
||||
time = 'rightNow';
|
||||
spyOn(window, 'Date').and.callFake(() => ({
|
||||
getTime: () => {
|
||||
return time;
|
||||
},
|
||||
}));
|
||||
spyCall();
|
||||
});
|
||||
|
||||
it('calls trigger_csv_download with filename', () => {
|
||||
let filename = 'data-' + time + '.csv';
|
||||
|
||||
queryToolActions.download(sqlEditorController);
|
||||
|
||||
expect(sqlEditorController.trigger_csv_download).toHaveBeenCalledWith(filename);
|
||||
});
|
||||
it('calls trigger_csv_download with filename', callCSVDownload);
|
||||
});
|
||||
});
|
||||
|
||||
@ -369,13 +372,7 @@ describe('queryToolActions', () => {
|
||||
});
|
||||
|
||||
describe('when there is empty selection', () => {
|
||||
beforeEach(() => {
|
||||
setUpSpies('', 'a string\nddd\nsss');
|
||||
|
||||
sqlEditorController.gridView.query_tool_obj.getCursor = () => {
|
||||
return 3;
|
||||
};
|
||||
});
|
||||
beforeEach(beforeEachEmptySelection);
|
||||
|
||||
it('comments the current line', () => {
|
||||
let codeMirrorObj = sqlEditorController.gridView.query_tool_obj;
|
||||
@ -416,13 +413,7 @@ describe('queryToolActions', () => {
|
||||
});
|
||||
|
||||
describe('when there is empty selection', () => {
|
||||
beforeEach(() => {
|
||||
setUpSpies('', 'a string\nddd\nsss');
|
||||
|
||||
sqlEditorController.gridView.query_tool_obj.getCursor = () => {
|
||||
return 3;
|
||||
};
|
||||
});
|
||||
beforeEach(beforeEachEmptySelection);
|
||||
|
||||
it('comments the current line', () => {
|
||||
let codeMirrorObj = sqlEditorController.gridView.query_tool_obj;
|
||||
@ -463,13 +454,7 @@ describe('queryToolActions', () => {
|
||||
});
|
||||
|
||||
describe('when there is empty selection', () => {
|
||||
beforeEach(() => {
|
||||
setUpSpies('', 'a string\nddd\nsss');
|
||||
|
||||
sqlEditorController.gridView.query_tool_obj.getCursor = () => {
|
||||
return 3;
|
||||
};
|
||||
});
|
||||
beforeEach(beforeEachEmptySelection);
|
||||
|
||||
it('uncomments the current line', () => {
|
||||
let codeMirrorObj = sqlEditorController.gridView.query_tool_obj;
|
||||
@ -496,31 +481,26 @@ describe('queryToolActions', () => {
|
||||
});
|
||||
|
||||
describe('toggleCaseOfSelectedText', () => {
|
||||
|
||||
let doesNothingTestCase = ()=> {
|
||||
it('does nothing', () => {
|
||||
expect(
|
||||
queryToolActions.toggleCaseOfSelectedText(sqlEditorController)
|
||||
).not.toBeDefined();
|
||||
});
|
||||
};
|
||||
|
||||
describe('when there is no query text', () => {
|
||||
beforeEach(() => {
|
||||
setUpSpies('', '');
|
||||
});
|
||||
it('does nothing', () => {
|
||||
expect(
|
||||
queryToolActions.toggleCaseOfSelectedText(sqlEditorController)
|
||||
).not.toBeDefined();
|
||||
});
|
||||
doesNothingTestCase();
|
||||
});
|
||||
|
||||
describe('when there is empty selection', () => {
|
||||
beforeEach(() => {
|
||||
setUpSpies('', 'a string\nddd\nsss');
|
||||
beforeEach(beforeEachEmptySelection);
|
||||
|
||||
sqlEditorController.gridView.query_tool_obj.getCursor = () => {
|
||||
return 3;
|
||||
};
|
||||
});
|
||||
|
||||
it('does nothing', () => {
|
||||
expect(
|
||||
queryToolActions.toggleCaseOfSelectedText(sqlEditorController)
|
||||
).not.toBeDefined();
|
||||
});
|
||||
doesNothingTestCase();
|
||||
});
|
||||
|
||||
describe('when selected query is in lower case', () => {
|
||||
@ -528,11 +508,7 @@ describe('queryToolActions', () => {
|
||||
setUpSpies('string', 'a string\nddd\nsss');
|
||||
});
|
||||
|
||||
it('toggle the selection and string should be in upper case', () => {
|
||||
queryToolActions.toggleCaseOfSelectedText(sqlEditorController);
|
||||
expect(replaceSelectionSpy
|
||||
).toHaveBeenCalledWith('STRING');
|
||||
});
|
||||
toggleSelectionStringUpperCase();
|
||||
|
||||
it('(negative scenario toggle the selection and string should be in upper case', () => {
|
||||
queryToolActions.toggleCaseOfSelectedText(sqlEditorController);
|
||||
@ -564,11 +540,7 @@ describe('queryToolActions', () => {
|
||||
setUpSpies('sTRIng', 'a string\nddd\nsss');
|
||||
});
|
||||
|
||||
it('toggle the selection and string should be in upper case', () => {
|
||||
queryToolActions.toggleCaseOfSelectedText(sqlEditorController);
|
||||
expect(replaceSelectionSpy
|
||||
).toHaveBeenCalledWith('STRING');
|
||||
});
|
||||
toggleSelectionStringUpperCase();
|
||||
|
||||
it('(negative scenario toggle the selection and string should be in upper case', () => {
|
||||
queryToolActions.toggleCaseOfSelectedText(sqlEditorController);
|
||||
|
@ -16,6 +16,15 @@ import {
|
||||
import {TreeFake} from '../tree/tree_fake';
|
||||
import {TreeNode} from '../../../pgadmin/static/js/tree/tree_nodes';
|
||||
|
||||
let beforeEachResponseError = (networkMock)=> {
|
||||
networkMock.onPut(/.*/).reply(() => {
|
||||
return [500, {
|
||||
success: 0,
|
||||
errormsg: 'some error message',
|
||||
}];
|
||||
});
|
||||
};
|
||||
|
||||
describe('#enableTriggers', () => {
|
||||
let networkMock;
|
||||
let tree;
|
||||
@ -120,12 +129,7 @@ describe('#enableTriggers', () => {
|
||||
|
||||
describe('backend responds with error', () => {
|
||||
beforeEach(() => {
|
||||
networkMock.onPut(/.*/).reply(() => {
|
||||
return [500, {
|
||||
success: 0,
|
||||
errormsg: 'some error message',
|
||||
}];
|
||||
});
|
||||
beforeEachResponseError(networkMock);
|
||||
});
|
||||
|
||||
it('displays an error alert', (done) => {
|
||||
@ -254,12 +258,7 @@ describe('#disableTriggers', () => {
|
||||
|
||||
describe('backend responds with error', () => {
|
||||
beforeEach(() => {
|
||||
networkMock.onPut(/.*/).reply(() => {
|
||||
return [500, {
|
||||
success: 0,
|
||||
errormsg: 'some error message',
|
||||
}];
|
||||
});
|
||||
beforeEachResponseError(networkMock);
|
||||
});
|
||||
|
||||
it('displays an error alert', (done) => {
|
||||
|
Loading…
Reference in New Issue
Block a user