Add linting support, and, well, lint.

REL-1_X
Shruti B Iyer 2017-06-12 16:55:14 +01:00 committed by Dave Page
parent 659eb1c1e8
commit 3f4f8b9e77
31 changed files with 429 additions and 405 deletions

45
web/.eslintrc.js Normal file
View File

@ -0,0 +1,45 @@
module.exports = {
'env': {
'browser': true,
'es6': true,
'amd': true,
'jasmine': true,
},
'extends': 'eslint:recommended',
'parserOptions': {
'ecmaFeatures': {
'experimentalObjectRestSpread': true,
'jsx': true
},
'sourceType': 'module'
},
'plugins': [
'react'
],
'globals': {
'_': true,
'module': true,
},
'rules': {
'indent': [
'error',
2
],
'linebreak-style': [
'error',
'unix'
],
'quotes': [
'error',
'single'
],
'semi': [
'error',
'always'
],
'comma-dangle': [
'error',
'always-multiline'
]
}
};

View File

@ -22,7 +22,7 @@ module.exports = function (config) {
// list of files to exclude
exclude: [
'pgadmin/static/vendor/**/*[Tt]est.js',
'pgadmin/static/vendor/**/*[Ss]pec.js'
'pgadmin/static/vendor/**/*[Ss]pec.js',
],
// preprocess matching files before serving them to the browser
@ -62,6 +62,6 @@ module.exports = function (config) {
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
concurrency: Infinity,
});
};

View File

@ -5,6 +5,8 @@
"babel-preset-es2015": "~6.24.0",
"babel-preset-react": "~6.23.0",
"enzyme": "~2.8.2",
"eslint": "^3.19.0",
"eslint-plugin-react": "^6.10.3",
"jasmine-core": "~2.5.2",
"karma": "~1.5.0",
"karma-babel-preprocessor": "^6.0.1",
@ -34,9 +36,11 @@
"watchify": "~3.9.0"
},
"scripts": {
"bundle": "yarn run webpack -- --optimize-minimize --config webpack.config.js",
"test:karma-once": "yarn run karma start -- --single-run",
"test:karma": "yarn run karma start",
"linter": "yarn run eslint pgadmin/static/jsx/**/*.jsx pgadmin/static/js/selection/*.js regression/javascript/**/*.jsx regression/javascript/**/*.js *.js",
"webpacker": "yarn run webpack -- --optimize-minimize --config webpack.config.js",
"bundle": "yarn run linter && yarn run webpacker",
"test:karma-once": "yarn run linter && yarn run karma start -- --single-run",
"test:karma": "yarn run linter && yarn run karma start",
"test:feature": "yarn run bundle && python regression/runtests.py --pkg feature_tests",
"test": "yarn run test:karma-once && yarn run bundle && python regression/runtests.py"
}

View File

