mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
- Improve the UI - Allow copy/paste from sets of rows, columns or arbitrary blocks of cells Patch by Matt, Shruti, Joao and Sarah @ Pivotal Fixes #2476
140 lines
4.4 KiB
JavaScript
140 lines
4.4 KiB
JavaScript
/////////////////////////////////////////////////////////////
|
|
//
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
//
|
|
// Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
|
// This software is released under the PostgreSQL Licence
|
|
//
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
define(
|
|
["jquery",
|
|
"slickgrid/slick.grid",
|
|
"sources/selection/xcell_selection_model",
|
|
"sources/selection/copy_data",
|
|
"sources/selection/clipboard",
|
|
"sources/selection/range_selection_helper"
|
|
],
|
|
function ($, SlickGrid, XCellSelectionModel, copyData, clipboard, RangeSelectionHelper) {
|
|
describe('copyData', function () {
|
|
var grid, sqlEditor, gridContainer, buttonPasteRow;
|
|
|
|
beforeEach(function () {
|
|
var data = [[1, "leopord", "12"],
|
|
[2, "lion", "13"],
|
|
[3, "puma", "9"]];
|
|
|
|
var columns = [
|
|
{
|
|
id: 'row-header-column',
|
|
name: 'row header column name',
|
|
selectable: false,
|
|
display_name: 'row header column name',
|
|
column_type: 'text'
|
|
},
|
|
{
|
|
name: "id",
|
|
pos: 0,
|
|
label: "id<br> numeric",
|
|
cell: "number",
|
|
can_edit: false,
|
|
type: "numeric"
|
|
}, {
|
|
name: "brand",
|
|
pos: 1,
|
|
label: "flavor<br> character varying",
|
|
cell: "string",
|
|
can_edit: false,
|
|
type: "character varying"
|
|
}, {
|
|
name: "size",
|
|
pos: 2,
|
|
label: "size<br> numeric",
|
|
cell: "number",
|
|
can_edit: false,
|
|
type: "numeric"
|
|
}
|
|
]
|
|
;
|
|
gridContainer = $("<div id='grid'></div>");
|
|
$("body").append(gridContainer);
|
|
buttonPasteRow = $("<button id='btn-paste-row' disabled></button>");
|
|
$("body").append(buttonPasteRow);
|
|
grid = new Slick.Grid("#grid", data, columns, {});
|
|
grid.setSelectionModel(new XCellSelectionModel());
|
|
sqlEditor = {slickgrid: grid};
|
|
});
|
|
|
|
afterEach(function() {
|
|
gridContainer.remove();
|
|
buttonPasteRow.remove();
|
|
});
|
|
|
|
describe("when rows are selected", function () {
|
|
beforeEach(function () {
|
|
grid.getSelectionModel().setSelectedRanges([
|
|
RangeSelectionHelper.rangeForRow(grid, 0),
|
|
RangeSelectionHelper.rangeForRow(grid, 2)]
|
|
);
|
|
});
|
|
|
|
it("copies them", function () {
|
|
spyOn(clipboard, 'copyTextToClipboard');
|
|
|
|
copyData.apply(sqlEditor);
|
|
|
|
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'");
|
|
});
|
|
|
|
describe("when the user can edit the grid", function () {
|
|
it("enables the paste row button", function () {
|
|
copyData.apply(_.extend({can_edit: true}, sqlEditor));
|
|
|
|
expect($("#btn-paste-row").prop('disabled')).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("when a column is selected", function () {
|
|
beforeEach(function () {
|
|
var firstDataColumn = RangeSelectionHelper.rangeForColumn(grid, 1);
|
|
grid.getSelectionModel().setSelectedRanges([firstDataColumn])
|
|
});
|
|
|
|
it("copies text to the clipboard", function () {
|
|
spyOn(clipboard, 'copyTextToClipboard');
|
|
|
|
copyData.apply(sqlEditor);
|
|
|
|
expect(clipboard.copyTextToClipboard).toHaveBeenCalled();
|
|
|
|
var copyArg = clipboard.copyTextToClipboard.calls.mostRecent().args[0];
|
|
var rowStrings = copyArg.split('\n');
|
|
expect(rowStrings[0]).toBe("1");
|
|
expect(rowStrings[1]).toBe("2");
|
|
expect(rowStrings[2]).toBe("3");
|
|
});
|
|
|
|
it("sets copied_rows to empty", function () {
|
|
copyData.apply(sqlEditor);
|
|
|
|
expect(sqlEditor.copied_rows.length).toBe(0);
|
|
});
|
|
|
|
describe("when the user can edit the grid", function () {
|
|
beforeEach(function () {
|
|
copyData.apply(_.extend({can_edit: true}, sqlEditor));
|
|
});
|
|
|
|
it("disables the paste row button", function () {
|
|
expect($("#btn-paste-row").prop('disabled')).toBe(true);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|