mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Allow configuration of CSV and clipboard formatting of query results. Fixes #2781
This commit is contained in:
committed by
Dave Page
parent
2579458091
commit
0c566f132e
@@ -22,11 +22,12 @@ describe('copyData', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
SlickGrid = Slick.Grid;
|
||||
var data = [{'id': 1, 'brand':'leopord', 'size':'12', '__temp_PK': '123'},
|
||||
{'id': 2, 'brand':'lion', 'size':'13', '__temp_PK': '456'},
|
||||
{'id': 3, 'brand':'puma', 'size':'9', '__temp_PK': '789'}],
|
||||
var data = [{'id': 1, 'brand':'leopord', 'size':12, '__temp_PK': '123'},
|
||||
{'id': 2, 'brand':'lion', 'size':13, '__temp_PK': '456'},
|
||||
{'id': 3, 'brand':'puma', 'size':9, '__temp_PK': '789'}],
|
||||
dataView = new Slick.Data.DataView();
|
||||
|
||||
var CSVOptions = {'quoting': 'strings', 'quote_char': '"', 'field_separator': ','};
|
||||
var columns = [
|
||||
{
|
||||
id: 'row-header-column',
|
||||
@@ -66,6 +67,7 @@ describe('copyData', function () {
|
||||
buttonPasteRow = $('<button id="btn-paste-row" disabled></button>');
|
||||
$('body').append(buttonPasteRow);
|
||||
grid = new SlickGrid('#grid', dataView, columns, {});
|
||||
grid.CSVOptions = CSVOptions;
|
||||
dataView.setItems(data, '__temp_PK');
|
||||
grid.setSelectionModel(new XCellSelectionModel());
|
||||
sqlEditor = {slickgrid: grid};
|
||||
@@ -93,8 +95,8 @@ describe('copyData', function () {
|
||||
expect(sqlEditor.copied_rows.length).toBe(2);
|
||||
|
||||
expect(clipboard.copyTextToClipboard).toHaveBeenCalled();
|
||||
expect(clipboard.copyTextToClipboard.calls.mostRecent().args[0]).toContain('1,\'leopord\',\'12\'');
|
||||
expect(clipboard.copyTextToClipboard.calls.mostRecent().args[0]).toContain('3,\'puma\',\'9\'');
|
||||
expect(clipboard.copyTextToClipboard.calls.mostRecent().args[0]).toContain('1,"leopord",12');
|
||||
expect(clipboard.copyTextToClipboard.calls.mostRecent().args[0]).toContain('3,"puma",9');
|
||||
});
|
||||
|
||||
describe('when the user can edit the grid', function () {
|
||||
|
||||
@@ -132,7 +132,7 @@ describe('RangeBoundaryNavigator', function () {
|
||||
});
|
||||
|
||||
describe('#rangesToCsv', function () {
|
||||
var data, columnDefinitions, ranges;
|
||||
var data, columnDefinitions, ranges, CSVOptions;
|
||||
beforeEach(function () {
|
||||
data = [{'id':1, 'animal':'leopard', 'size':'12'},
|
||||
{'id':2, 'animal':'lion', 'size':'13'},
|
||||
@@ -143,16 +143,21 @@ describe('RangeBoundaryNavigator', function () {
|
||||
{name: 'animal', field: 'animal', pos: 1},
|
||||
{name: 'size', field: 'size', pos: 2}];
|
||||
ranges = [new Slick.Range(0, 0, 0, 2), new Slick.Range(3, 0, 3, 2)];
|
||||
|
||||
CSVOptions = [{'quoting': 'all', 'quote_char': '"', 'field_separator': ','},
|
||||
{'quoting': 'strings', 'quote_char': '"', 'field_separator': ';'},
|
||||
{'quoting': 'strings', 'quote_char': '\'', 'field_separator': '|'},
|
||||
{'quoting': 'none', 'quote_char': '"', 'field_separator': '\t'}];
|
||||
});
|
||||
|
||||
it('returns csv for the provided ranges', function () {
|
||||
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, ranges);
|
||||
expect(csvResult).toEqual('1,\'leopard\',\'12\'\n4,\'tiger\',\'10\'');
|
||||
it('returns csv for the provided ranges for CSV options quoting All with char " with field separator ,', function () {
|
||||
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, ranges, CSVOptions[0]);
|
||||
expect(csvResult).toEqual('"1","leopard","12"\n"4","tiger","10"');
|
||||
});
|
||||
|
||||
describe('when no cells are selected', function () {
|
||||
describe('when no cells are selected for CSV options quoting Strings with char " with field separator ;', function () {
|
||||
it('should return an empty string', function () {
|
||||
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, []);
|
||||
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, [], CSVOptions[1]);
|
||||
|
||||
expect(csvResult).toEqual('');
|
||||
});
|
||||
@@ -167,14 +172,14 @@ describe('RangeBoundaryNavigator', function () {
|
||||
ranges = [new Slick.Range(0, 0, 0, 3), new Slick.Range(3, 0, 3, 3)];
|
||||
});
|
||||
|
||||
it('returns csv for the columns with data', function () {
|
||||
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, ranges);
|
||||
it('returns csv for the columns with data for CSV options quoting Strings with char \' with field separator |', function () {
|
||||
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, ranges, CSVOptions[2]);
|
||||
|
||||
expect(csvResult).toEqual('1,\'leopard\',\'12\'\n4,\'tiger\',\'10\'');
|
||||
expect(csvResult).toEqual('1|\'leopard\'|\'12\'\n4|\'tiger\'|\'10\'');
|
||||
});
|
||||
describe('when no cells are selected', function () {
|
||||
describe('when no cells are selected for CSV options quoting none with field separator tab', function () {
|
||||
it('should return an empty string', function () {
|
||||
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, []);
|
||||
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, [], CSVOptions[3]);
|
||||
|
||||
expect(csvResult).toEqual('');
|
||||
});
|
||||
|
||||
@@ -36,10 +36,12 @@ describe('#handleQueryOutputKeyboardEvent', function () {
|
||||
columnDefinitions = [{name: 'checkboxColumn'},
|
||||
{pos: 1, name: 'firstColumn', field: 'firstColumn'},
|
||||
{ pos: 2, name: 'secondColumn', field: 'secondColumn'}],
|
||||
dataView = new Slick.Data.DataView();
|
||||
dataView = new Slick.Data.DataView(),
|
||||
CSVOptions = {'quoting': 'all', 'quote_char': '\'', 'field_separator': ','};
|
||||
|
||||
grid = new Slick.Grid($('<div></div>'), dataView, columnDefinitions);
|
||||
grid.setSelectionModel(new XCellSelectionModel());
|
||||
grid.CSVOptions = CSVOptions;
|
||||
dataView.setItems(data, '__temp_PK');
|
||||
slickEvent = {
|
||||
grid: grid,
|
||||
|
||||
Reference in New Issue
Block a user