@ -1,6 +1,6 @@
define([
'jquery',
'sources/selection/range_selection_helper'
'sources/selection/range_selection_helper',
], function ($, RangeSelectionHelper) {
var ActiveCellCapture = function () {
@ -37,8 +37,8 @@ define([
};
$.extend(this, {
"init": init,
"destroy": destroy,
'init': init,
'destroy': destroy,
});
function onDragEndHandler(event, dragData) {
@ -105,7 +105,7 @@ define([
}
}
function onActiveCellChangedHandler(event, args) {
function onActiveCellChangedHandler(event) {
if (bypassDefaultActiveCellRangeChange) {
bypassDefaultActiveCellRangeChange = false;
event.stopPropagation();
@ -188,4 +188,4 @@ define([
};
return ActiveCellCapture;
});
});

View File

@ -1,7 +1,7 @@
define(['sources/gettext', 'alertify'], function (gettext, alertify) {
var clipboard = {
copyTextToClipboard: function (text) {
var textArea = document.createElement("textarea");
var textArea = document.createElement('textarea');
//
// *** This styling is an extra step which is likely not required. ***
@ -55,7 +55,7 @@ define(['sources/gettext', 'alertify'], function (gettext, alertify) {
}
document.body.removeChild(textArea);
}
},
};
return clipboard;
});

View File

@ -1,7 +1,7 @@
define([
'jquery',
'sources/selection/range_selection_helper',
'slickgrid'
'slickgrid',
], function ($, RangeSelectionHelper) {
var ColumnSelector = function () {
var Slick = window.Slick;
@ -21,7 +21,7 @@ define([
if (isColumnSelectable(columnDefinition)) {
var $columnHeader = $(event.target);
if (hasClickedChildOfColumnHeader(event)) {
$columnHeader = $(event.target).parents(".slick-header-column");
$columnHeader = $(event.target).parents('.slick-header-column');
}
$columnHeader.toggleClass('selected');
@ -63,7 +63,7 @@ define([
};
var hasClickedChildOfColumnHeader = function (event) {
return !$(event.target).hasClass("slick-header-column");
return !$(event.target).hasClass('slick-header-column');
};
var isColumnSelectable = function (columnDefinition) {
@ -87,16 +87,16 @@ define([
return _.map(columnDefinitions, function (columnDefinition) {
if (isColumnSelectable(columnDefinition)) {
var name =
"<span data-cell-type='column-header-row' " +
" data-test='output-column-header'" +
" data-column-id='" + columnDefinition.id + "'>" +
" <span class='column-description'>" +
" <span class='column-name'>" + columnDefinition.display_name + "</span>" +
" <span class='column-type'>" + columnDefinition.column_type + "</span>" +
" </span>" +
"</span>";
'<span data-cell-type=\'column-header-row\' ' +
' data-test=\'output-column-header\'' +
' data-column-id=\'' + columnDefinition.id + '\'>' +
' <span class=\'column-description\'>' +
' <span class=\'column-name\'>' + columnDefinition.display_name + '</span>' +
' <span class=\'column-type\'>' + columnDefinition.column_type + '</span>' +
' </span>' +
'</span>';
return _.extend(columnDefinition, {
name: name
name: name,
});
} else {
return columnDefinition;
@ -105,8 +105,8 @@ define([
};
$.extend(this, {
"init": init,
"getColumnDefinitions": getColumnDefinitions
'init': init,
'getColumnDefinitions': getColumnDefinitions,
});
};
return ColumnSelector;

View File

@ -3,8 +3,8 @@ define([
'underscore',
'sources/selection/clipboard',
'sources/selection/range_selection_helper',
'sources/selection/range_boundary_navigator'
],
'sources/selection/range_boundary_navigator',
],
function ($, _, clipboard, RangeSelectionHelper, rangeBoundaryNavigator) {
var copyData = function () {
var self = this;
@ -32,20 +32,8 @@ function ($, _, clipboard, RangeSelectionHelper, rangeBoundaryNavigator) {
var setPasteRowButtonEnablement = function (canEditFlag, isEnabled) {
if (canEditFlag) {
$("#btn-paste-row").prop('disabled', !isEnabled);
$('#btn-paste-row').prop('disabled', !isEnabled);
}
};
var allTheRangesAreFullRows = function (ranges, columnDefinitions) {
var colRangeBounds = ranges.map(function (range) {
return [range.fromCell, range.toCell];
});
if(RangeSelectionHelper.isFirstColumnData(columnDefinitions)) {
return _.isEqual(_.union.apply(null, colRangeBounds), [0, columnDefinitions.length - 1]);
}
return _.isEqual(_.union.apply(null, colRangeBounds), [0, columnDefinitions.length - 1]);
};
return copyData
});
return copyData;
});

View File

@ -1,70 +1,67 @@
define(['jquery',
'sources/selection/column_selector',
'sources/selection/row_selector',
'sources/selection/range_selection_helper',
'sources/url_for'
],
function ($, ColumnSelector, RowSelector, RangeSelectionHelper, url_for) {
var Slick = window.Slick;
'sources/selection/column_selector',
'sources/selection/row_selector',
'sources/selection/range_selection_helper',
'sources/url_for',
], function ($, ColumnSelector, RowSelector, RangeSelectionHelper, url_for) {
var GridSelector = function (columnDefinitions) {
var rowSelector = new RowSelector(columnDefinitions);
var columnSelector = new ColumnSelector(columnDefinitions);
var GridSelector = function (columnDefinitions) {
var rowSelector = new RowSelector(columnDefinitions);
var columnSelector = new ColumnSelector(columnDefinitions);
var init = function (grid) {
this.grid = grid;
grid.onHeaderClick.subscribe(function (event, eventArguments) {
if (eventArguments.column.selectAllOnClick) {
toggleSelectAll(grid);
}
});
var init = function (grid) {
this.grid = grid;
grid.onHeaderClick.subscribe(function (event, eventArguments) {
if (eventArguments.column.selectAllOnClick) {
toggleSelectAll(grid);
}
});
grid.getSelectionModel().onSelectedRangesChanged
grid.getSelectionModel().onSelectedRangesChanged
.subscribe(handleSelectedRangesChanged.bind(null, grid));
grid.registerPlugin(rowSelector);
grid.registerPlugin(columnSelector);
};
grid.registerPlugin(rowSelector);
grid.registerPlugin(columnSelector);
};
var getColumnDefinitions = function (columnDefinitions) {
columnDefinitions = columnSelector.getColumnDefinitions(columnDefinitions);
columnDefinitions = rowSelector.getColumnDefinitions(columnDefinitions);
var getColumnDefinitions = function (columnDefinitions) {
columnDefinitions = columnSelector.getColumnDefinitions(columnDefinitions);
columnDefinitions = rowSelector.getColumnDefinitions(columnDefinitions);
columnDefinitions[0].selectAllOnClick = true;
columnDefinitions[0].name = '<span data-id="select-all" ' +
columnDefinitions[0].selectAllOnClick = true;
columnDefinitions[0].name = '<span data-id="select-all" ' +
'title="Select/Deselect All">' +
'<br>' +
columnDefinitions[0].name +
'<img class="select-all-icon" src="' + url_for('static', {'filename': 'img/select-all-icon.png'}) + '"></img>'
'</span>';
return columnDefinitions;
};
function handleSelectedRangesChanged(grid) {
if(RangeSelectionHelper.isEntireGridSelected(grid)) {
$("[data-id='select-all']").addClass("selected");
} else {
$("[data-id='select-all']").removeClass("selected");
}
}
function toggleSelectAll(grid) {
if (RangeSelectionHelper.isEntireGridSelected(grid)) {
selectNone(grid);
} else {
RangeSelectionHelper.selectAll(grid);
}
}
function selectNone(grid) {
var selectionModel = grid.getSelectionModel();
selectionModel.setSelectedRanges([]);
}
$.extend(this, {
"init": init,
"getColumnDefinitions": getColumnDefinitions
});
'<img class="select-all-icon" src="' + url_for('static', {'filename': 'img/select-all-icon.png'}) + '"></img>';
'</span>';
return columnDefinitions;
};
return GridSelector;
});
function handleSelectedRangesChanged(grid) {
if(RangeSelectionHelper.isEntireGridSelected(grid)) {
$('[data-id=\'select-all\']').addClass('selected');
} else {
$('[data-id=\'select-all\']').removeClass('selected');
}
}
function toggleSelectAll(grid) {
if (RangeSelectionHelper.isEntireGridSelected(grid)) {
selectNone(grid);
} else {
RangeSelectionHelper.selectAll(grid);
}
}
function selectNone(grid) {
var selectionModel = grid.getSelectionModel();
selectionModel.setSelectedRanges([]);
}
$.extend(this, {
'init': init,
'getColumnDefinitions': getColumnDefinitions,
});
};
return GridSelector;
});

View File

@ -104,13 +104,13 @@ function (RangeSelectionHelper) {
var val = data[rowId][columnDefinitions[colId].pos];
if (val && _.isObject(val)) {
val = "'" + JSON.stringify(val) + "'";
} else if (val && typeof val != "number" && typeof val != "boolean") {
val = "'" + val.toString() + "'";
val = '\'' + JSON.stringify(val) + '\'';
} else if (val && typeof val != 'number' && typeof val != 'boolean') {
val = '\'' + val.toString() + '\'';
} else if (_.isNull(val) || _.isUndefined(val)) {
val = '';
}
return val;
}
},
};
});

View File

@ -8,19 +8,19 @@ define(['slickgrid'], function () {
var isRangeSelected = function (selectedRanges, range) {
return _.any(selectedRanges, function (selectedRange) {
return isSameRange(selectedRange, range)
return isSameRange(selectedRange, range);
});
};
var isAnyCellOfColumnSelected = function (selectedRanges, column) {
return _.any(selectedRanges, function (selectedRange) {
return selectedRange.fromCell <= column && selectedRange.toCell >= column
return selectedRange.fromCell <= column && selectedRange.toCell >= column;
});
};
var isAnyCellOfRowSelected = function (selectedRanges, row) {
return _.any(selectedRanges, function (selectedRange) {
return selectedRange.fromRow <= row && selectedRange.toRow >= row
return selectedRange.fromRow <= row && selectedRange.toRow >= row;
});
};
@ -33,8 +33,8 @@ define(['slickgrid'], function () {
var removeRange = function (selectedRanges, range) {
return _.filter(selectedRanges, function (selectedRange) {
return !(isSameRange(selectedRange, range))
})
return !(isSameRange(selectedRange, range));
});
};
var addRange = function (ranges, range) {
@ -45,11 +45,11 @@ define(['slickgrid'], function () {
var areAllRangesSingleRows = function (ranges, grid) {
return _.every(ranges, function (range) {
return range.fromRow == range.toRow && rangeHasCompleteRows(grid, range);
})
});
};
var areAllRangesSingleColumns = function (ranges, grid) {
return _.every(ranges, isRangeAColumn.bind(this, grid))
return _.every(ranges, isRangeAColumn.bind(this, grid));
};
var rangeForRow = function (grid, rowId) {
@ -61,7 +61,7 @@ define(['slickgrid'], function () {
};
var rangeForColumn = function (grid, columnIndex) {
return new Slick.Range(0, columnIndex, grid.getDataLength() - 1, columnIndex)
return new Slick.Range(0, columnIndex, grid.getDataLength() - 1, columnIndex);
};
var getRangeOfWholeGrid = function (grid) {
@ -81,13 +81,13 @@ define(['slickgrid'], function () {
var areAllRangesCompleteColumns = function (grid, ranges) {
return _.every(ranges, function (range) {
return rangeHasCompleteColumns(grid, range);
})
});
};
var areAllRangesCompleteRows = function (grid, ranges) {
return _.every(ranges, function (range) {
return rangeHasCompleteRows(grid, range);
})
});
};
var getIndexesOfCompleteRows = function (grid, ranges) {
@ -158,5 +158,5 @@ define(['slickgrid'], function () {
isAnyCellOfColumnSelected: isAnyCellOfColumnSelected,
isRangeEntirelyWithinSelectedRanges: isRangeEntirelyWithinSelectedRanges,
isAnyCellOfRowSelected: isAnyCellOfRowSelected,
}
});
};
});

View File

@ -1,7 +1,7 @@
define([
'jquery',
'sources/selection/range_selection_helper',
'slickgrid'
'slickgrid',
], function ($, RangeSelectionHelper) {
var RowSelector = function () {
var Slick = window.Slick;
@ -19,7 +19,7 @@ define([
if (grid.getColumns()[args.cell].id === 'row-header-column') {
var $rowHeaderSpan = $(event.target);
if ($rowHeaderSpan.data('cell-type') != "row-header-selector") {
if ($rowHeaderSpan.data('cell-type') != 'row-header-selector') {
$rowHeaderSpan = $(event.target).find('[data-cell-type="row-header-selector"]');
}
@ -82,16 +82,16 @@ define([
formatter: function (rowIndex) {
return '<span ' +
'data-row="' + rowIndex + '" ' +
'data-cell-type="row-header-selector"/>'
'data-cell-type="row-header-selector"/>';
},
width: 30
width: 30,
});
return columnDefinitions;
};
$.extend(this, {
"init": init,
"getColumnDefinitions": getColumnDefinitions
'init': init,
'getColumnDefinitions': getColumnDefinitions,
});
};

View File

@ -11,7 +11,7 @@ define(
[
'jquery',
'underscore',
'sources/selection/range_selection_helper'
'sources/selection/range_selection_helper',
],
function ($, _, RangeSelectionHelper) {
function disableButton(selector) {
@ -55,7 +55,7 @@ define(
_.each(_.keys(gridRow), function (columnPos) {
if (_.contains(primaryKeyColumnIndices, Number(columnPos)))
rowToStage[columnPos] = gridRow[columnPos];
})
});
}
return rowToStage;
}
@ -72,7 +72,7 @@ define(
return stagedRows;
}
var setStagedRows = function (e, args) {
var setStagedRows = function () {
var self = this;
function setStagedRows(rowsToStage) {
@ -88,7 +88,7 @@ define(
function areAllSelectionsEntireRows() {
return RangeSelectionHelper.areAllRangesCompleteRows(self.grid,
self.selection.getSelectedRanges())
self.selection.getSelectedRanges());
}
var selectedRanges = this.selection.getSelectedRanges();
@ -98,7 +98,7 @@ define(
}
if (areAllSelectionsEntireRows()) {
var selectedRows = RangeSelectionHelper.getIndexesOfCompleteRows(this.grid, this.selection.getSelectedRanges())
var selectedRows = RangeSelectionHelper.getIndexesOfCompleteRows(this.grid, this.selection.getSelectedRanges());
var stagedRows = getPrimaryKeysForSelectedRows(self, selectedRows);
setStagedRows(stagedRows);
if (_.isEmpty(stagedRows)) {

View File

@ -4,7 +4,7 @@ define([
'sources/selection/range_selection_helper',
'sources/slickgrid/pgslick.cellrangeselector',
'slickgrid'
'slickgrid',
], function ($, _, RangeSelectionHelper, PGCellRangeSelector) {
var XCellSelectionModel = function (options) {
@ -13,25 +13,24 @@ define([
var KEY_ARROW_UP = 38;
var KEY_ARROW_DOWN = 40;
var Slick = window.Slick;
var _grid;
var _canvas;
var _ranges = [];
var _self = this;
var _selector = new PGCellRangeSelector({
"selectionCss": {
"border": "2px solid black"
}
'selectionCss': {
'border': '2px solid black',
},
});
var _options;
var _defaults = {
selectActiveCell: true
selectActiveCell: true,
};
function init(grid) {
_options = $.extend(true, {}, _defaults, options);
_grid = grid;
_canvas = _grid.getCanvasNode();
_grid.onActiveCellChanged.subscribe(handleActiveCellChange);
_grid.onKeyDown.subscribe(handleKeyDown);
grid.registerPlugin(_selector);
@ -82,7 +81,7 @@ define([
}
}
function handleBeforeCellRangeSelected(e, args) {
function handleBeforeCellRangeSelected(e) {
if (_grid.getEditorLock().isActive()) {
e.stopPropagation();
return false;
@ -169,18 +168,18 @@ define([
var mobileCell = getMobileCellFromRange(lastSelectedRange, anchorActiveCell);
switch (getKeycode()) {
case KEY_ARROW_LEFT:
mobileCell.cell -= 1;
break;
case KEY_ARROW_RIGHT:
mobileCell.cell += 1;
break;
case KEY_ARROW_UP:
mobileCell.row -= 1;
break;
case KEY_ARROW_DOWN:
mobileCell.row += 1;
break;
case KEY_ARROW_LEFT:
mobileCell.cell -= 1;
break;
case KEY_ARROW_RIGHT:
mobileCell.cell += 1;
break;
case KEY_ARROW_UP:
mobileCell.row -= 1;
break;
case KEY_ARROW_DOWN:
mobileCell.row += 1;
break;
}
var newSelectedRange = getNewRange(anchorActiveCell, mobileCell);
@ -206,7 +205,7 @@ define([
}
}
function handleWindowMouseUp(event) {
function handleWindowMouseUp() {
var selectedRange = _selector.getCurrentRange();
if (!_.isUndefined(selectedRange)) {
_grid.onDragEnd.notify({range: selectedRange});
@ -214,14 +213,14 @@ define([
}
$.extend(this, {
"getSelectedRanges": getSelectedRanges,
"setSelectedRanges": setSelectedRanges,
"setSelectedRows": setSelectedRows,
'getSelectedRanges': getSelectedRanges,
'setSelectedRanges': setSelectedRanges,
'setSelectedRows': setSelectedRows,
"init": init,
"destroy": destroy,
'init': init,
'destroy': destroy,
"onSelectedRangesChanged": new Slick.Event()
'onSelectedRangesChanged': new Slick.Event(),
});
};
return XCellSelectionModel;

View File

@ -15,7 +15,7 @@ define([
var MenuItem = pgAdmin.Browser.MenuItem;
var menuItem;
describe("when we create a menu item", function () {
describe('when we create a menu item', function () {
describe('and it is disabled', function () {
beforeEach(function () {
menuItem = new MenuItem({enable: false, icon: 'fa fa-car'});

View File

@ -7,24 +7,24 @@
//
//////////////////////////////////////////////////////////////////////////
define(["sources/check_node_visibility"],
function (checkNodeVisibility, pgBrowser) {
describe("checkNodeVisibility", function () {
define(['sources/check_node_visibility'],
function (checkNodeVisibility) {
describe('checkNodeVisibility', function () {
var browser;
browser = jasmine.createSpyObj('browser', [
'node_preference_data', 'get_preference']
'node_preference_data', 'get_preference']
);
describe("when node is server collection", function () {
it("returns true", function () {
describe('when node is server collection', function () {
it('returns true', function () {
expect(checkNodeVisibility(browser, 'coll-server')).toEqual(true);
});
});
describe("when node is server", function () {
it("returns true", function () {
describe('when node is server', function () {
it('returns true', function () {
expect(checkNodeVisibility(browser, 'server')).toEqual(true);
});
});

View File

@ -8,5 +8,5 @@
//////////////////////////////////////////////////////////////////////////
define(function () {
return {}
return {};
});

View File

@ -18,6 +18,7 @@ define([
var onColumnsResizedFunction;
var onHeaderMouseEnterFunction;
var onHeaderMouseLeaveFunction;
var Slick = window.Slick;
beforeEach(function () {
getSelectedRangesSpy = jasmine.createSpy('getSelectedRangesSpy');
@ -27,15 +28,15 @@ define([
return {
getSelectedRanges: getSelectedRangesSpy,
setSelectedRanges: setSelectedRangesSpy,
}
};
},
getColumns: function () {
return [
{id: 'row-header-column'},
{id: 'column-1'},
{id: 'column-2'}
]
{id: 'column-2'},
];
},
onDragEnd: jasmine.createSpyObj('onDragEnd', ['subscribe']),
@ -47,7 +48,7 @@ define([
onHeaderMouseEnter: jasmine.createSpyObj('onHeaderMouseEnter', ['subscribe']),
onHeaderMouseLeave: jasmine.createSpyObj('onHeaderMouseLeave', ['subscribe']),
getDataLength: function () { return 10 },
getDataLength: function () { return 10; },
setActiveCell: jasmine.createSpy('setActiveCell'),
getActiveCell: jasmine.createSpy('getActiveCell'),
@ -108,7 +109,7 @@ define([
describe('when a different column is clicked', function () {
beforeEach(function () {
onHeaderClickFunction({}, {column: {pos: 4}})
onHeaderClickFunction({}, {column: {pos: 4}});
});
it('should set the active cell to the newly clicked columns top cell', function () {
@ -217,7 +218,7 @@ define([
describe('when the third column is clicked (thereby deselecting it)', function () {
beforeEach(function () {
onHeaderClickFunction({}, {column: {pos: 21}})
onHeaderClickFunction({}, {column: {pos: 21}});
});
it('should set the active cell to the second column', function () {
@ -227,7 +228,7 @@ define([
describe('when the second column is clicked (thereby deselecting it)', function () {
beforeEach(function () {
onHeaderClickFunction({}, {column: {pos: 5}})
onHeaderClickFunction({}, {column: {pos: 5}});
});
it('should not set the active cell', function () {
@ -268,7 +269,7 @@ define([
beforeEach(function () {
grid.getActiveCell.and.returnValue({row: 4, cell: 5});
getSelectedRangesSpy.and.returnValue([
new Slick.Range(4, 5)
new Slick.Range(4, 5),
]);
});
@ -283,7 +284,7 @@ define([
beforeEach(function () {
grid.getActiveCell.and.returnValue({row: 3, cell: 1});
getSelectedRangesSpy.and.returnValue([
RangeSelectionHelper.rangeForRow(grid, 3)
RangeSelectionHelper.rangeForRow(grid, 3),
]);
});
@ -307,7 +308,7 @@ define([
grid.getActiveCell.and.returnValue({row: 3, cell: 1});
getSelectedRangesSpy.and.returnValue([
RangeSelectionHelper.rangeForRow(grid, 5),
RangeSelectionHelper.rangeForRow(grid, 3)
RangeSelectionHelper.rangeForRow(grid, 3),
]);
});
@ -330,7 +331,7 @@ define([
describe('and the editable new row', function () {
beforeEach(function () {
onClickFunction({}, {row: 10, cell: 0})
onClickFunction({}, {row: 10, cell: 0});
});
it('does not select the row', function () {
expect(grid.setActiveCell).not.toHaveBeenCalled();

View File

@ -22,10 +22,12 @@ import 'sources/slickgrid/pgslick.cellrangeselector';
describe('ColumnSelector', function () {
var container, data, columns, options;
var SlickGrid = Slick.Grid;
var KEY_RIGHT = 39;
var KEY_LEFT = 37;
var KEY_UP = 38;
var KEY_DOWN = 40;
var KEY = {
RIGHT: 39,
LEFT: 37,
UP: 38,
DOWN: 40,
};
beforeEach(function () {
container = $('<div></div>');
@ -35,11 +37,11 @@ describe('ColumnSelector', function () {
data = [{
'some-column-name': 'first value',
'second column': 'second value',
'third column': 'nonselectable value'
'third column': 'nonselectable value',
}, {
'some-column-name': 'row 1 - first value',
'second column': 'row 1 - second value',
'third column': 'row 1 - nonselectable value'
'third column': 'row 1 - nonselectable value',
}];
columns = [
@ -48,36 +50,36 @@ describe('ColumnSelector', function () {
name: 'row header column name',
selectable: false,
display_name: 'row header column name',
column_type: 'text'
column_type: 'text',
},
{
id: '1',
name: 'some-column-name',
pos: 0,
display_name: 'some-column-name',
column_type: 'text'
column_type: 'text',
},
{
id: '2',
name: 'second column',
pos: 1,
display_name: 'second column',
column_type: 'json'
column_type: 'json',
},
{
id: 'third-column-id',
name: 'third column',
pos: 2,
display_name: 'third column',
column_type: 'text'
column_type: 'text',
},
{
name: 'some-non-selectable-column',
selectable: false,
pos: 3,
display_name: 'some-non-selectable-column',
column_type: 'numeric'
}
column_type: 'numeric',
},
];
});
@ -170,7 +172,7 @@ describe('ColumnSelector', function () {
describe('and presses shift + right-arrow', function () {
beforeEach(function () {
pressShiftArrow(KEY_RIGHT);
pressShiftArrow(KEY.RIGHT);
});
it('keeps the last column selected', function () {
@ -202,7 +204,7 @@ describe('ColumnSelector', function () {
describe('and presses shift + right-arrow', function () {
it('first and second columns are selected', function () {
pressShiftArrow(KEY_RIGHT);
pressShiftArrow(KEY.RIGHT);
var selectedRanges = cellSelectionModel.getSelectedRanges();
@ -266,7 +268,7 @@ describe('ColumnSelector', function () {
var selectedRanges = cellSelectionModel.getSelectedRanges();
expect(selectedRanges.length).toEqual(0);
})
});
});
describe('when the column is not selectable', function () {

View File

@ -19,52 +19,51 @@ import XCellSelectionModel from 'sources/selection/xcell_selection_model';
describe('copyData', function () {
var grid, sqlEditor, gridContainer, buttonPasteRow;
var Slick, SlickGrid;
var SlickGrid;
beforeEach(function () {
Slick = window.Slick;
SlickGrid = Slick.Grid;
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'
}
]
{
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 = new SlickGrid('#grid', data, columns, {});
grid.setSelectionModel(new XCellSelectionModel());
sqlEditor = {slickgrid: grid};
});

View File

@ -8,7 +8,6 @@
//////////////////////////////////////////////////////////////////////////
import $ from 'jquery';
import _ from 'underscore';
import Slick from 'slickgrid';
import 'slickgrid.grid';
@ -18,21 +17,20 @@ import XCellSelectionModel from 'sources/selection/xcell_selection_model';
describe('GridSelector', function () {
var container, data, columns, gridSelector, xCellSelectionModel;
var Slick, SlickGrid;
var SlickGrid;
beforeEach(function () {
Slick = window.Slick;
SlickGrid = Slick.Grid;
container = $('<div></div>');
container.height(9999);
columns = [{
id: '1',
name: 'some-column-name',
pos: 0
pos: 0,
}, {
id: '2',
name: 'second column',
pos: 1
pos: 1,
}];
gridSelector = new GridSelector();
@ -42,7 +40,7 @@ describe('GridSelector', function () {
for (var i = 0; i < 10; i++) {
data.push({'some-column-name': 'some-value-' + i, 'second column': 'second value ' + i});
}
var grid = new Slick.Grid(container, data, columns);
var grid = new SlickGrid(container, data, columns);
xCellSelectionModel = new XCellSelectionModel();
grid.setSelectionModel(xCellSelectionModel);

View File

@ -23,8 +23,8 @@ describe('RangeBoundaryNavigator', function () {
});
});
describe("when the ranges all overlap partially or touch", function () {
it("returns one long range", function () {
describe('when the ranges all overlap partially or touch', function () {
it('returns one long range', function () {
var rangeBounds = [[3, 6], [1, 4], [7, 14]];
var union = rangeBoundaryNavigator.getUnion(rangeBounds);
@ -32,7 +32,7 @@ describe('RangeBoundaryNavigator', function () {
expect(union).toEqual([[1, 14]]);
});
it("returns them in order from lowest to highest", function () {
it('returns them in order from lowest to highest', function () {
var rangeBounds = [[3, 6], [2, 3], [10, 12]];
var union = rangeBoundaryNavigator.getUnion(rangeBounds);
@ -40,9 +40,9 @@ describe('RangeBoundaryNavigator', function () {
expect(union).toEqual([[2, 6], [10, 12]]);
});
describe("when one range completely overlaps another", function() {
describe('when one range completely overlaps another', function() {
it("returns them in order from lowest to highest", function () {
it('returns them in order from lowest to highest', function () {
var rangeBounds = [[9, 14], [2, 3], [11, 13]];
var union = rangeBoundaryNavigator.getUnion(rangeBounds);
@ -51,19 +51,19 @@ describe('RangeBoundaryNavigator', function () {
});
});
describe("when one range is a subset of another", function () {
it("returns the larger range", function () {
describe('when one range is a subset of another', function () {
it('returns the larger range', function () {
var rangeBounds = [[2, 6], [1, 14], [8, 10]];
var union = rangeBoundaryNavigator.getUnion(rangeBounds);
expect(union).toEqual([[1, 14]]);
})
})
});
});
});
describe("when the ranges do not touch", function () {
it("returns them in order from lowest to highest", function () {
describe('when the ranges do not touch', function () {
it('returns them in order from lowest to highest', function () {
var rangeBounds = [[3, 6], [1, 1], [8, 10]];
var union = rangeBoundaryNavigator.getUnion(rangeBounds);
@ -73,8 +73,8 @@ describe('RangeBoundaryNavigator', function () {
});
});
describe("#mapDimensionBoundaryUnion", function () {
it("returns a list of the results of the callback", function () {
describe('#mapDimensionBoundaryUnion', function () {
it('returns a list of the results of the callback', function () {
var rangeBounds = [[0, 1], [3, 3]];
var callback = function () {
return 'hello';
@ -83,7 +83,7 @@ describe('RangeBoundaryNavigator', function () {
expect(result).toEqual(['hello', 'hello', 'hello']);
});
it("calls the callback with each index in the dimension", function () {
it('calls the callback with each index in the dimension', function () {
var rangeBounds = [[0, 1], [3, 3]];
var callback = jasmine.createSpy('callbackSpy');
rangeBoundaryNavigator.mapDimensionBoundaryUnion(rangeBounds, callback);
@ -91,7 +91,7 @@ describe('RangeBoundaryNavigator', function () {
});
});
describe("#mapOver2DArray", function () {
describe('#mapOver2DArray', function () {
var data, rowCollector, processCell;
beforeEach(function () {
data = [[0, 1, 2, 3], [2, 2, 2, 2], [4, 5, 6, 7]];
@ -103,76 +103,75 @@ describe('RangeBoundaryNavigator', function () {
};
});
it("calls the callback for each item in the ranges", function () {
it('calls the callback for each item in the ranges', function () {
var rowRanges = [[0, 0], [2, 2]];
var colRanges = [[0, 3]];
var selectionResult = rangeBoundaryNavigator.mapOver2DArray(rowRanges, colRanges, processCell, rowCollector);
expect(selectionResult).toEqual(["[0,1,2,3]", "[4,5,6,7]"]);
expect(selectionResult).toEqual(['[0,1,2,3]', '[4,5,6,7]']);
});
describe("when the ranges are out of order/duplicated", function () {
describe('when the ranges are out of order/duplicated', function () {
var rowRanges, colRanges;
beforeEach(function () {
rowRanges = [[2, 2], [2, 2], [0, 0]];
colRanges = [[0, 3]];
});
it("uses the union of the ranges", function () {
spyOn(rangeBoundaryNavigator, "getUnion").and.callThrough();
it('uses the union of the ranges', function () {
spyOn(rangeBoundaryNavigator, 'getUnion').and.callThrough();
var selectionResult = rangeBoundaryNavigator.mapOver2DArray(rowRanges, colRanges, processCell, rowCollector);
expect(rangeBoundaryNavigator.getUnion).toHaveBeenCalledWith(rowRanges);
expect(rangeBoundaryNavigator.getUnion).toHaveBeenCalledWith(colRanges);
expect(selectionResult).toEqual(["[0,1,2,3]", "[4,5,6,7]"]);
expect(selectionResult).toEqual(['[0,1,2,3]', '[4,5,6,7]']);
});
});
});
describe("#rangesToCsv", function () {
describe('#rangesToCsv', function () {
var data, columnDefinitions, ranges;
beforeEach(function () {
data = [[1, "leopard", "12"],
[2, "lion", "13"],
[3, "cougar", "9"],
[4, "tiger", "10"]];
data = [[1, 'leopard', '12'],
[2, 'lion', '13'],
[3, 'cougar', '9'],
[4, 'tiger', '10']];
columnDefinitions = [{name: 'id', pos: 0}, {name: 'animal', pos: 1}, {name: 'size', pos: 2}];
ranges = [new Slick.Range(0, 0, 0, 2), new Slick.Range(3, 0, 3, 2)];
});
it("returns csv for the provided ranges", function () {
it('returns csv for the provided ranges', function () {
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, ranges);
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 () {
it("should return an empty string", function () {
describe('when no cells are selected', function () {
it('should return an empty string', function () {
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, []);
expect(csvResult).toEqual('');
});
});
describe("when there is an extra column with checkboxes", function () {
describe('when there is an extra column with checkboxes', function () {
beforeEach(function () {
columnDefinitions = [{name: 'not-a-data-column'}, {name: 'id', pos: 0}, {name: 'animal', pos: 1}, {
name: 'size',
pos: 2
pos: 2,
}];
ranges = [new Slick.Range(0, 0, 0, 3), new Slick.Range(3, 0, 3, 3)];
});
it("returns csv for the columns with data", function () {
it('returns csv for the columns with data', function () {
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, ranges);
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 () {
it("should return an empty string", function () {
describe('when no cells are selected', function () {
it('should return an empty string', function () {
var csvResult = rangeBoundaryNavigator.rangesToCsv(data, columnDefinitions, []);
expect(csvResult).toEqual('');
@ -180,4 +179,4 @@ describe('RangeBoundaryNavigator', function () {
});
});
});
});
});

View File

@ -3,21 +3,21 @@ import Slick from 'slickgrid';
import 'slickgrid.grid';
import RangeSelectionHelper from 'sources/selection/range_selection_helper';
describe("RangeSelectionHelper utility functions", function () {
describe('RangeSelectionHelper utility functions', function () {
var grid;
beforeEach(function () {
var container, data, columns, options;
container = $("<div></div>");
container = $('<div></div>');
container.height(9999);
columns = [{
id: '1',
name: 'some-column-name',
pos: 0
pos: 0,
}, {
id: 'second-column-id',
name: 'second column',
pos: 1
pos: 1,
}];
data = [];
@ -29,18 +29,18 @@ describe("RangeSelectionHelper utility functions", function () {
grid.invalidate();
});
describe("#getIndexesOfCompleteRows", function () {
describe("when selected ranges are not rows", function () {
it("returns an empty array", function () {
describe('#getIndexesOfCompleteRows', function () {
describe('when selected ranges are not rows', function () {
it('returns an empty array', function () {
var rowlessRanges = [RangeSelectionHelper.rangeForColumn(grid, 1)];
expect(RangeSelectionHelper.getIndexesOfCompleteRows(grid, rowlessRanges))
.toEqual([]);
});
});
describe("when selected range", function () {
describe("is a single row", function () {
it("returns an array with one index", function () {
describe('when selected range', function () {
describe('is a single row', function () {
it('returns an array with one index', function () {
var singleRowRange = [RangeSelectionHelper.rangeForRow(grid, 1)];
expect(RangeSelectionHelper.getIndexesOfCompleteRows(grid, singleRowRange))
@ -48,8 +48,8 @@ describe("RangeSelectionHelper utility functions", function () {
});
});
describe("is multiple rows", function () {
it("returns an array of each row's index", function () {
describe('is multiple rows', function () {
it('returns an array of each row\'s index', function () {
var multipleRowRange = [
RangeSelectionHelper.rangeForRow(grid, 0),
RangeSelectionHelper.rangeForRow(grid, 3),
@ -62,10 +62,10 @@ describe("RangeSelectionHelper utility functions", function () {
});
});
describe("contains a multi row selection", function () {
it("returns an array of each individual row's index", function () {
describe('contains a multi row selection', function () {
it('returns an array of each individual row\'s index', function () {
var multipleRowRange = [
new Slick.Range(3, 0, 5, 1)
new Slick.Range(3, 0, 5, 1),
];
var indexesOfCompleteRows = RangeSelectionHelper.getIndexesOfCompleteRows(grid, multipleRowRange);
@ -73,11 +73,11 @@ describe("RangeSelectionHelper utility functions", function () {
expect(indexesOfCompleteRows).toEqual([3, 4, 5]);
});
describe("and also contains a selection that is not a row", function () {
it("returns an array of only the complete rows' indexes", function () {
describe('and also contains a selection that is not a row', function () {
it('returns an array of only the complete rows\' indexes', function () {
var multipleRowRange = [
new Slick.Range(8, 1, 9, 1),
new Slick.Range(3, 0, 5, 1)
new Slick.Range(3, 0, 5, 1),
];
var indexesOfCompleteRows = RangeSelectionHelper.getIndexesOfCompleteRows(grid, multipleRowRange);

View File

@ -8,7 +8,6 @@
//////////////////////////////////////////////////////////////////////////
import $ from 'jquery';
import _ from 'underscore';
import Slick from 'slickgrid';
import 'slickgrid.grid';
@ -18,10 +17,12 @@ import ActiveCellCapture from 'sources/selection/active_cell_capture';
import XCellSelectionModel from 'sources/selection/xcell_selection_model';
describe('RowSelector', function () {
var KEY_RIGHT = 39;
var KEY_LEFT = 37;
var KEY_UP = 38;
var KEY_DOWN = 40;
var KEY = {
RIGHT: 39,
LEFT: 37,
UP: 38,
DOWN: 40,
};
var container, data, columnDefinitions, grid, cellSelectionModel;
var SlickGrid = Slick.Grid;
@ -34,12 +35,12 @@ describe('RowSelector', function () {
id: '1',
name: 'some-column-name',
selectable: true,
pos: 0
pos: 0,
}, {
id: '2',
name: 'second column',
selectable: true,
pos: 1
pos: 1,
}];
var rowSelector = new RowSelector();
@ -134,7 +135,7 @@ describe('RowSelector', function () {
describe('and presses shift + down-arrow', function () {
beforeEach(function () {
pressShiftArrow(KEY_DOWN);
pressShiftArrow(KEY.DOWN);
});
it('keeps the last row selected', function () {
@ -301,7 +302,7 @@ describe('RowSelector', function () {
var selectedRanges = cellSelectionModel.getSelectedRanges();
expect(selectedRanges.length).toEqual(0);
})
});
});
});

View File

@ -8,9 +8,9 @@
//////////////////////////////////////////////////////////////
define([
"jquery",
"underscore",
"sources/selection/set_staged_rows",
'jquery',
'underscore',
'sources/selection/set_staged_rows',
], function ($, _, SetStagedRows) {
describe('set_staged_rows', function () {
var sqlEditorObj, gridSpy, deleteButton, copyButton, selectionSpy;
@ -20,7 +20,7 @@ define([
{0: 'one', 1: 'two', __temp_PK: '123'},
{0: 'three', 1: 'four', __temp_PK: '456'},
{0: 'five', 1: 'six', __temp_PK: '789'},
{0: 'seven', 1: 'eight', __temp_PK: '432'}
{0: 'seven', 1: 'eight', __temp_PK: '432'},
]);
gridSpy.getColumns.and.returnValue([
{
@ -29,7 +29,7 @@ define([
}, {
pos: 1,
selectable: true,
}
},
]);
selectionSpy = jasmine.createSpyObj('selectionSpy', ['setSelectedRows', 'getSelectedRanges']);
@ -42,23 +42,23 @@ define([
editor: {
handler: {
data_store: {
staged_rows: {'456': {}}
staged_rows: {'456': {}},
},
can_edit: false
}
can_edit: false,
},
},
keys: null,
selection: selectionSpy,
columns: [
{
name: 'a pk column',
pos: 0
pos: 0,
},
{
name: 'some column',
pos: 1
}
]
pos: 1,
},
],
};
$('body').append(deleteButton);
@ -195,7 +195,7 @@ define([
{0: 'one', 1: 'two', __temp_PK: '123'},
{1: 'four', __temp_PK: '456'},
{1: 'six', __temp_PK: '789'},
{0: 'seven', 1: 'eight', __temp_PK: '432'}
{0: 'seven', 1: 'eight', __temp_PK: '432'},
]);
});
@ -228,7 +228,7 @@ define([
it('should not clear the staged rows', function () {
expect(sqlEditorObj.editor.handler.data_store.staged_rows).toEqual({
'456': {0: 'three'},
'789': {0: 'five'}
'789': {0: 'five'},
});
});

View File

@ -10,6 +10,7 @@
import XCellSelectionModel from 'sources/selection/xcell_selection_model';
import 'slickgrid.grid';
import Slick from 'slickgrid';
import $ from 'jquery';
describe('XCellSelectionModel', function () {
var KEY_RIGHT = 39;
@ -31,15 +32,15 @@ describe('XCellSelectionModel', function () {
}, {
id: '1',
name: 'some-column-name',
pos: 0
pos: 0,
}, {
id: 'second-column-id',
name: 'second column',
pos: 1
pos: 1,
}, {
id: 'third-column-id',
name: 'third column',
pos: 2
pos: 2,
},
];
@ -52,13 +53,13 @@ describe('XCellSelectionModel', function () {
'fourth column': 'fourth value ' + i,
});
}
container = $("<div></div>");
container = $('<div></div>');
container.height(9999);
container.width(9999);
grid = new SlickGrid(container, data, columns);
grid.setSelectionModel(new XCellSelectionModel());
$("body").append(container);
$('body').append(container);
});
afterEach(function () {
@ -397,13 +398,13 @@ describe('XCellSelectionModel', function () {
target: $cell,
isPropagationStopped: jasmine.createSpy('isPropagationStopped').and.returnValue(false),
isImmediatePropagationStopped: jasmine.createSpy('isImmediatePropagationStopped').and.returnValue(false),
stopImmediatePropagation: jasmine.createSpy('stopImmediatePropagation')
stopImmediatePropagation: jasmine.createSpy('stopImmediatePropagation'),
};
dd = {
grid: grid,
startX: cellLeftPosition(initialPosition.cell),
startY: cellTopPosition($cell, initialPosition.row)
startY: cellTopPosition($cell, initialPosition.row),
};
grid.onDragStart.notify(dd, event, grid);
@ -421,7 +422,7 @@ describe('XCellSelectionModel', function () {
stopImmediatePropagation: jasmine.createSpy('stopImmediatePropagation'),
pageX: cellLeftPosition(finalPosition.cell),
pageY: cellTopPosition($cell, finalPosition.row)
pageY: cellTopPosition($cell, finalPosition.row),
};
grid.onDrag.notify(dd, event, grid);
@ -448,7 +449,7 @@ describe('XCellSelectionModel', function () {
});
it('do not notify onDragEnd', function () {
expect(grid.onDragEnd.notify).not.toHaveBeenCalled()
expect(grid.onDragEnd.notify).not.toHaveBeenCalled();
});
});
@ -482,14 +483,14 @@ describe('XCellSelectionModel', function () {
});
function pressKey(keyCode) {
var pressEvent = new $.Event("keydown");
var pressEvent = new $.Event('keydown');
pressEvent.which = keyCode;
$(container.find('.grid-canvas')).trigger(pressEvent);
}
function pressShiftPlusKey(keyCode) {
var pressEvent = new $.Event("keydown");
var pressEvent = new $.Event('keydown');
pressEvent.shiftKey = true;
pressEvent.which = keyCode;

View File

@ -7,59 +7,59 @@
//
//////////////////////////////////////////////////////////////////////////
define(["sources/size_prettify"], function (sizePrettify) {
describe("sizePrettify", function () {
describe("when size is 0", function () {
it("returns 0 bytes", function () {
expect(sizePrettify(0)).toEqual("0 bytes");
define(['sources/size_prettify'], function (sizePrettify) {
describe('sizePrettify', function () {
describe('when size is 0', function () {
it('returns 0 bytes', function () {
expect(sizePrettify(0)).toEqual('0 bytes');
});
});
describe("when size >= 10kB and size < 10 MB", function () {
it("returns size in kB", function () {
expect(sizePrettify(10240)).toEqual("10 kB");
describe('when size >= 10kB and size < 10 MB', function () {
it('returns size in kB', function () {
expect(sizePrettify(10240)).toEqual('10 kB');
});
it("returns size in kB", function () {
expect(sizePrettify(99999)).toEqual("98 kB");
it('returns size in kB', function () {
expect(sizePrettify(99999)).toEqual('98 kB');
});
});
describe("when size >= 10MB and size < 10 GB", function () {
it("returns size in MB", function () {
expect(sizePrettify(10485760)).toEqual("10 MB");
describe('when size >= 10MB and size < 10 GB', function () {
it('returns size in MB', function () {
expect(sizePrettify(10485760)).toEqual('10 MB');
});
it("returns size in MB", function () {
expect(sizePrettify(44040192)).toEqual("42 MB");
it('returns size in MB', function () {
expect(sizePrettify(44040192)).toEqual('42 MB');
});
});
describe("when size >= 10GB and size < 10 TB", function () {
it("returns size in GB", function () {
expect(sizePrettify(10737418240)).toEqual("10 GB");
describe('when size >= 10GB and size < 10 TB', function () {
it('returns size in GB', function () {
expect(sizePrettify(10737418240)).toEqual('10 GB');
});
it("returns size in GB", function () {
expect(sizePrettify(10736344498176)).toEqual("9999 GB");
it('returns size in GB', function () {
expect(sizePrettify(10736344498176)).toEqual('9999 GB');
});
});
describe("when size >= 10TB and size < 10 PB", function () {
it("returns size in TB", function () {
expect(sizePrettify(10995116277760)).toEqual("10 TB");
describe('when size >= 10TB and size < 10 PB', function () {
it('returns size in TB', function () {
expect(sizePrettify(10995116277760)).toEqual('10 TB');
});
it("returns size in TB", function () {
expect(sizePrettify(29995116277760)).toEqual("27 TB");
it('returns size in TB', function () {
expect(sizePrettify(29995116277760)).toEqual('27 TB');
});
});
describe("when size >= 10 PB", function () {
it("returns size in PB", function () {
expect(sizePrettify(11258999068426200)).toEqual("10 PB");
describe('when size >= 10 PB', function () {
it('returns size in PB', function () {
expect(sizePrettify(11258999068426200)).toEqual('10 PB');
});
});

View File

@ -7,16 +7,17 @@
//
//////////////////////////////////////////////////////////////
import $ from "jquery";
import SlickGrid from "slickgrid.grid";
import XCellSelectionModel from "sources/selection/xcell_selection_model";
import CellSelector from "sources/slickgrid/cell_selector";
import RangeSelectionHelper from "sources/selection/range_selection_helper";
import $ from 'jquery';
import Slick from 'slickgrid';
import 'slickgrid.grid';
import XCellSelectionModel from 'sources/selection/xcell_selection_model';
import CellSelector from 'sources/slickgrid/cell_selector';
import RangeSelectionHelper from 'sources/selection/range_selection_helper';
describe("CellSelector", function () {
describe('CellSelector', function () {
var container, columns, cellSelector, data, cellSelectionModel, grid;
beforeEach(function () {
container = $("<div></div>");
container = $('<div></div>');
container.height(9999);
container.width(9999);
columns = [{
@ -39,17 +40,17 @@ describe("CellSelector", function () {
grid.registerPlugin(cellSelector);
grid.invalidate();
$("body").append(container);
$('body').append(container);
});
afterEach(function () {
$("body").find(container).remove();
$('body').find(container).remove();
});
describe("when the user clicks or tabs to a cell", function () {
it("sets the selected range to that cell", function () {
describe('when the user clicks or tabs to a cell', function () {
it('sets the selected range to that cell', function () {
var row = 1, column = 0;
$(container.find(".slick-row .slick-cell.l" + column)[row]).click();
$(container.find('.slick-row .slick-cell.l' + column)[row]).click();
var selectedRanges = cellSelectionModel.getSelectedRanges();
expect(selectedRanges.length).toBe(1);
@ -59,14 +60,14 @@ describe("CellSelector", function () {
expect(selectedRanges[0].toRow).toBe(1);
});
it("deselects previously selected ranges", function () {
it('deselects previously selected ranges', function () {
var row2Range = RangeSelectionHelper.rangeForRow(grid, 2);
var ranges = RangeSelectionHelper.addRange(cellSelectionModel.getSelectedRanges(),
row2Range);
cellSelectionModel.setSelectedRanges(ranges);
var row = 4, column = 1;
$(container.find(".slick-row .slick-cell.l" + column)[row]).click();
$(container.find('.slick-row .slick-cell.l' + column)[row]).click();
expect(RangeSelectionHelper.isRangeSelected(cellSelectionModel.getSelectedRanges(), row2Range))
.toBe(false);

View File

@ -13,10 +13,10 @@ import RangeSelectionHelper from 'sources/selection/range_selection_helper';
import XCellSelectionModel from 'sources/selection/xcell_selection_model';
import Slick from 'slickgrid';
import 'slickgrid.grid';
import $ from 'jquery';
describe('#handleQueryOutputKeyboardEvent', function () {
var event, view, grid, slickEvent;
var event, grid, slickEvent;
var SlickGrid = Slick.Grid;
var handleQueryOutputKeyboardEvent;
@ -27,7 +27,7 @@ describe('#handleQueryOutputKeyboardEvent', function () {
metaKey: false,
which: -1,
keyCode: -1,
preventDefault: jasmine.createSpy('preventDefault')
preventDefault: jasmine.createSpy('preventDefault'),
};
var data = [['', '0,0-cell-content', '0,1-cell-content'],
@ -35,22 +35,20 @@ describe('#handleQueryOutputKeyboardEvent', function () {
['', '2,0-cell-content', '2,1-cell-content']];
var columnDefinitions = [{name: 'checkboxColumn'}, {pos: 1, name: 'firstColumn'}, {
pos: 2,
name: 'secondColumn'
name: 'secondColumn',
}];
grid = new SlickGrid($('<div></div>'), data, columnDefinitions);
grid.setSelectionModel(new XCellSelectionModel());
slickEvent = {
grid: grid
grid: grid,
};
view = {};
spyOn(clipboard, 'copyTextToClipboard');
handleQueryOutputKeyboardEvent = HandleQueryOutputKeyboardEvent.bind(window);
debugger
});
describe("when a range is selected", function () {
describe('when a range is selected', function () {
beforeEach(function () {
grid.getSelectionModel().setSelectedRanges([
RangeSelectionHelper.rangeForRow(grid, 0),
@ -58,39 +56,39 @@ describe('#handleQueryOutputKeyboardEvent', function () {
]);
});
describe("pressing Command + C", function () {
describe('pressing Command + C', function () {
beforeEach(function () {
event.metaKey = true;
event.keyCode = 67;
});
it("copies the cell content to the clipboard", function () {
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'");
expect(clipboard.copyTextToClipboard).toHaveBeenCalledWith('\'0,0-cell-content\',\'0,1-cell-content\'\n\'2,0-cell-content\',\'2,1-cell-content\'');
});
});
describe("pressing Ctrl + C", function () {
describe('pressing Ctrl + C', function () {
beforeEach(function () {
event.ctrlKey = true;
event.keyCode = 67;
});
it("copies the cell content to the clipboard", function () {
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'");
expect(clipboard.copyTextToClipboard).toHaveBeenCalledWith('\'0,0-cell-content\',\'0,1-cell-content\'\n\'2,0-cell-content\',\'2,1-cell-content\'');
});
});
describe("pressing Command + A", function () {
describe('pressing Command + A', function () {
beforeEach(function () {
event.metaKey = true;
event.keyCode = 65;
});
it("selects the entire grid to ranges", function () {
it('selects the entire grid to ranges', function () {
handleQueryOutputKeyboardEvent(event, slickEvent);
expect(RangeSelectionHelper.isEntireGridSelected(grid)).toBeTruthy();
@ -98,13 +96,13 @@ describe('#handleQueryOutputKeyboardEvent', function () {
});
});
describe("pressing Ctrl + A", function () {
describe('pressing Ctrl + A', function () {
beforeEach(function () {
event.ctrlKey = true;
event.keyCode = 65;
});
it("selects the entire grid to ranges", function () {
it('selects the entire grid to ranges', function () {
handleQueryOutputKeyboardEvent(event, slickEvent);
expect(RangeSelectionHelper.isEntireGridSelected(grid)).toBeTruthy();
@ -113,14 +111,14 @@ describe('#handleQueryOutputKeyboardEvent', function () {
});
});
describe("when no ranges are selected", function () {
describe("pressing Command + A", function () {
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 () {
it('selects the entire grid to ranges', function () {
handleQueryOutputKeyboardEvent(event, slickEvent);
expect(RangeSelectionHelper.isEntireGridSelected(grid)).toBeTruthy();
@ -128,13 +126,13 @@ describe('#handleQueryOutputKeyboardEvent', function () {
});
});
describe("pressing Ctrl + A", function () {
describe('pressing Ctrl + A', function () {
beforeEach(function () {
event.ctrlKey = true;
event.keyCode = 65;
});
it("selects the entire grid to ranges", function () {
it('selects the entire grid to ranges', function () {
handleQueryOutputKeyboardEvent(event, slickEvent);
expect(RangeSelectionHelper.isEntireGridSelected(grid)).toBeTruthy();

View File

@ -7,18 +7,18 @@
//
//////////////////////////////////////////////////////////////////////////
define(["sources/sqleditor_utils"],
define(['sources/sqleditor_utils'],
function (SqlEditorUtils) {
describe("SqlEditorUtils", function () {
describe('SqlEditorUtils', function () {
describe("Generate a random string of size 10", function () {
it("returns string of length 10", function () {
describe('Generate a random string of size 10', function () {
it('returns string of length 10', function () {
expect(SqlEditorUtils.epicRandomString(10).length).toEqual(10);
});
});
describe("Generate a unique hash for given string", function () {
it("returns unique hash", function () {
describe('Generate a unique hash for given string', function () {
it('returns unique hash', function () {
expect(SqlEditorUtils.getHash('select * from test')).toEqual(403379630);
});
});

View File

@ -8,7 +8,6 @@ const regressionDir = path.resolve(__dirname, 'regression');
module.exports = {
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
_: 'underscore',
'underscore.string': 'underscore.string',

View File

@ -1199,15 +1199,7 @@ concat-stream@1.5.0:
readable-stream "~2.0.0"
typedarray "~0.0.5"
concat-stream@^1.5.2:
version "1.6.0"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.0.tgz#0aac662fd52be78964d5532f694784e70110acf7"
dependencies:
inherits "^2.0.3"
readable-stream "^2.2.2"
typedarray "^0.0.6"
concat-stream@~1.5.0, concat-stream@~1.5.1:
concat-stream@^1.5.2, concat-stream@~1.5.0, concat-stream@~1.5.1:
version "1.5.2"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.5.2.tgz#708978624d856af41a5a741defdd261da752c266"
dependencies:
@ -2329,7 +2321,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"
inherits@2, inherits@2.0.3, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.0, inherits@~2.0.1:
inherits@2, inherits@2.0.3, inherits@^2.0.1, inherits@~2.0.0, inherits@~2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
@ -3577,7 +3569,7 @@ read-pkg@^1.0.0:
normalize-package-data "^2.3.2"
path-type "^1.0.0"
readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.2.6:
readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5, readable-stream@^2.2.6:
version "2.2.11"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.11.tgz#0796b31f8d7688007ff0b93a8088d34aa17c0f72"
dependencies:
@ -4239,7 +4231,7 @@ type-is@~1.6.15:
media-typer "0.3.0"
mime-types "~2.1.15"
typedarray@^0.0.6, typedarray@~0.0.5:
typedarray@~0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"