PageRenderTime 62ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/test/column.js

https://github.com/rhinoman/backgrid
JavaScript | 141 lines | 105 code | 29 blank | 7 comment | 0 complexity | d75b6bc2f3bf9e954d2e4c1412ba9638 MD5 | raw file
Possible License(s): MIT
  1. /*
  2. backgrid
  3. http://github.com/wyuenho/backgrid
  4. Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors
  5. Licensed under the MIT license.
  6. */
  7. describe("A Column", function () {
  8. it("throws TypeError when initialized without a cell", function () {
  9. expect(function () {
  10. new Backgrid.Column({
  11. name: "name"
  12. });
  13. }).toThrow(new TypeError("'cell' is required"));
  14. });
  15. it("throws TypeError when initialized without a name", function () {
  16. expect(function () {
  17. new Backgrid.Column({
  18. cell: 1
  19. });
  20. }).toThrow(new TypeError("'name' is required"));
  21. });
  22. it("must be initialized with at least name and cell", function () {
  23. expect(function () {
  24. new Backgrid.Column({
  25. name: "name",
  26. cell: 1
  27. });
  28. }).not.toThrow();
  29. });
  30. it("has a label the same as name if no label given", function () {
  31. var col = new Backgrid.Column({
  32. name: "name",
  33. cell: 1
  34. });
  35. expect(col.get("label")).toBe("name");
  36. });
  37. it("sortValue can be a string or a function", function () {
  38. var Col = Backgrid.Column.extend({
  39. mySortValue: function () {}
  40. });
  41. var col = new Col({
  42. name: "name",
  43. cell: "string",
  44. sortValue: "mySortValue"
  45. });
  46. expect(col.sortValue()).toBe(Col.prototype.mySortValue);
  47. var mySortValue = function () {};
  48. col = new Col({
  49. name: "name",
  50. cell: "string",
  51. sortValue: mySortValue
  52. });
  53. expect(col.sortValue()).toBe(mySortValue);
  54. });
  55. it("sortable can be a string or a boolean", function () {
  56. var Col = Backgrid.Column.extend({
  57. mySortable: function () {}
  58. });
  59. var col = new Col({
  60. name: "name",
  61. cell: "string",
  62. sortable: "mySortable"
  63. });
  64. expect(col.sortable()).toBe(Col.prototype.mySortable);
  65. col = new Col({
  66. name: "name",
  67. cell: "string",
  68. sortable: false
  69. });
  70. expect(col.sortable()).toBe(false);
  71. });
  72. it("editable can be a string or a boolean", function () {
  73. var Col = Backgrid.Column.extend({
  74. myEditable: function () {}
  75. });
  76. var col = new Col({
  77. name: "name",
  78. cell: "string",
  79. editable: "myEditable"
  80. });
  81. expect(col.editable()).toBe(Col.prototype.myEditable);
  82. col = new Col({
  83. name: "name",
  84. cell: "string",
  85. editable: false
  86. });
  87. expect(col.editable()).toBe(false);
  88. });
  89. it("renderable can be a string or a boolean", function () {
  90. var Col = Backgrid.Column.extend({
  91. myRenderable: function () {}
  92. });
  93. var col = new Col({
  94. name: "name",
  95. cell: "string",
  96. renderable: "myRenderable"
  97. });
  98. expect(col.renderable()).toBe(Col.prototype.myRenderable);
  99. col = new Col({
  100. name: "name",
  101. cell: "string",
  102. renderable: false
  103. });
  104. expect(col.renderable()).toBe(false);
  105. });
  106. });
  107. describe("A Columns", function () {
  108. it("is a Backbone.Collection of Column objects", function () {
  109. expect(new Backgrid.Columns().model).toBe(Backgrid.Column);
  110. });
  111. });