PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/javascripts/app/views/aspects_dropdown_view_spec.js

https://bitbucket.org/cfield/diaspora
JavaScript | 126 lines | 106 code | 20 blank | 0 comment | 0 complexity | dc846468fa2812d5c8527f11e2d55018 MD5 | raw file
  1. describe("app.views.AspectsDropdown", function () {
  2. function selectedAspects(view){
  3. return _.pluck(view.$("input.aspect_ids").serializeArray(), "value")
  4. }
  5. beforeEach(function () {
  6. loginAs({
  7. aspects:[
  8. { id:3, name:"sauce" },
  9. { id:5, name:"conf" },
  10. { id:7, name:"lovers" }
  11. ]
  12. })
  13. this.view = new app.views.AspectsDropdown({model:factory.statusMessage({aspect_ids:undefined})})
  14. })
  15. describe("rendering", function () {
  16. beforeEach(function () {
  17. this.view.render()
  18. })
  19. it("sets aspect_ids to 'public' by default", function () {
  20. expect(this.view.$("input.aspect_ids:checked").val()).toBe("public")
  21. })
  22. it("defaults to Public Visibility", function () {
  23. expect(this.view.$("input.aspect_ids.public")).toBeChecked()
  24. expect($.trim(this.view.$(".dropdown-toggle .text").text())).toBe("Public")
  25. })
  26. it("sets aspect_ids to 'public'", function () {
  27. expect(selectedAspects(this.view)).toEqual(["public"])
  28. })
  29. it("sets the dropdown title to 'public'", function () {
  30. expect(this.view.$(".dropdown-toggle .text").text()).toBe("Public")
  31. })
  32. describe("setVisibility", function () {
  33. function checkInput(input){
  34. input.attr("checked", "checked")
  35. input.trigger("change")
  36. }
  37. function uncheckInput(input){
  38. input.attr("checked", false)
  39. input.trigger("change")
  40. }
  41. describe("selecting All Aspects", function () {
  42. beforeEach(function () {
  43. this.input = this.view.$("input#aspect_ids_all_aspects")
  44. checkInput(this.input)
  45. })
  46. it("calls set aspect_ids to 'all'", function () {
  47. expect(selectedAspects(this.view)).toEqual(["all_aspects"])
  48. })
  49. it("sets the dropdown title to 'public'", function () {
  50. expect($.trim(this.view.$(".dropdown-toggle .text").text())).toBe("All Aspects")
  51. })
  52. })
  53. describe("selecting An Aspect", function () {
  54. beforeEach(function () {
  55. this.input = this.view.$("input[name='lovers']")
  56. checkInput(this.input)
  57. })
  58. it("sets the dropdown title to the aspect title", function () {
  59. expect($.trim(this.view.$(".dropdown-toggle .text").text())).toBe("lovers")
  60. })
  61. it("sets aspect_ids to to the aspect id", function () {
  62. expect(selectedAspects(this.view)).toEqual(["7"])
  63. })
  64. describe("selecting another aspect", function () {
  65. beforeEach(function () {
  66. this.input = this.view.$("input[name='sauce']")
  67. checkInput(this.input)
  68. })
  69. it("sets aspect_ids to the selected aspects", function () {
  70. expect(selectedAspects(this.view)).toEqual(["3", "7"])
  71. })
  72. it("sets the button text to the number of selected aspects", function () {
  73. expect($.trim(this.view.$(".dropdown-toggle .text").text())).toBe("In 2 aspects")
  74. checkInput(this.view.$("input[name='conf']"))
  75. expect($.trim(this.view.$(".dropdown-toggle .text").text())).toBe("In 3 aspects")
  76. uncheckInput(this.view.$("input[name='conf']"))
  77. expect($.trim(this.view.$(".dropdown-toggle .text").text())).toBe("In 2 aspects")
  78. })
  79. describe("deselecting another aspect", function () {
  80. it("removes the clicked aspect", function () {
  81. expect(selectedAspects(this.view)).toEqual(["3", "7"])
  82. expect($.trim(this.view.$(".dropdown-toggle .text").text())).toBe("In 2 aspects")
  83. uncheckInput(this.view.$("input[name='lovers']"))
  84. expect(selectedAspects(this.view)).toEqual(["3"])
  85. expect($.trim(this.view.$(".dropdown-toggle .text").text())).toBe("sauce")
  86. })
  87. })
  88. describe("selecting all_aspects", function () {
  89. it("sets aspect_ids to all_aspects", function () {
  90. expect(selectedAspects(this.view)).toEqual(["3", "7"])
  91. checkInput(this.view.$("input[name='All Aspects']"))
  92. expect(selectedAspects(this.view)).toEqual(["all_aspects"])
  93. })
  94. })
  95. describe("selecting public", function () {
  96. it("sets aspect_ids to public", function () {
  97. expect(selectedAspects(this.view)).toEqual(["3", "7"])
  98. checkInput(this.view.$("input[name='Public']"))
  99. expect(selectedAspects(this.view)).toEqual(["public"])
  100. })
  101. })
  102. })
  103. })
  104. })
  105. })
  106. })