Bring React into the tree, and add linting and bundling framework for the JS etc.

This commit is contained in:
Shruti B Iyer
2017-06-12 16:51:54 +01:00
committed by Dave Page
parent af43ccfc07
commit 659eb1c1e8
32 changed files with 6680 additions and 1840 deletions

View File

@@ -1,139 +1,142 @@
/////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// 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;
import $ from 'jquery';
beforeEach(function () {
var data = [[1, "leopord", "12"],
[2, "lion", "13"],
[3, "puma", "9"]];
import Slick from 'slickgrid';
import 'slickgrid.grid';
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};
});
import clipboard from '../../../pgadmin/static/js/selection/clipboard';
import copyData from '../../../pgadmin/static/js/selection/copy_data';
import RangeSelectionHelper from 'sources/selection/range_selection_helper';
import XCellSelectionModel from 'sources/selection/xcell_selection_model';
afterEach(function() {
gridContainer.remove();
buttonPasteRow.remove();
});
describe('copyData', function () {
var grid, sqlEditor, gridContainer, buttonPasteRow;
var Slick, SlickGrid;
describe("when rows are selected", function () {
beforeEach(function () {
grid.getSelectionModel().setSelectedRanges([
RangeSelectionHelper.rangeForRow(grid, 0),
RangeSelectionHelper.rangeForRow(grid, 2)]
);
});
beforeEach(function () {
Slick = window.Slick;
SlickGrid = Slick.Grid;
var data = [[1, 'leopord', '12'],
[2, 'lion', '13'],
[3, 'puma', '9']];
it("copies them", function () {
spyOn(clipboard, 'copyTextToClipboard');
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};
});
copyData.apply(sqlEditor);
afterEach(function () {
gridContainer.remove();
buttonPasteRow.remove();
});
expect(sqlEditor.copied_rows.length).toBe(2);
describe('when rows are selected', function () {
beforeEach(function () {
grid.getSelectionModel().setSelectedRanges([
RangeSelectionHelper.rangeForRow(grid, 0),
RangeSelectionHelper.rangeForRow(grid, 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'");
});
it('copies them', function () {
spyOn(clipboard, 'copyTextToClipboard');
describe("when the user can edit the grid", function () {
it("enables the paste row button", function () {
copyData.apply(_.extend({can_edit: true}, sqlEditor));
copyData.apply(sqlEditor);
expect($("#btn-paste-row").prop('disabled')).toBe(false);
});
});
});
expect(sqlEditor.copied_rows.length).toBe(2);
describe("when a column is selected", function () {
beforeEach(function () {
var firstDataColumn = RangeSelectionHelper.rangeForColumn(grid, 1);
grid.getSelectionModel().setSelectedRanges([firstDataColumn])
});
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\'');
});
it("copies text to the clipboard", function () {
spyOn(clipboard, 'copyTextToClipboard');
describe('when the user can edit the grid', function () {
it('enables the paste row button', function () {
copyData.apply(_.extend({can_edit: true}, sqlEditor));
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);
});
});
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);
});
});
});
});