it('Should render a table row with a checkbox column', function () { var row = rowFactory.createTableRow({id: 'id', checkbox1: true, checkbox2: false}, { id: 'id', columns: [ { id: 'checkbox1', type: 'checkbox', width: '50%', formatter: function (id, value) { return value; } }, { id: 'checkbox2', type: 'checkbox', width: '50%', formatter: function (id, value) { return value; } } ] }); expect(row).to.equal('<tr data-row-id="id">' + '<td class="" data-col-id="checkbox1" style="width:50%">' + '<input type="checkbox" checked="checked"/>' + '</td>' + '<td class="" data-col-id="checkbox2" style="width:50%">' + '<input type="checkbox"/>' + '</td>' + '</tr>'); });
it('Should format the cell value', function () { var columns = _.map(this.columns, function (column) { return _.extend(column, { formatter: function (id, value) { switch (id) { case 'col_1': return 'aa'; case 'col_2': return 'bb'; case 'nested.col_3': return 'cc'; } return value; }, link: null }); }); var stateManager = { isEditable: function () { return false; } }; var row = rowFactory.createTableRow(this.obj, { id: 'id', columns: columns, rows: {}, stateManager: stateManager }); expect(row).to.equal('<tr data-row-id="id">' + '<td class="" data-col-id="col_1" style="width:33.3%"><div>aa</div></td>' + '<td class="alignment-center" data-col-id="col_2" style="width:33.3%">' + '<div>bb</div></td>' + '<td class="alignment-right" data-col-id="nested.col_3" style="width:33.3%">' + '<div>cc</div></td></tr>'); });
it('Should send tree properties to create table data', function () { var obj = { id: '1', foo: 'foo', bar: 'bar' }; var options = { id: 'id', treeMode: true, columns: [ { name: 'foo' }, { name: 'bar' } ], rows: 'rows', stateManager: 'stateManager' }; var spy = this.sandbox.stub(cellFactory, 'createTableData', function () { return ''; }); rowFactory.createTableRow(obj, options, 'level', 'treeState'); expect(spy.callCount).to.equal(2); var passedOptions = spy.args[0][0]; expect(passedOptions.column.name).to.equal('foo'); expect(passedOptions.obj).to.equal(obj); expect(passedOptions.rows).to.equal('rows'); expect(passedOptions.stateManager).to.equal('stateManager'); expect(passedOptions.treeColumn).to.be.true; expect(passedOptions.level).to.equal('level'); expect(passedOptions.treeState).to.equal('treeState'); passedOptions = spy.args[1][0]; expect(passedOptions.column.name).to.equal('bar'); expect(passedOptions.obj).to.equal(obj); expect(passedOptions.rows).to.equal('rows'); expect(passedOptions.stateManager).to.equal('stateManager'); expect(passedOptions.treeColumn).to.be.false; expect(passedOptions.level).to.equal('level'); expect(passedOptions.treeState).to.equal('treeState'); });
it('Should render a table row', function () { this.columns.push({ id: 'col_4', title: '', width: '100%', link: 'row-link-id', formatter: function (value) { return value; } }); var row = rowFactory.createTableRow(this.obj, { id: 'id', columns: this.columns, rows: {link: 'row-link-id'}, stateManager: { isEditable: function (rowId, colId) { if (colId === 'col_2') { return true; } return false; } } }); expect(row).to.equal('<tr data-row-id="id">' + '<td class="" data-col-id="col_1" style="width:33.3%">' + '<a href="http://www.google.com">a</a></td>' + '<td class="alignment-center" data-col-id="col_2" style="width:33.3%">' + '<div class="input-group">' + '<span class="input-group-addon">$</span>' + '<input type="text" class="form-control" value="b"/>' + '</div>' + '</td>' + '<td class="alignment-right" data-col-id="nested.col_3" style="width:33.3%">' + '<div>c</div></td>' + '<td class="" data-col-id="col_4" style="width:100%">' + '<a class="glyphicon glyphicon-arrow-right" ' + 'href="http://www.yahoo.com"></a></td>' + '</tr>'); // use a different id row = rowFactory.createTableRow(this.obj, { id: 'fooId', columns: this.columns, rows: {link: 'row-link-id'}, stateManager: { isEditable: function (rowId, colId) { if (colId === 'col_2') { return true; } return false; } } }); expect(row).to.equal('<tr data-row-id="foo-id">' + '<td class="" data-col-id="col_1" style="width:33.3%">' + '<a href="http://www.google.com">a</a></td>' + '<td class="alignment-center" data-col-id="col_2" style="width:33.3%">' + '<div class="input-group">' + '<span class="input-group-addon">$</span>' + '<input type="text" class="form-control" value="b"/>' + '</div>' + '</td>' + '<td class="alignment-right" data-col-id="nested.col_3" style="width:33.3%">' + '<div>c</div></td>' + '<td class="" data-col-id="col_4" style="width:100%">' + '<a class="glyphicon glyphicon-arrow-right" ' + 'href="http://www.yahoo.com"></a></td>' + '</tr>'); });