aboutsummaryrefslogtreecommitdiffstats
path: root/vaadin-grid/test/grid-editor-handler.html
diff options
context:
space:
mode:
Diffstat (limited to 'vaadin-grid/test/grid-editor-handler.html')
-rw-r--r--vaadin-grid/test/grid-editor-handler.html202
1 files changed, 202 insertions, 0 deletions
diff --git a/vaadin-grid/test/grid-editor-handler.html b/vaadin-grid/test/grid-editor-handler.html
new file mode 100644
index 0000000..20c6e66
--- /dev/null
+++ b/vaadin-grid/test/grid-editor-handler.html
@@ -0,0 +1,202 @@
+<!DOCTYPE html>
+<html>
+
+<head lang="en">
+ <meta charset="UTF-8">
+ <title></title>
+ <script src="../../webcomponentsjs/webcomponents-lite.min.js"></script>
+ <script src="../../web-component-tester/browser.js"></script>
+
+ <script src="common.js"></script>
+
+ <link rel="import" href="../vaadin-grid.html">
+</head>
+
+<body>
+
+<div id="gridwrapper"></div>
+
+<script>
+ describe.feature('using editor handler', function() {
+ var editorHandler;
+
+ beforeEach(function() {
+ grid.columns = [{name: 'Name'}, {name: 'Value'}];
+ grid.editor.cancel();
+
+ editorHandler = {
+ getCellEditor: function(columnObject) {
+ var input = document.createElement("input");
+ return input;
+ },
+ bind: function(req) {
+ for (var i = 0; i < req.grid.columns.length; i++) {
+ var col = req.grid.columns[i];
+ if (!col.readOnly) {
+ var el = req.getCellEditor(col);
+ el.value = req.dataItem[i];
+ }
+ }
+ req.success();
+ },
+ save: function(req) {
+ var failingColumns = [];
+ for (var i = 0; i < req.grid.columns.length; i++) {
+ var col = req.grid.columns[i];
+ var el = req.getCellEditor(col);
+ if (el.value == "fail") {
+ failingColumns.push(col);
+ }
+ }
+ if (failingColumns.length > 0) {
+ req.failure("Save failed", failingColumns);
+ } else {
+ req.success();
+ }
+ }
+ };
+
+ grid.editor.handler = editorHandler;
+
+ return grid;
+ });
+
+ it('editor: enabled', function() {
+ grid.columns[0].name = "name";
+ grid.columns[1].name = "value";
+ grid.editor.handler = editorHandler;
+ expect(grid.editor.editRow.bind(grid.editor, 0)).to.throw("editor is not enabled");
+ grid.editor.enabled = true;
+ grid.editor.editRow(0);
+
+ assert.isTrue(gridContainsText(grid, "v-grid-editor"));
+ });
+
+ it('editor: saveButtonText and cancelButtonText', function() {
+ grid.columns[0].name = "name";
+ grid.columns[1].name = "value";
+ grid.editor.handler = editorHandler;
+ grid.editor.enabled = true;
+ grid.editor.editRow(0);
+ grid.editor.saveButtonText = "saveButtonTextFoo";
+ grid.editor.cancelButtonText = "cancelButtonTextFoo";
+
+ assert.isTrue(gridContainsText(grid, "saveButtonTextFoo"));
+ assert.isTrue(gridContainsText(grid, "cancelButtonTextFoo"));
+ });
+
+ it('editor: editrow', function() {
+ grid.columns[0].name = "name";
+ grid.columns[1].name = "value";
+ grid.editor.handler = editorHandler;
+ grid.editor.enabled = true;
+
+ grid.editor.editRow(0);
+ assert.equal(qLocal(".v-grid-editor input").value, "Grid");
+ grid.editor.cancel();
+ assert.isFalse(gridContainsText(grid, "v-grid-editor"));
+ grid.editor.editRow(1);
+ assert.equal(qLocal(".v-grid-editor input").value, "VaadinX");
+ grid.editor.save();
+ assert.isFalse(gridContainsText(grid, "v-grid-editor"));
+
+ expect(grid.editor.editRow.bind(grid.editor, 10)).to.throw("Row index");
+ });
+
+ it('editor: failure', function() {
+ grid.columns[0].name = "name";
+ grid.columns[1].name = "value";
+ grid.editor.handler = editorHandler;
+ grid.editor.enabled = true;
+
+ grid.editor.editRow(0);
+ var fields = qaLocal(".v-grid-editor input");
+ fields[0].value = "fail";
+ grid.editor.save();
+
+ assert.isTrue(gridContainsText(grid, "Save failed"));
+ var cells = qaLocal(".v-grid-editor-cells > div");
+ assert.isTrue(cells[0].classList.contains("error"));
+ assert.isFalse(cells[1].classList.contains("error"));
+
+ });
+
+ it('editor: return null cell editor', function() {
+ grid.columns[0].name = "name";
+ grid.columns[1].name = "value";
+ grid.editor.handler = {
+ getCellEditor: function(columnObject) {
+ return columnObject === grid.columns[0] ? null : undefined;
+ },
+ bind: function(req) {
+ req.success();
+ }
+ };
+ grid.editor.enabled = true;
+
+ grid.editor.editRow(0);
+ var cells = qaLocal(".v-grid-editor .v-grid-editor-cells > div");
+ assert.lengthOf(cells, 2);
+
+ var editors = qaLocal(".v-grid-editor .v-grid-editor-cells > div *");
+ assert.lengthOf(editors, 0);
+ });
+
+ it('editor: element instance after save', function() {
+ grid.editor.enabled = true;
+ grid.editor.handler = editorHandler;
+
+ var editor1, editor2;
+ editorHandler.save = function(req) {
+ if (!editor1) {
+ editor1 = req.getCellEditor(grid.columns[0]);
+ req.failure();
+ } else {
+ editor2 = req.getCellEditor(grid.columns[0]);
+ req.success();
+ }
+ };
+ grid.editor.editRow(0);
+
+ //Save fails
+ grid.editor.save();
+ //Save succeeds
+ grid.editor.save();
+
+ assert.equal(editor1, editor2);
+ });
+
+ // fails because of replacing columns doesn't render row contents,
+ // see https://trello.com/c/8e27Tv3q/58-v-grid-bugs
+ it.skip('editor: default editor', function() {
+ grid.editor.enabled = true;
+ grid.editor.editRow(0);
+
+ return grid.then(function() {
+ assert.equal("Grid", grid.querySelector('tbody tr td').textContent);
+ assert.equal("Grid", grid.querySelector('input').value);
+
+ grid.querySelector('input').value = "Foo";
+ grid.editor.save();
+ });
+
+ });
+
+ it('editor: getCellEditor and read-only columns', function() {
+ grid.columns[0].readOnly = true;
+
+ sinon.spy(editorHandler, "getCellEditor");
+
+ grid.editor.handler = editorHandler;
+ grid.editor.enabled = true;
+ grid.editor.editRow(0);
+
+ assert.isTrue(editorHandler.getCellEditor.calledOnce);
+
+ editorHandler.getCellEditor.restore();
+ });
+ });
+</script>
+
+</body>
+</html>