/test/column.js
JavaScript | 141 lines | 105 code | 29 blank | 7 comment | 0 complexity | d75b6bc2f3bf9e954d2e4c1412ba9638 MD5 | raw file
Possible License(s): MIT
- /*
- backgrid
- http://github.com/wyuenho/backgrid
- Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors
- Licensed under the MIT license.
- */
- describe("A Column", function () {
- it("throws TypeError when initialized without a cell", function () {
- expect(function () {
- new Backgrid.Column({
- name: "name"
- });
- }).toThrow(new TypeError("'cell' is required"));
- });
- it("throws TypeError when initialized without a name", function () {
- expect(function () {
- new Backgrid.Column({
- cell: 1
- });
- }).toThrow(new TypeError("'name' is required"));
- });
- it("must be initialized with at least name and cell", function () {
- expect(function () {
- new Backgrid.Column({
- name: "name",
- cell: 1
- });
- }).not.toThrow();
- });
- it("has a label the same as name if no label given", function () {
- var col = new Backgrid.Column({
- name: "name",
- cell: 1
- });
- expect(col.get("label")).toBe("name");
- });
- it("sortValue can be a string or a function", function () {
- var Col = Backgrid.Column.extend({
- mySortValue: function () {}
- });
- var col = new Col({
- name: "name",
- cell: "string",
- sortValue: "mySortValue"
- });
- expect(col.sortValue()).toBe(Col.prototype.mySortValue);
- var mySortValue = function () {};
- col = new Col({
- name: "name",
- cell: "string",
- sortValue: mySortValue
- });
- expect(col.sortValue()).toBe(mySortValue);
- });
- it("sortable can be a string or a boolean", function () {
- var Col = Backgrid.Column.extend({
- mySortable: function () {}
- });
- var col = new Col({
- name: "name",
- cell: "string",
- sortable: "mySortable"
- });
- expect(col.sortable()).toBe(Col.prototype.mySortable);
- col = new Col({
- name: "name",
- cell: "string",
- sortable: false
- });
- expect(col.sortable()).toBe(false);
- });
- it("editable can be a string or a boolean", function () {
- var Col = Backgrid.Column.extend({
- myEditable: function () {}
- });
- var col = new Col({
- name: "name",
- cell: "string",
- editable: "myEditable"
- });
- expect(col.editable()).toBe(Col.prototype.myEditable);
- col = new Col({
- name: "name",
- cell: "string",
- editable: false
- });
- expect(col.editable()).toBe(false);
- });
- it("renderable can be a string or a boolean", function () {
- var Col = Backgrid.Column.extend({
- myRenderable: function () {}
- });
- var col = new Col({
- name: "name",
- cell: "string",
- renderable: "myRenderable"
- });
- expect(col.renderable()).toBe(Col.prototype.myRenderable);
- col = new Col({
- name: "name",
- cell: "string",
- renderable: false
- });
- expect(col.renderable()).toBe(false);
- });
- });
- describe("A Columns", function () {
- it("is a Backbone.Collection of Column objects", function () {
- expect(new Backgrid.Columns().model).toBe(Backgrid.Column);
- });
- });