3
http://github.com/wyuenho/backgrid
5
Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors
6
Licensed under the MIT @license.
8
describe("A Grid", function () {
10
var Book = Backbone.Model.extend({});
11
var Books = Backbone.Collection.extend({
17
beforeEach(function () {
20
title: "Alice's Adventures in Wonderland"
23
title: "A Tale of Two Cities"
26
title: "The Catcher in the Rye"
29
grid = new Backgrid.Grid({
35
footer: Backgrid.Footer
39
it("throws TypeError if a list of column definition is not given", function () {
44
}).toThrow(new TypeError("'columns' is required"));
47
it("throws TypeError if a collection is not given", function () {
55
}).toThrow(new TypeError("'collection' is required"));
58
it("renders a table with a header, body and an optional footer section", function () {
60
spyOn(grid, "trigger");
61
spyOn(grid.header, "render").andCallThrough();
62
spyOn(grid.footer, "render").andCallThrough();
63
spyOn(grid.body, "render").andCallThrough();
67
expect(grid.el.tagName).toBe("TABLE");
68
expect(grid.header.render.calls.length).toBe(1);
69
expect(grid.footer.render.calls.length).toBe(1);
70
expect(grid.body.render.calls.length).toBe(1);
71
expect(grid.trigger.calls.length).toBe(1);
72
expect(grid.trigger).toHaveBeenCalledWith("backgrid:rendered", grid);
75
it("will render a table with the header, body, footer and row classes supplied in the constructor options", function () {
77
var CustomHeader = Backgrid.Header.extend({});
78
var CustomBody = Backgrid.Body.extend({});
79
var CustomRow = Backgrid.Row.extend({});
80
var CustomFooter = Backgrid.Footer.extend({});
82
grid = new Backgrid.Grid({
92
className: "class-name"
97
expect(grid.header instanceof CustomHeader).toBe(true);
98
expect(grid.body instanceof CustomBody).toBe(true);
99
expect(grid.body.rows[0] instanceof CustomRow).toBe(true);
100
expect(grid.footer instanceof CustomFooter).toBe(true);
102
expect(grid.header.className).not.toBe("class-name");
103
expect(grid.body.className).not.toBe("class-name");
104
expect(grid.body.rows[0].className).not.toBe("class-name");
105
expect(grid.footer.className).not.toBe("class-name");
108
it("will clean up all its decendant views when remove is called", function () {
109
expect(grid.remove().constructor).toBe(Backgrid.Grid);
112
it("will refresh on columns reset", function () {
114
grid.columns.reset([{
118
expect(grid.el.innerHTML).toBe('<thead><tr><th><a>id<b class="sort-caret"></b></a></th></tr></thead>' +
120
'<tbody><tr><td class="integer-cell">1</td></tr>' +
121
'<tr><td class="integer-cell">2</td></tr>' +
122
'<tr><td class="integer-cell">3</td></tr></tbody>');