jobsubSpec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. describe("JobSubModel", function(){
  2. var viewModel;
  3. function getSampleDesign(id, canSubmit, canDelete){
  4. return {
  5. "url_params":"/fake/params/url/"+id,
  6. "description":"[Sample] Jasmine Job "+id,
  7. "last_modified":1350993390 + id,
  8. "can_delete":canDelete,
  9. "owner":"jasmine",
  10. "url_edit":"/fake/edit/url/"+id,
  11. "url_submit":"/fake/submit/url/"+id,
  12. "id":id,
  13. "can_submit":canSubmit,
  14. "name":"jasmine_job_"+id,
  15. "url_clone":"/fake/clone/url/"+id,
  16. "url_delete":"/fake/delete/url/"+id,
  17. "type":"mapreduce"
  18. }
  19. }
  20. var sampleDesigns = [
  21. getSampleDesign(1, true, true),
  22. getSampleDesign(2, false, true),
  23. getSampleDesign(3, false, false)
  24. ];
  25. beforeEach(function(){
  26. viewModel = new JobSubModel(sampleDesigns);
  27. ko.applyBindings(viewModel);
  28. });
  29. it("should render the design table on applyBindings", function(){
  30. expect($("#designs tr").length).toEqual(viewModel.designs().length);
  31. });
  32. describe("When clicking select all", function(){
  33. it("should select first all designs and deselect them all", function(){
  34. viewModel.selectAll();
  35. expect(viewModel.selectedDesigns().length).toEqual(viewModel.designs().length);
  36. viewModel.selectAll();
  37. expect(viewModel.selectedDesigns().length).toEqual(0);
  38. });
  39. it("should add a css class to the 'Select All' checkbox", function(){
  40. viewModel.selectAll();
  41. expect($("#selectAll").hasClass("icon-ok")).toBeTruthy();
  42. });
  43. it("should disable the action buttons", function(){
  44. viewModel.selectAll();
  45. expect($(".btn:enabled").length).toEqual(0);
  46. });
  47. });
  48. describe("When selecting a design", function(){
  49. it("should return a selectedDesign", function(){
  50. viewModel.designs()[0].selected(true);
  51. expect(viewModel.selectedDesign().name).toEqual(viewModel.designs()[0].name);
  52. });
  53. it("should always enable the clone button", function(){
  54. viewModel.designs()[0].selected(true);
  55. expect($(".btn:enabled:contains('Clone')").length).toEqual(1);
  56. viewModel.designs()[0].selected(false);
  57. expect($(".btn:enabled:contains('Clone')").length).toEqual(0);
  58. viewModel.designs()[1].selected(true);
  59. expect($(".btn:enabled:contains('Clone')").length).toEqual(1);
  60. });
  61. it("should enable the submit button if canSubmit is true", function(){
  62. viewModel.designs()[0].selected(true);
  63. expect($(".btn:enabled:contains('Submit')").length).toEqual(1);
  64. viewModel.designs()[0].selected(false);
  65. viewModel.designs()[1].selected(true);
  66. expect($(".btn:enabled:contains('Submit')").length).toEqual(0);
  67. });
  68. it("should enable the edit button if canSubmit is true", function(){
  69. viewModel.designs()[0].selected(true);
  70. expect($(".btn:enabled:contains('Edit')").length).toEqual(1);
  71. viewModel.designs()[0].selected(false);
  72. viewModel.designs()[1].selected(true);
  73. expect($(".btn:enabled:contains('Edit')").length).toEqual(0);
  74. });
  75. it("should enable the delete button if canDelete is true", function(){
  76. viewModel.designs()[1].selected(true);
  77. expect($(".btn:enabled:contains('Delete')").length).toEqual(1);
  78. viewModel.designs()[1].selected(false);
  79. viewModel.designs()[2].selected(true);
  80. expect($(".btn:enabled:contains('Delete')").length).toEqual(0);
  81. });
  82. });
  83. });