Skip to content
This repository was archived by the owner on Apr 2, 2019. It is now read-only.

Commit da772ae

Browse files
author
Joe
committed
add spec coverage
-spec to check that the colspan updates dynamically -spec to check that the event handler doesn't blow up if there isn't an emptyView
1 parent 0de1bf7 commit da772ae

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/body.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ var Body = Backgrid.Body = Backbone.View.extend({
5959
this.listenTo(collection, "reset", this.refresh);
6060
this.listenTo(collection, "backgrid:sort", this.sort);
6161
this.listenTo(collection, "backgrid:edited", this.moveToNextCell);
62+
6263
this.listenTo(this.columns, "add remove", this.updateEmptyRow);
6364
},
6465

test/body.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,23 @@ describe("A Body", function () {
224224
expect(body.$el.find("tr.empty > td").attr("colspan")).toBe("1");
225225
});
226226

227+
it("will update the colspan of the empty row as columns are changed", function () {
228+
col.reset();
229+
body = new Backgrid.Body({
230+
emptyText: " ",
231+
columns: [{
232+
name: "id",
233+
cell: "integer"
234+
}],
235+
collection: col
236+
});
237+
body.render();
238+
239+
expect(body.$el.find("tr.empty > td").attr("colspan")).toBe("1");
240+
body.columns.push({name: "age", cell: "integer"});
241+
expect(body.$el.find("tr.empty > td").attr("colspan")).toBe("2");
242+
});
243+
227244
it("will clear the empty row if a new model is added to an empty collection", function () {
228245
col.reset();
229246
body = new Backgrid.Body({
@@ -270,6 +287,13 @@ describe("A Body", function () {
270287
expect(body.$el.find("tr.empty").length).toBe(1);
271288
});
272289

290+
it("won't call render from updateEmptyRow if there is no emptyView", function () {
291+
var pushColumn = function () {
292+
body.columns.push({name: "age", cell: "integer"});
293+
};
294+
expect(pushColumn).not.toThrow();
295+
});
296+
273297
it("#sort will throw a RangeError is direction is not ascending, descending or null", function () {
274298
body = new Backgrid.Body({
275299
collection: col,

0 commit comments

Comments
 (0)