datatable-mutable-tests.js revision 3166f4121e57f4bd184a5b2cf85c38d776d1db86
11ef335b17a11da1b70c6a80cabe20ef74058481Luke SmithYUI.add('datatable-mutable-tests', function(Y) {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smithvar suite = new Y.Test.Suite("datatable-mutable");
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smithsuite.add(new Y.Test.Case({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith name: "lifecycle and instantiation",
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "Y.DataTable should be augmented": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isTrue(
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith new Y.DataTable().hasImpl(Y.DataTable.Mutable));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "Y.DataTable.Base should not be augmented": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isFalse(
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith new Y.DataTable.Base().hasImpl(Y.DataTable.Mutable));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "Y.DataTable constructor should not error": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = new Y.DataTable({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns: ['a'],
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith data: [{a:1}]
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isInstanceOf(Y.DataTable, table);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isTrue(table.hasImpl(Y.DataTable.Mutable));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test autoSync values": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var config = {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns: ['a'],
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith data: [{a:1}]
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith }, table;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table = new Y.DataTable(config);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isFalse(table.get('autoSync'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith config.autoSync = false;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table = new Y.DataTable(config);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isFalse(table.get('autoSync'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith config.autoSync = true;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table = new Y.DataTable(config);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isTrue(table.get('autoSync'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith config.autoSync = 'bogus';
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table = new Y.DataTable(config);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isFalse(table.get('autoSync'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith config.autoSync = { create: true, update: true, 'delete': false };
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table = new Y.DataTable(config);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isFalse(table.get('autoSync'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test set('autoSync')": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = new Y.DataTable({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns: ['a'],
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith data: [{a:1}]
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isFalse(table.get('autoSync'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.set('autoSync', false);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isFalse(table.get('autoSync'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.set('autoSync', true);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isTrue(table.get('autoSync'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.set('autoSync', 'add');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isTrue(table.get('autoSync'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.set('autoSync', { create: true, update: true, 'delete': false });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isTrue(table.get('autoSync'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith }
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith}));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smithsuite.add(new Y.Test.Case({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith name: "addColumn",
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith setUp: function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith this.table = new Y.DataTable({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns: ['a', 'b', 'c'],
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith data: [{ a: 1, b: 2, c: 3 }]
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith tearDown: function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith this.table.destroy();
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test addColumn() does nothing": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var columns = this.table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith this.table.addColumn();
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(columns, this.table.get('columns'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(3, this.table.get('columns').length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test addColumn(string)": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn('d');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isObject(table.getColumn('d'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('d', table.get('columns.d.key'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns = table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(3, Y.Array.indexOf(columns, table.get('columns.d')));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(4, columns.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test addColumn(config)": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn({ key: 'd' });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isObject(table.getColumn('d'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('d', table.get('columns.d.key'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns = table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(3, Y.Array.indexOf(columns, table.get('columns.d')));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(4, columns.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test addColumn(string, number)": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn('d', 1);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isObject(table.getColumn('d'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('d', table.get('columns.d.key'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns = table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(1, Y.Array.indexOf(columns, table.get('columns.d')));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(4, columns.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test addColumn(config, number)": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn({ key: 'd' }, 1);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isObject(table.getColumn('d'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('d', table.get('columns.d.key'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns = table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(1, Y.Array.indexOf(columns, table.get('columns.d')));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(4, columns.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test addColumn(string, [number, number])": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns, column;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith // Can't resolve [3, 1]
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn('f', [3, 1]);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isNull(table.getColumn('f'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns = table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(3, columns.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn({ name: 'parent', children: ['d', 'e'] });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn('f', [3, 1]);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isObject(table.getColumn('f'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('f', table.get('columns.f.key'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns = table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith column = table.get('columns.f');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(-1, Y.Array.indexOf(columns, column));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(1, Y.Array.indexOf(columns[3].children, column));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(4, columns.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(6, table._displayColumns.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test addColumn(config, [number, number])": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns, column;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith // Can't resolve [3, 1]
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn({ key: 'f' }, [3, 1]);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isNull(table.getColumn('f'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns = table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(3, columns.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn({ name: 'parent', children: ['d', 'e'] });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn({ key: 'f' }, [3, 1]);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isObject(table.getColumn('f'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('f', table.get('columns.f.key'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns = table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith column = table.get('columns.f');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(-1, Y.Array.indexOf(columns, column));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(1, Y.Array.indexOf(columns[3].children, column));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(4, columns.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(6, table._displayColumns.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "addColumn event should fire": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith onFired = false,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith afterFired = false;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.on('addColumn', function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith onFired = true;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.after('addColumn', function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith afterFired = true;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn('d');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isTrue(onFired);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isTrue(afterFired);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "addColumn event should have column config and index": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith column, index;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.on('addColumn', function (e) {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith column = e.column;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith index = e.index;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn('d');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isObject(table.get('columns.d'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isObject(column);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(column, table.get('columns.d'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(3, index);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "addColumn event should be preventable": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.on('addColumn', function (e) {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith e.preventDefault();
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn('d');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isUndefined(table.get('columns.d'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "addColumn event e.index modification should update destination": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.on('addColumn', function (e) {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith e.index = 1;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn('d', 2);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(1, Y.Array.indexOf(table.get('columns'), table.get('columns.d')));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "addColumn should be chainable": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(this.table, this.table.addColumn('d'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith }
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith}));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smithsuite.add(new Y.Test.Case({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith name: "modifyColumn",
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith setUp: function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith this.table = new Y.DataTable({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith columns: [{ key: 'a', foo: 'foo' }, 'b', 'c'],
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith data: [{ a: 1, b: 2, c: 3 }]
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith tearDown: function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith this.table.destroy();
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test modifyColumn() does nothing": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var columns = this.table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith this.table.modifyColumn();
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(columns, this.table.get('columns'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(3, this.table.get('columns').length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('foo', this.table.get('columns.a.foo'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test modifyColumn(string) does nothing": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var columns = this.table.get('columns');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith this.table.modifyColumn('a');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(columns, this.table.get('columns'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(3, this.table.get('columns').length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('foo', this.table.get('columns.a.foo'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test modifyColumn(string, obj)": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.modifyColumn('a', { foo: 'bar' });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('bar', table.get('columns.a.foo'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test modifyColumn(number, obj)": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.modifyColumn(0, { foo: 'bar' });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('bar', table.get('columns.a.foo'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "test modifyColumn([number, number], obj)": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.addColumn({ children: [ { key: 'd', foo: 'A' }, 'e' ] });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.modifyColumn([3, 0], { foo: 'B' });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('B', table.get('columns.d.foo'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "modifyColumn event should fire": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith onFired = false,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith afterFired = false;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.on('modifyColumn', function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith onFired = true;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.after('modifyColumn', function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith afterFired = true;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.modifyColumn('a', { foo: 'bar' });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isTrue(onFired);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isTrue(afterFired);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "modifyColumn event should have column config and newColumnDef": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table,
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith column, config;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.on('modifyColumn', function (e) {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith column = e.column;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith config = e.newColumnDef;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.modifyColumn('a', { foo: 'bar' });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('a', column);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.isObject(config);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "modifyColumn event should be preventable": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.on('modifyColumn', function (e) {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith e.preventDefault();
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.modifyColumn('a', { foo: 'bar' });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('foo', table.get('columns.a.foo'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "modifyColumn event e.newColumnDef modification should apply": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith var table = this.table;
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.on('modifyColumn', function (e) {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith e.newColumnDef = { bar: 'bar' };
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith table.modifyColumn('a', { foo: 'bar' });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('foo', table.get('columns.a.foo'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame('bar', table.get('columns.a.bar'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith "modifyColumn should be chainable": function () {
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith Y.Assert.areSame(this.table, this.table.modifyColumn('a', {foo: 'B'}));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith }
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith}));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smithsuite.add(new Y.Test.Case({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith name: "removeColumn",
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith setUp: function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith this.table = new Y.DataTable({
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith columns: [ 'a', 'b', 'c', { children: [ 'd', 'e' ] } ],
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith data: [{ a: 1, b: 1, c: 1, d: 1, e: 1 }]
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith });
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith },
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith tearDown: function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith this.table.destroy();
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith },
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith "test removeColumn() does nothing": function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith var table = this.table,
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith columns = table.get('columns');
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.removeColumn();
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame(columns, table.get('columns'));
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame(4, table.get('columns').length);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isObject(table.getColumn('a'));
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith },
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith "test removeColumn(string)": function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith var table = this.table;
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.removeColumn('a');
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame(3, table.get('columns').length);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame(4, table._displayColumns.length);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isNull(table.getColumn('a'));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.removeColumn('d');
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame(3, table._displayColumns.length);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isNull(table.getColumn('d'));
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith },
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith "test removeColumn(number)": function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith var table = this.table;
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.removeColumn(0);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame(3, table.get('columns').length);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame(4, table._displayColumns.length);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isNull(table.getColumn('a'));
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith },
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith "test removeColumn([number, number])": function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith var table = this.table;
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.removeColumn([3, 0]);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame(4, table.get('columns').length);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame(4, table._displayColumns.length);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isNull(table.getColumn('d'));
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isObject(table.getColumn([3, 0]));
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame('e', table.getColumn([3, 0]).key);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith },
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith "removeColumn event should fire": function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith var table = this.table,
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith onFired = false,
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith afterFired = false;
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.on('removeColumn', function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith onFired = true;
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith });
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.after('removeColumn', function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith afterFired = true;
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith });
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.removeColumn('a');
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isTrue(onFired);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isTrue(afterFired);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith },
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith "removeColumn event should have column config": function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith var table = this.table,
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith column;
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.on('removeColumn', function (e) {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith column = e.column;
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith });
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.removeColumn('a');
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame('a', column);
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith },
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith "removeColumn event should be preventable": function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith var table = this.table;
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.on('removeColumn', function (e) {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith e.preventDefault();
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith });
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.removeColumn('a');
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isObject(table.getColumn('a'));
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith },
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith "removeColumn event e.column modification should apply": function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith var table = this.table;
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.on('removeColumn', function (e) {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith e.column = 'a';
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith });
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith table.removeColumn('d');
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isNull(table.getColumn('a'));
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.isObject(table.getColumn('d'));
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith },
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith "removeColumn should be chainable": function () {
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith Y.Assert.areSame(this.table, this.table.removeColumn('a'));
7ec3441e48d9669a482acaafd2eef499d699c8b8Luke Smith }
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith}));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smithsuite.add(new Y.Test.Case({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith name: "moveColumn",
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith setUp: function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith this.table = new Y.DataTable({
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith columns: [ 'a', 'b', 'c', { children: [ 'd', 'e' ] } ],
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith data: [{ a: 1, b: 1, c: 1, d: 1, e: 1 }]
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith });
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith tearDown: function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith this.table.destroy();
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "test moveColumn() does nothing": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn();
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(2).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn([3, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([3, 1]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "test moveColumn(name) does nothing": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn('c');
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(2).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn([3, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([3, 1]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "test moveColumn(string, number)": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn('a', 2);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(2).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn([3, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([3, 1]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame(2, table.getColumn(3).children.length);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn('d', 0);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(2).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(3).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([4, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame(1, table.getColumn(4).children.length);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "test moveColumn(number, number)": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn(0, 2);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(2).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn([3, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([3, 1]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame(2, table.getColumn(3).children.length);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "test moveColumn([number, number], number)": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn([3, 1], 0);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn(2).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(3).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn([4, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame(1, table.getColumn(4).children.length);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "test moveColumn(string, [number, number])": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn('b', [3, 1]);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn([2, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn([2, 1]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([2, 2]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame(3, table.getColumn(2).children.length);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "test moveColumn(number, [number, number])": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn(1, [3, 1]);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn([2, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn([2, 1]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([2, 2]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame(3, table.getColumn(2).children.length);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "test moveColumn([number, number], [number, number])": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn([3, 1], [3, 0]);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(2).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([3, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn([3, 1]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame(2, table.getColumn(3).children.length);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "moveColumn event should fire": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table,
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith onFired = false,
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith afterFired = false;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.on('moveColumn', function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith onFired = true;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith });
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.after('moveColumn', function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith afterFired = true;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith });
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn('a', 2);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.isTrue(onFired);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.isTrue(afterFired);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "moveColumn event should have column and index": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table,
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith column, index;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.on('moveColumn', function (e) {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith column = e.column;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith index = e.index;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith });
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn('c', 3);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', column);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame(3, index);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "moveColumn event should be preventable": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.on('moveColumn', function (e) {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith e.preventDefault();
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith });
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn('a', 2);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(2).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn([3, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([3, 1]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame(2, table.getColumn(3).children.length);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "moveColumn event e.column modification should apply": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.on('moveColumn', function (e) {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith e.column = 'a';
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith });
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn('b', 3);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn([2, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([2, 1]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(3).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "moveColumn event e.index modification should apply": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith var table = this.table;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.on('moveColumn', function (e) {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith e.index = 0;
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith });
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith table.moveColumn('d', 2);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('d', table.getColumn(0).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('a', table.getColumn(1).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('b', table.getColumn(2).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('c', table.getColumn(3).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame('e', table.getColumn([4, 0]).key);
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith },
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith "moveColumn should be chainable": function () {
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith Y.Assert.areSame(this.table, this.table.moveColumn('a', 2));
76cf59cc4ac47a3272fcea3f528327465fa14404Luke Smith }
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith}));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smithsuite.add(new Y.Test.Case({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith name: "addRow",
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith setUp: function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith this.table = new Y.DataTable({
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith columns: [ 'a', 'b', 'c' ],
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith data: [{ a: 1, b: 1, c: 1 }]
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith tearDown: function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith this.table.destroy();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRow() should do nothing": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith count = table.data.size();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:add', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.fail("ModelList add event triggered");
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.addRow();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(count, table.data.size());
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRow(data) should create a new Model in the data": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith count = table.data.size();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.addRow({ a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(count + 1, table.data.size());
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRow(data) should fire the data's add event": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired, afterFired;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.on('*:add', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:add', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith afterFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.addRow({ a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(beforeFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(afterFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRow(data, { sync: true }) should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('create', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.addRow({ a: 2, b: 2, c: 2 }, { sync: true });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRow(data) with autoSync:true should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.set('autoSync', true);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('create', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.addRow({ a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRow(...) should be chainable": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(this.table, this.table.addRow({ a: 2, b: 2, c: 2 }));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith }
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith}));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smithsuite.add(new Y.Test.Case({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith name: "addRows",
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith setUp: function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith this.table = new Y.DataTable({
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith columns: [ 'a', 'b', 'c' ],
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith data: [{ a: 1, b: 1, c: 1 }]
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith tearDown: function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith this.table.destroy();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRows() should do nothing": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith count = table.data.size();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:add', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.fail("ModelList add event triggered");
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.addRows();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(count, table.data.size());
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRows([data]) should create a new Model in the data": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith count = table.data.size();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.addRows([
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { a: 2, b: 2, c: 2 },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { a: 3, b: 3, c: 3 }
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith ]);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(count + 2, table.data.size());
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRows([data]) should fire the data's add event": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired, afterFired;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.on('*:add', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:add', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith afterFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.addRows([
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { a: 2, b: 2, c: 2 },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { a: 3, b: 3, c: 3 }
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith ]);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(beforeFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(afterFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRows([data], { sync: true }) should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('create', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.addRows([
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { a: 2, b: 2, c: 2 },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { a: 3, b: 3, c: 3 }
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith ], { sync: true });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRows([data]) with autoSync:true should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.set('autoSync', true);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('create', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.addRows([
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { a: 2, b: 2, c: 2 },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { a: 3, b: 3, c: 3 }
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith ]);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "addRows(...) should be chainable": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(this.table, this.table.addRows([
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { a: 2, b: 2, c: 2 },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { a: 3, b: 3, c: 3 }
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith ]));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith }
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith}));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smithsuite.add(new Y.Test.Case({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith name: "modifyRow",
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith setUp: function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith this.table = new Y.DataTable({
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith columns: [ 'a', 'b', 'c' ],
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith data: [{ id: 'item1', a: 1, b: 1, c: 1 }]
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith tearDown: function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith this.table.destroy();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow() should do nothing": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith count = table.data.size();
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:change', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.fail("ModelList change event triggered");
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(count, table.data.size());
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(index, data) should change the Model attributes": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(0, { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('a'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('b'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('c'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(id, data) should change the Model attributes": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model.get('id'), { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('a'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('b'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('c'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(clientId, data) should change the Model attributes": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model.get('clientId'), { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('a'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('b'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('c'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(model, data) should change the Model attributes": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model, { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('a'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('b'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(2, model.get('c'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(index, data) should fire the model's change event": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired, afterFired;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.on('*:change', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:change', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith afterFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(0, { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(beforeFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(afterFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(id, data) should fire the model's change event": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired, afterFired;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.on('*:change', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:change', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith afterFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model.get('id'), { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(beforeFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(afterFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(clientId, data) should fire the model's model event": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired, afterFired;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.on('*:change', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:change', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith afterFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model.get('clientId'), { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(beforeFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(afterFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(model, data) should fire the model's change event": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired, afterFired;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.on('*:change', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:change', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith afterFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model, { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(beforeFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(afterFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(index, data, { sync: true }) should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('update', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(0, { a: 2, b: 2, c: 2 }, { sync: true });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(id, data, { sync: true }) should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('update', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model.get('id'), { a: 2, b: 2, c: 2 }, { sync: true });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(clientId, data, { sync: true }) should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('update', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model.get('clientId'), { a: 2, b: 2, c: 2 }, { sync: true });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(model, data, { sync: true }) should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('update', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model, { a: 2, b: 2, c: 2 }, { sync: true });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(index, data) with autoSync: true should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.set('autoSync', true);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('update', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(0, { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(id, data) with autoSync: true should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.set('autoSync', true);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('update', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model.get('id'), { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(clientId, data) with autoSync: true should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.set('autoSync', true);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('update', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model.get('clientId'), { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(model, data) with autoSync: true should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.set('autoSync', true);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('update', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.modifyRow(model, { a: 2, b: 2, c: 2 });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "modifyRow(...) should be chainable": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(this.table, this.table.modifyRow(0, { a: 2 }));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith }
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith}));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smithsuite.add(new Y.Test.Case({
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith name: "removeRow",
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith setUp: function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith this.table = new Y.DataTable({
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith columns: [ 'a', 'b', 'c' ],
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith data: [
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { id: 'item1', a: 1, b: 1, c: 1 },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith { id: 'item2', a: 2, b: 2, c: 2 }
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith ]
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith tearDown: function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith this.table.destroy();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow() should do nothing": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith count = table.data.size();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:delete', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.fail("ModelList delete event triggered");
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(count, table.data.size());
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(index) should delete the Model": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(1),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith count = table.data.size();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(0);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(count - 1, table.data.size());
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(model, table.data.item(0));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(id) should delete the Model attributes": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(1),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith count = table.data.size();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(table.data.item(0).get('id'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(count - 1, table.data.size());
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(model, table.data.item(0));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(clientId) should delete the Model attributes": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(1),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith count = table.data.size();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(table.data.item(0).get('clientId'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(count - 1, table.data.size());
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(model, table.data.item(0));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(model) should delete the Model attributes": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(1),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith count = table.data.size();
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(table.data.item(0));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(count - 1, table.data.size());
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(model, table.data.item(0));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(index) should fire the data's remove event": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired, afterFired;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.on('*:remove', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:remove', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith afterFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(0);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(beforeFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(afterFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(id, data) should fire the data's remove event": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired, afterFired;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.on('*:remove', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:remove', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith afterFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(model.get('id'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(beforeFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(afterFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(clientId, data) should fire the data's remove event": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired, afterFired;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.on('*:remove', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:remove', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith afterFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(model.get('clientId'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(beforeFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(afterFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(model, data) should fire the data's remove event": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired, afterFired;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.on('*:remove', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith beforeFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.after('*:remove', function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith afterFired = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(model);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(beforeFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(afterFired);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(index, { sync: true }) should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('delete', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(0, { sync: true });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(id, { sync: true }) should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('delete', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(model.get('id'), { sync: true });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(clientId, { sync: true }) should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('delete', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(model.get('clientId'), { sync: true });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(model, { sync: true }) should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('delete', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(model, { sync: true });
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(index) with autoSync: true should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.set('autoSync', true);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('delete', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(0);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(id) with autoSync: true should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.set('autoSync', true);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('delete', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(model.get('id'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(clientId) with autoSync: true should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.set('autoSync', true);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('delete', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(model.get('clientId'));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(model) with autoSync: true should trigger Model sync": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith var table = this.table,
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith model = table.data.item(0),
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.set('autoSync', true);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.data.model.prototype.sync = function (action) {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame('delete', action);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith syncCalled = true;
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith };
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith table.removeRow(model);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.isTrue(syncCalled);
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith },
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith "removeRow(...) should be chainable": function () {
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith Y.Assert.areSame(this.table, this.table.removeRow(0, { a: 2 }));
3166f4121e57f4bd184a5b2cf85c38d776d1db86Luke Smith }
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith}));
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke SmithY.Test.Runner.add(suite);
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith
11ef335b17a11da1b70c6a80cabe20ef74058481Luke Smith}, '@VERSION@' ,{requires:['datatable-mutable', 'test']});