PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/test/column.js

https://github.com/TechnotronicOz/backgrid
JavaScript | 149 lines | 109 code | 33 blank | 7 comment | 0 complexity | ba3cdf9a29baa0eb07a0d6e0b0afe7a5 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("must be initialized with at least name and cell", function () {
  9. expect(function () {
  10. new Backgrid.Column({
  11. name: "name",
  12. cell: 1
  13. });
  14. }).not.toThrow();
  15. });
  16. it("has a label the same as name if no label given", function () {
  17. var col = new Backgrid.Column({
  18. name: "name",
  19. cell: 1
  20. });
  21. expect(col.get("label")).toBe("name");
  22. });
  23. it("sortValue can be a string or a function", function () {
  24. var Col = Backgrid.Column.extend({
  25. mySortValue: function () {}
  26. });
  27. var col = new Col({
  28. name: "name",
  29. cell: "string",
  30. sortValue: "mySortValue"
  31. });
  32. expect(col.sortValue()).toBe(Col.prototype.mySortValue);
  33. var mySortValue = function () {};
  34. col = new Col({
  35. name: "name",
  36. cell: "string",
  37. sortValue: mySortValue
  38. });
  39. expect(col.sortValue()).toBe(mySortValue);
  40. });
  41. it("sortable can be a string or a boolean or a function", function () {
  42. var Col = Backgrid.Column.extend({
  43. mySortable: function () {}
  44. });
  45. var col = new Col({
  46. name: "name",
  47. cell: "string",
  48. sortable: "mySortable"
  49. });
  50. expect(col.sortable()).toBe(Col.prototype.mySortable);
  51. col = new Col({
  52. name: "name",
  53. cell: "string",
  54. sortable: false
  55. });
  56. expect(col.sortable()).toBe(false);
  57. col = new Col({
  58. name: "name",
  59. cell: "string",
  60. sortable: function () { return false; }
  61. });
  62. expect(col.sortable()).toBe(col.get("sortable"));
  63. });
  64. it("editable can be a string or a boolean or a function", function () {
  65. var Col = Backgrid.Column.extend({
  66. myEditable: function () {}
  67. });
  68. var col = new Col({
  69. name: "name",
  70. cell: "string",
  71. editable: "myEditable"
  72. });
  73. expect(col.editable()).toBe(Col.prototype.myEditable);
  74. col = new Col({
  75. name: "name",
  76. cell: "string",
  77. editable: false
  78. });
  79. expect(col.editable()).toBe(false);
  80. col = new Col({
  81. name: "name",
  82. cell: "string",
  83. editable: function () { return false; }
  84. });
  85. expect(col.editable()).toBe(col.get("editable"));
  86. });
  87. it("renderable can be a string or a boolean or a function", function () {
  88. var Col = Backgrid.Column.extend({
  89. myRenderable: function () {}
  90. });
  91. var col = new Col({
  92. name: "name",
  93. cell: "string",
  94. renderable: "myRenderable"
  95. });
  96. expect(col.renderable()).toBe(Col.prototype.myRenderable);
  97. col = new Col({
  98. name: "name",
  99. cell: "string",
  100. renderable: false
  101. });
  102. expect(col.renderable()).toBe(false);
  103. col = new Col({
  104. name: "name",
  105. cell: "string",
  106. renderable: function () { return false; }
  107. });
  108. expect(col.renderable()).toBe(col.get("renderable"));
  109. });
  110. });
  111. describe("A Columns", function () {
  112. it("is a Backbone.Collection of Column objects", function () {
  113. expect(new Backgrid.Columns().model).toBe(Backgrid.Column);
  114. });
  115. });